Bugzilla – Attachment 1438 Details for
Bug 1424
Cannot signal a process over a channel (rfc 4254, section 6.9)
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Move signo2name functions to channels.c
openssh-signal.patch (text/plain), 5.94 KB, created by
Darren Tucker
on 2008-01-08 13:16:30 AEDT
(
hide
)
Description:
Move signo2name functions to channels.c
Filename:
MIME Type:
Creator:
Darren Tucker
Created:
2008-01-08 13:16:30 AEDT
Size:
5.94 KB
patch
obsolete
>Index: channels.c >=================================================================== >RCS file: /cvs/openssh/channels.c,v >retrieving revision 1.255 >diff -u -p -r1.255 channels.c >--- channels.c 28 Dec 2007 15:43:51 -0000 1.255 >+++ channels.c 8 Jan 2008 01:27:28 -0000 >@@ -3237,3 +3237,47 @@ auth_request_forwarding(void) > packet_send(); > packet_write_wait(); > } >+ >+/* for conversion of signals to/from ssh channel request names */ >+ >+static struct { >+ int signo; >+ char *name; >+} no2name[] = { >+ { SIGABRT, "ABRT" }, >+ { SIGALRM, "ALRM" }, >+ { SIGFPE, "FPE" }, >+ { SIGHUP, "HUP" }, >+ { SIGILL, "ILL" }, >+ { SIGINT, "INT" }, >+ { SIGKILL, "KILL" }, >+ { SIGPIPE, "PIPE" }, >+ { SIGQUIT, "QUIT" }, >+ { SIGSEGV, "SEGV" }, >+ { SIGTERM, "TERM" }, >+ { SIGUSR1, "USR1" }, >+ { SIGUSR2, "USR2" }, >+ { -1, NULL } >+}; >+ >+int >+chan_signame2no(char *name) >+{ >+ int i; >+ >+ for (i = 0; no2name[i].signo != -1; i++) >+ if (strcmp(no2name[i].name, name) == 0) >+ return no2name[i].signo; >+ return -1; >+} >+ >+char * >+chan_signo2name(int signo) >+{ >+ int i; >+ >+ for (i = 0; no2name[i].signo != -1; i++) >+ if (no2name[i].signo == signo) >+ return no2name[i].name; >+ return NULL; >+} >Index: channels.h >=================================================================== >RCS file: /cvs/openssh/channels.h,v >retrieving revision 1.82 >diff -u -p -r1.82 channels.h >--- channels.h 12 Jun 2007 13:38:54 -0000 1.82 >+++ channels.h 8 Jan 2008 01:27:28 -0000 >@@ -247,4 +247,7 @@ void chan_rcvd_ieof(Channel *); > void chan_write_failed(Channel *); > void chan_obuf_empty(Channel *); > >+int chan_signame2no(char *); >+char *chan_signo2name(int); >+ > #endif >Index: clientloop.c >=================================================================== >RCS file: /cvs/openssh/clientloop.c,v >retrieving revision 1.171 >diff -u -p -r1.171 clientloop.c >--- clientloop.c 28 Dec 2007 22:37:10 -0000 1.171 >+++ clientloop.c 8 Jan 2008 01:27:28 -0000 >@@ -950,6 +950,16 @@ client_process_control(fd_set *readset) > } > > static void >+ssh_send_signal(char *signame) >+{ >+ debug("sending signal %s to session %d", signame, session_ident); >+ channel_request_start(session_ident, "signal", 0); >+ packet_put_cstring(signame); >+ packet_send(); >+ packet_write_wait(); >+} >+ >+static void > process_cmdline(void) > { > void (*handler)(int); >@@ -982,6 +992,9 @@ process_cmdline(void) > "Request remote forward"); > logit(" -KR[bind_address:]port " > "Cancel remote forward"); >+ if (compat20) >+ logit(" -S[signal] or SIG[signal] " >+ "Send signal"); > if (!options.permit_local_command) > goto out; > logit(" !args " >@@ -995,6 +1008,16 @@ process_cmdline(void) > goto out; > } > >+ if (*s == 'S' && compat20) { >+ /* accept, eg, "SIGHUP" as a command */ >+ if (strncmp(s, "SIG", 3) == 0) >+ s += 3; >+ else >+ s++; >+ ssh_send_signal(s); >+ goto out; >+ } >+ > if (*s == 'K') { > delete = 1; > s++; >@@ -1551,6 +1574,26 @@ client_loop(int have_pty, int escape_cha > if (FD_ISSET(connection_out, writeset)) > packet_write_poll(); > } >+ >+ /* >+ * If there was no shell or command requested, there will be no remote >+ * exit status to be returned. In that case, clear error code if the >+ * connection was deliberately terminated at this end. >+ */ >+ if (no_shell_flag && received_signal == SIGTERM) { >+ received_signal = 0; >+ exit_status = 0; >+ } >+ >+ if (received_signal && compat20) { >+ char *signame = chan_signo2name(received_signal); >+ if (signame != NULL) { >+ debug("passed signal %s to server", signame); >+ ssh_send_signal(signame); >+ } else >+ debug("non-standard signal %s", signame); >+ } >+ > if (readset) > xfree(readset); > if (writeset) >@@ -1573,16 +1616,6 @@ client_loop(int have_pty, int escape_cha > unset_nonblock(fileno(stdout)); > if (!isatty(fileno(stderr))) > unset_nonblock(fileno(stderr)); >- >- /* >- * If there was no shell or command requested, there will be no remote >- * exit status to be returned. In that case, clear error code if the >- * connection was deliberately terminated at this end. >- */ >- if (no_shell_flag && received_signal == SIGTERM) { >- received_signal = 0; >- exit_status = 0; >- } > > if (received_signal) > fatal("Killed by signal %d.", (int) received_signal); >Index: session.c >=================================================================== >RCS file: /cvs/openssh/session.c,v >retrieving revision 1.356 >diff -u -p -r1.356 session.c >--- session.c 17 Sep 2007 06:09:15 -0000 1.356 >+++ session.c 8 Jan 2008 01:27:28 -0000 >@@ -1989,6 +1989,36 @@ session_env_req(Session *s) > } > > static int >+session_signal_req(Session *s) >+{ >+ char *signame; >+ int sig, success = 0; >+ >+ signame = packet_get_string(NULL); >+ sig = chan_signame2no(signame); >+ packet_check_eom(); >+ >+ if (sig >= 0) { >+ if (s->pid > 0) { >+ debug("session_signal_req: signal %s, killpg(%d, %d)", >+ signame, s->pid, sig); >+ temporarily_use_uid(s->pw); >+ if (killpg(s->pid, sig) < 0) >+ error("session_signal_req: killpg(%d, %d): %s", >+ s->pid, sig, strerror(errno)); >+ else >+ success = 1; >+ restore_uid(); >+ } >+ } else >+ debug("session_signal_req: unknown signal %s", signame); >+ >+ xfree(signame); >+ return success; >+} >+ >+ >+static int > session_auth_agent_req(Session *s) > { > static int called = 0; >@@ -2043,7 +2073,9 @@ session_input_channel_req(Channel *c, co > success = session_window_change_req(s); > } else if (strcmp(rtype, "break") == 0) { > success = session_break_req(s); >- } >+ } else if (strcmp(rtype, "signal") == 0) { >+ success = session_signal_req(s); >+ } > > return success; > } >Index: session.h >=================================================================== >RCS file: /cvs/openssh/session.h,v >retrieving revision 1.33 >diff -u -p -r1.33 session.h >--- session.h 5 Aug 2006 02:39:40 -0000 1.33 >+++ session.h 8 Jan 2008 01:27:28 -0000 >@@ -78,4 +78,6 @@ void do_setusercontext(struct passwd *) > void child_set_env(char ***envp, u_int *envsizep, const char *name, > const char *value); > >+int chan_signame2no(char *); >+char *chan_signo2name(int); > #endif
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 1424
:
1432
|
1438
|
1699
|
1700
|
1709
|
2500
|
3120