Bugzilla – Attachment 2115 Details for
Bug 1955
pidfile contains non-existing process id for a short while after restart
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
use synchronization pipes in process daemonize
openssh-5.6p1-wait-for-child.patch (text/plain), 2.00 KB, created by
Petr Lautrbach
on 2011-12-07 01:03:21 AEDT
(
hide
)
Description:
use synchronization pipes in process daemonize
Filename:
MIME Type:
Creator:
Petr Lautrbach
Created:
2011-12-07 01:03:21 AEDT
Size:
2.00 KB
patch
obsolete
>diff --git a/sshd.c b/sshd.c >index f91dacc..33652bf 100644 >--- a/sshd.c >+++ b/sshd.c >@@ -1296,6 +1296,53 @@ server_accept_loop(int *sock_in, int *sock_out, int *newsock, int *config_s) > } > } > >+int >+daemon_sync(int nochdir, int noclose, int *sync) >+{ >+ int fd, child_pipe[2]; >+ char buf; >+ >+ if (sync == NULL) >+ return (-1); >+ >+ if (pipe(child_pipe) == 0) >+ *sync = child_pipe[1]; >+ else >+ *sync = -1; >+ >+ switch (fork()) { >+ case -1: >+ return (-1); >+ case 0: >+ break; >+ default: >+ if (*sync > -1) { >+ close(child_pipe[1]); >+ read(child_pipe[0], &buf, 1); >+ close(child_pipe[0]); >+ } >+ _exit(0); >+ } >+ >+ if (*sync > -1) >+ close(child_pipe[0]); >+ >+ if (setsid() == -1) >+ return (-1); >+ >+ if (!nochdir) >+ (void)chdir("/"); >+ >+ if (!noclose && (fd = open(_PATH_DEVNULL, O_RDWR, 0)) != -1) { >+ (void)dup2(fd, STDIN_FILENO); >+ (void)dup2(fd, STDOUT_FILENO); >+ (void)dup2(fd, STDERR_FILENO); >+ if (fd > 2) >+ (void)close (fd); >+ } >+ return (0); >+} >+ > > /* > * Main program for the daemon. >@@ -1311,7 +1358,7 @@ main(int ac, char **av) > char *test_user = NULL, *test_host = NULL, *test_addr = NULL; > int remote_port; > char *line, *p, *cp; >- int config_s[2] = { -1 , -1 }; >+ int sync_p = -1, config_s[2] = { -1 , -1 }; > u_int64_t ibytes, obytes; > mode_t new_umask; > Key *key; >@@ -1758,7 +1805,7 @@ main(int ac, char **av) > #ifdef TIOCNOTTY > int fd; > #endif /* TIOCNOTTY */ >- if (daemon(0, 0) < 0) >+ if (daemon_sync(0, 0, &sync_p) < 0) > fatal("daemon() failed: %.200s", strerror(errno)); > > /* Disconnect from the controlling tty. */ >@@ -1808,7 +1855,6 @@ main(int ac, char **av) > */ > if (!debug_flag) { > FILE *f = fopen(options.pid_file, "w"); >- > if (f == NULL) { > error("Couldn't create pid file \"%s\": %s", > options.pid_file, strerror(errno)); >@@ -1816,6 +1862,9 @@ main(int ac, char **av) > fprintf(f, "%ld\n", (long) getpid()); > fclose(f); > } >+ if (sync_p > -1) >+ write(sync_p, "1", 1); >+ close(sync_p); > } > > /* Accept a connection and return in a forked child */
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 1955
: 2115