20 #include <sys/types.h> 40 pcmk__procfs_process_info(
const 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;
181 #if HAVE_LINUX_PROCFS 182 char procfs_exe_path[PATH_MAX];
185 if (snprintf(procfs_exe_path, PATH_MAX,
"/proc/%lld/exe",
186 (
long long)
pid) >= PATH_MAX) {
190 link_rc = readlink(procfs_exe_path,
path, path_size - 1);
193 }
else if (link_rc >= (path_size - 1)) {
197 path[link_rc] =
'\0';
201 #endif // HAVE_LINUX_PROCFS 213 #if HAVE_LINUX_PROCFS 214 static bool have_pids =
false;
215 static bool checked =
false;
226 #endif // HAVE_LINUX_PROCFS #define crm_notice(fmt, args...)
int pcmk__procfs_pid2path(pid_t pid, char path[], size_t path_size)
bool pcmk__procfs_has_pids(void)
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...)