[systemd-devel] [PATCH] initctl: support 'telinit u/q'

Lennart Poettering lennart at poettering.net
Mon Aug 1 14:23:26 PDT 2011


On Sat, 30.07.11 18:23, Tom Gundersen (teg at jklm.no) wrote:

> We send SIGTERM (resp., SIGHUP) when we receive request for changing to
> runlevel 'u' (resp., 'q').
> 
> As initctl is already async, we just send the signals rather than first
> attempting to connect to sytemd over dbus and then falling back to
> kill.

Applied. Thanks!

> ---
>  src/initctl.c |   19 ++++++++++++++++++-
>  1 files changed, 18 insertions(+), 1 deletions(-)
> 
> diff --git a/src/initctl.c b/src/initctl.c
> index dd74314..ea1acd1 100644
> --- a/src/initctl.c
> +++ b/src/initctl.c
> @@ -165,7 +165,24 @@ static void request_process(Server *s, const struct init_request *req) {
>                  if (!isprint(req->runlevel))
>                          log_error("Got invalid runlevel. Ignoring.");
>                  else
> -                        change_runlevel(s, req->runlevel);
> +                        switch (req->runlevel) {
> +
> +                        /* we are async anyway, so just use kill for reexec/reload */
> +                        case 'u':
> +                        case 'U':
> +                                if (kill(1, SIGTERM) < 0)
> +                                        log_error("kill() failed: %m");
> +                                break;
> +
> +                        case 'q':
> +                        case 'Q':
> +                                if (kill(1, SIGHUP) < 0)
> +                                        log_error("kill() failed: %m");
> +                                break;
> +
> +                        default:
> +                                change_runlevel(s, req->runlevel);
> +                        }
>                  return;
>  
>          case INIT_CMD_POWERFAIL:


Lennart

-- 
Lennart Poettering - Red Hat, Inc.


More information about the systemd-devel mailing list