[Crash-utility] [PATCH] cmdline: allow to specify a script directly in pipeline

Kazuhito Hagio k-hagio at ab.jp.nec.com
Thu Sep 27 16:49:26 UTC 2018


Currently, when using pipe in command line, we cannot specify
a script with shebang directly like this:

  crash> foreach bt | ./analyze.awk
  crash: pipe operation failed

  (or it looks like crash can loop until Ctrl-C depending on timing)

This is a bit confusing and inconvenient because it's not shell-like
behavior.

The cause is that output_command_to_pids() searches /proc/PID/stat
files for "(path/to/script)" string and cannot find such process,
and also the ps kludge doesn't work well in this case.  This patch
removes the part except its file name like "(script)" so that it can
find the process.

Signed-off-by: Kazuhito Hagio <k-hagio at ab.jp.nec.com>
---
 cmdline.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/cmdline.c b/cmdline.c
index ee08f06..c0a9f4f 100644
--- a/cmdline.c
+++ b/cmdline.c
@@ -806,7 +806,7 @@ output_command_to_pids(void)
         char buf1[BUFSIZE];
         char buf2[BUFSIZE];
         char lookfor[BUFSIZE+2];
-        char *pid, *name, *status, *p_pid, *pgrp;
+        char *pid, *name, *status, *p_pid, *pgrp, *comm;
 	char *arglist[MAXARGS];
 	int argc;
 	FILE *pipe;
@@ -815,7 +815,8 @@ output_command_to_pids(void)
 	retries = 0;
 	shell_has_exited = FALSE;
 	pc->pipe_pid = pc->pipe_shell_pid = 0;
-        sprintf(lookfor, "(%s)", pc->pipe_command);
+	comm = strrchr(pc->pipe_command, '/');
+	sprintf(lookfor, "(%s)", comm ? ++comm : pc->pipe_command);
 	stall(1000);
 retry:
         if (is_directory("/proc") && (dirp = opendir("/proc"))) {
-- 
1.8.3.1




More information about the Crash-utility mailing list