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

Dave Anderson anderson at redhat.com
Thu Sep 27 19:14:11 UTC 2018



----- Original Message -----
> 
> On 9/27/2018 1:42 PM, Dave Anderson wrote:
> > 
> > 
> > ----- Original Message -----
> >> 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.
> > 
> > Just to clarify, is this is due to using "./analyze.awk" (with the preceding "./"), 
> > whereas if you were to use "analyze.awk", it would work OK?
> 
> No, it doesn't because "sh -c analyze.awk" does not work.
> This behavior will not change with this patch, and I think
> it should not change.
> 
> [before]
>   crash> bt | awk -f analyze.awk
>   analyzed
>   crash> bt | ./analyze.awk
>   crash: pipe operation failed
>   crash> bt | analyze.awk
>   sh: analyze.awk: command not found
>   crash: pipe operation failed
> 
> [after]
>   crash> bt | awk -f analyze.awk
>   analyzed
>   crash> bt | ./analyze.awk
>   analyzed
>   crash> bt | analyze.awk
>   sh: analyze.awk: command not found
>   crash: pipe operation failed
> 
> Thanks,
> Kazu

OK, it appears that if the output script (with #!) is specified beginning
with either "./" or "/" it would fail.  (and works OK with the patch)

Dave

  
> > 
> > Dave
> > 
> > 
> >>
> >> 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
> >>
> >> --
> >> Crash-utility mailing list
> >> Crash-utility at redhat.com
> >> https://www.redhat.com/mailman/listinfo/crash-utility
> >>
> > 
> > --
> > Crash-utility mailing list
> > Crash-utility at redhat.com
> > https://www.redhat.com/mailman/listinfo/crash-utility
> > 
> 
> --
> Crash-utility mailing list
> Crash-utility at redhat.com
> https://www.redhat.com/mailman/listinfo/crash-utility
> 




More information about the Crash-utility mailing list