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

Function crm_lock_pidfile

lib/common/utils.c:1332–1363  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1330}
1331
1332static int
1333crm_lock_pidfile(const char *filename)
1334{
1335 long mypid = 0;
1336 int fd = 0, rc = 0;
1337 char buf[LOCKSTRLEN + 1];
1338
1339 mypid = (unsigned long)getpid();
1340
1341 rc = crm_pidfile_inuse(filename, 0);
1342 if(rc != pcmk_ok && rc != -ENOENT) {
1343 /* locked by existing process - give up */
1344 return -1;
1345 }
1346
1347 if ((fd = open(filename, O_CREAT | O_WRONLY | O_EXCL, 0644)) < 0) {
1348 /* Hmmh, why did we fail? Anyway, nothing we can do about it */
1349 return -errno;
1350 }
1351
1352 snprintf(buf, sizeof(buf), "%*lu\n", LOCKSTRLEN - 1, mypid);
1353 rc = write(fd, buf, LOCKSTRLEN);
1354 close(fd);
1355
1356 if(rc != LOCKSTRLEN) {
1357 crm_perror(LOG_ERR, "Incomplete write to %s", filename);
1358 return -errno;
1359
1360 }
1361
1362 return crm_pidfile_inuse(filename, mypid);
1363}
1364
1365void
1366crm_make_daemon(const char *name, gboolean daemonize, const char *pidfile)

Callers 1

crm_make_daemonFunction · 0.85

Calls 1

crm_pidfile_inuseFunction · 0.85

Tested by

no test coverage detected