From f1069d3986eb3fbb4e9945ec669566efe5cb5cd7 Mon Sep 17 00:00:00 2001 From: Gerrit Pape Date: Thu, 24 Sep 2009 21:17:22 +0000 Subject: * pathexec_env.c, pathexec.h: add function pathexec_env_run(). * chpst.c, man/chpst.8: new option -b argv0: run prog with different 0th argument. --- src/chpst.c | 15 ++++++++++----- src/pathexec.h | 1 + src/pathexec_env.c | 9 +++++++-- 3 files changed, 18 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/chpst.c b/src/chpst.c index 1bfc8e0..6518c55 100644 --- a/src/chpst.c +++ b/src/chpst.c @@ -20,7 +20,7 @@ #include "openreadclose.h" #include "direntry.h" -#define USAGE_MAIN " [-vP012] [-u user[:group]] [-U user[:group]] [-e dir] [-/ root] [-n nice] [-l|-L lock] [-m n] [-d n] [-o n] [-p n] [-f n] [-c n] prog" +#define USAGE_MAIN " [-vP012] [-u user[:group]] [-U user[:group]] [-b argv0] [-e dir] [-/ root] [-n nice] [-l|-L lock] [-m n] [-d n] [-o n] [-p n] [-f n] [-c n] prog" #define FATAL "chpst: fatal: " #define WARNING "chpst: warning: " @@ -40,6 +40,7 @@ void usage() { strerr_die4x(100, "usage: ", progname, USAGE_MAIN, "\n"); } char *set_user =0; char *env_user =0; +const char *argv0 =0; const char *env_dir =0; unsigned int verbose =0; unsigned int pgrp =0; @@ -264,7 +265,7 @@ void pgrphack(int, const char *const *); void setlock(int, const char *const *); void softlimit(int, const char *const *); -int main(int argc, const char *const *argv) { +int main(int argc, const char **argv) { int opt; int i; unsigned long ul; @@ -285,11 +286,12 @@ int main(int argc, const char *const *argv) { if (str_equal(progname, "setlock")) setlock(argc, argv); if (str_equal(progname, "softlimit")) softlimit(argc, argv); - while ((opt =getopt(argc, argv, "u:U:e:m:d:o:p:f:c:r:t:/:n:l:L:vP012V")) + while ((opt =getopt(argc, argv, "u:U:b:e:m:d:o:p:f:c:r:t:/:n:l:L:vP012V")) != opteof) switch(opt) { case 'u': set_user =(char*)optarg; break; case 'U': env_user =(char*)optarg; break; + case 'b': argv0 =(char*)optarg; break; case 'e': env_dir =optarg; break; case 'm': if (optarg[scan_ulong(optarg, &ul)]) usage(); @@ -327,7 +329,7 @@ int main(int argc, const char *const *argv) { } argv +=optind; if (! argv || ! *argv) usage(); - + if (pgrp) setsid(); if (env_dir) edir(env_dir); if (root) { @@ -345,7 +347,10 @@ int main(int argc, const char *const *argv) { if (nostdout) if (close(1) == -1) fatal("unable to close stdout"); if (nostderr) if (close(2) == -1) fatal("unable to close stderr"); slimit(); - pathexec(argv); + + progname =*argv; + if (argv0) *argv =argv0; + pathexec_env_run(progname, argv); fatal2("unable to run", *argv); return(0); } diff --git a/src/pathexec.h b/src/pathexec.h index 61da922..d46ab17 100644 --- a/src/pathexec.h +++ b/src/pathexec.h @@ -5,6 +5,7 @@ extern void pathexec_run(const char *,const char * const *,const char * const *); extern int pathexec_env(const char *,const char *); +extern void pathexec_env_run(const char *, const char * const *); extern void pathexec(const char * const *); #endif diff --git a/src/pathexec_env.c b/src/pathexec_env.c index 0779c75..1305469 100644 --- a/src/pathexec_env.c +++ b/src/pathexec_env.c @@ -22,7 +22,7 @@ int pathexec_env(const char *s,const char *t) return stralloc_cat(&plus,&tmp); } -void pathexec(const char *const *argv) +void pathexec_env_run(const char *file, const char *const *argv) { const char **e; unsigned int elen; @@ -64,6 +64,11 @@ void pathexec(const char *const *argv) } e[elen] = 0; - pathexec_run(*argv,argv,e); + pathexec_run(file,argv,e); alloc_free(e); } + +void pathexec(const char *const *argv) +{ + return pathexec_env_run(*argv, argv); +} -- cgit 1.4.1