diff options
Diffstat (limited to 'daemon.c')
-rw-r--r-- | daemon.c | 78 |
1 files changed, 24 insertions, 54 deletions
@@ -235,7 +235,7 @@ static int service_enabled; static int git_daemon_config(const char *var, const char *value, void *cb) { - if (!prefixcmp(var, "daemon.") && + if (starts_with(var, "daemon.") && !strcmp(var + 7, service_looking_at->config_name)) { service_enabled = git_config_bool(var, value); return 0; @@ -475,14 +475,6 @@ static void make_service_overridable(const char *name, int ena) die("No such service %s", name); } -static char *xstrdup_tolower(const char *str) -{ - char *p, *dup = xstrdup(str); - for (p = dup; *p; p++) - *p = tolower(*p); - return dup; -} - static void parse_host_and_port(char *hostport, char **host, char **port) { @@ -633,7 +625,7 @@ static int execute(void) for (i = 0; i < ARRAY_SIZE(daemon_service); i++) { struct daemon_service *s = &(daemon_service[i]); int namelen = strlen(s->name); - if (!prefixcmp(line, "git-") && + if (starts_with(line, "git-") && !strncmp(s->name, line + 4, namelen) && line[namelen + 4] == ' ') { /* @@ -1056,11 +1048,6 @@ static void drop_privileges(struct credentials *cred) /* nothing */ } -static void daemonize(void) -{ - die("--detach not supported on this platform"); -} - static struct credentials *prepare_credentials(const char *user_name, const char *group_name) { @@ -1102,24 +1089,6 @@ static struct credentials *prepare_credentials(const char *user_name, return &c; } - -static void daemonize(void) -{ - switch (fork()) { - case 0: - break; - case -1: - die_errno("fork failed"); - default: - exit(0); - } - if (setsid() == -1) - die_errno("setsid failed"); - close(0); - close(1); - close(2); - sanitize_stdfds(); -} #endif static void store_pid(const char *path) @@ -1165,11 +1134,11 @@ int main(int argc, char **argv) for (i = 1; i < argc; i++) { char *arg = argv[i]; - if (!prefixcmp(arg, "--listen=")) { + if (starts_with(arg, "--listen=")) { string_list_append(&listen_addr, xstrdup_tolower(arg + 9)); continue; } - if (!prefixcmp(arg, "--port=")) { + if (starts_with(arg, "--port=")) { char *end; unsigned long n; n = strtoul(arg+7, &end, 0); @@ -1199,19 +1168,19 @@ int main(int argc, char **argv) export_all_trees = 1; continue; } - if (!prefixcmp(arg, "--access-hook=")) { + if (starts_with(arg, "--access-hook=")) { access_hook = arg + 14; continue; } - if (!prefixcmp(arg, "--timeout=")) { + if (starts_with(arg, "--timeout=")) { timeout = atoi(arg+10); continue; } - if (!prefixcmp(arg, "--init-timeout=")) { + if (starts_with(arg, "--init-timeout=")) { init_timeout = atoi(arg+15); continue; } - if (!prefixcmp(arg, "--max-connections=")) { + if (starts_with(arg, "--max-connections=")) { max_connections = atoi(arg+18); if (max_connections < 0) max_connections = 0; /* unlimited */ @@ -1221,7 +1190,7 @@ int main(int argc, char **argv) strict_paths = 1; continue; } - if (!prefixcmp(arg, "--base-path=")) { + if (starts_with(arg, "--base-path=")) { base_path = arg+12; continue; } @@ -1229,7 +1198,7 @@ int main(int argc, char **argv) base_path_relaxed = 1; continue; } - if (!prefixcmp(arg, "--interpolated-path=")) { + if (starts_with(arg, "--interpolated-path=")) { interpolated_path = arg+20; continue; } @@ -1241,11 +1210,11 @@ int main(int argc, char **argv) user_path = ""; continue; } - if (!prefixcmp(arg, "--user-path=")) { + if (starts_with(arg, "--user-path=")) { user_path = arg + 12; continue; } - if (!prefixcmp(arg, "--pid-file=")) { + if (starts_with(arg, "--pid-file=")) { pid_file = arg + 11; continue; } @@ -1254,35 +1223,35 @@ int main(int argc, char **argv) log_syslog = 1; continue; } - if (!prefixcmp(arg, "--user=")) { + if (starts_with(arg, "--user=")) { user_name = arg + 7; continue; } - if (!prefixcmp(arg, "--group=")) { + if (starts_with(arg, "--group=")) { group_name = arg + 8; continue; } - if (!prefixcmp(arg, "--enable=")) { + if (starts_with(arg, "--enable=")) { enable_service(arg + 9, 1); continue; } - if (!prefixcmp(arg, "--disable=")) { + if (starts_with(arg, "--disable=")) { enable_service(arg + 10, 0); continue; } - if (!prefixcmp(arg, "--allow-override=")) { + if (starts_with(arg, "--allow-override=")) { make_service_overridable(arg + 17, 1); continue; } - if (!prefixcmp(arg, "--forbid-override=")) { + if (starts_with(arg, "--forbid-override=")) { make_service_overridable(arg + 18, 0); continue; } - if (!prefixcmp(arg, "--informative-errors")) { + if (!strcmp(arg, "--informative-errors")) { informative_errors = 1; continue; } - if (!prefixcmp(arg, "--no-informative-errors")) { + if (!strcmp(arg, "--no-informative-errors")) { informative_errors = 0; continue; } @@ -1333,9 +1302,10 @@ int main(int argc, char **argv) if (inetd_mode || serve_mode) return execute(); - if (detach) - daemonize(); - else + if (detach) { + if (daemonize()) + die("--detach not supported on this platform"); + } else sanitize_stdfds(); if (pid_file) |