2013-10-07 12:03:26 -04:00
|
|
|
/* See LICENSE file for copyright and license details. */
|
2013-10-07 11:37:23 -04:00
|
|
|
#include <errno.h>
|
2014-11-13 13:54:28 -05:00
|
|
|
#include <unistd.h>
|
2014-11-13 12:29:30 -05:00
|
|
|
|
2013-08-21 07:56:26 -04:00
|
|
|
#include "util.h"
|
|
|
|
|
|
|
|
static void
|
|
|
|
usage(void)
|
|
|
|
{
|
|
|
|
eprintf("usage: %s cmd [arg ...]\n", argv0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
2014-01-27 10:15:58 -05:00
|
|
|
int savederrno;
|
|
|
|
|
2017-08-05 17:50:39 -04:00
|
|
|
argv0 = *argv, argv0 ? (argc--, argv++) : (void *)0;
|
2013-08-21 07:56:26 -04:00
|
|
|
|
2015-03-01 18:20:35 -05:00
|
|
|
if (!argc)
|
2013-08-21 07:56:26 -04:00
|
|
|
usage();
|
|
|
|
|
2014-11-13 12:29:30 -05:00
|
|
|
if (getpgrp() == getpid()) {
|
|
|
|
switch (fork()) {
|
2013-08-21 07:56:26 -04:00
|
|
|
case -1:
|
2015-03-10 15:05:18 -04:00
|
|
|
eprintf("fork:");
|
2013-08-21 07:56:26 -04:00
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
default:
|
2014-10-02 18:46:04 -04:00
|
|
|
return 0;
|
2013-08-21 07:56:26 -04:00
|
|
|
}
|
|
|
|
}
|
2014-11-13 12:29:30 -05:00
|
|
|
if (setsid() < 0)
|
2013-08-21 07:56:26 -04:00
|
|
|
eprintf("setsid:");
|
|
|
|
execvp(argv[0], argv);
|
2014-01-27 10:15:58 -05:00
|
|
|
savederrno = errno;
|
|
|
|
weprintf("execvp %s:", argv[0]);
|
2015-03-01 18:20:35 -05:00
|
|
|
|
2015-03-08 20:04:34 -04:00
|
|
|
_exit(126 + (savederrno == ENOENT));
|
2013-08-21 07:56:26 -04:00
|
|
|
}
|