unix/fiss

src/supervise/need_restart.c in master
Repositories | Summary | Log | Files | LICENSE

need_restart.c (569B) download


 1#include "common.h"
 2#include "defs.h"
 3
 4#include <fcntl.h>
 5#include <stdbool.h>
 6
 7
 8bool need_restart(void) {
 9	struct flock lock = {
10		.l_type   = F_WRLCK,
11		.l_whence = SEEK_SET,
12		.l_start  = 0,
13		.l_len    = 0
14	};
15
16	if (service.should_restart)
17		return true;
18
19	if (fcntl(service.supervise.lock, F_GETLK, &lock) == -1)
20		errprint("unable to retrieve locks of 'supervise/depends'");
21	// F_SETLK could throw if lock couldn't be placed, F_GETLK should not throw
22	THROW_MIN(, "unable to retrieve locks of 'supervise/depends'", EXIT_PERM);
23
24	return lock.l_type != F_ULOCK;
25}