All of lore.kernel.org
 help / color / mirror / Atom feed
From: Petr Lautrbach <plautrba@redhat.com>
To: Nicolas Iooss <nicolas.iooss@m4x.org>
Cc: selinux@vger.kernel.org
Subject: Re: [PATCH 3/3] restorecond/user: handle SIGTERM properly
Date: Mon, 27 Apr 2020 22:58:16 +0200	[thread overview]
Message-ID: <20200427205816.GA28535@workstation> (raw)
In-Reply-To: <20200413162413.1161803-3-nicolas.iooss@m4x.org>

[-- Attachment #1: Type: text/plain, Size: 3046 bytes --]

On Mon, Apr 13, 2020 at 06:24:13PM +0200, Nicolas Iooss wrote:
> When restorecond starts, it installs a SIGTERM handler in order to exit
> cleanly (by removing its PID file). When restorecond --user starts,
> there is no PID file, and g_main_loop_run() does not stop when master_fd
> is closed. This leads to an unkillable service, which is an issue.
> 
> Fix this by overriding the handler for SIGTERM in restorecond --user.
> 
> Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>

The whole patchset

Acked-by: Petr Lautrbach <plautrba@redhat.com>

and merged.

Thanks!


> ---
>  restorecond/user.c | 54 +++++++++++++++++++++++++++++++---------------
>  1 file changed, 37 insertions(+), 17 deletions(-)
> 
> diff --git a/restorecond/user.c b/restorecond/user.c
> index f940fd4e6678..a24b8407b048 100644
> --- a/restorecond/user.c
> +++ b/restorecond/user.c
> @@ -46,6 +46,7 @@
>  #include "restorecond.h"
>  #include "stringslist.h"
>  #include <glib.h>
> +#include <glib-unix.h>
>  
>  static int local_lock_fd = -1;
>  
> @@ -250,35 +251,54 @@ static void end_local_server(void) {
>  	local_lock_fd = -1;
>  }
>  
> +static int sigterm_handler(gpointer user_data)
> +{
> +	GMainLoop *loop = user_data;
> +
> +	if (debug_mode)
> +		g_print("Received SIGTERM, exiting\n");
> +	g_main_loop_quit(loop);
> +	return FALSE;
> +}
> +
> +
>  int server(int master_fd, const char *watch_file) {
> -    GMainLoop *loop;
> +	GMainLoop *loop;
>  
> -    loop = g_main_loop_new (NULL, FALSE);
> +	loop = g_main_loop_new (NULL, FALSE);
>  
>  #ifdef HAVE_DBUS
> -    if (dbus_server(loop) != 0)
> +	if (dbus_server(loop) != 0)
>  #endif /* HAVE_DBUS */
> -	    if (local_server())
> -		    goto end;
> +		if (local_server())
> +			goto end;
>  
> -    read_config(master_fd, watch_file);
> +	read_config(master_fd, watch_file);
>  
> -    if (watch_list_isempty()) goto end;
> +	if (watch_list_isempty())
> +		goto end;
>  
> -    set_matchpathcon_flags(MATCHPATHCON_NOTRANS);
> +	set_matchpathcon_flags(MATCHPATHCON_NOTRANS);
>  
> -    GIOChannel *c = g_io_channel_unix_new(master_fd);
> +	GIOChannel *c = g_io_channel_unix_new(master_fd);
>  
> -    g_io_add_watch_full( c,
> -			 G_PRIORITY_HIGH,
> -			 G_IO_IN|G_IO_ERR|G_IO_HUP,
> -			 io_channel_callback, NULL, NULL);
> +	g_io_add_watch_full(c,
> +			    G_PRIORITY_HIGH,
> +			    G_IO_IN|G_IO_ERR|G_IO_HUP,
> +			    io_channel_callback, NULL, NULL);
>  
> -    g_main_loop_run (loop);
> +	/* Handle SIGTERM */
> +	g_unix_signal_add_full(G_PRIORITY_DEFAULT,
> +			       SIGTERM,
> +			       sigterm_handler,
> +			       loop,
> +			       NULL);
> +
> +	g_main_loop_run (loop);
>  
>  end:
> -    end_local_server();
> -    g_main_loop_unref (loop);
> -    return 0;
> +	end_local_server();
> +	g_main_loop_unref (loop);
> +	return 0;
>  }
>  
> -- 
> 2.26.0
> 

-- 
()  ascii ribbon campaign - against html e-mail 
/\  www.asciiribbon.org   - against proprietary attachments

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

      reply	other threads:[~2020-04-27 20:58 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-13 16:24 [PATCH 1/3] restorecond: migrate to GDbus API provided by glib-gio Nicolas Iooss
2020-04-13 16:24 ` [PATCH 2/3] restorecond: add systemd user service Nicolas Iooss
2020-04-13 16:24 ` [PATCH 3/3] restorecond/user: handle SIGTERM properly Nicolas Iooss
2020-04-27 20:58   ` Petr Lautrbach [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200427205816.GA28535@workstation \
    --to=plautrba@redhat.com \
    --cc=nicolas.iooss@m4x.org \
    --cc=selinux@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.