2013-10-07 16:03:26 +00:00
|
|
|
/* See LICENSE file for copyright and license details. */
|
2013-10-07 15:37:23 +00:00
|
|
|
#include <errno.h>
|
2013-08-21 11:56:26 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "util.h"
|
|
|
|
|
|
|
|
static void
|
|
|
|
usage(void)
|
|
|
|
{
|
|
|
|
eprintf("usage: %s cmd [arg ...]\n", argv0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
2014-01-27 15:15:58 +00:00
|
|
|
int savederrno;
|
|
|
|
|
2013-08-21 11:56:26 +00:00
|
|
|
ARGBEGIN {
|
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
} ARGEND;
|
|
|
|
|
|
|
|
if (argc < 1)
|
|
|
|
usage();
|
|
|
|
|
|
|
|
if(getpgrp() == getpid()) {
|
|
|
|
switch(fork()){
|
|
|
|
case -1:
|
|
|
|
eprintf("fork:");
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
default:
|
2014-10-02 22:46:04 +00:00
|
|
|
return 0;
|
2013-08-21 11:56:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if(setsid() < 0)
|
|
|
|
eprintf("setsid:");
|
|
|
|
execvp(argv[0], argv);
|
2014-01-27 15:15:58 +00:00
|
|
|
savederrno = errno;
|
|
|
|
weprintf("execvp %s:", argv[0]);
|
|
|
|
return (savederrno == ENOENT) ? 127 : 126;
|
2013-08-21 11:56:26 +00:00
|
|
|
}
|