mirror of
https://github.com/warmcat/libwebsockets.git
synced 2025-03-16 00:00:07 +01:00
daemonize work under systemd
Signed-off-by: Andy Green <andy.green@linaro.org>
This commit is contained in:
parent
3310dd19b5
commit
df9be06522
2 changed files with 12 additions and 11 deletions
|
@ -41,7 +41,7 @@ child_handler(int signum)
|
||||||
switch (signum) {
|
switch (signum) {
|
||||||
|
|
||||||
case SIGALRM: /* timed out daemonizing */
|
case SIGALRM: /* timed out daemonizing */
|
||||||
exit(1);
|
exit(0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SIGUSR1: /* positive confirmation we daemonized well */
|
case SIGUSR1: /* positive confirmation we daemonized well */
|
||||||
|
@ -52,7 +52,7 @@ child_handler(int signum)
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"unable to create lock file %s, code=%d (%s)\n",
|
"unable to create lock file %s, code=%d (%s)\n",
|
||||||
lock_path, errno, strerror(errno));
|
lock_path, errno, strerror(errno));
|
||||||
exit(1);
|
exit(5);
|
||||||
}
|
}
|
||||||
len = sprintf(sz, "%u", pid_daemon);
|
len = sprintf(sz, "%u", pid_daemon);
|
||||||
sent = write(fd, sz, len);
|
sent = write(fd, sz, len);
|
||||||
|
@ -62,10 +62,11 @@ child_handler(int signum)
|
||||||
lock_path, errno, strerror(errno));
|
lock_path, errno, strerror(errno));
|
||||||
|
|
||||||
close(fd);
|
close(fd);
|
||||||
exit(!!(sent == len));
|
exit(0);
|
||||||
|
//!!(sent == len));
|
||||||
|
|
||||||
case SIGCHLD: /* daemonization failed */
|
case SIGCHLD: /* daemonization failed */
|
||||||
exit(1);
|
exit(6);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -98,8 +99,8 @@ lws_daemonize(const char *_lock_path)
|
||||||
char buf[10];
|
char buf[10];
|
||||||
|
|
||||||
/* already a daemon */
|
/* already a daemon */
|
||||||
if (getppid() == 1)
|
// if (getppid() == 1)
|
||||||
return 1;
|
// return 1;
|
||||||
|
|
||||||
fd = open(_lock_path, O_RDONLY);
|
fd = open(_lock_path, O_RDONLY);
|
||||||
if (fd >= 0) {
|
if (fd >= 0) {
|
||||||
|
@ -138,7 +139,7 @@ lws_daemonize(const char *_lock_path)
|
||||||
if (pid_daemon < 0) {
|
if (pid_daemon < 0) {
|
||||||
fprintf(stderr, "unable to fork daemon, code=%d (%s)",
|
fprintf(stderr, "unable to fork daemon, code=%d (%s)",
|
||||||
errno, strerror(errno));
|
errno, strerror(errno));
|
||||||
exit(1);
|
exit(9);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If we got a good PID, then we can exit the parent process. */
|
/* If we got a good PID, then we can exit the parent process. */
|
||||||
|
@ -153,7 +154,7 @@ lws_daemonize(const char *_lock_path)
|
||||||
|
|
||||||
pause();
|
pause();
|
||||||
/* should not be reachable */
|
/* should not be reachable */
|
||||||
exit(1);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* At this point we are executing as the child process */
|
/* At this point we are executing as the child process */
|
||||||
|
@ -176,7 +177,7 @@ lws_daemonize(const char *_lock_path)
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"unable to create a new session, code %d (%s)",
|
"unable to create a new session, code %d (%s)",
|
||||||
errno, strerror(errno));
|
errno, strerror(errno));
|
||||||
exit(1);
|
exit(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -187,7 +188,7 @@ lws_daemonize(const char *_lock_path)
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"unable to change directory to %s, code %d (%s)",
|
"unable to change directory to %s, code %d (%s)",
|
||||||
"/", errno, strerror(errno));
|
"/", errno, strerror(errno));
|
||||||
exit(1);
|
exit(3);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Redirect standard files to /dev/null */
|
/* Redirect standard files to /dev/null */
|
||||||
|
|
|
@ -268,7 +268,7 @@ int main(int argc, char **argv)
|
||||||
*/
|
*/
|
||||||
if (daemonize && lws_daemonize("/tmp/.lwsts-lock")) {
|
if (daemonize && lws_daemonize("/tmp/.lwsts-lock")) {
|
||||||
fprintf(stderr, "Failed to daemonize\n");
|
fprintf(stderr, "Failed to daemonize\n");
|
||||||
return 1;
|
return 10;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue