ssid

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

ssid.c (741B)


      1 /* (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
      2  * See LICENSE file for license details.
      3  */
      4 #include <stdio.h>
      5 #include <unistd.h>
      6 #include <stdlib.h>
      7 #include <string.h>
      8 
      9 int
     10 main(int argc, char *argv[]) {
     11 	if(argc < 2) {
     12 		fputs("usage: ssid [-v] cmd [arg ...]\n", stderr);
     13 		exit(EXIT_FAILURE);
     14 	}
     15 	else if(!strncmp(argv[1], "-v", 3)) {
     16 		fputs("ssid-"VERSION", (C)opyright MMVI Anselm R. Garbe\n", stdout);
     17 		exit(EXIT_SUCCESS);
     18 	}
     19 	if(getpgrp() == getpid()) {
     20 		switch(fork()){
     21 			case -1:
     22 				perror("ssid: fork");
     23 				exit(1);
     24 			case 0:
     25 				break;
     26 			default:
     27 				exit(0);
     28 		}
     29 	}
     30 	if(setsid() < 0) {
     31 		perror("ssid: setsid");
     32 		exit(1);
     33 	}
     34 	execvp(argv[1], argv + 1);
     35 	perror("ssid: execvp");
     36 	exit(1);
     37 	return 0;
     38 }
     39