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;
#define crm_notice(fmt, args...)
unsigned int pcmk__procfs_num_cores(void)
int pcmk__pid_active(pid_t pid, const char *daemon)
#define crm_perror(level, fmt, args...)
Send a system error message to both the log and stderr.
pid_t pcmk__procfs_pid_of(const char *name)
bool pcmk__starts_with(const char *str, const char *prefix)
Check whether a string starts with a certain sequence.
#define crm_info(fmt, args...)