This commit is contained in:
Leonardo Taglialegne 2013-07-10 13:10:51 +02:00
Родитель 7a90114262
Коммит 75ceda12bb
2 изменённых файлов: 22 добавлений и 8 удалений

Просмотреть файл

@ -16,11 +16,11 @@ namespace Mono.WebServer.Fpm
try {
if (!child.Process.HasExited)
child.Process.Kill();
}
catch (InvalidOperationException) {
} catch (InvalidOperationException) {
// Died between the if and the kill
}
}
children.RemoveAll(child => child.Process.HasExited);
}
public static void TermChildren()
@ -33,14 +33,20 @@ namespace Mono.WebServer.Fpm
// Died between the if and the kill
}
}
children.RemoveAll (child => child.Process.HasExited);
}
public static void StartChildren(FileInfo[] configFiles, ConfigurationManager configurationManager)
{
if (configFiles == null)
throw new ArgumentNullException ("configFiles");
if (configurationManager == null)
throw new ArgumentNullException ("configurationManager");
foreach (var fileInfo in configFiles) {
Logger.Write(LogLevel.Debug, "Loading {0}", fileInfo.Name);
var childConfigurationManager = new ChildConfigurationManager();
childConfigurationManager.LoadXmlConfig(fileInfo.FullName);
string fullName = fileInfo.FullName;
childConfigurationManager.LoadXmlConfig(fullName);
string user = childConfigurationManager.User;
string fastCgiCommand = configurationManager.FastCgiCommand;
@ -48,13 +54,13 @@ namespace Mono.WebServer.Fpm
if (Platform.IsUnix) {
if (String.IsNullOrEmpty(user)) {
Logger.Write(LogLevel.Warning, "Configuration file {0} didn't specify username, defaulting to file owner", fileInfo.Name);
user = UnixFileSystemInfo.GetFileSystemEntry(fileInfo.FullName).OwnerUser.UserName;
user = UnixFileSystemInfo.GetFileSystemEntry(fullName).OwnerUser.UserName;
}
child = Spawner.RunAs(user, Spawner.SpawnChild, fileInfo, fastCgiCommand);
child = Spawner.RunAs(user, Spawner.SpawnChild, fullName, fastCgiCommand);
} else {
Logger.Write(LogLevel.Warning, "Configuration file {0} didn't specify username, defaulting to the current one", fileInfo.Name);
child = Spawner.SpawnChild(fileInfo, fastCgiCommand);
child = Spawner.SpawnChild(fullName, fastCgiCommand);
}
children.Add(child);
}

Просмотреть файл

@ -9,18 +9,26 @@ namespace Mono.WebServer.Fpm
{
public static T RunAs<T, T1, T2>(string user, Func<T1, T2, T> action, T1 arg0, T2 arg1)
{
if (user == null)
throw new ArgumentNullException ("user");
if (action == null)
throw new ArgumentNullException ("action");
using (var identity = new WindowsIdentity(user))
using (identity.Impersonate())
return action(arg0, arg1);
}
public static ChildInfo SpawnChild(FileInfo fileInfo, string fastCgiCommand)
public static ChildInfo SpawnChild(string fullName, string fastCgiCommand)
{
if (fullName == null)
throw new ArgumentNullException ("fullName");
if (fastCgiCommand == null)
throw new ArgumentNullException ("fastCgiCommand");
var info = new ChildInfo {
Process = new Process {
StartInfo = new ProcessStartInfo {
FileName = fastCgiCommand,
Arguments = String.Format("--config-file {0}", fileInfo.FullName),
Arguments = String.Format("--config-file \"{0}\"", fullName),
UseShellExecute = true
}
}