25 static pid_t last_asked_pid = 0;
33 if ((rc < 0) && (errno == ESRCH)) {
43 if (last_asked_pid !=
pid) {
44 crm_info(
"Cannot examine PID %lld: %s",
53 bool checked_through_kill = (rc == 0);
54 char exe_path[PATH_MAX], myexe_path[PATH_MAX];
60 if ((kill(
pid, 0) < 0) && (errno == ESRCH)) {
64 if (last_asked_pid !=
pid) {
66 crm_info(
"Could not get executable for PID %lld: %s " 70 crm_err(
"Could not get executable for PID %lld: %s " 78 return checked_through_kill?
pcmk_rc_ok : EACCES;
84 if (daemon[0] !=
'/') {
88 rc = snprintf(myexe_path,
sizeof(myexe_path),
"%s", daemon);
91 if (rc > 0 && rc <
sizeof(myexe_path) && !strcmp(exe_path, myexe_path)) {
116 long long pid_read = 0;
119 CRM_CHECK((filename != NULL) && (
pid != NULL),
return EINVAL);
121 fd = open(filename, O_RDONLY);
126 if ((fstat(fd, &sbuf) >= 0) && (sbuf.st_size <
LOCKSTRLEN)) {
132 if (read(fd, buf,
sizeof(buf)) < 1) {
138 rc = sscanf(buf,
"%lld", &pid_read);
145 *
pid = (pid_t) pid_read;
146 crm_trace(
"Read pid %lld from %s", pid_read, filename);
148 }
else if (rc == 0) {
173 const char *expected_name, pid_t *
pid)
175 pid_t pidfile_pid = 0;
187 }
else if ((expected_pid > 0) && (pidfile_pid == expected_pid)) {
196 }
else if ((expected_pid > 0) && (pidfile_pid != expected_pid)) {
216 pid_t mypid = getpid();
227 fd = open(filename, O_CREAT | O_WRONLY | O_EXCL, 0644);
232 snprintf(buf,
sizeof(buf),
"%*lld\n",
LOCKSTRLEN - 1, (
long long) mypid);
237 crm_perror(LOG_ERR,
"Incomplete write to %s", filename);
#define CRM_CHECK(expr, failure_action)
int pcmk__read_pidfile(const char *filename, pid_t *pid)
int pcmk__pid_active(pid_t pid, const char *daemon)
const char * pcmk_rc_str(int rc)
Get a user-friendly description of a return code.
bool pcmk__procfs_has_pids(void)
#define crm_trace(fmt, args...)
int pcmk__pidfile_matches(const char *filename, pid_t expected_pid, const char *expected_name, pid_t *pid)
#define crm_perror(level, fmt, args...)
Send a system error message to both the log and stderr.
#define crm_err(fmt, args...)
int pcmk__procfs_pid2path(pid_t pid, char path[], size_t path_size)
int pcmk__lock_pidfile(const char *filename, const char *name)
#define crm_info(fmt, args...)