Save a few bytes and make it easier to read.
This commit is contained in:
parent
a818eebf7b
commit
208443fa0e
@ -85,18 +85,20 @@ static bool pid_is_exec(pid_t pid, const char *const *argv)
|
|||||||
char buffer[PATH_MAX];
|
char buffer[PATH_MAX];
|
||||||
char *p;
|
char *p;
|
||||||
int fd;
|
int fd;
|
||||||
int r;
|
ssize_t bytes;
|
||||||
|
|
||||||
/* Check it's the right binary */
|
/* Check it's the right binary */
|
||||||
snprintf(cmdline, sizeof(cmdline), "/proc/%u/exe", pid);
|
snprintf(cmdline, sizeof(cmdline), "/proc/%u/exe", pid);
|
||||||
memset(buffer, 0, sizeof(buffer));
|
bytes = readlink(cmdline, buffer, sizeof(buffer));
|
||||||
if (readlink(cmdline, buffer, sizeof(buffer)) != -1) {
|
if (bytes > 0) {
|
||||||
|
buffer[bytes] = '\0';
|
||||||
if (strcmp(*argv, buffer) == 0)
|
if (strcmp(*argv, buffer) == 0)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
/* We should cater for deleted binaries too */
|
/* We should cater for deleted binaries too */
|
||||||
if (strlen(buffer) > 10) {
|
bytes = strlen(buffer);
|
||||||
p = buffer + (strlen(buffer) - 10);
|
if (bytes) {
|
||||||
|
p = buffer + (bytes - 10);
|
||||||
if (strcmp(p, " (deleted)") == 0) {
|
if (strcmp(p, " (deleted)") == 0) {
|
||||||
*p = '\0';
|
*p = '\0';
|
||||||
if (strcmp(buffer, *argv) == 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)
|
if ((fd = open(cmdline, O_RDONLY)) < 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
r = read(fd, buffer, sizeof(buffer));
|
bytes = read(fd, buffer, sizeof(buffer));
|
||||||
close(fd);
|
close(fd);
|
||||||
if (r == -1)
|
if (bytes == -1)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
buffer[r] = '\0';
|
buffer[bytes] = '\0';
|
||||||
p = buffer;
|
p = buffer;
|
||||||
while (*argv) {
|
while (*argv) {
|
||||||
if (strcmp(*argv, p) != 0)
|
if (strcmp(*argv, p) != 0)
|
||||||
|
Loading…
Reference in New Issue
Block a user