aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2023-12-15 11:55:30 +0000
committerRon Yorston <rmy@pobox.com>2023-12-15 11:55:30 +0000
commitba7d37766ec090e87a6a9cc3af685521390c6c6d (patch)
treee50a0ecb67c22bbcb497b9eea7208f7c75789b6a
parent06e977c68e8cbfdd50b19a9197f31ba5af02c0d4 (diff)
downloadbusybox-w32-ba7d37766ec090e87a6a9cc3af685521390c6c6d.tar.gz
busybox-w32-ba7d37766ec090e87a6a9cc3af685521390c6c6d.tar.bz2
busybox-w32-ba7d37766ec090e87a6a9cc3af685521390c6c6d.zip
httpd: fix return code when run in background
When httpd was run in the background the return code of the parent process was incorrect. It seems when spawn() is run in _P_DETACH mode it returns 0 on success, not a process handle. Fix the test for the return code and alter mingw_spawn_detach() so it doesn't treat the return from spawn() as a handle. Saves 32 bytes.
-rw-r--r--include/mingw.h2
-rw-r--r--networking/httpd.c4
-rw-r--r--win32/process.c16
3 files changed, 7 insertions, 15 deletions
diff --git a/include/mingw.h b/include/mingw.h
index eab756184..46cbe03f8 100644
--- a/include/mingw.h
+++ b/include/mingw.h
@@ -549,7 +549,7 @@ int utimes(const char *file_name, const struct timeval times[2]);
549 549
550char ** FAST_FUNC grow_argv(char **argv, int n); 550char ** FAST_FUNC grow_argv(char **argv, int n);
551pid_t FAST_FUNC mingw_spawn(char **argv); 551pid_t FAST_FUNC mingw_spawn(char **argv);
552pid_t FAST_FUNC mingw_spawn_detach(char **argv); 552intptr_t FAST_FUNC mingw_spawn_detach(char **argv);
553intptr_t FAST_FUNC mingw_spawn_proc(const char **argv); 553intptr_t FAST_FUNC mingw_spawn_proc(const char **argv);
554int mingw_execv(const char *cmd, char *const *argv); 554int mingw_execv(const char *cmd, char *const *argv);
555int mingw_execvp(const char *cmd, char *const *argv); 555int mingw_execvp(const char *cmd, char *const *argv);
diff --git a/networking/httpd.c b/networking/httpd.c
index 2b2d14076..0de56a47a 100644
--- a/networking/httpd.c
+++ b/networking/httpd.c
@@ -2863,9 +2863,7 @@ static void mingw_daemonize(char **argv)
2863 xdup2(fd, 2); 2863 xdup2(fd, 2);
2864 close(fd); 2864 close(fd);
2865 2865
2866 if (mingw_spawn_detach(new_argv)) 2866 exit(mingw_spawn_detach(new_argv) == -1 ? EXIT_FAILURE : EXIT_SUCCESS);
2867 exit_SUCCESS(); /* parent */
2868 exit(EXIT_FAILURE); /* parent */
2869} 2867}
2870#endif 2868#endif
2871 2869
diff --git a/win32/process.c b/win32/process.c
index 54d98e1d9..a07ea06ed 100644
--- a/win32/process.c
+++ b/win32/process.c
@@ -333,26 +333,20 @@ mingw_spawnvp(int mode, const char *cmd, char *const *argv)
333 return -1; 333 return -1;
334} 334}
335 335
336static pid_t 336pid_t FAST_FUNC
337mingw_spawn_pid(int mode, char **argv) 337mingw_spawn(char **argv)
338{ 338{
339 intptr_t ret; 339 intptr_t ret;
340 340
341 ret = mingw_spawnvp(mode, argv[0], (char *const *)argv); 341 ret = mingw_spawnvp(P_NOWAIT, argv[0], (char *const *)argv);
342 342
343 return ret == -1 ? (pid_t)-1 : (pid_t)GetProcessId((HANDLE)ret); 343 return ret == -1 ? (pid_t)-1 : (pid_t)GetProcessId((HANDLE)ret);
344} 344}
345 345
346pid_t FAST_FUNC 346intptr_t FAST_FUNC
347mingw_spawn(char **argv)
348{
349 return mingw_spawn_pid(P_NOWAIT, argv);
350}
351
352pid_t FAST_FUNC
353mingw_spawn_detach(char **argv) 347mingw_spawn_detach(char **argv)
354{ 348{
355 return mingw_spawn_pid(P_DETACH, argv); 349 return mingw_spawnvp(P_DETACH, argv[0], argv);
356} 350}
357 351
358intptr_t FAST_FUNC 352intptr_t FAST_FUNC