summaryrefslogtreecommitdiffstats
path: root/sys-utils/setsid.c
diff options
context:
space:
mode:
authorKarel Zak2017-11-08 11:38:26 +0100
committerKarel Zak2017-11-08 11:38:26 +0100
commit180176213000b15cabc7bf39f7cad656b8f5ae38 (patch)
treec69c8ef9dfa393baf9f61bd2fe297e2b0299de95 /sys-utils/setsid.c
parentrtcwake: add note about HW and sleep to the man page (diff)
downloadkernel-qcow2-util-linux-180176213000b15cabc7bf39f7cad656b8f5ae38.tar.gz
kernel-qcow2-util-linux-180176213000b15cabc7bf39f7cad656b8f5ae38.tar.xz
kernel-qcow2-util-linux-180176213000b15cabc7bf39f7cad656b8f5ae38.zip
setsid: new option --fork
Let's make semantic more predictable. Addresses: https://github.com/karelzak/util-linux/issues/518 Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'sys-utils/setsid.c')
-rw-r--r--sys-utils/setsid.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/sys-utils/setsid.c b/sys-utils/setsid.c
index 0b1395232..2991da058 100644
--- a/sys-utils/setsid.c
+++ b/sys-utils/setsid.c
@@ -38,6 +38,7 @@ static void __attribute__((__noreturn__)) usage(void)
fputs(USAGE_OPTIONS, out);
fputs(_(" -c, --ctty set the controlling terminal to the current one\n"), out);
+ fputs(_(" -f, --fork always fork\n"), out);
fputs(_(" -w, --wait wait program to exit, and use the same return\n"), out);
printf(USAGE_HELP_OPTIONS(16));
@@ -48,13 +49,14 @@ static void __attribute__((__noreturn__)) usage(void)
int main(int argc, char **argv)
{
- int ch;
+ int ch, forcefork = 0;
int ctty = 0;
pid_t pid;
int status = 0;
static const struct option longopts[] = {
{"ctty", no_argument, NULL, 'c'},
+ {"fork", no_argument, NULL, 'f'},
{"wait", no_argument, NULL, 'w'},
{"version", no_argument, NULL, 'V'},
{"help", no_argument, NULL, 'h'},
@@ -66,7 +68,7 @@ int main(int argc, char **argv)
textdomain(PACKAGE);
atexit(close_stdout);
- while ((ch = getopt_long(argc, argv, "+Vhcw", longopts, NULL)) != -1)
+ while ((ch = getopt_long(argc, argv, "+Vhcfw", longopts, NULL)) != -1)
switch (ch) {
case 'V':
printf(UTIL_LINUX_VERSION);
@@ -74,6 +76,9 @@ int main(int argc, char **argv)
case 'c':
ctty=1;
break;
+ case 'f':
+ forcefork = 1;
+ break;
case 'w':
status = 1;
break;
@@ -88,7 +93,7 @@ int main(int argc, char **argv)
errtryhelp(EXIT_FAILURE);
}
- if (getpgrp() == getpid()) {
+ if (forcefork || getpgrp() == getpid()) {
pid = fork();
switch (pid) {
case -1: