summary refs log tree commit diff
diff options
context:
space:
mode:
authorGerrit Pape <pape@smarden.org>2009-09-24 21:17:22 +0000
committerGerrit Pape <pape@smarden.org>2009-09-24 21:17:22 +0000
commitf1069d3986eb3fbb4e9945ec669566efe5cb5cd7 (patch)
tree1beb93926669bcf1343840cc95cae8dbb31e04f0
parent1ce8ddf8e5d6ed8559a4eebbff0f4bde17fce6bf (diff)
downloadrunit-f1069d3986eb3fbb4e9945ec669566efe5cb5cd7.tar.gz
runit-f1069d3986eb3fbb4e9945ec669566efe5cb5cd7.tar.xz
runit-f1069d3986eb3fbb4e9945ec669566efe5cb5cd7.zip
* 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.
-rw-r--r--man/chpst.810
-rw-r--r--package/CHANGES5
-rw-r--r--src/chpst.c15
-rw-r--r--src/pathexec.h1
-rw-r--r--src/pathexec_env.c9
5 files changed, 33 insertions, 7 deletions
diff --git a/man/chpst.8 b/man/chpst.8
index c67ec65..43c0b8d 100644
--- 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
index ab432b4..4a21614 100644
--- 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
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);
+}