[PATCH 3/4] support/shell-container.c: Add builtin kill

DJ Delorie dj@redhat.com
Tue Mar 24 19:37:34 GMT 2020


Adhemerval Zanella via Libc-alpha <libc-alpha@sourceware.org> writes:
> +/* Emulate the "/bin/kill" command.  Options are ignored.  */

"Options" meaning -TERM and the like?  Because arguments aren't
ignored...

> +static int
> +kill_func (char **argv)
> +{
> +  int signum = SIGTERM;
> +  int i;
> +
> +  for (i = 0; argv[i]; i++)
> +    {
> +      pid_t pid;
> +      if (strcmp (argv[i], "$$") == 0)
> +	pid = getpid ();
> +      else
> +	pid = atoi (argv[i]);
> +      kill (pid, signum);
> +    }
> +  return 0;
> +}
> +

Ok.

> +  { "kill", kill_func },

Ok.  I draw the line at adding a mail reader, though ;-)

> @@ -264,6 +284,11 @@ run_command_array (char **argv)
>        if (rv)
>  	exit (rv);
>      }
> +  else if (WIFSIGNALED (status))
> +    {
> +      int sig = WTERMSIG (status);
> +      raise (sig);
> +    }
>    else
>      exit (1);
>  }

Ok.

Reviewed-by: DJ Delorie <dj@redhat.com>



More information about the Libc-alpha mailing list