diff options
author | Roy Marples <roy@marples.name> | 2008-08-20 10:02:11 +0000 |
---|---|---|
committer | Roy Marples <roy@marples.name> | 2008-08-20 10:02:11 +0000 |
commit | 1ab1e9328a6313ae7d77957168484ce4b52fdf5d (patch) | |
tree | 5369c0f16c55fa3bf5bc8836bf35636e425abf39 /src | |
parent | a9f7d2d5e5df184fd2eae38422605333e483c4d0 (diff) |
Add -k,--umask option, Gentoo #232455.
Diffstat (limited to 'src')
-rw-r--r-- | src/includes/rc-misc.h | 1 | ||||
-rw-r--r-- | src/rc/checkpath.c | 22 | ||||
-rw-r--r-- | src/rc/rc-misc.c | 22 | ||||
-rw-r--r-- | src/rc/start-stop-daemon.c | 11 |
4 files changed, 33 insertions, 23 deletions
diff --git a/src/includes/rc-misc.h b/src/includes/rc-misc.h index 4bdeb01f..91e15895 100644 --- a/src/includes/rc-misc.h +++ b/src/includes/rc-misc.h @@ -157,4 +157,5 @@ _unused static const char *basename_c(const char *path) return (path); } +int parse_mode(mode_t *, char *); #endif diff --git a/src/rc/checkpath.c b/src/rc/checkpath.c index 8726dca8..7ea94f09 100644 --- a/src/rc/checkpath.c +++ b/src/rc/checkpath.c @@ -106,28 +106,6 @@ static int do_check(char *path, uid_t uid, gid_t gid, mode_t mode, int file) return 0; } -/* Based on busybox */ -static int parse_mode (mode_t *mode, char *text) -{ - char *p; - unsigned long l; - - /* Check for a numeric mode */ - if ((*text - '0') < 8) { - l = strtoul(text, &p, 8); - if (*p || l > 07777U) { - errno = EINVAL; - return -1; - } - *mode = (mode_t) l; - return 0; - } - - /* We currently don't check g+w type stuff */ - errno = EINVAL; - return -1; -} - static int parse_owner(struct passwd **user, struct group **group, const char *owner) { diff --git a/src/rc/rc-misc.c b/src/rc/rc-misc.c index 191fa3d4..22e2e309 100644 --- a/src/rc/rc-misc.c +++ b/src/rc/rc-misc.c @@ -374,3 +374,25 @@ pid_t exec_service(const char *service, const char *arg) return pid; } + +int +parse_mode(mode_t *mode, char *text) +{ + char *p; + unsigned long l; + + /* Check for a numeric mode */ + if ((*text - '0') < 8) { + l = strtoul(text, &p, 8); + if (*p || l > 07777U) { + errno = EINVAL; + return -1; + } + *mode = (mode_t) l; + return 0; + } + + /* We currently don't check g+w type stuff */ + errno = EINVAL; + return -1; +} diff --git a/src/rc/start-stop-daemon.c b/src/rc/start-stop-daemon.c index 76f2b028..dfecd609 100644 --- a/src/rc/start-stop-daemon.c +++ b/src/rc/start-stop-daemon.c @@ -499,7 +499,7 @@ static void handle_signal(int sig) #include "_usage.h" -#define getoptstring "KN:R:Sbc:d:e:g:mn:op:s:tu:r:x:1:2:" getoptstring_COMMON +#define getoptstring "KN:R:Sbc:d:e:g:k:mn:op:s:tu:r:x:1:2:" getoptstring_COMMON static const struct option longopts[] = { { "stop", 0, NULL, 'K'}, { "nicelevel", 1, NULL, 'N'}, @@ -510,6 +510,7 @@ static const struct option longopts[] = { { "chuid", 1, NULL, 'c'}, { "chdir", 1, NULL, 'd'}, { "env", 1, NULL, 'e'}, + { "umask", 1, NULL, 'k'}, { "group", 1, NULL, 'g'}, { "make-pidfile", 0, NULL, 'm'}, { "name", 1, NULL, 'n'}, @@ -534,6 +535,7 @@ static const char * const longopts_help[] = { "deprecated, use --user", "Change the PWD", "Set an environment string", + "Set the umask for the daemon", "Change the process group", "Create a pidfile", "Match process name", @@ -601,6 +603,7 @@ int start_stop_daemon(int argc, char **argv) char line[130]; FILE *fp; size_t len; + mode_t numask; TAILQ_INIT(&schedule); atexit(cleanup); @@ -696,6 +699,12 @@ int start_stop_daemon(int argc, char **argv) } break; + case 'k': + if (parse_mode(&numask, optarg)) + eerrorx("%s: invalid mode `%s'", + applet, optarg); + break; + case 'm': /* --make-pidfile */ makepidfile = true; break; |