From 1db144c6779b29b9de42626057442a419fae4bce Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Thu, 9 Jul 2015 03:24:20 +0200 Subject: [PATCH] Functions pidfile_read() and pidfile_poll() now provied by libite. Signed-off-by: Joachim Nilsson --- helpers.h | 3 --- libite | 2 +- pid.c | 75 ------------------------------------------------------- 3 files changed, 1 insertion(+), 79 deletions(-) diff --git a/helpers.h b/helpers.h index 3c589fe1..80648c05 100644 --- a/helpers.h +++ b/helpers.h @@ -74,9 +74,6 @@ void runlevel_set (int pre, int now); int runlevel_get (void); char *runlevel_string (int levels); -pid_t pidfile_read (char *pidfile); -pid_t pidfile_poll (char *cmd, char *path); - int pid_alive (pid_t pid); char *pid_get_name (pid_t pid, char *name, size_t len); diff --git a/libite b/libite index e4c5a0e7..8db31462 160000 --- a/libite +++ b/libite @@ -1 +1 @@ -Subproject commit e4c5a0e77eb319883c4d680f466da2fb97675a33 +Subproject commit 8db314623a682913cf565835ff3326a81cc609b9 diff --git a/pid.c b/pid.c index 8298f22d..22dffcc1 100644 --- a/pid.c +++ b/pid.c @@ -31,81 +31,6 @@ #include "libite/lite.h" -/** - * pidfile_read - Reads a PID value from a pidfile. - * @pidfile: File containing PID, usually in /var/run/.pid - * - * This function takes a @pidfile and returns the PID found therein. - * - * Returns: - * On invalid @pidfile -1 and @errno set to %EINVAL, when @pidfile does not exist -1 - * and errno set to %ENOENT. When the pidfile is empty or when its contents cannot - * be translated this function returns zero (0), on success this function returns - * a PID value greater than one. PID 1 is reserved for the system init process. - */ -pid_t pidfile_read(char *pidfile) -{ - pid_t pid = 0; - char buf[16]; - FILE *fp; - - if (!pidfile) { - errno = EINVAL; - return -1; - } - - if (!fexist(pidfile)) - return -1; - - fp = fopen(pidfile, "r"); - if (!fp) - return -1; - - if (fgets(buf, sizeof(buf), fp)) { - errno = 0; - pid = (pid_t)strtol(buf, NULL, 10); - if (errno) - pid = 0; /* Failed conversion. */ - } - fclose(fp); - - return pid; -} - -/** - * pidfile_poll - Poll for the existence of a pidfile and return PID - * @cmd: Process name, or command, called to expect a pidfile - * @path: Path to pidfile to poll for - * - * This function polls for the pidfile at @path for at most 5 seconds - * before timing out. If the file is created within that time span the - * file is read and its PID contents returned. - * - * Returns: - * The PID read from @path, or zero on timeout. - */ -pid_t pidfile_poll(char *cmd, char *path) -{ - pid_t pid = 0; - int tries = 0; - - /* Timeout = 100 * 50ms = 5s */ - while (!fexist(path) && tries++ < 100) { - /* Wait 50ms between retries */ - usleep(50000); - } - - if (!fexist(path)) { - _e("Timeout! No PID found for %s, pidfile %s does not exist?", cmd, path); - pid = 0; - } else { - pid = pidfile_read(path); - } - - return pid; -} - - /** * pid_alive - Check if a given process ID is running * @pid: Process ID to check for.