1 /* Copyright (C) 2009 Trend Micro Inc.
4 * This program is a free software; you can redistribute it
5 * and/or modify it under the terms of the GNU General Public
6 * License (version 2) as published by the FSF - Free Software
11 #include "rootcheck.h"
16 static char *_os_get_runps(const char *ps, int mpid)
19 char buf[OS_SIZE_2048 + 1];
20 char command[OS_SIZE_1024 + 1];
25 command[OS_SIZE_1024] = '\0';
27 snprintf(command, OS_SIZE_1024, "%s -p %d 2> /dev/null", ps, mpid);
28 fp = popen(command, "r");
30 while (fgets(buf, OS_SIZE_2048, fp) != NULL) {
31 tmp_str = strchr(buf, ':');
38 tmp_str = strchr(nbuf, ' ');
44 /* Remove whitespaces */
45 while (*tmp_str == ' ') {
51 tmp_str = strchr(nbuf, '\n');
57 return (strdup(nbuf));
66 /* Get list of Unix processes */
67 OSList *os_get_process_list()
70 pid_t max_pid = MAX_PID;
71 OSList *p_list = NULL;
72 char ps[OS_SIZE_1024 + 1];
74 /* Check where ps is */
75 memset(ps, '\0', OS_SIZE_1024 + 1);
76 strncpy(ps, "/bin/ps", OS_SIZE_1024);
78 strncpy(ps, "/usr/bin/ps", OS_SIZE_1024);
80 merror("%s: ERROR: 'ps' not found.", ARGV0);
85 /* Create process list */
86 p_list = OSList_Create();
88 merror(LIST_ERROR, ARGV0);
92 for (i = 1; i <= max_pid; i++) {
93 /* Check if the pid is present */
94 if ((!((getsid(i) == -1) && (errno == ESRCH))) &&
95 (!((getpgid(i) == -1) && (errno == ESRCH)))) {
99 p_name = _os_get_runps(ps, (int)i);
104 os_calloc(1, sizeof(Proc_Info), p_info);
105 p_info->p_path = p_name;
106 p_info->p_name = NULL;
107 OSList_AddData(p_list, p_info);