diff --git a/helpers.c b/helpers.c index 6ec86297..52beec94 100644 --- a/helpers.c +++ b/helpers.c @@ -116,6 +116,26 @@ void ifconfig(char *ifname, char *addr, char *mask, int up) close(sock); } +/** + * atonum - Convert string to integer + * @str: String value to convert. + * + * Returns: + * The converted (positive) number, or -1 on error, with @errno set. + */ +int atonum(char *str) +{ + int val; + char *end; + + errno = 0; + val = strtol(str, &end, 10); + if (errno || end == str) + return -1; + + return val; +} + /** * pidfile_read - Reads a PID value from a pidfile. @@ -294,11 +314,15 @@ int procname_kill(char *name, int signo) if (strncmp(pname, name, strlen(pname) - 1) == 0) { int error = errno; + int pid = atonum(entry->d_name); - if (kill(atoi(entry->d_name), signo)) { - FLOG_ERROR("Failed signalling(%d) %s: %s!", signo, name, strerror(error)); + if (-1 == pid) { + FLOG_ERROR("Failed converting %s to a PID: %s", entry->d_name, strerror(error)); } else { - result++; /* Track number of processes we deliver the signal to. */ + if (kill(pid, signo)) + FLOG_ERROR("Failed signalling(%d) %s: %s!", signo, name, strerror(error)); + else + result++; /* Track number of processes we deliver the signal to. */ } } } diff --git a/helpers.h b/helpers.h index ab2fe468..97aa8c7d 100644 --- a/helpers.h +++ b/helpers.h @@ -29,11 +29,11 @@ #include #define DO_LOG(level, fmt, args...) \ -{ \ +do { \ openlog("finit", LOG_CONS | LOG_PID, LOG_DAEMON); \ syslog(level, fmt, ##args); \ closelog(); \ -} +} while (0) #define FLOG_DEBUG(fmt, args...) DO_LOG(LOG_DEBUG, fmt, ##args) #define FLOG_INFO(fmt, args...) DO_LOG(LOG_INFO, fmt, ##args) @@ -94,6 +94,8 @@ extern int verbose; int makepath (char *path); void ifconfig (char *ifname, char *addr, char *mask, int up); +int atonum (char *str); + pid_t pidfile_read (char *pidfile); pid_t pidfile_poll (char *cmd, char *path);