From: "Luis R. Rodriguez" <mcgrof@do-not-panic.com>
To: xen-devel@lists.xenproject.org
Cc: "Luis R. Rodriguez" <mcgrof@suse.com>
Subject: [PATCH v5 03/14] cxenstored: add support for systemd active sockets
Date: Tue, 20 May 2014 05:31:24 -0700 [thread overview]
Message-ID: <1400589095-3872-4-git-send-email-mcgrof@do-not-panic.com> (raw)
In-Reply-To: <1400589095-3872-1-git-send-email-mcgrof@do-not-panic.com>
From: "Luis R. Rodriguez" <mcgrof@suse.com>
This adds systemd socket activation support for the C xenstored.
Active sockets enable xenstored to be loaded only if required by a system
onto which Xen is installed on. Socket activation is handled by
systemd, once a port for a service which claims a socket is used
systemd will start the required services for it, on demand. For more
details on socket activation refer to Lennart's socket-activation
post regarding this [0].
Right now this code adds a no-op for this functionality, leaving the
enablement to be done later once systemd is properly hooked into
the build system. The socket activation is ordered in aligment with
the socket activation order passed on to systemd.
[0] http://0pointer.de/blog/projects/socket-activation2.html
Signed-off-by: Luis R. Rodriguez <mcgrof@suse.com>
---
tools/xenstore/xenstored_core.c | 49 ++++++++++++++++++++++++++++++++++++++++-
1 file changed, 48 insertions(+), 1 deletion(-)
diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_core.c
index 47f0722..e456e67 100644
--- a/tools/xenstore/xenstored_core.c
+++ b/tools/xenstore/xenstored_core.c
@@ -40,10 +40,12 @@
#include <signal.h>
#include <assert.h>
#include <setjmp.h>
+#include <config.h>
#include "utils.h"
#include "list.h"
#include "talloc.h"
+#include "xenstore.h"
#include "xenstore_lib.h"
#include "xenstored_core.h"
#include "xenstored_watch.h"
@@ -1706,6 +1708,11 @@ static void init_sockets(int **psock, int **pro_sock)
static int minus_one = -1;
*psock = *pro_sock = &minus_one;
}
+static void xen_claim_active_sockets(struct xs_sd_ctx *ctx, int **psock, int **pro_sock)
+{
+ static int minus_one = -1;
+ *psock = *pro_sock = &minus_one;
+}
#else
static int destroy_fd(void *_fd)
{
@@ -1714,6 +1721,26 @@ static int destroy_fd(void *_fd)
return 0;
}
+static void xen_claim_active_sockets(struct xs_sd_ctx *ctx, int **psock, int **pro_sock)
+{
+ int *sock, *ro_sock;
+ const char *soc_str = xs_daemon_socket();
+ const char *soc_str_ro = xs_daemon_socket_ro();
+
+ *psock = sock = talloc(talloc_autofree_context(), int);
+ *sock = xs_claim_active_socket(ctx, soc_str);
+ if (*sock <= 0)
+ barf_perror("%s", soc_str);
+
+ *pro_sock = ro_sock = talloc(talloc_autofree_context(), int);
+ *ro_sock = xs_claim_active_socket(ctx, soc_str_ro);
+ if (*ro_sock <= 0)
+ barf_perror("%s", soc_str_ro);
+
+ talloc_set_destructor(sock, destroy_fd);
+ talloc_set_destructor(ro_sock, destroy_fd);
+}
+
static void init_sockets(int **psock, int **pro_sock)
{
struct sockaddr_un addr;
@@ -1822,8 +1849,10 @@ int main(int argc, char *argv[])
bool dofork = true;
bool outputpid = false;
bool no_domain_init = false;
+ bool sd_booted = false;
const char *pidfile = NULL;
int timeout;
+ struct xs_sd_ctx *ctx;
while ((opt = getopt_long(argc, argv, "DE:F:HNPS:t:T:RLVW:", options,
NULL)) != -1) {
@@ -1884,6 +1913,16 @@ int main(int argc, char *argv[])
if (optind != argc)
barf("%s: No arguments desired", argv[0]);
+ ctx = xs_get_sd_ctx();
+ /* xs_sd_ctx can be NULL and that's OK */
+ if (xs_load_sd_required(ctx)) {
+ sd_booted = true;
+ dofork = false;
+ if (pidfile)
+ barf("%s: PID file not needed on systemd", argv[0]);
+ pidfile = NULL;
+ }
+
reopen_log();
/* make sure xenstored directories exist */
@@ -1905,7 +1944,11 @@ int main(int argc, char *argv[])
/* Don't kill us with SIGPIPE. */
signal(SIGPIPE, SIG_IGN);
- init_sockets(&sock, &ro_sock);
+ if (sd_booted)
+ xen_claim_active_sockets(ctx, &sock, &ro_sock);
+ else
+ init_sockets(&sock, &ro_sock);
+
init_pipe(reopen_log_pipe);
/* Setup the database */
@@ -1936,6 +1979,9 @@ int main(int argc, char *argv[])
/* Tell the kernel we're up and running. */
xenbus_notify_running();
+ if (sd_booted)
+ xs_sd_notify_ready(ctx);
+
/* Main loop. */
for (;;) {
struct connection *conn, *next;
@@ -2047,6 +2093,7 @@ int main(int argc, char *argv[])
initialize_fds(*sock, &sock_pollfd_idx, *ro_sock,
&ro_sock_pollfd_idx, &timeout);
}
+ xs_free_sd_ctx(ctx);
}
/*
--
2.0.0.rc3.18.g00a5b79
next prev parent reply other threads:[~2014-05-20 12:31 UTC|newest]
Thread overview: 62+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-20 12:31 [PATCH v5 00/14] xen: add systemd support Luis R. Rodriguez
2014-05-20 12:31 ` [PATCH v5 01/14] xenstored: enable usage of config.h on both xenstored and oxenstored Luis R. Rodriguez
2014-05-20 12:31 ` [PATCH v5 02/14] libxenstore.so: add support for systemd Luis R. Rodriguez
2014-05-21 14:35 ` Ian Campbell
2014-05-21 14:56 ` Ian Campbell
2014-05-21 16:32 ` Luis R. Rodriguez
2014-05-21 16:48 ` Ian Campbell
2014-05-21 17:15 ` Luis R. Rodriguez
2014-05-22 9:36 ` Ian Campbell
2014-05-22 9:59 ` Luis R. Rodriguez
2014-05-21 16:24 ` Luis R. Rodriguez
2014-05-21 16:39 ` Ian Campbell
2014-05-21 17:29 ` Luis R. Rodriguez
2014-05-22 9:39 ` Ian Campbell
2014-05-22 10:01 ` Luis R. Rodriguez
2014-05-20 12:31 ` Luis R. Rodriguez [this message]
2014-05-20 12:31 ` [PATCH v5 04/14] oxenstored: add support for systemd active sockets Luis R. Rodriguez
2014-05-20 12:31 ` [PATCH v5 05/14] oxenstored: force FD_CLOEXEC with Unix.set_close_on_exec on LSB init Luis R. Rodriguez
2014-05-20 12:31 ` [PATCH v5 06/14] tools/xendomains: make xl the default Luis R. Rodriguez
2014-05-21 15:05 ` Ian Campbell
2014-05-21 17:29 ` Luis R. Rodriguez
2014-05-20 12:31 ` [PATCH v5 07/14] tools/xendomains: do space cleanups Luis R. Rodriguez
2014-05-20 12:31 ` [PATCH v5 08/14] tools/xendomains: move to libexec and use a smaller init helper Luis R. Rodriguez
2014-05-20 12:31 ` [PATCH v5 09/14] autoconf: xen: force a refresh with autoconf Luis R. Rodriguez
2014-05-21 15:07 ` Ian Campbell
2014-05-21 17:35 ` Luis R. Rodriguez
2014-05-20 12:31 ` [PATCH v5 10/14] autoconf: update m4/pkg.m4 Luis R. Rodriguez
2014-05-20 12:31 ` [PATCH v5 11/14] autoconf: xen: move standard variables to a generic place Luis R. Rodriguez
2014-05-20 13:37 ` Jan Beulich
[not found] ` <537B76D1020000780001422C@suse.com>
2014-05-20 17:54 ` Luis R. Rodriguez
2014-05-21 7:32 ` Jan Beulich
2014-05-21 8:03 ` Luis R. Rodriguez
2014-05-21 8:11 ` Jan Beulich
2014-05-21 8:27 ` Luis R. Rodriguez
2014-05-21 10:33 ` Ian Campbell
2014-05-21 13:54 ` Jan Beulich
2014-05-21 15:14 ` Ian Campbell
2014-05-21 15:20 ` Jan Beulich
2014-05-21 15:26 ` Ian Campbell
2014-05-21 21:54 ` Luis R. Rodriguez
2014-05-22 9:46 ` Ian Campbell
2014-05-20 12:31 ` [PATCH v5 12/14] autoconf: xen: enable explicit preference option for xenstored preference Luis R. Rodriguez
2014-05-21 15:44 ` Ian Campbell
2014-05-21 23:02 ` Luis R. Rodriguez
2014-05-22 10:05 ` Ian Campbell
2014-05-23 23:20 ` Luis R. Rodriguez
2014-05-28 9:30 ` Ian Campbell
2014-05-29 16:09 ` Don Koch
2014-05-29 23:29 ` Luis R. Rodriguez
[not found] ` <20140529232918.GG26450@wotan.suse.de>
2014-06-01 6:15 ` [systemd-devel] " Lennart Poettering
[not found] ` <20140601061547.GC16257@tango.0pointer.de>
2014-06-05 0:31 ` Luis R. Rodriguez
[not found] ` <20140605003103.GB22052@wotan.suse.de>
2014-06-05 2:52 ` Cameron Norman
2014-06-05 11:22 ` Lennart Poettering
[not found] ` <20140605112213.GA17673@tango.0pointer.de>
2014-06-05 18:01 ` Luis R. Rodriguez
[not found] ` <20140605180137.GD22052@wotan.suse.de>
2014-06-05 19:24 ` Lennart Poettering
[not found] ` <20140605192421.GA6248@tango.0pointer.de>
2014-06-05 19:26 ` Andrew Lutomirski
[not found] ` <CALZWFR+LQ3XK4RQ335CNqjr8zucWw4GieKwZS3N5m0w4yJXuBA@mail.gmail.com>
2014-06-10 1:15 ` Luis R. Rodriguez
2014-05-20 12:31 ` [PATCH v5 13/14] xencommons: move module list into a generic place Luis R. Rodriguez
2014-05-20 13:40 ` Jan Beulich
[not found] ` <537B776D020000780001425E@suse.com>
2014-05-20 18:03 ` Luis R. Rodriguez
2014-05-20 12:31 ` [PATCH v5 14/14] systemd: add xen systemd service and module files Luis R. Rodriguez
2014-05-20 12:48 ` 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=1400589095-3872-4-git-send-email-mcgrof@do-not-panic.com \
--to=mcgrof@do-not-panic.com \
--cc=mcgrof@suse.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).