20 #include <sys/types.h>
40 pcmk__procfs_process_info(
struct dirent *entry,
char *
name, pid_t *
pid)
45 char procpath[128] = { 0 };
52 local_pid = atoi(entry->d_name);
53 if ((local_pid <= 0) || (strlen(entry->d_name) > 114)) {
57 *
pid = (pid_t) local_pid;
61 strcpy(procpath,
"/proc/");
62 strcat(procpath, entry->d_name);
63 fd = open(procpath, O_RDONLY);
67 if (fstat(fd, &statbuf) < 0) {
74 if (!S_ISDIR(statbuf.st_mode)) {
83 strcat(procpath,
"/status");
84 file = fopen(procpath,
"r");
88 if (fscanf(file,
"Name:\t%15[^\n]",
name) != 1) {
114 struct dirent *entry;
116 char entry_name[64] = { 0 };
118 dp = opendir(
"/proc");
120 crm_notice(
"Can not read /proc directory to track existing components");
124 while ((entry = readdir(dp)) != NULL) {
125 if ((pcmk__procfs_process_info(entry, entry_name, &
pid) ==
pcmk_rc_ok)
151 stream = fopen(
"/proc/stat",
"r");
152 if (stream == NULL) {
153 crm_perror(LOG_INFO,
"Could not open /proc/stat");
157 while (fgets(buffer,
sizeof(buffer), stream)) {
164 return cores? cores : 1;