Index: bin/sh/jobs.c =================================================================== --- bin/sh/jobs.c +++ bin/sh/jobs.c @@ -911,6 +911,9 @@ int wasroot; int i; + if (Sflag) + (void)setsid(); + TRACE(("Child shell %d\n", (int)getpid())); wasroot = rootshell; rootshell = 0; Index: bin/sh/options.h =================================================================== --- bin/sh/options.h +++ bin/sh/options.h @@ -68,15 +68,16 @@ #define hflag optval[18] #define nologflag optval[19] #define pipefailflag optval[20] +#define Sflag optval[21] -#define NSHORTOPTS 19 -#define NOPTS 21 +#define NSHORTOPTS 20 +#define NOPTS 22 extern char optval[NOPTS]; extern const char optletter[NSHORTOPTS]; #ifdef DEFINE_OPTIONS char optval[NOPTS]; -const char optletter[NSHORTOPTS] = "efIimnsxvVECabupTPh"; +const char optletter[NSHORTOPTS] = "efIimnsxvVECabupTPhS"; static const unsigned char optname[] = "\007errexit" "\006noglob" @@ -97,6 +98,7 @@ "\012trapsasync" "\010physical" "\010trackall" + "\006setsid" "\005nolog" "\010pipefail" ; Index: bin/sh/options.c =================================================================== --- bin/sh/options.c +++ bin/sh/options.c @@ -297,6 +297,8 @@ Eflag = 0; else if (&optval[idx] == &Eflag) Vflag = 0; + else if (&optval[idx] == &Sflag) + Sflag = 1; } } Index: bin/sh/sh.1 =================================================================== --- bin/sh/sh.1 +++ bin/sh/sh.1 @@ -32,7 +32,7 @@ .\" from: @(#)sh.1 8.6 (Berkeley) 5/4/95 .\" $FreeBSD$ .\" -.Dd July 6, 2020 +.Dd March 10, 2021 .Dt SH 1 .Os .Sh NAME @@ -40,14 +40,14 @@ .Nd command interpreter (shell) .Sh SYNOPSIS .Nm -.Op Fl /+abCEefhIimnPpTuVvx +.Op Fl /+abCEefhIimnPpSTuVvx .Op Fl /+o Ar longname .Oo .Ar script .Op Ar arg ... .Oc .Nm -.Op Fl /+abCEefhIimnPpTuVvx +.Op Fl /+abCEefhIimnPpSTuVvx .Op Fl /+o Ar longname .Fl c Ar string .Oo @@ -55,7 +55,7 @@ .Op Ar arg ... .Oc .Nm -.Op Fl /+abCEefhIimnPpTuVvx +.Op Fl /+abCEefhIimnPpSTuVvx .Op Fl /+o Ar longname .Fl s .Op Ar arg ... @@ -302,6 +302,10 @@ running (i.e., when set with the .Ic set command). +.It Fl S +When doing job control, call +.Xr setsid 2 +to create a new session. .It Fl T Li trapsasync When waiting for a child, execute traps immediately. If this option is not set,