Bugzilla – Attachment 15 Details for
Bug 92
Feature: -f -f, like -f, but fork() after port/display/agent open
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
feature patch for -f -f
openssh-doubl_dash_f.patch (text/plain), 3.97 KB, created by
Nicolas Williams
on 2002-02-02 06:23:26 AEDT
(
hide
)
Description:
feature patch for -f -f
Filename:
MIME Type:
Creator:
Nicolas Williams
Created:
2002-02-02 06:23:26 AEDT
Size:
3.97 KB
patch
obsolete
>Index: 3_0_2p1.1/ssh.c >--- 3_0_2p1.1/ssh.c Wed, 21 Nov 2001 10:38:46 -0500 >+++ 3_0_2p1_double_dash_f.1/ssh.c Fri, 01 Feb 2002 12:59:13 -0500 >@@ -111,6 +111,7 @@ > * background. > */ > int fork_after_authentication_flag = 0; >+int wait_for_port_open_before_fork = 0; > > /* > * General data structure for command line options and options configurable >@@ -330,6 +331,8 @@ > stdin_null_flag = 1; > break; > case 'f': >+ if (fork_after_authentication_flag) >+ wait_for_port_open_before_fork = 1; > fork_after_authentication_flag = 1; > stdin_null_flag = 1; > break; >@@ -1164,7 +1167,7 @@ > id = ssh_session2_open(); > > /* If requested, let ssh continue in the background. */ >- if (fork_after_authentication_flag) >+ if (fork_after_authentication_flag && !wait_for_port_open_before_fork) > if (daemon(1, 1) < 0) > fatal("daemon() failed: %.200s", strerror(errno)); > >Index: 3_0_2p1.1/clientloop.c >--- 3_0_2p1.1/clientloop.c Wed, 21 Nov 2001 10:38:46 -0500 >+++ 3_0_2p1_double_dash_f.1/clientloop.c Fri, 01 Feb 2002 12:59:13 -0500 >@@ -95,6 +95,9 @@ > */ > extern char *host; > >+extern int fork_after_authentication_flag; >+extern int wait_for_port_open_before_fork; >+ > /* > * Flag to indicate that we have received a window change signal which has > * not yet been processed. This will cause a message indicating the new >@@ -1007,6 +1010,80 @@ > > /*********/ > >+/* >+ * Detach the program (continue to serve connections, >+ * but put in background and no more new connections). >+ */ >+static >+void >+forkoff(int stop_listening, int detach) >+{ >+ pid_t pid; >+ int fd; >+ Channel *c; >+ >+ /* Restore tty modes. */ >+ leave_raw_mode(); >+ >+ /* Stop listening for new connections. */ >+ if (stop_listening) >+ channel_stop_listening(); >+ >+ fprintf(stderr, "Forking off into the background - %s", >+ stop_listening ? "no longer listening" : "still listening"); >+ >+ /* Fork into background. */ >+ pid = fork(); >+ if (pid < 0) { >+ error("fork: %.100s", strerror(errno)); >+ return; >+ } >+ if (pid != 0) { /* This is the parent. */ >+ /* The parent just exits. */ >+ exit(0); >+ } >+ >+ c = channel_lookup(session_ident); >+ if (c == NULL) >+ error("couldn't lookup session channel"); >+ >+ /* The child continues serving connections. */ >+ /* fake EOF on stdin */ >+ if (compat20) { >+ buffer_append(&stdin_buffer, "\004", 1); >+ } else if (!stdin_eof) { >+ /* >+ * Sending SSH_CMSG_EOF alone does not always appear >+ * to be enough. So we try to send an EOF character >+ * first. >+ */ >+ packet_start(SSH_CMSG_STDIN_DATA); >+ packet_put_string("\004", 1); >+ packet_send(); >+ /* Close stdin. */ >+ stdin_eof = 1; >+ if (buffer_len(&stdin_buffer) == 0) { >+ packet_start(SSH_CMSG_EOF); >+ packet_send(); >+ } >+ } >+ >+ if (detach) { >+ chan_read_failed(c); >+ chan_write_failed(c); >+ channel_close_fds(c); >+ fd = open(_PATH_DEVNULL, O_RDWR, 0); >+ if (fd < 0) >+ return; >+ (void) dup2(fd, STDIN_FILENO); >+ (void) dup2(fd, STDOUT_FILENO); >+ (void) dup2(fd, STDERR_FILENO); >+ if (fd > 2) >+ (void) close(fd); >+ (void) setsid(); >+ } >+} >+ > static void > client_input_stdout_data(int type, int plen, void *ctxt) > { >@@ -1187,6 +1264,8 @@ > packet_put_int(c->local_maxpacket); > packet_send(); > } >+ if (fork_after_authentication_flag && wait_for_port_open_before_fork) >+ forkoff(0, 1); > } else { > debug("failure %s", ctype); > packet_start(SSH2_MSG_CHANNEL_OPEN_FAILURE); >Index: 3_0_2p1.1/channels.h >--- 3_0_2p1.1/channels.h Wed, 21 Nov 2001 10:38:46 -0500 >+++ 3_0_2p1_double_dash_f.1/channels.h Fri, 01 Feb 2002 12:59:13 -0500 >@@ -153,6 +153,7 @@ > void channel_register_filter(int, channel_filter_fn *); > void channel_cancel_cleanup(int); > int channel_close_fd(int *); >+void channel_close_fds(Channel *); > > /* protocol handler */ > >Index: 3_0_2p1.1/channels.c >--- 3_0_2p1.1/channels.c Wed, 21 Nov 2001 10:38:46 -0500 >+++ 3_0_2p1_double_dash_f.1/channels.c Fri, 01 Feb 2002 12:59:13 -0500 >@@ -301,7 +301,7 @@ > > /* Close all channel fd/socket. */ > >-static void >+void > channel_close_fds(Channel *c) > { > debug3("channel_close_fds: channel %d: r %d w %d e %d",
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 92
: 15 |
1536