aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2008-04-30 10:55:42 +0000
committerRoy Marples <roy@marples.name>2008-04-30 10:55:42 +0000
commit10910876d1a9e53bae464864b735e99642cbc26e (patch)
treeadd673f8c4ffabb836a23695b7a5e360902cc53a /src
parent35b4978152b8591926dbe7e67e7ff6ede184f34e (diff)
Make the function a little smaller.
Diffstat (limited to 'src')
-rw-r--r--src/librc/librc-daemon.c34
1 files changed, 15 insertions, 19 deletions
diff --git a/src/librc/librc-daemon.c b/src/librc/librc-daemon.c
index 0bb0087e..f8134b59 100644
--- a/src/librc/librc-daemon.c
+++ b/src/librc/librc-daemon.c
@@ -56,30 +56,27 @@ static size_t strlcpy(char *dst, const char *src, size_t size)
#endif
#if defined(__linux__)
+
static bool pid_is_cmd(pid_t pid, const char *cmd)
{
char buffer[32];
FILE *fp;
int c;
+ bool retval = false;
snprintf(buffer, sizeof(buffer), "/proc/%d/stat", pid);
- if ((fp = fopen(buffer, "r")) == NULL)
- return false;
-
- while ((c = getc(fp)) != EOF && c != '(')
- ;
-
- if (c != '(') {
+ if ((fp = fopen(buffer, "r"))) {
+ while ((c = getc(fp)) != EOF && c != '(')
+ ;
+ if (c == '(') {
+ while ((c = getc(fp)) != EOF && c == *cmd)
+ cmd++;
+ if (c == ')' && *cmd == '\0')
+ retval = true;
+ }
fclose(fp);
- return false;
}
-
- while ((c = getc(fp)) != EOF && c == *cmd)
- cmd++;
-
- fclose(fp);
-
- return (c == ')' && *cmd == '\0') ? true : false;
+ return retval;
}
static bool pid_is_exec(pid_t pid, const char *const *argv)
@@ -101,7 +98,7 @@ static bool pid_is_exec(pid_t pid, const char *const *argv)
if (strlen(buffer) > 10) {
p = buffer + (strlen(buffer) - 10);
if (strcmp(p, " (deleted)") == 0) {
- *p = 0;
+ *p = '\0';
if (strcmp(buffer, *argv) == 0)
return true;
}
@@ -114,11 +111,10 @@ static bool pid_is_exec(pid_t pid, const char *const *argv)
r = read(fd, buffer, sizeof(buffer));
close(fd);
-
if (r == -1)
- return 0;
+ return false;
- buffer[r] = 0;
+ buffer[r] = '\0';
p = buffer;
while (*argv) {
if (strcmp(*argv, p) != 0)