]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
kill, procs: use pid_t for pids
authorSami Kerola <kerolasa@iki.fi>
Thu, 7 Mar 2013 20:02:46 +0000 (20:02 +0000)
committerKarel Zak <kzak@redhat.com>
Tue, 12 Mar 2013 14:24:04 +0000 (15:24 +0100)
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>
misc-utils/kill.c
misc-utils/kill.h
misc-utils/procs.c

index bce3348c96e4caa3b55a21d51c66373b64c842ba..051f56d8ff8d80ae0a12a69a049a55bc2d820d54 100644 (file)
@@ -158,7 +158,7 @@ int main (int argc, char *argv[])
     int errors, numsig, pid;
     char *ep, *arg;
     int do_pid, do_kill, check_all;
-    int *pids, *ip;
+    pid_t *pids, *ip;
 
     setlocale(LC_ALL, "");
     bindtextdomain(PACKAGE, LOCALEDIR);
@@ -422,12 +422,12 @@ static int usage(int status)
        return status;
 }
 
-static int kill_verbose (char *procname, int pid, int sig)
+static int kill_verbose (char *procname, pid_t pid, int sig)
 {
     int rc;
 
     if (sig < 0) {
-       printf ("%d\n", pid);
+       printf ("%ld\n", (long)pid);
        return 0;
     }
 #ifdef HAVE_SIGQUEUE
index 27a12a805a3e96af359f5966d184694341cb3e96..107f8019b3c066ff90f506e73ff5fe2884040551 100644 (file)
@@ -1 +1 @@
-extern int *get_pids (char *process_name, int get_all);
+extern pid_t *get_pids (char *process_name, int get_all);
index f3057fe1ef30c2251f34ea3af6c73270eb09dc07..dff7a7063b371faba845d2af8fbf537337804e56 100644 (file)
 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;