You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mt...@apache.org on 2010/03/16 06:13:25 UTC
svn commit: r923582 - in /commons/proper/daemon/trunk: ./
src/native/nt/procrun/apps/prunsrv/ src/native/nt/procrun/src/
Author: mturk
Date: Tue Mar 16 05:13:25 2010
New Revision: 923582
URL: http://svn.apache.org/viewvc?rev=923582&view=rev
Log:
Fix DAEMON-143 by not displaying message box from console applications. Also allow //US to behave like //IS if service was not installed
Modified:
commons/proper/daemon/trunk/RELEASE-NOTES.txt
commons/proper/daemon/trunk/src/native/nt/procrun/apps/prunsrv/prunsrv.c
commons/proper/daemon/trunk/src/native/nt/procrun/src/log.c
commons/proper/daemon/trunk/src/native/nt/procrun/src/private.h
commons/proper/daemon/trunk/src/native/nt/procrun/src/registry.c
commons/proper/daemon/trunk/src/native/nt/procrun/src/rprocess.c
commons/proper/daemon/trunk/src/native/nt/procrun/src/service.c
commons/proper/daemon/trunk/src/native/nt/procrun/src/utils.c
Modified: commons/proper/daemon/trunk/RELEASE-NOTES.txt
URL: http://svn.apache.org/viewvc/commons/proper/daemon/trunk/RELEASE-NOTES.txt?rev=923582&r1=923581&r2=923582&view=diff
==============================================================================
--- commons/proper/daemon/trunk/RELEASE-NOTES.txt (original)
+++ commons/proper/daemon/trunk/RELEASE-NOTES.txt Tue Mar 16 05:13:25 2010
@@ -36,7 +36,7 @@ NEW FEATURES:
BUG FIXES:
-1.0.3: DAEMON-108, DAEMON-128, DAEMON-139
+1.0.3: DAEMON-108, DAEMON-128, DAEMON-139, DAEMON-143
1.0.2: DAEMON-16, DAEMON-31, DAEMON-40, DAEMON-45, DAEMON-49, DAEMON-60,
DAEMON-84, DAEMON-90, DAEMON-91, DAEMON-92, DAEMON-93, DAEMON-94,
Modified: commons/proper/daemon/trunk/src/native/nt/procrun/apps/prunsrv/prunsrv.c
URL: http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/native/nt/procrun/apps/prunsrv/prunsrv.c?rev=923582&r1=923581&r2=923582&view=diff
==============================================================================
--- commons/proper/daemon/trunk/src/native/nt/procrun/apps/prunsrv/prunsrv.c (original)
+++ commons/proper/daemon/trunk/src/native/nt/procrun/apps/prunsrv/prunsrv.c Tue Mar 16 05:13:25 2010
@@ -319,6 +319,8 @@ static void printUsage(LPAPXCMDLINE lpCm
fwprintf(stderr, L" //RS[//ServiceName] Run Service\n");
fwprintf(stderr, L" //SS[//ServiceName] Stop Service\n");
fwprintf(stderr, L" //TS[//ServiceName] Run Service as console application\n");
+ fwprintf(stderr, L" //PP[//Num Seconds] Sleep for n Seconds (defaults to 60)\n");
+ fwprintf(stderr, L" //VS Display version\n");
fwprintf(stderr, L" Options:\n");
while (_options[i].szName) {
fwprintf(stderr, L" --%s\n", _options[i].szName);
@@ -608,7 +610,7 @@ static BOOL docmdDeleteService(LPAPXCMDL
lpCmdline->szApplication);
}
else {
- apxDisplayError(TRUE, NULL, 0, "Unable to delete %S service",
+ apxDisplayError(FALSE, NULL, 0, "Unable to delete %S service",
lpCmdline->szApplication);
}
apxCloseHandle(hService);
@@ -646,7 +648,7 @@ static BOOL docmdStopService(LPAPXCMDLIN
}
else
- apxDisplayError(TRUE, NULL, 0, "Unable to open %S service",
+ apxDisplayError(FALSE, NULL, 0, "Unable to open %S service",
lpCmdline->szApplication);
apxCloseHandle(hService);
apxLogWrite(APXLOG_MARK_INFO "Stop service finished.");
@@ -661,13 +663,23 @@ static BOOL docmdUpdateService(LPAPXCMDL
apxLogWrite(APXLOG_MARK_INFO "Updating service...");
hService = apxCreateService(gPool, SC_MANAGER_CREATE_SERVICE, FALSE);
- if (IS_INVALID_HANDLE(hService)) {
+ if (IS_INVALID_HANDLE(hService)) {
apxLogWrite(APXLOG_MARK_ERROR "Unable to open the Service Manager");
return FALSE;
}
SetLastError(0);
/* Open the service */
- if (apxServiceOpen(hService, lpCmdline->szApplication, SERVICE_ALL_ACCESS)) {
+ if (!apxServiceOpen(hService, lpCmdline->szApplication, SERVICE_ALL_ACCESS)) {
+ /* Close the existing manager handler.
+ * It will be reopened inside install.
+ */
+ apxCloseHandle(hService);
+ /* In case service doesn't exist try to install it.
+ * Install will fail if there is no minimum parameters required.
+ */
+ return docmdInstallService(lpCmdline);
+ }
+ else {
DWORD dwStart = SERVICE_NO_CHANGE;
DWORD dwType = SERVICE_NO_CHANGE;
LPCWSTR su = NULL;
@@ -709,11 +721,6 @@ static BOOL docmdUpdateService(LPAPXCMDL
rv = (rv && saveConfiguration(lpCmdline));
}
- else {
- apxDisplayError(TRUE, NULL, 0, "Unable to open %S service",
- lpCmdline->szApplication);
- rv = FALSE;
- }
apxCloseHandle(hService);
apxLogWrite(APXLOG_MARK_INFO "Update service finished.");
return rv;
@@ -1360,10 +1367,10 @@ void __cdecl main(int argc, char **argv)
LPAPXCMDLINE lpCmdline;
- if (argc > 1 && strncmp(argv[1], "//PP//", 6) == 0) {
+ if (argc > 1 && strncmp(argv[1], "//PP", 4) == 0) {
/* Handy sleep routine defaulting to 1 minute */
DWORD ss = 60;
- if (argv[1][6]) {
+ if (argv[1][4] && argv[1][5] && argv[1][6]) {
int us = atoi(argv[1] + 6);
if (us > 0)
ss = (DWORD)us;
@@ -1382,12 +1389,14 @@ void __cdecl main(int argc, char **argv)
rv = 1;
goto cleanup;
}
- apxCmdlineLoadEnvVars(lpCmdline);
- if (lpCmdline->dwCmdIndex < 5 &&
- !loadConfiguration(lpCmdline)) {
- apxLogWrite(APXLOG_MARK_ERROR "Load configuration failed");
- rv = 2;
- goto cleanup;
+ apxCmdlineLoadEnvVars(lpCmdline);
+ if (lpCmdline->dwCmdIndex < 5) {
+ if (!loadConfiguration(lpCmdline) &&
+ lpCmdline->dwCmdIndex < 4) {
+ apxLogWrite(APXLOG_MARK_ERROR "Load configuration failed");
+ rv = 2;
+ goto cleanup;
+ }
}
apxLogOpen(gPool, SO_LOGPATH, SO_LOGPREFIX);
@@ -1456,7 +1465,11 @@ void __cdecl main(int argc, char **argv)
}
cleanup:
- apxLogWrite(APXLOG_MARK_INFO "Commons Daemon procrun finished.");
+ if (rv)
+ apxLogWrite(APXLOG_MARK_ERROR "Commons Daemon procrun failed "
+ "with exit value: %d", rv);
+ else
+ apxLogWrite(APXLOG_MARK_INFO "Commons Daemon procrun finished");
if (lpCmdline)
apxCmdlineFree(lpCmdline);
if (_service_status_handle)
Modified: commons/proper/daemon/trunk/src/native/nt/procrun/src/log.c
URL: http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/native/nt/procrun/src/log.c?rev=923582&r1=923581&r2=923582&view=diff
==============================================================================
--- commons/proper/daemon/trunk/src/native/nt/procrun/src/log.c (original)
+++ commons/proper/daemon/trunk/src/native/nt/procrun/src/log.c Tue Mar 16 05:13:25 2010
@@ -16,6 +16,7 @@
#include "apxwin.h"
#include "private.h"
+#include <stdio.h>
#define LINE_SEP "\n"
#define LOGF_EXT L".%04d-%02d-%02d.log"
@@ -257,10 +258,7 @@ apxLogWrite(
if(f != szFile)
f++;
}
- lstrlcpyA(buffer, 1056, _log_level[dwLevel]);
- if (!dolock)
- lstrlcatA(buffer, 1056, "\n");
- szBp = &buffer[lstrlenA(buffer)];
+ szBp = &buffer[0];
if (!szFormat) {
FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
@@ -299,12 +297,14 @@ apxLogWrite(
t.wHour, t.wMinute, t.wSecond);
WriteFile(lf->hFile, sb, lstrlenA(sb), &wr, NULL);
}
- if (f) {
- wsprintfA(sb, "[%-4d %s] ", dwLine, f);
+ WriteFile(lf->hFile, _log_level[dwLevel],
+ strlen(_log_level[dwLevel]), &wr, NULL);
+ if (f && lf->dwLogLevel == APXLOG_LEVEL_DEBUG) {
+ wsprintfA(sb, "(%10s:%-4d) ", f, dwLine);
WriteFile(lf->hFile, sb, lstrlenA(sb), &wr, NULL);
}
-
WriteFile(lf->hFile, buffer, len, &wr, NULL);
+
/* Terminate the line */
WriteFile(lf->hFile, LINE_SEP, sizeof(LINE_SEP) - 1, &wr, NULL);
#ifdef _DEBUG_FULL
@@ -375,7 +375,15 @@ apxDisplayError(
sysbuf,
SIZ_DESLEN,
NULL);
- sysbuf[len] = 0;
+ if (len > 0) {
+ sysbuf[len] = '\0';
+ if (sysbuf[len - 1] == '\n') {
+ sysbuf[len - 1] = '\0';
+ --len;
+ }
+ }
+ else
+ sysbuf[0] = '\0';
}
if (szFormat) {
va_start(args, szFormat);
@@ -383,7 +391,7 @@ apxDisplayError(
va_end(args);
if (f) {
CHAR sb[SIZ_PATHLEN];
- wsprintfA(sb, "\n%s (%d)", f, dwLine);
+ wsprintfA(sb, "%s (%d)", f, dwLine);
lstrcatA(sysbuf, sb);
}
lstrlcatA(sysbuf, SIZ_HUGLEN, "\n");
@@ -393,10 +401,17 @@ apxDisplayError(
#ifdef _DEBUG_FULL
OutputDebugStringA(sysbuf);
#endif
- if (len > 0 && bDisplay) {
- nRet = MessageBoxA(NULL, sysbuf,
- "Application System Error",
- MB_ICONERROR | MB_OK | MB_SYSTEMMODAL);
+ if (len > 0) {
+ if (bDisplay) {
+ nRet = MessageBoxA(NULL, sysbuf,
+ "Application System Error",
+ MB_ICONERROR | MB_OK | MB_SYSTEMMODAL);
+ }
+ else {
+ fputs(sysbuf, stderr);
+ fputc('\n', stderr);
+ fflush(stderr);
+ }
}
/* Restore the last Error code */
SetLastError(err);
Modified: commons/proper/daemon/trunk/src/native/nt/procrun/src/private.h
URL: http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/native/nt/procrun/src/private.h?rev=923582&r1=923581&r2=923582&view=diff
==============================================================================
--- commons/proper/daemon/trunk/src/native/nt/procrun/src/private.h (original)
+++ commons/proper/daemon/trunk/src/native/nt/procrun/src/private.h Tue Mar 16 05:13:25 2010
@@ -234,11 +234,6 @@ extern APX_OSLEVEL _st_apx_oslevel;
#define APX_GET_OSLEVEL() ((_st_apx_oslevel == APX_WINVER_UNK) ? apxGetOsLevel() : _st_apx_oslevel)
-#ifdef _DEBUG
-void ErrorMessage(LPCTSTR szError, BOOL bFatal);
-#else
-#define ErrorMessage(szError, bFatal) ((void)0)
-#endif
/* zero separated, double zero terminated string */
struct APXMULTISZ {
DWORD dwAllocated; /* length including terminators */
Modified: commons/proper/daemon/trunk/src/native/nt/procrun/src/registry.c
URL: http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/native/nt/procrun/src/registry.c?rev=923582&r1=923581&r2=923582&view=diff
==============================================================================
--- commons/proper/daemon/trunk/src/native/nt/procrun/src/registry.c (original)
+++ commons/proper/daemon/trunk/src/native/nt/procrun/src/registry.c Tue Mar 16 05:13:25 2010
@@ -454,7 +454,7 @@ apxRegistryGetBinaryA(APXHANDLE hRegistr
DWORD rc, dwType = REG_BINARY;
rc = RegQueryValueExA(hKey, szValueName, NULL, &dwType, lpData, lpdwLength);
if (rc != ERROR_SUCCESS || dwType != REG_BINARY) {
- ErrorMessage(NULL, FALSE);
+ apxLogWrite(APXLOG_MARK_SYSERR);
return NULL;
}
lpReg->pCurrVal = lpData;
Modified: commons/proper/daemon/trunk/src/native/nt/procrun/src/rprocess.c
URL: http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/native/nt/procrun/src/rprocess.c?rev=923582&r1=923581&r2=923582&view=diff
==============================================================================
--- commons/proper/daemon/trunk/src/native/nt/procrun/src/rprocess.c (original)
+++ commons/proper/daemon/trunk/src/native/nt/procrun/src/rprocess.c Tue Mar 16 05:13:25 2010
@@ -261,38 +261,38 @@ static BOOL __apxProcCreateChildPipes(LP
if (!CreatePipe(&(lpProc->hChildStdInp),
&(lpProc->hChildInpWr),
lpProc->lpSA, 0)) {
- ErrorMessage(NULL, FALSE);
+ apxLogWrite(APXLOG_MARK_SYSERR);
goto cleanup;
}
if (!SetHandleInformation(lpProc->hChildInpWr,
HANDLE_FLAG_INHERIT, 0)) {
- ErrorMessage(NULL, FALSE);
+ apxLogWrite(APXLOG_MARK_SYSERR);
goto cleanup;
}
if (!CreatePipe(&(lpProc->hChildOutRd),
&(lpProc->hChildStdOut),
lpProc->lpSA, 0)) {
- ErrorMessage(NULL, FALSE);
+ apxLogWrite(APXLOG_MARK_SYSERR);
goto cleanup;
}
if (!SetHandleInformation(lpProc->hChildOutRd,
HANDLE_FLAG_INHERIT, 0)) {
- ErrorMessage(NULL, FALSE);
+ apxLogWrite(APXLOG_MARK_SYSERR);
goto cleanup;
}
if (!CreatePipe(&(lpProc->hChildErrRd),
&(lpProc->hChildStdErr),
lpProc->lpSA, 0)) {
- ErrorMessage(NULL, FALSE);
+ apxLogWrite(APXLOG_MARK_SYSERR);
goto cleanup;
}
if (!SetHandleInformation(lpProc->hChildErrRd,
HANDLE_FLAG_INHERIT, 0)) {
- ErrorMessage(NULL, FALSE);
+ apxLogWrite(APXLOG_MARK_SYSERR);
goto cleanup;
}
rv = TRUE;
@@ -488,7 +488,7 @@ apxCreateProcessW(APXHANDLE hPool, DWORD
LOGON32_PROVIDER_DEFAULT,
&hUser)) {
/* Logon Failed */
- ErrorMessage(NULL, TRUE);
+ apxLogWrite(APXLOG_MARK_SYSERR);
return NULL;
}
if (!DuplicateTokenEx(hUser,
@@ -499,14 +499,14 @@ apxCreateProcessW(APXHANDLE hPool, DWORD
&hUserToken)) {
CloseHandle(hUser);
/* Failed to duplicate the user token */
- ErrorMessage(NULL, TRUE);
+ apxLogWrite(APXLOG_MARK_SYSERR);
return NULL;
}
if (!ImpersonateLoggedOnUser(hUserToken)) {
CloseHandle(hUser);
CloseHandle(hUserToken);
/* failed to impersonate the logged user */
- ErrorMessage(NULL, TRUE);
+ apxLogWrite(APXLOG_MARK_SYSERR);
return NULL;
}
CloseHandle(hUser);
Modified: commons/proper/daemon/trunk/src/native/nt/procrun/src/service.c
URL: http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/native/nt/procrun/src/service.c?rev=923582&r1=923581&r2=923582&view=diff
==============================================================================
--- commons/proper/daemon/trunk/src/native/nt/procrun/src/service.c (original)
+++ commons/proper/daemon/trunk/src/native/nt/procrun/src/service.c Tue Mar 16 05:13:25 2010
@@ -43,7 +43,7 @@ static BOOL __apxIsValidServiceName(LPCW
{
do {
if (!IsCharAlphaNumericW(*szServiceName)) {
- apxDisplayError(TRUE, NULL, 0, "NonAlpha %d", *szServiceName);
+ apxDisplayError(FALSE, NULL, 0, "NonAlpha %d", *szServiceName);
return FALSE;
}
} while( *(++szServiceName));
@@ -524,8 +524,6 @@ apxServiceInstall(APXHANDLE hService, LP
if (IS_INVALID_HANDLE(lpService->hService)) {
apxLogWrite(APXLOG_MARK_SYSERR);
-
- ErrorMessage(NULL, FALSE);
return FALSE;
}
else {
@@ -591,7 +589,6 @@ apxServiceBrowse(APXHANDLE hService,
if (IS_INVALID_HANDLE(hLock)) {
apxLogWrite(APXLOG_MARK_SYSERR);
- ErrorMessage(NULL, FALSE);
return 0;
}
AplZeroMemory(&stEnum, sizeof(APXREGENUM));
Modified: commons/proper/daemon/trunk/src/native/nt/procrun/src/utils.c
URL: http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/native/nt/procrun/src/utils.c?rev=923582&r1=923581&r2=923582&view=diff
==============================================================================
--- commons/proper/daemon/trunk/src/native/nt/procrun/src/utils.c (original)
+++ commons/proper/daemon/trunk/src/native/nt/procrun/src/utils.c Tue Mar 16 05:13:25 2010
@@ -81,8 +81,8 @@ LPWSTR __apxGetEnvironmentVariableW(APXH
if (!(wsRet = apxPoolAlloc(hPool, (rc + 1) * sizeof(WCHAR))))
return NULL;
if (!GetEnvironmentVariableW(wsName, wsRet, rc)) {
+ apxLogWrite(APXLOG_MARK_SYSERR);
apxFree(wsRet);
- ErrorMessage(NULL, FALSE);
return NULL;
}
return wsRet;
@@ -100,8 +100,8 @@ LPSTR __apxGetEnvironmentVariableA(APXHA
if (!(szRet = apxPoolAlloc(hPool, rc + 1)))
return NULL;
if (!GetEnvironmentVariableA(szName, szRet, rc)) {
+ apxLogWrite(APXLOG_MARK_SYSERR);
apxFree(szRet);
- ErrorMessage(NULL, FALSE);
return NULL;
}
return szRet;
@@ -210,39 +210,6 @@ LPSTR MzWideToUTF8(LPCWSTR ws)
return str;
}
-#ifdef _DEBUG
-
-void ErrorMessage(LPCTSTR szError, BOOL bFatal)
-{
- LPVOID lpMsgBuf = NULL;
- UINT nType;
- int nRet;
- DWORD dwErr = GetLastError();
- if (bFatal)
- nType = MB_ICONERROR | MB_ABORTRETRYIGNORE | MB_SYSTEMMODAL;
- else
- nType = MB_ICONEXCLAMATION | MB_OK;
- if (szError) {
- nRet = MessageBox(NULL, szError, TEXT("Application Error"), nType);
- }
- else {
- FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
- FORMAT_MESSAGE_FROM_SYSTEM |
- FORMAT_MESSAGE_IGNORE_INSERTS,
- NULL,
- dwErr,
- MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL),
- (LPTSTR) &lpMsgBuf, 0, NULL);
- nRet = MessageBox(NULL, (LPCTSTR)lpMsgBuf,
- TEXT("Application System Error"), nType);
- LocalFree(lpMsgBuf);
- }
- if (bFatal && (nRet == IDCANCEL || nRet == IDABORT)) {
- ExitProcess(dwErr);
- }
-}
-#endif /* _DEBUG */
-
DWORD __apxGetMultiSzLengthA(LPCSTR lpStr, LPDWORD lpdwCount)
{
LPCSTR p = lpStr;