commit 2b7bef14e50f69b0d9b811ddf65b6bf626f01577
parent c9ea11743033ef1a4ce010ddcca2f1ac0ba3376b
Author: Gerrit Pape <pape@smarden.org>
Date: Thu, 24 Sep 2009 21:17:22 +0000
* 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.
Diffstat:
5 files changed, 33 insertions(+), 7 deletions(-)
diff --git a/man/chpst.8 b/man/chpst.8
@@ -8,6 +8,8 @@ chpst \- runs a program with a changed process state
.IR user ]
[\-U
.IR user ]
+[\-b
+.IR argv0 ]
[-e
.IR dir ]
[\-/
@@ -96,6 +98,14 @@ and
arguments are interpreted as uid and gid respectivly, and not looked up in
the password or group file.
.TP
+.B \-b \fIargv0
+argv0.
+Run
+.I prog
+with
+.I argv0
+as the 0th argument.
+.TP
.B \-e \fIdir
envdir.
Set various environment variables as specified by files in the directory
diff --git a/package/CHANGES b/package/CHANGES
@@ -1,3 +1,8 @@
+2.0.1
+ * 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.
+
2.0.0
Sun, 15 Jun 2008 15:31:05 +0000
diff --git 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
@@ -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
@@ -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);
+}