Add setsid(1) by arg

This commit is contained in:
sin 2013-08-21 12:56:26 +01:00
parent 7be94fd3c8
commit ddec3259aa
3 changed files with 50 additions and 0 deletions

View File

@ -68,6 +68,7 @@ SRC = \
rm.c \ rm.c \
rmdir.c \ rmdir.c \
sleep.c \ sleep.c \
setsid.c \
sort.c \ sort.c \
split.c \ split.c \
sponge.c \ sponge.c \

7
setsid.1 Normal file
View File

@ -0,0 +1,7 @@
.TH SETSID 1 sbase\-VERSION
.SH NAME
setsid \- run a program in a new session
.SH SYNOPSIS
.B setsid
.RI program
.RI [ arg ...]

42
setsid.c Normal file
View File

@ -0,0 +1,42 @@
/* (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
* See LICENSE file for license details. */
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include "util.h"
static void
usage(void)
{
eprintf("usage: %s cmd [arg ...]\n", argv0);
}
int
main(int argc, char *argv[])
{
ARGBEGIN {
default:
usage();
} ARGEND;
if (argc < 1)
usage();
if(getpgrp() == getpid()) {
switch(fork()){
case -1:
eprintf("fork:");
case 0:
break;
default:
exit(0);
}
}
if(setsid() < 0)
eprintf("setsid:");
execvp(argv[0], argv);
eprintf("execvp:");
/* NOTREACHED */
return 0;
}