Make the function a little smaller.
This commit is contained in:
parent
35b4978152
commit
10910876d1
@ -56,30 +56,27 @@ static size_t strlcpy(char *dst, const char *src, size_t size)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__linux__)
|
#if defined(__linux__)
|
||||||
|
|
||||||
static bool pid_is_cmd(pid_t pid, const char *cmd)
|
static bool pid_is_cmd(pid_t pid, const char *cmd)
|
||||||
{
|
{
|
||||||
char buffer[32];
|
char buffer[32];
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
int c;
|
int c;
|
||||||
|
bool retval = false;
|
||||||
|
|
||||||
snprintf(buffer, sizeof(buffer), "/proc/%d/stat", pid);
|
snprintf(buffer, sizeof(buffer), "/proc/%d/stat", pid);
|
||||||
if ((fp = fopen(buffer, "r")) == NULL)
|
if ((fp = fopen(buffer, "r"))) {
|
||||||
return false;
|
while ((c = getc(fp)) != EOF && c != '(')
|
||||||
|
;
|
||||||
while ((c = getc(fp)) != EOF && c != '(')
|
if (c == '(') {
|
||||||
;
|
while ((c = getc(fp)) != EOF && c == *cmd)
|
||||||
|
cmd++;
|
||||||
if (c != '(') {
|
if (c == ')' && *cmd == '\0')
|
||||||
|
retval = true;
|
||||||
|
}
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
return retval;
|
||||||
while ((c = getc(fp)) != EOF && c == *cmd)
|
|
||||||
cmd++;
|
|
||||||
|
|
||||||
fclose(fp);
|
|
||||||
|
|
||||||
return (c == ')' && *cmd == '\0') ? true : false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool pid_is_exec(pid_t pid, const char *const *argv)
|
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) {
|
if (strlen(buffer) > 10) {
|
||||||
p = buffer + (strlen(buffer) - 10);
|
p = buffer + (strlen(buffer) - 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)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -114,11 +111,10 @@ static bool pid_is_exec(pid_t pid, const char *const *argv)
|
|||||||
|
|
||||||
r = read(fd, buffer, sizeof(buffer));
|
r = read(fd, buffer, sizeof(buffer));
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
if (r == -1)
|
if (r == -1)
|
||||||
return 0;
|
return false;
|
||||||
|
|
||||||
buffer[r] = 0;
|
buffer[r] = '\0';
|
||||||
p = buffer;
|
p = buffer;
|
||||||
while (*argv) {
|
while (*argv) {
|
||||||
if (strcmp(*argv, p) != 0)
|
if (strcmp(*argv, p) != 0)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user