ssid

simple setsid replacement
git clone git://git.suckless.org/ssid
Log | Files | Refs | README | LICENSE

commit 5973e406065a5c93e9397e2b9315adda44d1d12b
Author: arg@suckless.org <unknown>
Date:   Tue, 10 Oct 2006 09:08:23 +0200

new stuff

Diffstat:
LICENSE | 21+++++++++++++++++++++
Makefile | 51+++++++++++++++++++++++++++++++++++++++++++++++++++
README | 19+++++++++++++++++++
config.mk | 21+++++++++++++++++++++
ssid.c | 39+++++++++++++++++++++++++++++++++++++++
5 files changed, 151 insertions(+), 0 deletions(-)

diff --git a/LICENSE b/LICENSE @@ -0,0 +1,21 @@ +MIT/X Consortium License + +(C)opyright MMV-MMVI Anselm R. Garbe <garbeam@gmail.com> + +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,51 @@ +# ssid - simple setsid +# (C)opyright MMVI Anselm R. Garbe + +include config.mk + +SRC = ssid.c +OBJ = ${SRC:.c=.o} + +all: options ssid + +options: + @echo ssid build options: + @echo "CFLAGS = ${CFLAGS}" + @echo "LDFLAGS = ${LDFLAGS}" + @echo "CC = ${CC}" + @echo "LD = ${LD}" + +.c.o: + @echo CC $< + @${CC} -c ${CFLAGS} $< + +${OBJ}: config.mk + +ssid: ${OBJ} + @echo LD $@ + @${LD} -o $@ ${OBJ} ${LDFLAGS} + @strip $@ + +clean: + @echo cleaning + @rm -f ssid ${OBJ} ssid-${VERSION}.tar.gz + +dist: clean + @echo creating dist tarball + @mkdir -p ssid-${VERSION} + @cp -R LICENSE Makefile README config.mk ${SRC} ssid-${VERSION} + @tar -cf ssid-${VERSION}.tar ssid-${VERSION} + @gzip ssid-${VERSION}.tar + @rm -rf ssid-${VERSION} + +install: all + @echo installing executable file to ${DESTDIR}${PREFIX}/bin + @mkdir -p ${DESTDIR}${PREFIX}/bin + @cp -f ssid ${DESTDIR}${PREFIX}/bin + @chmod 755 ${DESTDIR}${PREFIX}/bin/ssid + +uninstall: + @echo removing executable file from ${DESTDIR}${PREFIX}/bin + @rm -f ${DESTDIR}${PREFIX}/bin/ssid + +.PHONY: all options clean dist install uninstall diff --git a/README b/README @@ -0,0 +1,19 @@ +ssid - simple setsid +==================== +ssid is an extremly simple setsid replacement. + + +Installation +------------ +Edit config.mk to match your local setup. ssid is installed into +/usr/local by default. + +Afterwards enter the following command to build and install ssid +(if necessary as root): + + $ make clean install + + +Running ssid +------------ +Simply invoke the 'ssid' command with the required arguments. diff --git a/config.mk b/config.mk @@ -0,0 +1,21 @@ +# ssid version +VERSION = 0.1 + +# Customize below to fit your system + +# paths +PREFIX = /usr/local + +# includes and libs +INCS = -I. -I/usr/include +LIBS = -L/usr/lib -lc + +# flags +CFLAGS = -Os ${INCS} -DVERSION=\"${VERSION}\" +LDFLAGS = ${LIBS} +#CFLAGS = -g -Wall -O2 ${INCS} -DVERSION=\"${VERSION}\" +#LDFLAGS = -g ${LIBS} + +# compiler and linker +CC = cc +LD = ${CC} diff --git a/ssid.c b/ssid.c @@ -0,0 +1,39 @@ +/* (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> + +int +main(int argc, char *argv[]) { + if(argc < 2) { + fputs("usage: ssid [-v] cmd [arg ...]\n", stderr); + exit(EXIT_FAILURE); + } + else if(!strncmp(argv[1], "-v", 3)) { + fputs("ssid-"VERSION", (C)opyright MMVI Anselm R. Garbe\n", stdout); + exit(EXIT_SUCCESS); + } + if(getpgrp() == getpid()) { + switch(fork()){ + case -1: + perror("ssid: fork"); + exit(1); + case 0: + break; + default: + exit(0); + } + } + if(setsid() < 0) { + perror("ssid: setsid"); + exit(1); + } + execvp(argv[1], argv + 1); + perror("ssid: execvp"); + exit(1); + return 0; +} +