summaryrefslogtreecommitdiffstats
path: root/sys-utils/setsid.c
diff options
context:
space:
mode:
authorKarel Zak2006-12-07 00:25:46 +0100
committerKarel Zak2006-12-07 00:25:46 +0100
commitc07ebfa1e02d208ab12430e6791ea147bcfaf9c0 (patch)
treed44a755098286f5d553c7aea1a73d98c2995d6ec /sys-utils/setsid.c
parentImported from util-linux-2.10s tarball. (diff)
downloadkernel-qcow2-util-linux-c07ebfa1e02d208ab12430e6791ea147bcfaf9c0.tar.gz
kernel-qcow2-util-linux-c07ebfa1e02d208ab12430e6791ea147bcfaf9c0.tar.xz
kernel-qcow2-util-linux-c07ebfa1e02d208ab12430e6791ea147bcfaf9c0.zip
Imported from util-linux-2.11b tarball.
Diffstat (limited to 'sys-utils/setsid.c')
-rw-r--r--sys-utils/setsid.c22
1 files changed, 18 insertions, 4 deletions
diff --git a/sys-utils/setsid.c b/sys-utils/setsid.c
index 7aeb2de89..baf3b0aae 100644
--- a/sys-utils/setsid.c
+++ b/sys-utils/setsid.c
@@ -3,9 +3,12 @@
* Rick Sladkey <jrs@world.std.com>
* In the public domain.
*
- * 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@misiek.eu.org>
+ * 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@pld.ORG.PL>
* - added Native Language Support
*
+ * 2001-01-18 John Fremlin <vii@penguinpowered.com>
+ * - fork in case we are process group leader
+ *
*/
#include <stdio.h>
@@ -13,8 +16,8 @@
#include <stdlib.h>
#include "nls.h"
-int main(int argc, char *argv[])
-{
+int
+main(int argc, char *argv[]) {
setlocale(LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
@@ -24,8 +27,19 @@ int main(int argc, char *argv[])
argv[0]);
exit(1);
}
+ if (getpgrp() == getpid()) {
+ switch(fork()){
+ case -1:
+ perror("fork");
+ exit(1);
+ case 0: /* child */
+ break;
+ default: /* parent */
+ exit(0);
+ }
+ }
if (setsid() < 0) {
- perror("setsid");
+ perror("setsid"); /* cannot happen */
exit(1);
}
execvp(argv[1], argv + 1);