| 2184 | } |
| 2185 | |
| 2186 | int 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 | |
| 2224 | struct template_dir_cb_data { |
| 2225 | char *path; |
no test coverage detected