xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: George Dunlap <george.dunlap@citrix.com>
To: Wei Liu <wei.liu2@citrix.com>,
	George Dunlap <George.Dunlap@eu.citrix.com>
Cc: xen-devel <xen-devel@lists.xenproject.org>,
	"Luis R. Rodriguez" <mcgrof@suse.com>,
	Ian Campbell <ian.campbell@citrix.com>,
	"Luis R. Rodriguez" <mcgrof@do-not-panic.com>
Subject: Re: [PATCH v7 2/8] cxenstored: add support for systemd active sockets
Date: Thu, 6 Aug 2015 14:56:31 +0100	[thread overview]
Message-ID: <55C3678F.4060008@citrix.com> (raw)
In-Reply-To: <20150805181920.GB15719@zion.uk.xensource.com>

On 08/05/2015 07:19 PM, Wei Liu wrote:
> On Wed, Aug 05, 2015 at 06:24:37PM +0100, Wei Liu wrote:
> [...]
>>>
>>
>> Right. I misinterpreted sd_boot.
>>
>> You patch, however, has the undesirable effect that it fails to report
>> error if xenstored is started by systemd but couldn't claim the
>> socket. I don't think this is the correct behaviour.
>>
>> After consulting with systemd manual [0], I think we should check
>> sd_listen_fds return value to determine if it is started by systemd.
>> Currently it only checks for <= 0, which covers 1) not started by
>> systemd 2) an error occurs.
>>
>> Hopefully I interpret the doc correctly this time. I will prepare a
>> patch shortly.
>>
>> Wei.
>>
>> [0] http://www.freedesktop.org/software/systemd/man/sd_listen_fds.html
> 
> Patch attached. I start cxenstored by hand and it seems to works fine --
> now it fails with other errors. Can you test this patch to see if it
> works?
> 
> Apparently oxenstored has similar issues. If this patch works I will
> need to fix oxenstored, too. Time to test my ocaml-fu! :-/
> 
> ---8<---
> From a03eba6e258d8097b974366abb50b39af9e9abbf Mon Sep 17 00:00:00 2001
> From: Wei Liu <wei.liu2@citrix.com>
> Date: Wed, 5 Aug 2015 19:02:34 +0100
> Subject: [PATCH] cxenstored: fix systemd socket activation
> 
> There were two problems with original code:
> 
> 1. sd_booted() was used to determined if the process was started by
>    systemd, which was wrong.
> 2. Exit with error if pidfile was specified, which was too harsh.
> 
> These two combined made cxenstored unable to start by hand if it ran
> on a system which had systemd.
> 
> Fix issues with following changes:
> 
> 1. Use sd_listen_fds to determine if the process is started by systemd.
> 2. Don't exit if pidfile is specified.
> 
> Rename function and restructure code to make things clearer.
> 
> Signed-off-by: Wei Liu <wei.liu2@citrix.com>

I've booted with this patch using both the chkconfig+xencommons sysvinit
script, and the systemd method, and both work for me:

Tested-by: George Dunlap <george.dunlap@eu.citrix.com>

Thanks,
 -George

> ---
>  tools/xenstore/xenstored_core.c | 27 +++++++++++++++++++--------
>  1 file changed, 19 insertions(+), 8 deletions(-)
> 
> diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_core.c
> index b7e4936..57581e0 100644
> --- a/tools/xenstore/xenstored_core.c
> +++ b/tools/xenstore/xenstored_core.c
> @@ -1781,7 +1781,10 @@ static int xs_validate_active_socket(const char *connect_to)
>  	return xs_get_sd_fd(connect_to);
>  }
>  
> -static void xen_claim_active_sockets(int **psock, int **pro_sock)
> +/* Return true if started by systemd and false if not. Exit with
> + * error if things go wrong.
> + */
> +static bool systemd_checkin(int **psock, int **pro_sock)
>  {
>  	int *sock, *ro_sock;
>  	const char *soc_str = xs_daemon_socket();
> @@ -1789,7 +1792,11 @@ static void xen_claim_active_sockets(int **psock, int **pro_sock)
>  	int n;
>  
>  	n = sd_listen_fds(0);
> -	if (n <= 0) {
> +
> +	if (n == 0)
> +		return false;
> +
> +	 if (n < 0) {
>  		sd_notifyf(0, "STATUS=Failed to get any active sockets: %s\n"
>  			   "ERRNO=%i",
>  			   strerror(errno),
> @@ -1816,6 +1823,8 @@ static void xen_claim_active_sockets(int **psock, int **pro_sock)
>  
>  	talloc_set_destructor(sock, destroy_fd);
>  	talloc_set_destructor(ro_sock, destroy_fd);
> +
> +	return true;
>  }
>  #endif
>  
> @@ -1929,6 +1938,9 @@ int main(int argc, char *argv[])
>  	bool no_domain_init = false;
>  	const char *pidfile = NULL;
>  	int timeout;
> +#if defined(XEN_SYSTEMD_ENABLED)
> +	bool systemd;
> +#endif
>  
>  	while ((opt = getopt_long(argc, argv, "DE:F:HNPS:t:T:RLVW:", options,
>  				  NULL)) != -1) {
> @@ -1990,10 +2002,11 @@ int main(int argc, char *argv[])
>  		barf("%s: No arguments desired", argv[0]);
>  
>  #if defined(XEN_SYSTEMD_ENABLED)
> -	if (sd_booted()) {
> +	systemd = systemd_checkin(&sock, &ro_sock);
> +	if (systemd) {
>  		dofork = false;
>  		if (pidfile)
> -			barf("%s: PID file not needed on systemd", argv[0]);
> +			xprintf("%s: PID file not needed on systemd", argv[0]);
>  		pidfile = NULL;
>  	}
>  #endif
> @@ -2020,9 +2033,7 @@ int main(int argc, char *argv[])
>  	signal(SIGPIPE, SIG_IGN);
>  
>  #if defined(XEN_SYSTEMD_ENABLED)
> -	if (sd_booted())
> -		xen_claim_active_sockets(&sock, &ro_sock);
> -	else
> +	if (!systemd)
>  #endif
>  		init_sockets(&sock, &ro_sock);
>  
> @@ -2057,7 +2068,7 @@ int main(int argc, char *argv[])
>  	xenbus_notify_running();
>  
>  #if defined(XEN_SYSTEMD_ENABLED)
> -	if (sd_booted()) {
> +	if (systemd) {
>  		sd_notify(1, "READY=1");
>  		fprintf(stderr, SD_NOTICE "xenstored is ready\n");
>  	}
> 

  parent reply	other threads:[~2015-08-06 13:56 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-17 23:28 [PATCH v7 0/8] xen: add systemd support Luis R. Rodriguez
2014-07-17 23:28 ` [PATCH v7 1/8] xenstored: enable usage of config.h on both xenstored and oxenstored Luis R. Rodriguez
2014-07-17 23:28 ` [PATCH v7 2/8] cxenstored: add support for systemd active sockets Luis R. Rodriguez
2014-07-24 15:10   ` Ian Campbell
2014-07-24 15:54     ` Ian Campbell
2014-07-25 22:45     ` Luis R. Rodriguez
2014-07-28  9:48       ` Ian Campbell
2014-07-28 15:06         ` Luis R. Rodriguez
2015-08-05 10:06   ` George Dunlap
2015-08-05 10:17     ` Ian Campbell
2015-08-05 10:56       ` George Dunlap
2015-08-05 11:11         ` Ian Campbell
2015-08-05 11:14           ` Ian Campbell
2015-08-05 11:21           ` George Dunlap
2015-08-05 11:27             ` Ian Campbell
2015-08-05 13:17         ` Wei Liu
2015-08-05 16:30           ` George Dunlap
2015-08-05 17:24             ` Wei Liu
2015-08-05 18:19               ` Wei Liu
2015-08-06  9:13                 ` Ian Campbell
2015-08-06  9:20                   ` Wei Liu
2015-08-06  9:29                     ` Ian Campbell
2015-08-06  9:36                       ` Wei Liu
2015-08-06 10:17                   ` Wei Liu
2015-08-06 10:48                     ` Ian Campbell
2015-08-06 10:56                       ` Wei Liu
2015-08-06 11:03                         ` Ian Campbell
2015-08-06 13:56                 ` George Dunlap [this message]
2014-07-17 23:28 ` [PATCH v7 3/8] oxenstored: " Luis R. Rodriguez
2014-07-17 23:28 ` [PATCH v7 4/8] oxenstored: force FD_CLOEXEC with Unix.set_close_on_exec on LSB init Luis R. Rodriguez
2014-07-24 15:09   ` Ian Campbell
2014-07-17 23:28 ` [PATCH v7 5/8] autoconf: xen: move standard path variables to config/Paths.mk.in Luis R. Rodriguez
2014-07-24 15:29   ` Ian Campbell
2014-07-17 23:28 ` [PATCH v7 6/8] xencommons: move module list into a generic place Luis R. Rodriguez
2014-07-24 15:35   ` Ian Campbell
2014-07-25 23:16     ` Luis R. Rodriguez
2014-07-17 23:28 ` [PATCH v7 7/8] autoconf: xen: enable explicit preference option for xenstored preference Luis R. Rodriguez
2014-07-24 15:40   ` Ian Campbell
2014-07-25 23:25     ` Luis R. Rodriguez
2014-07-17 23:28 ` [PATCH v7 8/8] systemd: add xen systemd service and module files Luis R. Rodriguez
2014-07-24 15:47   ` Ian Campbell
2014-07-25 23:34     ` Luis R. Rodriguez

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=55C3678F.4060008@citrix.com \
    --to=george.dunlap@citrix.com \
    --cc=George.Dunlap@eu.citrix.com \
    --cc=ian.campbell@citrix.com \
    --cc=mcgrof@do-not-panic.com \
    --cc=mcgrof@suse.com \
    --cc=wei.liu2@citrix.com \
    --cc=xen-devel@lists.xenproject.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).