MCPcopy Index your code
hub / github.com/git/git / daemonize

Function daemonize

setup.c:2186–2222  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2184}
2185
2186int daemonize(void)
2187{
2188#ifdef NO_POSIX_GOODIES
2189 errno = ENOSYS;
2190 return -1;
2191#else
2192 pid_t parent_pid = getpid();
2193 pid_t child_pid = fork();
2194
2195 switch (child_pid) {
2196 case 0:
2197 /*
2198 * We're in the child process, so we take ownership of
2199 * all tempfiles.
2200 */
2201 reassign_tempfile_ownership(parent_pid, getpid());
2202 break;
2203 case -1:
2204 die_errno(_("fork failed"));
2205 default:
2206 /*
2207 * We're in the parent process, so we drop ownership of
2208 * all tempfiles to prevent us from removing them upon
2209 * exit.
2210 */
2211 reassign_tempfile_ownership(parent_pid, child_pid);
2212 exit(0);
2213 }
2214 if (setsid() == -1)
2215 die_errno(_("setsid failed"));
2216 close(0);
2217 close(1);
2218 close(2);
2219 sanitize_stdfds();
2220 return 0;
2221#endif
2222}
2223
2224struct template_dir_cb_data {
2225 char *path;

Callers 3

cmd_mainFunction · 0.85
cmd_gcFunction · 0.85
maintenance_run_tasksFunction · 0.85

Calls 4

forkFunction · 0.85
die_errnoFunction · 0.85
sanitize_stdfdsFunction · 0.85

Tested by

no test coverage detected