summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 242924c)
raw | patch | inline | side by side (parent: 242924c)
author | Jan Andres <jandres@gmx.net> | |
Sat, 31 Jan 2015 09:00:31 +0000 (10:00 +0100) | ||
committer | Marc Fournier <marc.fournier@camptocamp.com> | |
Tue, 19 May 2015 15:43:35 +0000 (17:43 +0200) |
pid_t may be defined as an int or a long depending on circumstances.
Use a long everywhere so we don't have to fiddle with typecasts.
This fixes an issue where an incorrect printf format string would
be used for a pid_t in 32-bit builds.
Use a long everywhere so we don't have to fiddle with typecasts.
This fixes an issue where an incorrect printf format string would
be used for a pid_t in 32-bit builds.
src/processes.c | patch | blob | history |
diff --git a/src/processes.c b/src/processes.c
index 71295fe35fcab2668a6cd433024b5d8be78d3e4f..baec9a9438785666531ce319d6fb3e11648ed7fa 100644 (file)
--- a/src/processes.c
+++ b/src/processes.c
#endif /*KERNEL_LINUX */
#if KERNEL_SOLARIS
-static const char *ps_get_cmdline (pid_t pid, /* {{{ */
+static const char *ps_get_cmdline (long pid, /* {{{ */
char *buffer, size_t buffer_size)
{
char path[PATH_MAX];
psinfo_t info;
int status;
- snprintf(path, sizeof (path), "/proc/%i/psinfo", pid);
+ snprintf(path, sizeof (path), "/proc/%li/psinfo", pid);
status = read_file_contents (path, (void *) &info, sizeof (info));
if (status != sizeof (info))
* The values for input and ouput chars are calculated "by hand"
* Added a few "solaris" specific process states as well
*/
-static int ps_read_process(int pid, procstat_t *ps, char *state)
+static int ps_read_process(long pid, procstat_t *ps, char *state)
{
char filename[64];
char f_psinfo[64], f_usage[64];
psinfo_t *myInfo;
prusage_t *myUsage;
- snprintf(filename, sizeof (filename), "/proc/%i/status", pid);
- snprintf(f_psinfo, sizeof (f_psinfo), "/proc/%i/psinfo", pid);
- snprintf(f_usage, sizeof (f_usage), "/proc/%i/usage", pid);
+ snprintf(filename, sizeof (filename), "/proc/%li/status", pid);
+ snprintf(f_psinfo, sizeof (f_psinfo), "/proc/%li/psinfo", pid);
+ snprintf(f_usage, sizeof (f_usage), "/proc/%li/usage", pid);
buffer = malloc(sizeof (pstatus_t));
while ((ent = readdir(proc)) != NULL)
{
- int pid;
+ long pid;
struct procstat ps;
procstat_entry_t pse;
+ char *endptr;
if (!isdigit ((int) ent->d_name[0]))
continue;
- if ((pid = atoi (ent->d_name)) < 1)
+ pid = strtol (ent->d_name, &endptr, 10);
+ if (*endptr != 0) /* value didn't completely parse as a number */
continue;
status = ps_read_process (pid, &ps, &state);
ps_list_add (ps.name,
- ps_get_cmdline ((pid_t) pid,
- cmdline, sizeof (cmdline)),
+ ps_get_cmdline (pid, cmdline, sizeof (cmdline)),
&pse);
} /* while(readdir) */
closedir (proc);