| 1363 | } |
| 1364 | |
| 1365 | void |
| 1366 | crm_make_daemon(const char *name, gboolean daemonize, const char *pidfile) |
| 1367 | { |
| 1368 | long pid; |
| 1369 | const char *devnull = "/dev/null"; |
| 1370 | |
| 1371 | if (daemonize == FALSE) { |
| 1372 | return; |
| 1373 | } |
| 1374 | |
| 1375 | pid = fork(); |
| 1376 | if (pid < 0) { |
| 1377 | fprintf(stderr, "%s: could not start daemon\n", name); |
| 1378 | crm_perror(LOG_ERR, "fork"); |
| 1379 | crm_exit(EX_USAGE); |
| 1380 | |
| 1381 | } else if (pid > 0) { |
| 1382 | crm_exit(EX_OK); |
| 1383 | } |
| 1384 | |
| 1385 | if (crm_lock_pidfile(pidfile) < 0) { |
| 1386 | pid = crm_read_pidfile(pidfile); |
| 1387 | if (crm_pid_active(pid) > 0) { |
| 1388 | crm_warn("%s: already running [pid %ld] (%s).\n", name, pid, pidfile); |
| 1389 | crm_exit(EX_OK); |
| 1390 | } |
| 1391 | } |
| 1392 | |
| 1393 | umask(S_IWGRP | S_IWOTH | S_IROTH); |
| 1394 | |
| 1395 | close(STDIN_FILENO); |
| 1396 | (void)open(devnull, O_RDONLY); /* Stdin: fd 0 */ |
| 1397 | close(STDOUT_FILENO); |
| 1398 | (void)open(devnull, O_WRONLY); /* Stdout: fd 1 */ |
| 1399 | close(STDERR_FILENO); |
| 1400 | (void)open(devnull, O_WRONLY); /* Stderr: fd 2 */ |
| 1401 | } |
| 1402 | |
| 1403 | gboolean |
| 1404 | crm_is_writable(const char *dir, const char *file, |
no test coverage detected