Bugzilla – Attachment 2896 Details for
Bug 2641
Add systemd notify code to to track running server
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
do not call daemon again when restarting on sighup
openssh-sighup-nodaemon.patch (text/plain), 2.25 KB, created by
Darren Tucker
on 2016-11-29 10:09:54 AEDT
(
hide
)
Description:
do not call daemon again when restarting on sighup
Filename:
MIME Type:
Creator:
Darren Tucker
Created:
2016-11-29 10:09:54 AEDT
Size:
2.25 KB
patch
obsolete
>diff --git a/misc.c b/misc.c >index 07d4179..cb615c1 100644 >--- a/misc.c >+++ b/misc.c >@@ -1251,3 +1251,21 @@ bind_permitted(int port, uid_t uid) > return 0; > return 1; > } >+ >+/* returns 1 if process is already daemonized, 0 otherwise */ >+int >+daemonized(void) >+{ >+ int fd; >+ >+ if ((fd = open(_PATH_TTY, O_RDONLY | O_NOCTTY)) >= 0) { >+ close(fd); >+ return 0; /* have controlling terminal */ >+ } >+ if (getppid() != 1) >+ return 0; /* parent is not init */ >+ if (getsid(0) != getpid()) >+ return 0; /* not session leader */ >+ debug3("already daemonized"); >+ return 1; >+} >diff --git a/misc.h b/misc.h >index 3578e8e..d2fe876 100644 >--- a/misc.h >+++ b/misc.h >@@ -31,6 +31,7 @@ struct Forward { > > int forward_equals(const struct Forward *, const struct Forward *); > int bind_permitted(int, uid_t); >+int daemonized(void); > > /* Common server and client forwarding options. */ > struct ForwardOptions { >diff --git a/sshd.c b/sshd.c >index 816611c..356b35f 100644 >--- a/sshd.c >+++ b/sshd.c >@@ -1343,7 +1343,7 @@ main(int ac, char **av) > struct ssh *ssh = NULL; > extern char *optarg; > extern int optind; >- int r, opt, i, j, on = 1; >+ int r, opt, i, j, on = 1, already_daemon; > int sock_in = -1, sock_out = -1, newsock = -1; > const char *remote_ip; > int remote_port; >@@ -1802,11 +1802,12 @@ main(int ac, char **av) > log_init(__progname, options.log_level, options.log_facility, log_stderr); > > /* >- * If not in debugging mode, and not started from inetd, disconnect >- * from the controlling terminal, and fork. The original process >- * exits. >+ * If not in debugging mode, not started from inetd and not already >+ * daemonized (eg re-exec via SIGHUP), disconnect from the controlling >+ * terminal, and fork. The original process exits. > */ >- if (!(debug_flag || inetd_flag || no_daemon_flag)) { >+ already_daemon = daemonized(); >+ if (!(debug_flag || inetd_flag || no_daemon_flag || already_daemon)) { > #ifdef TIOCNOTTY > int fd; > #endif /* TIOCNOTTY */ >@@ -1849,7 +1850,7 @@ main(int ac, char **av) > * Write out the pid file after the sigterm handler > * is setup and the listen sockets are bound > */ >- if (options.pid_file != NULL && !debug_flag) { >+ if (options.pid_file != NULL && !debug_flag && !already_daemon) { > FILE *f = fopen(options.pid_file, "w"); > > if (f == NULL) {
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 2641
:
2893
| 2896 |
2950
|
3099