Skip to content

Commit

Permalink
Client, Win: append .exe to service process program name if missing
Browse files Browse the repository at this point in the history
  • Loading branch information
davidpanderson committed Aug 14, 2017
1 parent 1c6fddb commit 7930686
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions client/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,26 +454,19 @@ int main(int argc, char** argv) {
if (strcmp(argv[index], "-detach") == 0 || strcmp(argv[index], "--detach") == 0 ||
strcmp(argv[index], "-detach_console") == 0 || strcmp(argv[index], "--detach_console") == 0
) {
int i, len;
char *commandLine;
int i, len=1024;
char commandLine[1024];
STARTUPINFO si;
PROCESS_INFORMATION pi;

argv[index] = "-detach_phase_two";

// start with space for two '"'s
len = 2;
for (i = 0; i < argc; i++) {
len += (int)strlen(argv[i]) + 1;
}
if ((commandLine = (char *) malloc(len)) == NULL) {
// Drop back ten and punt. Can't do the detach thing, so we just carry on.
// At least the program will start.
break;
}
commandLine[0] = '"';
// OK, we can safely use strcpy and strcat, since we know that we allocated enough
strlcpy(&commandLine[1], argv[0], len);
strlcpy(commandLine, argv[0], len);
if (!strstr(commandLine, ".exe")) {
strlcat(commandLine, ".exe", len);
}
strlcat(commandLine, "\"", len);
for (i = 1; i < argc; i++) {
strlcat(commandLine, " ", len);
Expand All @@ -489,6 +482,7 @@ int main(int argc, char** argv) {
exit(0);
}
break;

}
#endif

Expand Down

0 comments on commit 7930686

Please sign in to comment.