The following commit has been merged in the master branch:
commit e827c3fa3ccd371bce16687e300ee6a0b2cb1851
Author: Guillem Jover <[email protected]>
Date: Mon Nov 26 20:01:12 2012 +0100
s-s-d: Refactor option setup off main() into new setup_options() function
diff --git a/utils/start-stop-daemon.c b/utils/start-stop-daemon.c
index 265e80a..20a6505 100644
--- a/utils/start-stop-daemon.c
+++ b/utils/start-stop-daemon.c
@@ -975,6 +975,69 @@ parse_options(int argc, char * const *argv)
badusage("--no-close is only relevant with --background");
}
+static void
+setup_options(void)
+{
+ if (execname) {
+ char *fullexecname;
+
+ /* If it's a relative path, normalize it. */
+ if (execname[0] != '/')
+ execname = newpath(changedir, execname);
+
+ if (changeroot)
+ fullexecname = newpath(changeroot, execname);
+ else
+ fullexecname = execname;
+
+ if (stat(fullexecname, &exec_stat))
+ fatal("unable to stat %s", fullexecname);
+
+ if (fullexecname != execname)
+ free(fullexecname);
+ }
+
+ if (userspec && sscanf(userspec, "%d", &user_id) != 1) {
+ struct passwd *pw;
+
+ pw = getpwnam(userspec);
+ if (!pw)
+ fatal("user '%s' not found", userspec);
+
+ user_id = pw->pw_uid;
+ }
+
+ if (changegroup && sscanf(changegroup, "%d", &runas_gid) != 1) {
+ struct group *gr;
+
+ gr = getgrnam(changegroup);
+ if (!gr)
+ fatal("group '%s' not found", changegroup);
+ changegroup = gr->gr_name;
+ runas_gid = gr->gr_gid;
+ }
+ if (changeuser) {
+ struct passwd *pw;
+ struct stat st;
+
+ if (sscanf(changeuser, "%d", &runas_uid) == 1)
+ pw = getpwuid(runas_uid);
+ else
+ pw = getpwnam(changeuser);
+ if (!pw)
+ fatal("user '%s' not found", changeuser);
+ changeuser = pw->pw_name;
+ runas_uid = pw->pw_uid;
+ if (changegroup == NULL) {
+ /* Pass the default group of this user. */
+ changegroup = ""; /* Just empty. */
+ runas_gid = pw->pw_gid;
+ }
+ if (stat(pw->pw_dir, &st) == 0)
+ setenv("HOME", pw->pw_dir, 1);
+ }
+}
+
#if defined(OSHurd)
static void
init_procset(void)
@@ -1746,66 +1809,11 @@ main(int argc, char **argv)
progname = argv[0];
parse_options(argc, argv);
+ setup_options();
+
argc -= optind;
argv += optind;
- if (execname) {
- char *fullexecname;
-
- /* If it's a relative path, normalize it. */
- if (execname[0] != '/')
- execname = newpath(changedir, execname);
-
- if (changeroot)
- fullexecname = newpath(changeroot, execname);
- else
- fullexecname = execname;
-
- if (stat(fullexecname, &exec_stat))
- fatal("unable to stat %s", fullexecname);
-
- if (fullexecname != execname)
- free(fullexecname);
- }
-
- if (userspec && sscanf(userspec, "%d", &user_id) != 1) {
- struct passwd *pw;
-
- pw = getpwnam(userspec);
- if (!pw)
- fatal("user '%s' not found", userspec);
-
- user_id = pw->pw_uid;
- }
-
- if (changegroup && sscanf(changegroup, "%d", &runas_gid) != 1) {
- struct group *gr = getgrnam(changegroup);
- if (!gr)
- fatal("group '%s' not found", changegroup);
- changegroup = gr->gr_name;
- runas_gid = gr->gr_gid;
- }
- if (changeuser) {
- struct passwd *pw;
- struct stat st;
-
- if (sscanf(changeuser, "%d", &runas_uid) == 1)
- pw = getpwuid(runas_uid);
- else
- pw = getpwnam(changeuser);
- if (!pw)
- fatal("user '%s' not found", changeuser);
- changeuser = pw->pw_name;
- runas_uid = pw->pw_uid;
- if (changegroup == NULL) {
- /* Pass the default group of this user. */
- changegroup = ""; /* Just empty. */
- runas_gid = pw->pw_gid;
- }
- if (stat(pw->pw_dir, &st) == 0)
- setenv("HOME", pw->pw_dir, 1);
- }
-
if (action == action_start)
do_start(argc, argv);
--
dpkg's main repository
--
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]