]> xenbits.xensource.com Git - xen.git/commitdiff
tools/xenstored: add early_init() function
authorJuergen Gross <jgross@suse.com>
Mon, 5 Feb 2024 10:49:50 +0000 (11:49 +0100)
committerJulien Grall <jgrall@amazon.com>
Mon, 5 Feb 2024 19:26:32 +0000 (19:26 +0000)
Some xenstored initialization needs to be done in the daemon case only,
so split it out into a new early_init() function being a stub in the
stubdom case.

Remove the call of talloc_enable_leak_report_full(), as it serves no
real purpose: the daemon only ever exits due to a crash, in which case
a log of talloc()ed memory hardly has any value.

Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Jason Andryuk <jandryuk@gmail.com>
Reviewed-by: Julien Grall <jgrall@amazon.com>
tools/xenstored/core.c
tools/xenstored/core.h
tools/xenstored/minios.c
tools/xenstored/posix.c

index d4c76d71dc6528f1ab862e291d68b5edee14bf71..eba7744fde5af2fb19eb545d299ec81760ff3730 100644 (file)
@@ -79,7 +79,7 @@ char **orig_argv;
 LIST_HEAD(connections);
 int tracefd = -1;
 bool keep_orphans = false;
-static int reopen_log_pipe[2];
+int reopen_log_pipe[2];
 static int reopen_log_pipe0_pollfd_idx = -1;
 char *tracefile = NULL;
 static struct hashtable *nodes;
@@ -2612,7 +2612,7 @@ static void destroy_fds(void)
                close(sock);
 }
 
-static void init_sockets(void)
+void init_sockets(void)
 {
        struct sockaddr_un addr;
        const char *soc_str = xenstore_daemon_path();
@@ -2903,34 +2903,10 @@ int main(int argc, char *argv[])
        if (optind != argc)
                barf("%s: No arguments desired", argv[0]);
 
-       reopen_log();
-
-       /* Make sure xenstored directory exists. */
-       /* Errors ignored here, will be reported when we open files */
-       mkdir(xenstore_daemon_rundir(), 0755);
-
-       if (dofork) {
-               openlog("xenstored", 0, LOG_DAEMON);
-               if (!live_update)
-                       daemonize();
-       }
-       if (pidfile)
-               write_pidfile(pidfile);
-
-       /* Talloc leak reports go to stderr, which is closed if we fork. */
-       if (!dofork)
-               talloc_enable_leak_report_full();
-
-       /* Don't kill us with SIGPIPE. */
-       signal(SIGPIPE, SIG_IGN);
+       early_init(live_update, dofork, pidfile);
 
        talloc_enable_null_tracking();
 
-#ifndef NO_SOCKETS
-       if (!live_update)
-               init_sockets();
-#endif
-
        init_pipe(reopen_log_pipe);
 
        /* Listen to hypervisor. */
index 480b0f5f7b104180fcbd0e3661c79335fbba2224..72173f168456ee52ff73aec9e002660be38fd3fa 100644 (file)
@@ -384,12 +384,11 @@ static inline bool domain_is_unprivileged(const struct connection *conn)
 
 /* Return the event channel used by xenbus. */
 evtchn_port_t get_xenbus_evtchn(void);
+void early_init(bool live_update, bool dofork, const char *pidfile);
 
-/* Write out the pidfile */
-void write_pidfile(const char *pidfile);
+void init_sockets(void);
+extern int reopen_log_pipe[2];
 
-/* Fork but do not close terminal FDs */
-void daemonize(void);
 /* Close stdin/stdout/stderr to complete daemonize */
 void finish_daemonize(void);
 
index 0779efbf9127f95b2cb25f3dbdb670a36b61ee28..4f48f6308378c7c1274bd10e2012749ccf7d54ec 100644 (file)
 #include "core.h"
 #include <xen/grant_table.h>
 
-void write_pidfile(const char *pidfile)
-{
-}
-
-void daemonize(void)
-{
-}
-
 void finish_daemonize(void)
 {
 }
@@ -54,3 +46,6 @@ void unmap_xenbus(void *interface)
        xengnttab_unmap(*xgt_handle, interface, 1);
 }
 
+void early_init(bool live_update, bool dofork, const char *pidfile)
+{
+}
index 7e03dd982da540b6ba3a6cbc08108ee017461da5..9463ef5c8d7e77194fdd20ea23697149824c1915 100644 (file)
 #include <sys/stat.h>
 #include <unistd.h>
 #include <fcntl.h>
+#include <signal.h>
 #include <stdlib.h>
+#include <syslog.h>
 #include <sys/mman.h>
+#include <xen-tools/xenstore-common.h>
 
 #include "utils.h"
 #include "core.h"
 #include "osdep.h"
 
-void write_pidfile(const char *pidfile)
+static void write_pidfile(const char *pidfile)
 {
        char buf[100];
        int len;
@@ -49,7 +52,7 @@ void write_pidfile(const char *pidfile)
 }
 
 /* Stevens. */
-void daemonize(void)
+static void daemonize(void)
 {
        pid_t pid;
 
@@ -157,3 +160,27 @@ void *xenbus_map(void)
 
        return addr;
 }
+
+void early_init(bool live_update, bool dofork, const char *pidfile)
+{
+       reopen_log();
+
+       /* Make sure xenstored directory exists. */
+       /* Errors ignored here, will be reported when we open files */
+       mkdir(xenstore_daemon_rundir(), 0755);
+
+       if (dofork) {
+               openlog("xenstored", 0, LOG_DAEMON);
+               if (!live_update)
+                       daemonize();
+       }
+
+       if (pidfile)
+               write_pidfile(pidfile);
+
+       /* Don't kill us with SIGPIPE. */
+       signal(SIGPIPE, SIG_IGN);
+
+       if (!live_update)
+               init_sockets();
+}