| 1222 | #define LOCKSTRLEN 11 |
| 1223 | |
| 1224 | int |
| 1225 | crm_pid_active(long pid) |
| 1226 | { |
| 1227 | if (pid <= 0) { |
| 1228 | return -1; |
| 1229 | |
| 1230 | } else if (kill(pid, 0) < 0 && errno == ESRCH) { |
| 1231 | return 0; |
| 1232 | } |
| 1233 | #ifndef HAVE_PROC_PID |
| 1234 | return 1; |
| 1235 | #else |
| 1236 | { |
| 1237 | int rc = 0; |
| 1238 | int running = 0; |
| 1239 | char proc_path[PATH_MAX], exe_path[PATH_MAX], myexe_path[PATH_MAX]; |
| 1240 | |
| 1241 | /* check to make sure pid hasn't been reused by another process */ |
| 1242 | snprintf(proc_path, sizeof(proc_path), "/proc/%lu/exe", pid); |
| 1243 | |
| 1244 | rc = readlink(proc_path, exe_path, PATH_MAX - 1); |
| 1245 | if (rc < 0) { |
| 1246 | crm_perror(LOG_ERR, "Could not read from %s", proc_path); |
| 1247 | goto bail; |
| 1248 | } |
| 1249 | |
| 1250 | exe_path[rc] = 0; |
| 1251 | snprintf(proc_path, sizeof(proc_path), "/proc/%lu/exe", (long unsigned int)getpid()); |
| 1252 | rc = readlink(proc_path, myexe_path, PATH_MAX - 1); |
| 1253 | if (rc < 0) { |
| 1254 | crm_perror(LOG_ERR, "Could not read from %s", proc_path); |
| 1255 | goto bail; |
| 1256 | } |
| 1257 | |
| 1258 | myexe_path[rc] = 0; |
| 1259 | if (strcmp(exe_path, myexe_path) == 0) { |
| 1260 | running = 1; |
| 1261 | } |
| 1262 | } |
| 1263 | |
| 1264 | bail: |
| 1265 | return running; |
| 1266 | #endif |
| 1267 | } |
| 1268 | |
| 1269 | static int |
| 1270 | crm_read_pidfile(const char *filename) |
no outgoing calls
no test coverage detected