2013-10-07 12:03:26 -04:00
|
|
|
/* See LICENSE file for copyright and license details. */
|
2014-11-13 13:54:28 -05:00
|
|
|
#include <errno.h>
|
2013-06-14 12:55:25 -04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2014-11-13 13:54:28 -05:00
|
|
|
#include <unistd.h>
|
2014-11-13 12:29:30 -05:00
|
|
|
|
2013-06-14 12:55:25 -04:00
|
|
|
#include "util.h"
|
|
|
|
|
|
|
|
extern char **environ;
|
|
|
|
|
2014-04-22 09:44:16 -04:00
|
|
|
static void
|
|
|
|
usage(void)
|
|
|
|
{
|
2015-03-02 08:50:43 -05:00
|
|
|
eprintf("usage: %s [-i] [-u var] ... [var=value] ... [cmd [arg ...]]\n", argv0);
|
2014-04-22 09:44:16 -04:00
|
|
|
}
|
2013-06-14 12:55:25 -04:00
|
|
|
|
|
|
|
int
|
2014-04-18 06:51:18 -04:00
|
|
|
main(int argc, char *argv[])
|
2013-06-14 12:55:25 -04:00
|
|
|
{
|
2015-03-08 20:04:34 -04:00
|
|
|
int savederrno;
|
|
|
|
|
2013-06-14 12:55:25 -04:00
|
|
|
ARGBEGIN {
|
|
|
|
case 'i':
|
2015-02-20 07:28:24 -05:00
|
|
|
if (environ)
|
2013-07-18 15:28:08 -04:00
|
|
|
*environ = NULL;
|
2013-06-14 12:55:25 -04:00
|
|
|
break;
|
|
|
|
case 'u':
|
|
|
|
unsetenv(EARGF(usage()));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
} ARGEND;
|
|
|
|
|
2015-03-02 08:50:43 -05:00
|
|
|
for (; *argv && strchr(*argv, '='); argc--, argv++)
|
2013-06-14 12:55:25 -04:00
|
|
|
putenv(*argv);
|
|
|
|
|
2014-11-13 12:29:30 -05:00
|
|
|
if (*argv) {
|
2013-06-14 12:55:25 -04:00
|
|
|
execvp(*argv, argv);
|
2015-03-08 20:04:34 -04:00
|
|
|
savederrno = errno;
|
|
|
|
weprintf("execvp %s:", *argv);
|
|
|
|
_exit(126 + (savederrno == EEXIST));
|
2013-06-14 12:55:25 -04:00
|
|
|
}
|
|
|
|
|
2015-03-02 08:50:43 -05:00
|
|
|
for (; environ && *environ; environ++)
|
|
|
|
puts(*environ);
|
2013-06-14 12:55:25 -04:00
|
|
|
|
2014-10-02 18:46:04 -04:00
|
|
|
return 0;
|
2013-06-14 12:55:25 -04:00
|
|
|
}
|