diff options
| author | Sami Kerola <kerolasa@iki.fi> | 2013-03-07 20:02:46 +0000 |
|---|---|---|
| committer | Karel Zak <kzak@redhat.com> | 2013-03-12 15:24:04 +0100 |
| commit | ea72260cbebcc2e2c98ae4ea5de4e6debba2a472 (patch) | |
| tree | 7386519a973ff67e943af5a1739161a19d53d199 /misc-utils/procs.c | |
| parent | 44e5fcddc0b510c21bb050a471530f1d8c538d69 (diff) | |
| download | util-linux-ea72260cbebcc2e2c98ae4ea5de4e6debba2a472.tar.gz | |
kill, procs: use pid_t for pids
Reference: http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/include/linux/threads.h#n30
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'misc-utils/procs.c')
| -rw-r--r-- | misc-utils/procs.c | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/misc-utils/procs.c b/misc-utils/procs.c index f3057fe1ef..dff7a7063b 100644 --- a/misc-utils/procs.c +++ b/misc-utils/procs.c @@ -28,16 +28,16 @@ extern char *mybasename (char *); static char *parse_parens (char *buf); -int * +pid_t * get_pids (char *process_name, int get_all) { DIR *dir; struct dirent *ent; int status; - char *dname, fname[100], *cp, buf[256]; + char fname[100], *cp, buf[256], *end; struct stat st; uid_t uid; FILE *fp; - int pid, *pids, num_pids, pids_size; + pid_t pid, *pids, num_pids, pids_size; dir = opendir ("/proc"); if (! dir) { @@ -49,10 +49,10 @@ get_pids (char *process_name, int get_all) { num_pids = pids_size = 0; while ((ent = readdir (dir)) != NULL) { - dname = ent->d_name; - if (! isdigit (*dname)) continue; - pid = atoi (dname); - sprintf (fname, "/proc/%d/cmdline", pid); + pid = strtol(ent->d_name, &end, 10); + if (errno || ent->d_name == end || (end && *end)) + continue; + sprintf (fname, "/proc/%ld/cmdline", (long)pid); /* get the process owner */ status = stat (fname, &st); if (status != 0) continue; @@ -65,7 +65,7 @@ get_pids (char *process_name, int get_all) { /* an empty command line means the process is swapped out */ if (! cp || ! *cp) { /* get the process name from the statfile */ - sprintf (fname, "/proc/%d/stat", pid); + sprintf (fname, "/proc/%ld/stat", (long)pid); fp = fopen (fname, "r"); if (! fp) continue; cp = fgets (buf, sizeof (buf), fp); @@ -78,7 +78,7 @@ get_pids (char *process_name, int get_all) { if (strcmp (process_name, mybasename (cp))) continue; while (pids_size < num_pids + 2) { pids_size += 5; - pids = (int *) xrealloc (pids, sizeof (int) * pids_size); + pids = xrealloc (pids, sizeof(pid_t) * pids_size); } if (pids) { pids[num_pids++] = pid; |
