Your message dated Wed, 23 Jul 2014 22:52:59 +0100
with message-id 
<CAD=6cZqeKJx5yMCLBoXT-KUGP+5V-YGdhfnG=HLm=e9jspu...@mail.gmail.com>
and subject line Close #495881 - util-linux: setsid masks return code of child 
process when invoked as process group leader
has caused the Debian Bug report #495881,
regarding util-linux: setsid masks return code of child process when invoked as 
process group leader
to be marked as done.

This means that you claim that the problem has been dealt with.
If this is not the case it is now your responsibility to reopen the
Bug report if necessary, and/or fix the problem forthwith.

(NB: If you are a system administrator and have no idea what this
message is talking about, this may indicate a serious mail system
misconfiguration somewhere. Please contact [email protected]
immediately.)


-- 
495881: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=495881
Debian Bug Tracking System
Contact [email protected] with problems
--- Begin Message ---
Package: util-linux
Version: 2.13.1.1-1
Severity: normal
Tags: patch

/usr/bin/setsid behaves differently when invoked as a process group
leader than when invoked as a member of an existing process group.

In the process group leader case, it forks and runs a child process as
a separate session.  This is the right thing to do (since the setsid()
system call does not work for process group leaders), but the parent
then exits immediately with exit status 0.

In the process group member case, it simply exec()s and then runs to
completion.

This means three significant behaviors vary depending on whether
setsid is invoked as a process group leader or not:


Exit Status
-----------

  setsid false

will return 0 when invoked as a process group leader, and 1 otherwise.


Speed of termination
--------------------

Long-running invocations like this:

  setsid find /

will immediately return when invoked as a process group leader (though
find itself will keep running), but will run until find completes when
invoked as a regular member of a process group.


Signal Handling
---------------

When invoked as a process group leader, during the window when both
parent and child process are alive, signals sent to setsid will not be
passed to the child process, afaict.

Non-leader invocations will receive the signals directly.



I don't understand /usr/bin/setsid terribly well: is this difference
in behavior desirable for some reason?  If so, why?  The shipped
documentation (setsid(1)) makes no mention of these behavioral
inconsistencies.

Attached is a patch that makes the behavior more similar w.r.t. exit
status and speed of termination (though signal handling remains
different).  The patch also fleshes out the documentation a bit.  The
change seems reasonable to me, but i might well be missing something.

Feedback on this patch (and the ideas behind it) would be much
appreciated.

Regards,

        --dkg

-- System Information:
Debian Release: lenny/sid
  APT prefers testing
  APT policy: (500, 'testing'), (200, 'unstable'), (101, 'experimental')
Architecture: i386 (i686)

Kernel: Linux 2.6.26-1-686 (SMP w/1 CPU core)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/bash

Versions of packages util-linux depends on:
ii  libc6                  2.7-13            GNU C Library: Shared libraries
ii  libncurses5            5.6+20080713-1    shared libraries for terminal hand
ii  libselinux1            2.0.65-2          SELinux shared libraries
ii  libslang2              2.1.3-3           The S-Lang programming library - r
ii  libuuid1               1.41.0-3          universally unique id library
ii  lsb-base               3.2-19            Linux Standard Base 3.2 init scrip
ii  tzdata                 2008e-3           time zone and daylight-saving time
ii  zlib1g                 1:1.2.3.3.dfsg-12 compression library - runtime

util-linux recommends no packages.

Versions of packages util-linux suggests:
ii  console-tools            1:0.2.3dbs-65.1 Linux console and font utilities
ii  dosfstools               2.11-6          utilities for making and checking 
pn  util-linux-locales       <none>          (no description available)

-- no debconf information
diff -ruN sys-utils.orig/setsid.1 sys-utils/setsid.1
--- sys-utils.orig/setsid.1	2007-08-13 06:39:47.000000000 -0400
+++ sys-utils/setsid.1	2008-08-20 23:09:06.000000000 -0400
@@ -8,7 +8,15 @@
 .BI setsid " program" " [ " "arg ..." " ]"
 .SH DESCRIPTION
 .B setsid
-runs a program in a new session.
+runs a program in a new session.  If invoked as a process group
+leader, it will fork and run the child in a new session.
+.SH "EXIT STATUS"
+.B setsid
+returns the exit status of the program being run.  If it was invoked
+as a process group leader and the child does not terminate normally
+(e.g. if it terminated from an unhandled signal),
+.B setsid
+will return 111.
 .SH "SEE ALSO"
 .BR setsid (2)
 .SH AUTHOR
diff -ruN sys-utils.orig/setsid.c sys-utils/setsid.c
--- sys-utils.orig/setsid.c	2007-04-25 08:43:38.000000000 -0400
+++ sys-utils/setsid.c	2008-08-20 22:58:55.000000000 -0400
@@ -8,16 +8,23 @@
  *
  * 2001-01-18 John Fremlin <[email protected]>
  * - fork in case we are process group leader
+ * 
+ * 2008-08-20 Daniel Kahn Gillmor <[email protected]>
+ * - if forked, wait on child process and emit its return code (exit
+ *   111 if child doesn't exit cleanly).
  *
  */
 
 #include <stdio.h>
 #include <unistd.h>
 #include <stdlib.h>
+#include <sys/types.h>
+#include <sys/wait.h>
 #include "nls.h"
 
 int
 main(int argc, char *argv[]) {
+	int pid, status;
 	setlocale(LC_ALL, "");
 	bindtextdomain(PACKAGE, LOCALEDIR);
 	textdomain(PACKAGE);
@@ -28,14 +35,23 @@
 		exit(1);
 	}
 	if (getpgrp() == getpid()) {
-		switch(fork()){
+		pid = fork();
+		switch(pid){
 		case -1:
 			perror("fork");
 			exit(1);
 		case 0:		/* child */
 			break;
 		default:	/* parent */
-			exit(0);
+			if (wait(&status) != pid) {
+				perror("wait");
+				exit(1);
+			}
+			if (WIFEXITED(status)) 
+				exit(WEXITSTATUS(status));
+
+			fprintf(stderr, "setsid child %d did not exit normally\n", pid);
+			exit(111);
 		}
 	}
 	if (setsid() < 0) {

--- End Message ---
--- Begin Message ---
version: 2.24.2-1

I'm closing this bug now since the fix for the bug you reported was
included in the new (upstream) version.

If you can still reproduce it feel free to reopen and provide more info.

thanks
regards
althaser

--- End Message ---

Reply via email to