[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen master] cxenstored: fix systemd socket activation



commit 81d758afca7c3c1e3ccbd78154b33d64fd7757fb
Author:     Wei Liu <wei.liu2@xxxxxxxxxx>
AuthorDate: Mon Aug 10 09:00:16 2015 +0100
Commit:     Ian Campbell <ian.campbell@xxxxxxxxxx>
CommitDate: Thu Aug 13 10:23:58 2015 +0100

    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.
    
    A side effect of this patch is that gcc 4.8 with -Wmaybe-uninitialized
    in non-debug build spits out spurious warning about sock and ro_sock
    might be uninitialized. Since CentOS 7 ships gcc 4.8, we need to work
    around that by setting sock and ro_sock to NULL at the beginning of
    main.
    
    Signed-off-by: Wei Liu <wei.liu2@xxxxxxxxxx>
    Tested-by: George Dunlap <george.dunlap@xxxxxxxxxxxxx>
    Acked-by: Ian Campbell <ian.campbell@xxxxxxxxxx>
---
 tools/xenstore/xenstored_core.c |   29 ++++++++++++++++++++---------
 1 files changed, 20 insertions(+), 9 deletions(-)

diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_core.c
index b7e4936..87cb715 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
 
@@ -1922,13 +1931,16 @@ int priv_domid = 0;
 
 int main(int argc, char *argv[])
 {
-       int opt, *sock, *ro_sock;
+       int opt, *sock = NULL, *ro_sock = NULL;
        int sock_pollfd_idx = -1, ro_sock_pollfd_idx = -1;
        bool dofork = true;
        bool outputpid = false;
        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");
        }
--
generated by git-patchbot for /home/xen/git/xen.git#master

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.