Adjust 'after' so that it tries more rigorously to parse the input master git-svn
authorsimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Mon, 3 Dec 2012 18:58:16 +0000 (18:58 +0000)
committersimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Mon, 3 Dec 2012 18:58:16 +0000 (18:58 +0000)
pid, and hence will complain about 'NONE' or 'MULTIPLE' as output by
'pid'. Correspondingly, adjust some comments in 'pid', including in
particular suggesting its use with 'after'.

git-svn-id: svn://svn.tartarus.org/sgt/utils@9719 cda61777-01e9-0310-a592-d414129be87e

after/after.c
pid/pid.but
pid/pid.c

index af8b3a5..eb74813 100644 (file)
@@ -274,7 +274,14 @@ int main(int argc, char **argv)
                fprintf(stderr, "%s: parameter `%s' unexpected\n", pname, p);
                return 1;
            } else {
-               pid = atoi(p);
+                char *end;
+                errno = 0;
+               pid = strtol(p, &end, 0);
+                if (errno == ERANGE || *end || pid < 0) {
+                    fprintf(stderr, "%s: unable to parse `%s' as a pid\n",
+                            pname, p);
+                    return 1;
+                }
            }
        }
     }
index 8f424e6..c8075c9 100644 (file)
@@ -37,12 +37,12 @@ By default, \cw{pid} outputs exactly one process ID, or the word
 \cq{NONE} or \cq{MULTIPLE} if it finds no matching process or more
 than one. This is a mode suitable for use as an argument to
 \cw{strace} (which expects exactly one process ID after its \cw{-p}
-argument) or \cw{gdb} (which expects a single pid too); the \cq{NONE}
-or \cq{MULTIPLE} answers will provoke a command-line parsing error
-rather than trying to trace the wrong process or expanding to a less
-obviously wrong command line. Use the \cw{-a} option to instead make
-\cw{pid} output a full list of pids that match (e.g. if you want to
-pass them all to \cw{kill}(\e{1}).
+argument) or \cw{gdb} or \cw{after} (which expect a single pid as an
+argument); the \cq{NONE} or \cq{MULTIPLE} answers will provoke a
+command-line parsing error rather than trying to trace the wrong
+process or expanding to a less obviously wrong command line. Use the
+\cw{-a} option to instead make \cw{pid} output a full list of pids
+that match (e.g. if you want to pass them all to \cw{kill}(\e{1}).
 
 You can also provide arguments to the command you're searching for, to
 narrow your search further. For example, if you have several
index da2f6ad..5d3245a 100644 (file)
--- a/pid/pid.c
+++ b/pid/pid.c
@@ -3,9 +3,11 @@
  *
  * Same basic idea as Debian's "pidof", in that you type 'pid command'
  * and it finds a process running that command and gives you the pid;
- * but souped up with various pragmatic features such as recognising
- * well known interpreters (so you can search for, say, 'pid
- * script.sh' as well as 'pid bash' and have it do what you meant).
+ * but differs in details, for example it will search for scripts by
+ * default rather than requiring pidof's -x option, and it will also
+ * look for command-line arguments ('pid make test') and try to find
+ * the parent process of a bunch of forks from the same shell script
+ * invocation.
  *
  * Currently tested only on Linux using /proc directly, but I've tried
  * to set it up so that the logic of what processes to choose is