2006-05-15 03:20:24 +04:00
|
|
|
/*
|
|
|
|
* (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>
|
2006-05-19 19:38:45 +04:00
|
|
|
#include <string.h>
|
2006-05-15 03:20:24 +04:00
|
|
|
|
2006-05-17 12:36:56 +04:00
|
|
|
static char version[] = "wmiisetsid - " VERSION ", (C)opyright MMVI Anselm R. Garbe\n";
|
|
|
|
|
|
|
|
static void
|
|
|
|
usage()
|
|
|
|
{
|
2006-05-17 22:35:04 +04:00
|
|
|
fprintf(stderr, "%s", "usage: wmiisetsid [-v] cmd [arg ...]\n");
|
2006-05-17 12:36:56 +04:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2006-05-15 03:20:24 +04:00
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
2006-05-17 12:36:56 +04:00
|
|
|
/* command line args */
|
|
|
|
if(argc < 2)
|
|
|
|
usage();
|
2006-05-17 13:55:22 +04:00
|
|
|
else if(!strncmp(argv[1], "-v", 3)) {
|
2006-05-17 12:36:56 +04:00
|
|
|
fprintf(stdout, "%s", version);
|
|
|
|
exit(0);
|
2006-05-15 03:20:24 +04:00
|
|
|
}
|
|
|
|
if(getpgrp() == getpid()) {
|
|
|
|
switch(fork()){
|
|
|
|
case -1:
|
|
|
|
perror("wmiisetsid: fork");
|
|
|
|
exit(1);
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(setsid() < 0) {
|
|
|
|
perror("wmiisetsid: setsid");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
execvp(argv[1], argv + 1);
|
|
|
|
perror("wmiisetsid: execvp");
|
|
|
|
exit(1);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|