]> xenbits.xensource.com Git - xen.git/commitdiff
tools: remove systemd xenstore socket definitions
authorJuergen Gross <jgross@suse.com>
Tue, 2 Aug 2016 16:10:44 +0000 (18:10 +0200)
committerWei Liu <wei.liu2@citrix.com>
Fri, 5 Aug 2016 09:37:02 +0000 (10:37 +0100)
On a system with systemd the xenstore sockets are created via systemd.
Remove the related configuration files in order to be able to decide
at runtime whether the sockets should be created or not. This will
enable Xen to start xenstore either via a daemon or via a stub domain.

As the xenstore domain start program will exit after it has done its
job prepare the same behaviour to be tolerated by systemd for the
xenstore daemon by specifying the appropriate flags in the service
file.

A rerun of autogen.sh is required.

Signed-off-by: Juergen Gross <jgross@suse.com>
Acked-by: Wei Liu <wei.liu2@citrix.com>
Acked-by: David Scott <dave@recoil.org>
12 files changed:
tools/configure
tools/configure.ac
tools/hotplug/Linux/systemd/Makefile
tools/hotplug/Linux/systemd/xenstored.service.in
tools/hotplug/Linux/systemd/xenstored.socket.in [deleted file]
tools/hotplug/Linux/systemd/xenstored_ro.socket.in [deleted file]
tools/ocaml/xenstored/systemd.ml
tools/ocaml/xenstored/systemd.mli
tools/ocaml/xenstored/systemd_stubs.c
tools/ocaml/xenstored/utils.ml
tools/ocaml/xenstored/xenstored.ml
tools/xenstore/xenstored_core.c

index 5b5dccef38cf6f9b2deff7b38b1fea16e61a2eee..1c84c6c025a0f18f3152a7ed5e8373a18595683c 100755 (executable)
@@ -9670,7 +9670,7 @@ fi
 
 if test "x$systemd" = "xy"; then :
 
-    ac_config_files="$ac_config_files hotplug/Linux/systemd/proc-xen.mount hotplug/Linux/systemd/var-lib-xenstored.mount hotplug/Linux/systemd/xen-init-dom0.service hotplug/Linux/systemd/xen-qemu-dom0-disk-backend.service hotplug/Linux/systemd/xen-watchdog.service hotplug/Linux/systemd/xenconsoled.service hotplug/Linux/systemd/xendomains.service hotplug/Linux/systemd/xendriverdomain.service hotplug/Linux/systemd/xenstored.service hotplug/Linux/systemd/xenstored.socket hotplug/Linux/systemd/xenstored_ro.socket"
+    ac_config_files="$ac_config_files hotplug/Linux/systemd/proc-xen.mount hotplug/Linux/systemd/var-lib-xenstored.mount hotplug/Linux/systemd/xen-init-dom0.service hotplug/Linux/systemd/xen-qemu-dom0-disk-backend.service hotplug/Linux/systemd/xen-watchdog.service hotplug/Linux/systemd/xenconsoled.service hotplug/Linux/systemd/xendomains.service hotplug/Linux/systemd/xendriverdomain.service hotplug/Linux/systemd/xenstored.service"
 
 
 fi
@@ -10394,8 +10394,6 @@ do
     "hotplug/Linux/systemd/xendomains.service") CONFIG_FILES="$CONFIG_FILES hotplug/Linux/systemd/xendomains.service" ;;
     "hotplug/Linux/systemd/xendriverdomain.service") CONFIG_FILES="$CONFIG_FILES hotplug/Linux/systemd/xendriverdomain.service" ;;
     "hotplug/Linux/systemd/xenstored.service") CONFIG_FILES="$CONFIG_FILES hotplug/Linux/systemd/xenstored.service" ;;
-    "hotplug/Linux/systemd/xenstored.socket") CONFIG_FILES="$CONFIG_FILES hotplug/Linux/systemd/xenstored.socket" ;;
-    "hotplug/Linux/systemd/xenstored_ro.socket") CONFIG_FILES="$CONFIG_FILES hotplug/Linux/systemd/xenstored_ro.socket" ;;
 
   *) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5;;
   esac
index 87e14a8c98aeac311be5af266da25bf354521e3e..f991ab312818f0ff9b286cc44eeddf4048837735 100644 (file)
@@ -438,8 +438,6 @@ AS_IF([test "x$systemd" = "xy"], [
     hotplug/Linux/systemd/xendomains.service
     hotplug/Linux/systemd/xendriverdomain.service
     hotplug/Linux/systemd/xenstored.service
-    hotplug/Linux/systemd/xenstored.socket
-    hotplug/Linux/systemd/xenstored_ro.socket
     ])
 ])
 
index 558e459a19ffaac64e0e1994ccb2bc208c85e282..7d24bbedea6b0c821870607977cd7fbc59e8c9a7 100644 (file)
@@ -6,9 +6,6 @@ XEN_SYSTEMD_MODULES = xen.conf
 XEN_SYSTEMD_MOUNT =  proc-xen.mount
 XEN_SYSTEMD_MOUNT += var-lib-xenstored.mount
 
-XEN_SYSTEMD_SOCKET  = xenstored.socket
-XEN_SYSTEMD_SOCKET += xenstored_ro.socket
-
 XEN_SYSTEMD_SERVICE  = xenstored.service
 XEN_SYSTEMD_SERVICE += xenconsoled.service
 XEN_SYSTEMD_SERVICE += xen-qemu-dom0-disk-backend.service
@@ -19,7 +16,6 @@ XEN_SYSTEMD_SERVICE += xendriverdomain.service
 
 ALL_XEN_SYSTEMD =      $(XEN_SYSTEMD_MODULES)  \
                        $(XEN_SYSTEMD_MOUNT)    \
-                       $(XEN_SYSTEMD_SOCKET)   \
                        $(XEN_SYSTEMD_SERVICE)
 
 .PHONY: all
@@ -38,7 +34,6 @@ install: $(ALL_XEN_SYSTEMD)
                $(INSTALL_DIR) $(DESTDIR)$(XEN_SYSTEMD_DIR)
        [ -d $(DESTDIR)$(XEN_SYSTEMD_MODULES_LOAD) ] || \
                $(INSTALL_DIR) $(DESTDIR)$(XEN_SYSTEMD_MODULES_LOAD)
-       $(INSTALL_DATA) *.socket $(DESTDIR)$(XEN_SYSTEMD_DIR)
        $(INSTALL_DATA) *.service $(DESTDIR)$(XEN_SYSTEMD_DIR)
        $(INSTALL_DATA) *.mount $(DESTDIR)$(XEN_SYSTEMD_DIR)
        $(INSTALL_DATA) *.conf $(DESTDIR)$(XEN_SYSTEMD_MODULES_LOAD)
index a5f836b5eb5119daf5cce6dfe2f7bd27854f0491..d520d70fcce356ca66a1c803ab66e24c4cb8b17c 100644 (file)
@@ -1,6 +1,6 @@
 [Unit]
 Description=The Xen xenstore
-Requires=xenstored_ro.socket xenstored.socket proc-xen.mount var-lib-xenstored.mount
+Requires=proc-xen.mount var-lib-xenstored.mount
 After=proc-xen.mount var-lib-xenstored.mount
 Before=libvirtd.service libvirt-guests.service
 RefuseManualStop=true
@@ -8,6 +8,8 @@ ConditionPathExists=/proc/xen/capabilities
 
 [Service]
 Type=notify
+NotifyAccess=all
+RemainAfterExit=true
 KillMode=none
 Environment=XENSTORED_ARGS=
 Environment=XENSTORED=@XENSTORED@
@@ -19,6 +21,5 @@ ExecStart=/bin/sh -c "exec $XENSTORED --no-fork $XENSTORED_ARGS"
 
 [Install]
 WantedBy=multi-user.target
-Also=xenstored_ro.socket xenstored.socket
 Also=proc-xen.mount
 Also=var-lib-xenstored.mount
diff --git a/tools/hotplug/Linux/systemd/xenstored.socket.in b/tools/hotplug/Linux/systemd/xenstored.socket.in
deleted file mode 100644 (file)
index 375c4b7..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-[Unit]
-Description=xenstore socket
-Requires=proc-xen.mount var-lib-xenstored.mount
-After=proc-xen.mount var-lib-xenstored.mount
-ConditionPathExists=/proc/xen/capabilities
-
-[Socket]
-ListenStream=@XEN_RUN_STORED@/socket
-SocketMode=0600
-Service=xenstored.service
-
-[Install]
-WantedBy=sockets.target
diff --git a/tools/hotplug/Linux/systemd/xenstored_ro.socket.in b/tools/hotplug/Linux/systemd/xenstored_ro.socket.in
deleted file mode 100644 (file)
index 82fe377..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-[Unit]
-Description=xenstore ro socket
-Requires=proc-xen.mount var-lib-xenstored.mount
-After=proc-xen.mount var-lib-xenstored.mount
-ConditionPathExists=/proc/xen/capabilities
-
-[Socket]
-ListenStream=@XEN_RUN_STORED@/socket_ro
-SocketMode=0660
-Service=xenstored.service
-
-[Install]
-WantedBy=sockets.target
index 732446d8e57fc995c2edce485fd20340c6628667..39127f712d7220dc61e4a9fd05c412b389b4eb4b 100644 (file)
@@ -12,6 +12,4 @@
  * GNU Lesser General Public License for more details.
  *)
 
-external sd_listen_fds: string -> Unix.file_descr = "ocaml_sd_listen_fds"
-external launched_by_systemd: unit -> bool = "ocaml_launched_by_systemd"
 external sd_notify_ready: unit -> unit = "ocaml_sd_notify_ready"
index 538fc5e1b523e6a6b24787129f06b8cd20397226..18b9331031f9c30292b43680dcd6962ea93e2d99 100644 (file)
  * GNU Lesser General Public License for more details.
  *)
 
-(** Calls the C library sd_listen_fds() function for us. Although
- *  the library doesn't accept argument we send one over to help
- *  us do sanity checks on the expected sockets *)
-val sd_listen_fds: string -> Unix.file_descr
-
-(** Tells us whether the process is launched by systemd *)
-val launched_by_systemd: unit -> bool
-
 (** Tells systemd we're ready *)
 external sd_notify_ready: unit -> unit = "ocaml_sd_notify_ready"
index 322f1e012ec1dd374fb8560e59217212cc22aad4..490156c06a46159357209ab7e3d9441a8c024657 100644 (file)
 
 #if defined(HAVE_SYSTEMD)
 
-#include <sys/socket.h>
 #include <systemd/sd-daemon.h>
 
 #include "_paths.h"
 
-/* Will work regardless of the order systemd gives them to us */
-static int oxen_get_sd_fd(const char *connect_to)
-{
-       int fd = SD_LISTEN_FDS_START;
-       int r;
-
-       while (fd <= SD_LISTEN_FDS_START + 1) {
-               r = sd_is_socket_unix(fd, SOCK_STREAM, 1, connect_to, 0);
-               if (r > 0)
-                       return fd;
-               fd++;
-       }
-
-       return -EBADR;
-}
-
-static int oxen_verify_socket_socket(const char *connect_to)
-{
-       if ((strcmp(XEN_RUN_STORED "/socket_ro", connect_to) != 0) &&
-           (strcmp(XEN_RUN_STORED "/socket", connect_to) != 0)) {
-               sd_notifyf(0, "STATUS=unexpected socket: %s\n"
-                          "ERRNO=%i",
-                          connect_to,
-                          EBADR);
-               return -EBADR;
-       }
-
-       return oxen_get_sd_fd(connect_to);
-}
-
-CAMLprim value ocaml_sd_listen_fds(value connect_to)
-{
-       CAMLparam1(connect_to);
-       CAMLlocal1(sock_ret);
-       int sock = -EBADR, n;
-
-       n = sd_listen_fds(0);
-       if (n <= 0) {
-               sd_notifyf(0, "STATUS=Failed to get any active sockets: %s\n"
-                          "ERRNO=%i",
-                          strerror(errno),
-                          errno);
-               caml_failwith("ocaml_sd_listen_fds() failed to get any sockets");
-       } else if (n != 2) {
-               fprintf(stderr, SD_ERR "Expected 2 fds but given %d\n", n);
-               sd_notifyf(0, "STATUS=Mismatch on number (2): %s\n"
-                          "ERRNO=%d",
-                          strerror(EBADR),
-                          EBADR);
-               caml_failwith("ocaml_sd_listen_fds() mismatch");
-       }
-
-       sock = oxen_verify_socket_socket(String_val(connect_to));
-       if (sock <= 0) {
-               fprintf(stderr, "failed to verify sock %s\n",
-                       String_val(connect_to));
-               caml_failwith("ocaml_sd_listen_fds_init() invalid socket");
-       }
-
-       sock_ret = Val_int(sock);
-
-       CAMLreturn(sock_ret);
-}
-
-CAMLprim value ocaml_launched_by_systemd(value ignore)
-{
-       CAMLparam1(ignore);
-       CAMLlocal1(ret);
-
-       ret = Val_false;
-
-       if (sd_listen_fds(0) > 0)
-               ret = Val_true;
-
-       CAMLreturn(ret);
-}
-
 CAMLprim value ocaml_sd_notify_ready(value ignore)
 {
        CAMLparam1(ignore);
@@ -121,26 +43,6 @@ CAMLprim value ocaml_sd_notify_ready(value ignore)
 
 #else
 
-CAMLprim value ocaml_sd_listen_fds(value connect_to)
-{
-       CAMLparam1(connect_to);
-       CAMLlocal1(sock_ret);
-
-       sock_ret = Val_int(-1U);
-
-       CAMLreturn(sock_ret);
-}
-
-CAMLprim value ocaml_launched_by_systemd(value ignore)
-{
-       CAMLparam1(ignore);
-       CAMLlocal1(ret);
-
-       ret = Val_false;
-
-       CAMLreturn(ret);
-}
-
 CAMLprim value ocaml_sd_notify_ready(value ignore)
 {
        CAMLparam1(ignore);
index 9f82c1ca8da699246f88f3ea02d479d0484999be..e89c1aff048d701603f7ad8ebc4d372c7cf36a59 100644 (file)
@@ -73,22 +73,15 @@ let trim_path path =
 let join_by_null ls = String.concat "\000" ls
 
 (* unix utils *)
-let create_regular_unix_socket name =
+let create_unix_socket name =
         Unixext.unlink_safe name;
         Unixext.mkdir_rec (Filename.dirname name) 0o700;
         let sockaddr = Unix.ADDR_UNIX(name) in
         let sock = Unix.socket Unix.PF_UNIX Unix.SOCK_STREAM 0 in
-        Unix.set_close_on_exec sock;
         Unix.bind sock sockaddr;
         Unix.listen sock 1;
         sock
 
-let create_unix_socket name =
-        if Systemd.launched_by_systemd() then
-                Systemd.sd_listen_fds name
-        else
-                create_regular_unix_socket name
-
 let read_file_single_integer filename =
        let fd = Unix.openfile filename [ Unix.O_RDONLY ] 0o640 in
        let buf = String.make 20 (char_of_int 0) in
index 7ea40262733bb017daf9cf2a953190e80a3f6382..2efcce6cdbd5872e89d7650a9849e14003b90142 100644 (file)
@@ -428,8 +428,7 @@ let _ =
                process_domains store cons domains
                in
 
-       if Systemd.launched_by_systemd () then
-               Systemd.sd_notify_ready ();
+       Systemd.sd_notify_ready ();
        while not !quit
        do
                try
index 693d47d4d10e59ec564dd95b15ee8a73fe76cf0a..3df977b0c86e85b2d5e45e2acc35736a152c4ae0 100644 (file)
@@ -1788,84 +1788,6 @@ static int destroy_fd(void *_fd)
        return 0;
 }
 
-#if defined(XEN_SYSTEMD_ENABLED)
-/* Will work regardless of the order systemd gives them to us */
-static int xs_get_sd_fd(const char *connect_to)
-{
-       int fd = SD_LISTEN_FDS_START;
-       int r;
-
-       while (fd <= SD_LISTEN_FDS_START + 1) {
-               r = sd_is_socket_unix(fd, SOCK_STREAM, 1, connect_to, 0);
-               if (r > 0)
-                       return fd;
-               fd++;
-       }
-
-       return -EBADR;
-}
-
-static int xs_validate_active_socket(const char *connect_to)
-{
-       if ((strcmp(xs_daemon_socket_ro(), connect_to) != 0) &&
-           (strcmp(xs_daemon_socket(), connect_to) != 0)) {
-               sd_notifyf(0, "STATUS=unexpected socket: %s\n"
-                          "ERRNO=%i",
-                          connect_to,
-                          EBADR);
-               return -EBADR;
-       }
-
-       return xs_get_sd_fd(connect_to);
-}
-
-/* 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();
-       const char *soc_str_ro = xs_daemon_socket_ro();
-       int n;
-
-       n = sd_listen_fds(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),
-                          errno);
-               barf_perror("sd_listen_fds() failed\n");
-       } else if (n != 2) {
-               fprintf(stderr, SD_ERR "Expected 2 fds but given %d\n", n);
-               sd_notifyf(0, "STATUS=Mismatch on number (2): %s\n"
-                          "ERRNO=%d",
-                          strerror(EBADR),
-                          EBADR);
-               barf_perror("sd_listen_fds() gave too many fds\n");
-       }
-
-       *psock = sock = talloc(talloc_autofree_context(), int);
-       *sock = xs_validate_active_socket(soc_str);
-       if (*sock <= 0)
-               barf_perror("%s", soc_str);
-
-       *pro_sock = ro_sock = talloc(talloc_autofree_context(), int);
-       *ro_sock = xs_validate_active_socket(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);
-
-       return true;
-}
-#endif
-
 static void init_sockets(int **psock, int **pro_sock)
 {
        struct sockaddr_un addr;
@@ -1984,9 +1906,7 @@ int main(int argc, char *argv[])
        const char *pidfile = NULL;
        const char *memfile = NULL;
        int timeout;
-#if defined(XEN_SYSTEMD_ENABLED)
-       bool systemd;
-#endif
+
 
        while ((opt = getopt_long(argc, argv, "DE:F:HNPS:t:T:RLVW:M:", options,
                                  NULL)) != -1) {
@@ -2050,16 +1970,6 @@ int main(int argc, char *argv[])
        if (optind != argc)
                barf("%s: No arguments desired", argv[0]);
 
-#if defined(XEN_SYSTEMD_ENABLED)
-       systemd = systemd_checkin(&sock, &ro_sock);
-       if (systemd) {
-               dofork = false;
-               if (pidfile)
-                       xprintf("%s: PID file not needed on systemd", argv[0]);
-               pidfile = NULL;
-       }
-#endif
-
        reopen_log();
 
        /* make sure xenstored directories exist */
@@ -2086,10 +1996,7 @@ int main(int argc, char *argv[])
                signal(SIGUSR1, do_talloc_report);
        }
 
-#if defined(XEN_SYSTEMD_ENABLED)
-       if (!systemd)
-#endif
-               init_sockets(&sock, &ro_sock);
+       init_sockets(&sock, &ro_sock);
 
        init_pipe(reopen_log_pipe);
 
@@ -2122,10 +2029,8 @@ int main(int argc, char *argv[])
        xenbus_notify_running();
 
 #if defined(XEN_SYSTEMD_ENABLED)
-       if (systemd) {
-               sd_notify(1, "READY=1");
-               fprintf(stderr, SD_NOTICE "xenstored is ready\n");
-       }
+       sd_notify(1, "READY=1");
+       fprintf(stderr, SD_NOTICE "xenstored is ready\n");
 #endif
 
        /* Main loop. */