setsid: add optional -f to force fork()

This commit is contained in:
Hiltjo Posthuma 2020-07-14 10:15:43 +02:00 committed by Michael Forney
parent 991ff90064
commit 0df09d5ba0
2 changed files with 9 additions and 3 deletions

View File

@ -1,4 +1,4 @@
.Dd 2015-10-08 .Dd 2020-07-14
.Dt SETSID 1 .Dt SETSID 1
.Os sbase .Os sbase
.Sh NAME .Sh NAME
@ -6,6 +6,7 @@
.Nd run a command in a new session .Nd run a command in a new session
.Sh SYNOPSIS .Sh SYNOPSIS
.Nm .Nm
.Op Fl f
.Ar cmd .Ar cmd
.Op Ar arg ... .Op Ar arg ...
.Sh DESCRIPTION .Sh DESCRIPTION

View File

@ -4,10 +4,12 @@
#include "util.h" #include "util.h"
static int fflag = 0;
static void static void
usage(void) usage(void)
{ {
eprintf("usage: %s cmd [arg ...]\n", argv0); eprintf("usage: %s cmd [-f] [arg ...]\n", argv0);
} }
int int
@ -16,6 +18,9 @@ main(int argc, char *argv[])
int savederrno; int savederrno;
ARGBEGIN { ARGBEGIN {
case 'f':
fflag = 1;
break;
default: default:
usage(); usage();
} ARGEND } ARGEND
@ -23,7 +28,7 @@ main(int argc, char *argv[])
if (!argc) if (!argc)
usage(); usage();
if (getpgrp() == getpid()) { if (fflag || getpgrp() == getpid()) {
switch (fork()) { switch (fork()) {
case -1: case -1:
eprintf("fork:"); eprintf("fork:");