\r
/* Arguments are optional */\r
char *flags;\r
- if (argc == 2) flags = "";\r
- else flags = argv[2];\r
+ size_t flagslen = 0;\r
+ size_t s = 0;\r
+ int i;\r
+ for (i = 2; i < argc; i++) flagslen += strlen(argv[i]) + 1;\r
+ if (! flagslen) flagslen = 1;\r
+\r
+ flags = (char *) HeapAlloc(GetProcessHeap(), 0, flagslen);\r
+ if (! flags) {\r
+ log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_OUT_OF_MEMORY, "flags", "pre_install_service()", 0);\r
+ return 2;\r
+ }\r
+ ZeroMemory(flags, flagslen);\r
+\r
+ /*\r
+ This probably isn't UTF8-safe and should use std::string or something\r
+ but it's been broken for the best part of a decade and due for a rewrite\r
+ anyway so it'll do as a quick-'n'-dirty fix. Note that we don't free\r
+ the flags buffer but as the program exits that isn't a big problem.\r
+ */\r
+ for (i = 2; i < argc; i++) {\r
+ size_t len = strlen(argv[i]);\r
+ memmove(flags + s, argv[i], len);\r
+ s += len;\r
+ if (i < argc - 1) flags[s++] = ' ';\r
+ }\r
\r
return install_service(argv[0], argv[1], flags);\r
}\r