Download raw body.
gotd PID issue
There is a mismatch between gotd process IDs shown by 'gotctl info' and gotd's debug logs, and the actual process IDs shown by pgrep, top, and in syslog. The reason is that the daemon(3) function forks and we don't take into account that this changes the PID. This patch makes gotd store its own PID after daemon(3), and avoids calling daemon(3) needlessly in child processes such that the PID the parent has stored for them will remain correct. diff 96afb0d62311dd459395b8eba2216094c18dfb67 84f2eb46f8ccd3cfbe6c89ef275dac40b135e932 commit - 96afb0d62311dd459395b8eba2216094c18dfb67 commit + 84f2eb46f8ccd3cfbe6c89ef275dac40b135e932 blob - 823a2d9d22e1f4f65df19bbbb7539f88ae4ce5a2 blob + 8f1e402bf783c0f47b4b9da20d73bbde74a93bfc --- gotd/gotd.c +++ gotd/gotd.c @@ -1789,12 +1789,12 @@ main(int argc, char **argv) log_setverbose(verbosity); if (proc_id == PROC_GOTD) { - gotd.pid = getpid(); snprintf(title, sizeof(title), "%s", gotd_proc_names[proc_id]); - start_listener(argv0, confpath, daemonize, verbosity); arc4random_buf(&clients_hash_key, sizeof(clients_hash_key)); if (daemonize && daemon(1, 0) == -1) fatal("daemon"); + gotd.pid = getpid(); + start_listener(argv0, confpath, daemonize, verbosity); } else if (proc_id == PROC_LISTEN) { snprintf(title, sizeof(title), "%s", gotd_proc_names[proc_id]); if (verbosity) { @@ -1808,13 +1808,9 @@ main(int argc, char **argv) fatal("cannot listen on unix socket %s", gotd.unix_socket_path); } - if (daemonize && daemon(0, 0) == -1) - fatal("daemon"); } else if (proc_id == PROC_AUTH) { snprintf(title, sizeof(title), "%s %s", gotd_proc_names[proc_id], repo_path); - if (daemonize && daemon(0, 0) == -1) - fatal("daemon"); } else if (proc_id == PROC_REPO_READ || proc_id == PROC_REPO_WRITE || proc_id == PROC_SESSION) { error = got_repo_pack_fds_open(&pack_fds); @@ -1827,8 +1823,6 @@ main(int argc, char **argv) fatalx("repository path not specified"); snprintf(title, sizeof(title), "%s %s", gotd_proc_names[proc_id], repo_path); - if (daemonize && daemon(0, 0) == -1) - fatal("daemon"); } else fatal("invalid process id %d", proc_id);
gotd PID issue