aboutsummaryrefslogtreecommitdiff
path: root/src/librc
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2008-04-30 15:26:29 +0000
committerRoy Marples <roy@marples.name>2008-04-30 15:26:29 +0000
commit208443fa0ecb600ce5c4122b32d9af2f2667a226 (patch)
treea32e42d62ecbca88bb0ac679684a5f836c9aafe8 /src/librc
parenta818eebf7b1064ed2c42eb37c23ecd73ee39d327 (diff)
Save a few bytes and make it easier to read.
Diffstat (limited to 'src/librc')
-rw-r--r--src/librc/librc-daemon.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/src/librc/librc-daemon.c b/src/librc/librc-daemon.c
index e1f32211..e2e3bbf1 100644
--- a/src/librc/librc-daemon.c
+++ b/src/librc/librc-daemon.c
@@ -85,18 +85,20 @@ static bool pid_is_exec(pid_t pid, const char *const *argv)
char buffer[PATH_MAX];
char *p;
int fd;
- int r;
+ ssize_t bytes;
/* Check it's the right binary */
snprintf(cmdline, sizeof(cmdline), "/proc/%u/exe", pid);
- memset(buffer, 0, sizeof(buffer));
- if (readlink(cmdline, buffer, sizeof(buffer)) != -1) {
+ bytes = readlink(cmdline, buffer, sizeof(buffer));
+ if (bytes > 0) {
+ buffer[bytes] = '\0';
if (strcmp(*argv, buffer) == 0)
return true;
/* We should cater for deleted binaries too */
- if (strlen(buffer) > 10) {
- p = buffer + (strlen(buffer) - 10);
+ bytes = strlen(buffer);
+ if (bytes) {
+ p = buffer + (bytes - 10);
if (strcmp(p, " (deleted)") == 0) {
*p = '\0';
if (strcmp(buffer, *argv) == 0)
@@ -109,12 +111,12 @@ static bool pid_is_exec(pid_t pid, const char *const *argv)
if ((fd = open(cmdline, O_RDONLY)) < 0)
return false;
- r = read(fd, buffer, sizeof(buffer));
+ bytes = read(fd, buffer, sizeof(buffer));
close(fd);
- if (r == -1)
+ if (bytes == -1)
return false;
- buffer[r] = '\0';
+ buffer[bytes] = '\0';
p = buffer;
while (*argv) {
if (strcmp(*argv, p) != 0)