summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2015-11-04 21:19:25 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2015-11-04 21:19:25 +0000
commit320cdee53ad9f2252403402fb0b41764cdc001fd (patch)
treeb43bac0f373531d1f1bb5ec6e658f125f8f5aed1 /src
parent2807442e2cff8645fc4fdb84efd257fe2b2c55a3 (diff)
downloads6-320cdee53ad9f2252403402fb0b41764cdc001fd.tar.xz
- add -g option to s6-envuidgid
- set s6-log processor wd to the logdir
Diffstat (limited to 'src')
-rw-r--r--src/daemontools-extras/s6-envuidgid.c58
-rw-r--r--src/daemontools-extras/s6-log.c32
2 files changed, 50 insertions, 40 deletions
diff --git a/src/daemontools-extras/s6-envuidgid.c b/src/daemontools-extras/s6-envuidgid.c
index 3712411..c0aaac2 100644
--- a/src/daemontools-extras/s6-envuidgid.c
+++ b/src/daemontools-extras/s6-envuidgid.c
@@ -2,6 +2,7 @@
#include <sys/types.h>
#include <pwd.h>
+#include <grp.h>
#include <limits.h>
#include <skalibs/uint64.h>
#include <skalibs/gidstuff.h>
@@ -12,26 +13,27 @@
#include <skalibs/fmtscan.h>
#include <skalibs/djbunix.h>
-#define USAGE "s6-envuidgid [ -i | -D defaultuid:defaultgid ] username prog..."
+#define USAGE "s6-envuidgid [ -i | -D defaultuid:defaultgid ] [ -g ] username prog..."
#define dieusage() strerr_dieusage(100, USAGE)
int main (int argc, char const *const *argv, char const *const *envp)
{
- struct passwd *pw ;
uint64 uid ;
gid_t gid ;
gid_t tab[NGROUPS_MAX] ;
int n = 0 ;
+ int dogroup = 0 ;
int insist = 1 ;
PROG = "s6-envuidgid" ;
{
subgetopt_t l = SUBGETOPT_ZERO ;
for (;;)
{
- register int opt = subgetopt_r(argc, argv, "iD:", &l) ;
+ register int opt = subgetopt_r(argc, argv, "giD:", &l) ;
if (opt == -1) break ;
switch (opt)
{
+ case 'g' : dogroup = 1 ; break ;
case 'i' : insist = 1 ; break ;
case 'D' :
{
@@ -58,28 +60,42 @@ int main (int argc, char const *const *argv, char const *const *envp)
}
if (argc < 2) dieusage() ;
- pw = getpwnam(argv[0]) ;
- if (pw)
+ if (dogroup)
{
- uid = pw->pw_uid ;
- gid = pw->pw_gid ;
- n = prot_readgroups(argv[0], tab, NGROUPS_MAX) ;
- if (n < 0)
- strerr_diefu2sys(111, "get supplementary groups for ", argv[0]) ;
- }
- else if (insist) strerr_dief2x(1, "unknown user: ", argv[0]) ;
-
- {
- unsigned int pos = 0 ;
- char fmt[19 + UINT64_FMT + (n+1) * GID_FMT] ;
- byte_copy(fmt + pos, 4, "UID=") ; pos += 4 ;
- pos += uint64_fmt(fmt + pos, uid) ;
- byte_copy(fmt + pos, 5, "\0GID=") ; pos += 5 ;
+ struct group *gr = getgrnam(argv[0]) ;
+ unsigned int pos = 4 ;
+ char fmt[4 + GID_FMT] = "GID=" ;
+ if (gr) gid = gr->gr_gid ;
+ else if (insist) strerr_dief2x(1, "unknown group: ", argv[0]) ;
pos += gid_fmt(fmt + pos, gid) ;
- byte_copy(fmt + pos, 9, "\0GIDLIST=") ; pos += 9 ;
- pos += gid_fmtlist(fmt + pos, tab, n) ;
fmt[pos++] = 0 ;
pathexec_r(argv+1, envp, env_len(envp), fmt, pos) ;
}
+ else
+ {
+ struct passwd *pw = getpwnam(argv[0]) ;
+ if (pw)
+ {
+ uid = pw->pw_uid ;
+ gid = pw->pw_gid ;
+ n = prot_readgroups(argv[0], tab, NGROUPS_MAX) ;
+ if (n < 0)
+ strerr_diefu2sys(111, "get supplementary groups for ", argv[0]) ;
+ }
+ else if (insist) strerr_dief2x(1, "unknown user: ", argv[0]) ;
+
+ {
+ unsigned int pos = 0 ;
+ char fmt[19 + UINT64_FMT + (n+1) * GID_FMT] ;
+ byte_copy(fmt + pos, 4, "UID=") ; pos += 4 ;
+ pos += uint64_fmt(fmt + pos, uid) ;
+ byte_copy(fmt + pos, 5, "\0GID=") ; pos += 5 ;
+ pos += gid_fmt(fmt + pos, gid) ;
+ byte_copy(fmt + pos, 9, "\0GIDLIST=") ; pos += 9 ;
+ pos += gid_fmtlist(fmt + pos, tab, n) ;
+ fmt[pos++] = 0 ;
+ pathexec_r(argv+1, envp, env_len(envp), fmt, pos) ;
+ }
+ }
strerr_dieexec(111, argv[1]) ;
}
diff --git a/src/daemontools-extras/s6-log.c b/src/daemontools-extras/s6-log.c
index bbb92b1..c3aec9c 100644
--- a/src/daemontools-extras/s6-log.c
+++ b/src/daemontools-extras/s6-log.c
@@ -306,27 +306,21 @@ static int finish (logdir_t *ldp, char const *name, char suffix)
static inline void exec_processor (logdir_t *ldp)
{
char const *cargv[4] = { EXECLINE_EXTBINPREFIX "execlineb", "-Pc", ldp->processor, 0 } ;
- unsigned int dirlen = str_len(ldp->dir) ;
int fd ;
- char x[dirlen + 10] ;
PROG = "s6-log (processor child)" ;
- byte_copy(x, dirlen, ldp->dir) ;
- byte_copy(x + dirlen, 10, "/previous") ;
- fd = open_readb(x) ;
- if (fd < 0) strerr_diefu2sys(111, "open_readb ", x) ;
- if (fd_move(0, fd) < 0) strerr_diefu2sys(111, "fd_move ", x) ;
- byte_copy(x + dirlen + 1, 10, "processed") ;
- fd = open_trunc(x) ;
- if (fd < 0) strerr_diefu2sys(111, "open_trunc ", x) ;
- if (fd_move(1, fd) < 0) strerr_diefu2sys(111, "fd_move ", x) ;
- byte_copy(x + dirlen + 1, 6, "state") ;
- fd = open_readb(x) ;
- if (fd < 0) strerr_diefu2sys(111, "open_readb ", x) ;
- if (fd_move(4, fd) < 0) strerr_diefu2sys(111, "fd_move ", x) ;
- byte_copy(x + dirlen + 1, 9, "newstate") ;
- fd = open_trunc(x) ;
- if (fd < 0) strerr_diefu2sys(111, "open_trunc ", x) ;
- if (fd_move(5, fd) < 0) strerr_diefu2sys(111, "fd_move ", x) ;
+ if (chdir(ldp->dir) < 0) strerr_diefu2sys(111, "chdir to ", ldp->dir) ;
+ fd = open_readb("previous") ;
+ if (fd < 0) strerr_diefu3sys(111, "open_readb ", ldp->dir, "/previous") ;
+ if (fd_move(0, fd) < 0) strerr_diefu3sys(111, "fd_move ", ldp->dir, "/previous") ;
+ fd = open_trunc("processed") ;
+ if (fd < 0) strerr_diefu3sys(111, "open_trunc ", ldp->dir, "/processed") ;
+ if (fd_move(1, fd) < 0) strerr_diefu3sys(111, "fd_move ", ldp->dir, "/processed") ;
+ fd = open_readb("state") ;
+ if (fd < 0) strerr_diefu3sys(111, "open_readb ", ldp->dir, "/state") ;
+ if (fd_move(4, fd) < 0) strerr_diefu3sys(111, "fd_move ", ldp->dir, "/state") ;
+ fd = open_trunc("newstate") ;
+ if (fd < 0) strerr_diefu3sys(111, "open_trunc ", ldp->dir, "/newstate") ;
+ if (fd_move(5, fd) < 0) strerr_diefu3sys(111, "fd_move ", ldp->dir, "/newstate") ;
selfpipe_finish() ;
sig_restore(SIGPIPE) ;
pathexec_run(cargv[0], cargv, (char const *const *)environ) ;