blob: baf3b0aae4de642727b4c025aa9206bf10e699ad (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
/*
* setsid.c -- execute a command in a new session
* Rick Sladkey <jrs@world.std.com>
* In the public domain.
*
* 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@pld.ORG.PL>
* - added Native Language Support
*
* 2001-01-18 John Fremlin <vii@penguinpowered.com>
* - fork in case we are process group leader
*
*/
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include "nls.h"
int
main(int argc, char *argv[]) {
setlocale(LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
if (argc < 2) {
fprintf(stderr, _("usage: %s program [arg ...]\n"),
argv[0]);
exit(1);
}
if (getpgrp() == getpid()) {
switch(fork()){
case -1:
perror("fork");
exit(1);
case 0: /* child */
break;
default: /* parent */
exit(0);
}
}
if (setsid() < 0) {
perror("setsid"); /* cannot happen */
exit(1);
}
execvp(argv[1], argv + 1);
perror("execvp");
exit(1);
}
|