signal forwarding support

Markus Friedl markus at openbsd.org
Mon Jan 20 07:20:01 EST 2003


On Sun, Jan 19, 2003 at 06:57:55PM +0900, Atsuhiko Yamanaka wrote:
> Has the newest version already supported it?  That sounds great!

ok, here's a patch.

Index: session.c
===================================================================
RCS file: /cvs/src/usr.bin/ssh/session.c,v
retrieving revision 1.152
diff -u -r1.152 session.c
--- session.c	10 Dec 2002 08:56:00 -0000	1.152
+++ session.c	19 Jan 2003 20:15:52 -0000
@@ -1502,6 +1502,51 @@
 }
 
 static int
+name2sig(char *name)
+{
+#define SSH_SIG(x) if (strcmp(name, #x) == 0) return SIG ## x
+	SSH_SIG(ABRT);
+	SSH_SIG(ALRM);
+	SSH_SIG(FPE);
+	SSH_SIG(HUP);
+	SSH_SIG(ILL);
+	SSH_SIG(INT);
+	SSH_SIG(KILL);
+	SSH_SIG(PIPE);
+	SSH_SIG(QUIT);
+	SSH_SIG(SEGV);
+	SSH_SIG(TERM);
+	SSH_SIG(USR1);
+	SSH_SIG(USR2);
+#undef	SSH_SIG
+	return -1;
+}
+
+static int
+session_signal_req(Session *s)
+{
+	char *signame;
+	int sig;
+
+	signame = packet_get_string(NULL);
+	sig = name2sig(signame);
+	xfree(signame);
+	packet_check_eom();
+
+	if (sig >= 0 && s->pid > 0) {
+		debug("session_signal_req: killpg(%d, %d)",
+		    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));
+		restore_uid();
+	}
+	return 0;
+}
+
+
+static int
 session_auth_agent_req(Session *s)
 {
 	static int called = 0;
@@ -1552,6 +1597,8 @@
 	}
 	if (strcmp(rtype, "window-change") == 0) {
 		success = session_window_change_req(s);
+ 	} else if (strcmp(rtype, "signal") == 0) {
+ 		success = session_signal_req(s);
 	}
 	return success;
 }




More information about the openssh-unix-dev mailing list