Skip to content

Commit

Permalink
Fixed #22 - Overriding TimeOut on Shutdown Command doesn't seem to work
Browse files Browse the repository at this point in the history
  • Loading branch information
tig committed Feb 6, 2022
1 parent b207e46 commit e94609d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Installer/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.2.9.1
2.2.9.11
8 changes: 8 additions & 0 deletions src/Commands/CommandInvoker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ public static CommandInvoker Create(string userCommandsFile, string currentVersi
cmd.UserDefined = true;
}

if (cmd.Enabled) {
if (cmd.UserDefined) {
Logger.Instance.Log4.Debug($"{commands.GetType().Name}: User defined command enabled: '****'");
}
else {
Logger.Instance.Log4.Debug($"{commands.GetType().Name}: Builtin command enabled: '{cmd}'");
}
}
commands.Add(cmd);
}
else {
Expand Down
12 changes: 9 additions & 3 deletions src/Commands/ShutdownCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,16 @@ public ShutdownCommand() {
// Serialzable, must have constructor
}

public ShutdownCommand(String type, int timeout) {
this.type = type;
this.TimeOut = timeout;
}

public override string ToString() {
return $"Cmd=\"{Cmd}\" Type=\"{Type}\" TimeOut=\"{TimeOut}\"";
}

public override ICommand Clone(Reply reply) => base.Clone(reply, new ShutdownCommand() { Type = this.Type });
public override ICommand Clone(Reply reply) => base.Clone(reply, new ShutdownCommand(Type, TimeOut));

// ICommand:Execute
public override bool Execute() {
Expand Down Expand Up @@ -107,10 +112,11 @@ public override bool Execute() {

public static void Shutdown(string shutdownArgs) {
Logger.Instance.Log4.Debug($"ShutdownCommand: Invoking 'shutdown.exe {shutdownArgs}'");

var proc = System.Diagnostics.Process.Start("shutdown", shutdownArgs);
proc.WaitForExit(1000);
proc.WaitForExit(1000 * 2);
if (proc.ExitCode != 0x0) {
Logger.Instance.Log4.Error($"ShutdownCommand: 'shutdown.exe {shutdownArgs}' failed ({proc.ExitCode:X}). Forcing Win32Exception...");
Logger.Instance.Log4.Error($"ShutdownCommand: 'shutdown.exe {shutdownArgs}' failed ({proc.ExitCode:X})");
throw new System.ComponentModel.Win32Exception(proc.ExitCode);
}
}
Expand Down

0 comments on commit e94609d

Please sign in to comment.