getpgrp

Darren Tucker dtucker at zip.com.au
Fri Feb 15 11:33:47 EST 2013


These days, sshd.c has:

static void
grace_alarm_handler(int sig)
{
...
        if (getpgid(0) == getpid()) {
                signal(SIGTERM, SIG_IGN);
                killpg(0, SIGTERM);
        }

        sigdie(...);
}

however (really) old BSDs do not have getpgid().  They do have
getpgrp(), which does what we want here. The question is what to do if
we have neither: return the pid (and thus terminate nothing) or return
-1 and kill everything wihout getting to the sigdie().  I vote for the
latter (since they're unlikely to be able to log anything in a
signal-safe manner anyway).

Index: configure.ac
===================================================================
RCS file: /var/cvs/openssh/configure.ac,v
retrieving revision 1.503
diff -u -p -r1.503 configure.ac
--- configure.ac	10 Feb 2013 23:39:13 -0000	1.503
+++ configure.ac	15 Feb 2013 00:26:37 -0000
@@ -1550,6 +1550,8 @@ AC_CHECK_FUNCS([ \
 	getopt \
 	getpeereid \
 	getpeerucred \
+	getpgid \
+	getpgrp \
 	_getpty \
 	getrlimit \
 	getttyent \
Index: openbsd-compat/bsd-misc.c
===================================================================
RCS file: /var/cvs/openssh/openbsd-compat/bsd-misc.c,v
retrieving revision 1.36
diff -u -p -r1.36 bsd-misc.c
--- openbsd-compat/bsd-misc.c	8 Nov 2010 22:26:23 -0000	1.36
+++ openbsd-compat/bsd-misc.c	15 Feb 2013 00:26:37 -0000
@@ -246,4 +246,18 @@ int isblank(int c)
 {
 	return (c == ' ' || c == '\t');
 }
+
+#ifndef HAVE_GETPGID
+pid_t
+getpgid(pid_t pid)
+{
+#ifdef HAVE_GETPGRP
+	if (pid == 0)
+		return getpgrp();
+#endif
+	errno = ESRCH;
+	return -1;
+}
+#endif
+
 #endif
Index: openbsd-compat/bsd-misc.h
===================================================================
RCS file: /var/cvs/openssh/openbsd-compat/bsd-misc.h,v
retrieving revision 1.21
diff -u -p -r1.21 bsd-misc.h
--- openbsd-compat/bsd-misc.h	3 Jul 2012 22:50:10 -0000	1.21
+++ openbsd-compat/bsd-misc.h	15 Feb 2013 00:26:37 -0000
@@ -102,4 +102,8 @@ mysig_t mysignal(int sig, mysig_t act);
 int	isblank(int);
 #endif
 
+#ifndef HAVE_GETPGID
+pid_t getpgid(pid_t);
+#endif
+
 #endif /* _BSD_MISC_H */
-- 
Darren Tucker (dtucker at zip.com.au)
GPG key 8FF4FA69 / D9A3 86E9 7EEE AF4B B2D4  37C9 C982 80C7 8FF4 FA69
    Good judgement comes with experience. Unfortunately, the experience
usually comes from bad judgement.


More information about the openssh-unix-dev mailing list