Author: ekohl
Date: Tue Jun 14 20:34:21 2016
New Revision: 71638
URL:
http://svn.reactos.org/svn/reactos?rev=71638&view=rev
Log:
[SC]
- Add the 'failure' command. The 'actions' option is not implemented yet.
Added:
trunk/reactos/base/applications/sc/failure.c (with props)
Modified:
trunk/reactos/base/applications/sc/CMakeLists.txt
trunk/reactos/base/applications/sc/misc.c
trunk/reactos/base/applications/sc/sc.c
trunk/reactos/base/applications/sc/sc.h
trunk/reactos/base/applications/sc/usage.c
Modified: trunk/reactos/base/applications/sc/CMakeLists.txt
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/sc/CMake…
==============================================================================
--- trunk/reactos/base/applications/sc/CMakeLists.txt [iso-8859-1] (original)
+++ trunk/reactos/base/applications/sc/CMakeLists.txt [iso-8859-1] Tue Jun 14 20:34:21
2016
@@ -7,6 +7,7 @@
create.c
delete.c
description.c
+ failure.c
misc.c
print.c
qfailure.c
Added: trunk/reactos/base/applications/sc/failure.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/sc/failu…
==============================================================================
--- trunk/reactos/base/applications/sc/failure.c (added)
+++ trunk/reactos/base/applications/sc/failure.c [iso-8859-1] Tue Jun 14 20:34:21 2016
@@ -0,0 +1,70 @@
+/*
+ * PROJECT: ReactOS Services
+ * LICENSE: GPL - See COPYING in the top level directory
+ * FILE: base/applications/sc/failure.c
+ * PURPOSE: Set the service failure actions
+ * COPYRIGHT: Copyright 2016 Eric Kohl
+ */
+
+#include "sc.h"
+
+BOOL
+SetFailure(
+ LPCTSTR *ServiceArgs,
+ INT ArgCount)
+{
+ SC_HANDLE hManager = NULL;
+ SC_HANDLE hService = NULL;
+ BOOL bResult = TRUE;
+ SERVICE_FAILURE_ACTIONS FailureActions;
+ LPCTSTR lpServiceName = NULL;
+
+ if (!ParseFailureArguments(ServiceArgs, ArgCount, &lpServiceName,
&FailureActions))
+ {
+ SetFailureUsage();
+ return FALSE;
+ }
+
+ hManager = OpenSCManager(NULL,
+ NULL,
+ SC_MANAGER_CONNECT);
+ if (hManager == NULL)
+ {
+ _tprintf(_T("[SC] OpenSCManager FAILED %lu:\n\n"), GetLastError());
+ bResult = FALSE;
+ goto done;
+ }
+
+ hService = OpenService(hManager,
+ lpServiceName,
+ SERVICE_CHANGE_CONFIG);
+ if (hService == NULL)
+ {
+ _tprintf(_T("[SC] OpenService FAILED %lu:\n\n"), GetLastError());
+ bResult = FALSE;
+ goto done;
+ }
+
+ if (!ChangeServiceConfig2(hService,
+ SERVICE_CONFIG_FAILURE_ACTIONS,
+ (LPBYTE)&FailureActions))
+ {
+ _tprintf(_T("[SC] ChangeServiceConfig2 FAILED %lu:\n\n"),
GetLastError());
+ bResult = FALSE;
+ goto done;
+ }
+
+ _tprintf(_T("[SC] ChangeServiceConfig2 SUCCESS\n\n"));
+
+done:
+ if (bResult == FALSE)
+ ReportLastError();
+
+ if (hService)
+ CloseServiceHandle(hService);
+
+ if (hManager)
+ CloseServiceHandle(hManager);
+
+ return bResult;
+}
Propchange: trunk/reactos/base/applications/sc/failure.c
------------------------------------------------------------------------------
svn:eol-style = native
Modified: trunk/reactos/base/applications/sc/misc.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/sc/misc.…
==============================================================================
--- trunk/reactos/base/applications/sc/misc.c [iso-8859-1] (original)
+++ trunk/reactos/base/applications/sc/misc.c [iso-8859-1] Tue Jun 14 20:34:21 2016
@@ -158,3 +158,70 @@
return (ArgCount == 0);
}
+
+
+BOOL
+ParseFailureArguments(
+ IN LPCTSTR *ServiceArgs,
+ IN INT ArgCount,
+ OUT LPCTSTR *ppServiceName,
+ OUT LPSERVICE_FAILURE_ACTIONS pFailureActions)
+{
+ INT /*i,*/ ArgIndex = 1;
+ LPCTSTR lpActions = NULL;
+ LPCTSTR lpReset = NULL;
+
+ if (ArgCount < 1)
+ return FALSE;
+
+ ZeroMemory(pFailureActions, sizeof(SERVICE_FAILURE_ACTIONS));
+
+ *ppServiceName = ServiceArgs[0];
+
+ ArgCount--;
+
+ while (ArgCount > 1)
+ {
+ if (!lstrcmpi(ServiceArgs[ArgIndex], _T("actions=")))
+ {
+ lpActions = (LPTSTR)ServiceArgs[ArgIndex + 1];
+ }
+ else if (!lstrcmpi(ServiceArgs[ArgIndex], _T("command=")))
+ {
+ pFailureActions->lpCommand = (LPTSTR)ServiceArgs[ArgIndex + 1];
+ }
+ else if (!lstrcmpi(ServiceArgs[ArgIndex], _T("reboot=")))
+ {
+ pFailureActions->lpRebootMsg = (LPTSTR)ServiceArgs[ArgIndex + 1];
+ }
+ else if (!lstrcmpi(ServiceArgs[ArgIndex], _T("reset=")))
+ {
+ lpReset = (LPTSTR)ServiceArgs[ArgIndex + 1];
+ }
+
+ ArgIndex += 2;
+ ArgCount -= 2;
+ }
+
+ if ((lpReset == NULL && lpActions != NULL) ||
+ (lpReset != NULL && lpActions == NULL))
+ {
+ _tprintf(_T("ERROR: The reset and actions options must be used
simultaneously.\n\n"));
+ return FALSE;
+ }
+
+ if (lpReset != NULL)
+ {
+ if (!lstrcmpi(lpReset, _T("infinite")))
+ pFailureActions->dwResetPeriod = INFINITE;
+ else
+ pFailureActions->dwResetPeriod = _ttoi(lpReset);
+ }
+
+ if (lpActions != NULL)
+ {
+ /* FIXME */
+ }
+
+ return (ArgCount == 0);
+}
Modified: trunk/reactos/base/applications/sc/sc.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/sc/sc.c?…
==============================================================================
--- trunk/reactos/base/applications/sc/sc.c [iso-8859-1] (original)
+++ trunk/reactos/base/applications/sc/sc.c [iso-8859-1] Tue Jun 14 20:34:21 2016
@@ -268,6 +268,10 @@
{
SetConfig(ServiceArgs, ArgCount);
}
+ else if (!lstrcmpi(Command, _T("failure")))
+ {
+ SetFailure(ServiceArgs, ArgCount);
+ }
else
{
MainUsage();
Modified: trunk/reactos/base/applications/sc/sc.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/sc/sc.h?…
==============================================================================
--- trunk/reactos/base/applications/sc/sc.h [iso-8859-1] (original)
+++ trunk/reactos/base/applications/sc/sc.h [iso-8859-1] Tue Jun 14 20:34:21 2016
@@ -44,6 +44,7 @@
BOOL QueryDescription(LPCTSTR ServiceName);
BOOL SetDescription(LPCTSTR ServiceName, LPCTSTR Description);
BOOL QueryFailure(LPCTSTR ServiceName);
+BOOL SetFailure(LPCTSTR *ServiceArgs, INT ArgCount);
/* print and error functions */
VOID PrintService(LPCTSTR ServiceName, LPSERVICE_STATUS_PROCESS pStatus, BOOL
bExtended);
@@ -56,6 +57,13 @@
INT ArgCount,
BOOL bChangeService,
OUT LPSERVICE_CREATE_INFO lpServiceInfo);
+
+BOOL
+ParseFailureArguments(
+ LPCTSTR *ServiceArgs,
+ INT ArgCount,
+ OUT LPCTSTR *ppServiceName,
+ OUT LPSERVICE_FAILURE_ACTIONS pFailureActions);
/* usage functions */
VOID MainUsage(VOID);
@@ -74,5 +82,6 @@
VOID QueryFailureUsage(VOID);
VOID SetDescriptionUsage(VOID);
VOID SetConfigUsage(VOID);
+VOID SetFailureUsage(VOID);
#endif /* _SC_PCH_ */
Modified: trunk/reactos/base/applications/sc/usage.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/sc/usage…
==============================================================================
--- trunk/reactos/base/applications/sc/usage.c [iso-8859-1] (original)
+++ trunk/reactos/base/applications/sc/usage.c [iso-8859-1] Tue Jun 14 20:34:21 2016
@@ -243,3 +243,22 @@
_T(" DisplayName= <display name>\n")
_T(" password= <password>\n"));
}
+
+VOID SetFailureUsage(VOID)
+{
+ _tprintf(_T("DESCRIPTION:\n")
+ _T(" Changes the actions upon failure.\n")
+ _T("USAGE:\n")
+ _T(" sc <server> failure [service name] <option1>
<option2>...\n")
+ _T("\n")
+ _T("OPTIONS:\n")
+ _T(" reset= <Length of period of no failures (in
seconds)\n")
+ _T(" after which to reset the failure count to 0 (may be
INFINITE)>\n")
+ _T(" (Must be used in conjunction with actions=
)\n")
+ _T(" reboot= <Message broadcast before rebooting on
failure>\n")
+ _T(" command= <Command line to be run on
failure>\n")
+ _T(" actions= <Failure actions and their delay time (in
milliseconds),\n")
+ _T(" separated by / (forward slash) -- e.g.,
run/5000/reboot/800\n")
+ _T(" Valid actions are <run|restart|reboot>
>\n")
+ _T(" (Must be used in conjunction with the reset=
option)\n"));
+}