MCPcopy Create free account
hub / github.com/ClusterLabs/pacemaker / crm_make_daemon

Function crm_make_daemon

lib/common/utils.c:1365–1401  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1363}
1364
1365void
1366crm_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
1403gboolean
1404crm_is_writable(const char *dir, const char *file,

Callers 2

mainFunction · 0.85
mainFunction · 0.85

Calls 4

crm_exitFunction · 0.85
crm_lock_pidfileFunction · 0.85
crm_read_pidfileFunction · 0.85
crm_pid_activeFunction · 0.85

Tested by

no test coverage detected