[hackers] [sbase] Add setsid(1) by arg || sin

From: <git_AT_suckless.org>
Date: Sat, 05 Oct 2013 16:29:49 +0200

commit ddec3259aad6b92727a4f82501b98a491176ac3b
Author: sin <sin_AT_2f30.org>
Date: Wed Aug 21 12:56:26 2013 +0100

    Add setsid(1) by arg

diff --git a/Makefile b/Makefile
index 99829d4..6112ddd 100644
--- a/Makefile
+++ b/Makefile
_AT_@ -68,6 +68,7 @@ SRC = \
         rm.c \
         rmdir.c \
         sleep.c \
+ setsid.c \
         sort.c \
         split.c \
         sponge.c \
diff --git a/setsid.1 b/setsid.1
new file mode 100644
index 0000000..3c65051
--- /dev/null
+++ b/setsid.1
_AT_@ -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 ...]
diff --git a/setsid.c b/setsid.c
new file mode 100644
index 0000000..796f8d7
--- /dev/null
+++ b/setsid.c
_AT_@ -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 ...]
", 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;
+}
Received on Sat Oct 05 2013 - 16:29:49 CEST

This archive was generated by hypermail 2.3.0 : Sat Oct 05 2013 - 16:37:00 CEST