X-Git-Url: http://git.iain.cx/?a=blobdiff_plain;ds=sidebyside;f=registry.cpp;h=6c1567ce152bb5806e329456f0ea542703849ced;hb=0dfa0fdb3a851b1ff69a0f0b308a3e1371286a57;hp=1e801ee06dfd7253e7a518a80f97016b34c1208d;hpb=5380a4a53d9b34d6c56ef3e8a022fcdc184593a3;p=nssm.git diff --git a/registry.cpp b/registry.cpp index 1e801ee..6c1567c 100644 --- a/registry.cpp +++ b/registry.cpp @@ -214,10 +214,10 @@ int get_environment(TCHAR *service_name, HKEY key, TCHAR *value, TCHAR **env, un /* Actually get the strings */ ret = RegQueryValueEx(key, value, 0, &type, (unsigned char *) *env, envlen); if (ret != ERROR_SUCCESS) { + log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_QUERYVALUE_FAILED, value, error_string(GetLastError()), 0); HeapFree(GetProcessHeap(), 0, *env); *env = 0; *envlen = 0; - log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_QUERYVALUE_FAILED, value, error_string(GetLastError()), 0); return 4; } @@ -392,6 +392,27 @@ int unformat_double_null(TCHAR *dn, unsigned long dnlen, TCHAR **unformatted, un } for (i = 0; i < dnlen; i++) if (dn[i] != _T('\r')) ++*newlen; + + /* Skip blank lines. */ + for (i = 0; i < dnlen; i++) { + if (dn[i] == _T('\r') && dn[i + 1] == _T('\n')) { + /* This is the last CRLF. */ + if (i >= dnlen - 2) break; + + /* + Strip at the start of the block or if the next characters are + CRLF too. + */ + if (! i || (dn[i + 2] == _T('\r') && dn[i + 3] == _T('\n'))) { + for (j = i + 2; j < dnlen; j++) dn[j - 2] = dn[j]; + dn[dnlen--] = _T('\0'); + dn[dnlen--] = _T('\0'); + i--; + --*newlen; + } + } + } + /* Must end with two NULLs. */ *newlen += 2;