commit edab84be7ab59c0673f7c4892228a36c1096d1dc
Author: finwo <finwo@pm.me>
Date: Fri, 5 Nov 2021 14:09:27 +0100
0.1.0
Diffstat:
4 files changed, 82 insertions(+), 0 deletions(-)
diff --git a/LICENSE b/LICENSE
@@ -0,0 +1,20 @@
+Copyright (c) 2005 Robbert Haarman
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/Makefile b/Makefile
@@ -0,0 +1,29 @@
+PREFIX ?= /usr/local
+bindir ?= ${PREFIX}/bin
+mandir ?= ${PREFIX}/share/man
+
+TARGETS = detach
+OBJECTS =
+
+all : $(TARGETS)
+
+clean :
+ #-rm $(OBJECTS)
+
+distclean : clean
+ -rm $(TARGETS)
+
+install : install-bin install-man
+
+install-bin : detach
+ [ -d '${bindir}' ] || mkdir -p '${bindir}'
+ install -s detach '${bindir}'
+
+install-man : detach.1
+ [ -d '${mandir}/man1' ] || mkdir -p '${mandir}/man1'
+ install -m 644 detach.1 '${mandir}/man1'
+
+love :
+ #unzip; strip; touch; finger; mount; fsck; more; yes; umount; sleep
+
+.PHONY : all clean distclean install install-bin install-man love
diff --git a/detach.1 b/detach.1
@@ -0,0 +1,17 @@
+.TH detach 1
+.SH NAME
+.B detach
+\- run a command after detaching from the terminal
+.SH SYNOPSIS
+\fBdetach\fR \fIcommand\fR [\fIargs\fR]
+
+Forks a new process, detaches is from the terminal, and executes
+command with the specified arguments.
+.SH EXAMPLE
+.B detach xterm
+
+Start an xterm that will not be closed when the current shell exits.
+.SH AUTHOR
+.B detach
+was written by Robbert Haarman. See http://inglorion.net/ for contact
+information.
diff --git a/detach.c b/detach.c
@@ -0,0 +1,16 @@
+#include <stdio.h>
+#include <unistd.h>
+
+int main(int argc, char **argv) {
+ int j;
+
+ j = 1;
+ if(fork()) return 0;
+ close(0);
+ close(1);
+ close(2);
+ setsid();
+ execvp(argv[j], &argv[j]);
+
+ return -1;
+}