| 1267 | } |
| 1268 | |
| 1269 | static int |
| 1270 | crm_read_pidfile(const char *filename) |
| 1271 | { |
| 1272 | int fd; |
| 1273 | long pid = -1; |
| 1274 | char buf[LOCKSTRLEN + 1]; |
| 1275 | |
| 1276 | if ((fd = open(filename, O_RDONLY)) < 0) { |
| 1277 | goto bail; |
| 1278 | } |
| 1279 | |
| 1280 | if (read(fd, buf, sizeof(buf)) < 1) { |
| 1281 | goto bail; |
| 1282 | } |
| 1283 | |
| 1284 | if (sscanf(buf, "%lu", &pid) > 0) { |
| 1285 | if (pid <= 0) { |
| 1286 | pid = -ESRCH; |
| 1287 | } |
| 1288 | } |
| 1289 | |
| 1290 | bail: |
| 1291 | if (fd >= 0) { |
| 1292 | close(fd); |
| 1293 | } |
| 1294 | return pid; |
| 1295 | } |
| 1296 | |
| 1297 | static int |
| 1298 | crm_pidfile_inuse(const char *filename, long mypid) |