16 #include <sys/types.h> 36 pcmk__procfs_process_info(
const struct dirent *entry,
char *
name, pid_t *
pid)
41 char procpath[128] = { 0 };
48 local_pid = atoi(entry->d_name);
49 if ((local_pid <= 0) || (strlen(entry->d_name) > 114)) {
53 *
pid = (pid_t) local_pid;
57 strcpy(procpath,
"/proc/");
58 strcat(procpath, entry->d_name);
59 fd = open(procpath, O_RDONLY);
63 if (fstat(fd, &statbuf) < 0) {
70 if (!S_ISDIR(statbuf.st_mode)) {
79 strcat(procpath,
"/status");
80 file = fopen(procpath,
"r");
84 if (fscanf(file,
"Name:\t%15[^\n]",
name) != 1) {
110 struct dirent *entry;
112 char entry_name[64] = { 0 };
114 dp = opendir(
"/proc");
116 crm_notice(
"Can not read /proc directory to track existing components");
120 while ((entry = readdir(dp)) != NULL) {
121 if ((pcmk__procfs_process_info(entry, entry_name, &
pid) ==
pcmk_rc_ok)
147 stream = fopen(
"/proc/stat",
"r");
148 if (stream == NULL) {
149 crm_perror(LOG_INFO,
"Could not open /proc/stat");
153 while (fgets(buffer,
sizeof(buffer), stream)) {
160 return cores? cores : 1;
177 #if HAVE_LINUX_PROCFS 178 char procfs_exe_path[PATH_MAX];
181 if (snprintf(procfs_exe_path, PATH_MAX,
"/proc/%lld/exe",
182 (
long long)
pid) >= PATH_MAX) {
186 link_rc = readlink(procfs_exe_path,
path, path_size - 1);
189 }
else if (link_rc >= (path_size - 1)) {
193 path[link_rc] =
'\0';
197 #endif // HAVE_LINUX_PROCFS 209 #if HAVE_LINUX_PROCFS 210 static bool have_pids =
false;
211 static bool checked =
false;
222 #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...)