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

[xen master] tools/xenstored: add early_init() function



commit e767a98f040d8274b0f1dc991b9eefbc13b39e2d
Author:     Juergen Gross <jgross@xxxxxxxx>
AuthorDate: Mon Feb 5 11:49:50 2024 +0100
Commit:     Julien Grall <jgrall@xxxxxxxxxx>
CommitDate: Mon Feb 5 19:26:32 2024 +0000

    tools/xenstored: add early_init() function
    
    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@xxxxxxxx>
    Reviewed-by: Jason Andryuk <jandryuk@xxxxxxxxx>
    Reviewed-by: Julien Grall <jgrall@xxxxxxxxxx>
---
 tools/xenstored/core.c   | 30 +++---------------------------
 tools/xenstored/core.h   |  7 +++----
 tools/xenstored/minios.c | 11 +++--------
 tools/xenstored/posix.c  | 31 +++++++++++++++++++++++++++++--
 4 files changed, 38 insertions(+), 41 deletions(-)

diff --git a/tools/xenstored/core.c b/tools/xenstored/core.c
index d4c76d71dc..eba7744fde 100644
--- a/tools/xenstored/core.c
+++ b/tools/xenstored/core.c
@@ -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. */
diff --git a/tools/xenstored/core.h b/tools/xenstored/core.h
index 480b0f5f7b..72173f1684 100644
--- a/tools/xenstored/core.h
+++ b/tools/xenstored/core.h
@@ -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);
 
diff --git a/tools/xenstored/minios.c b/tools/xenstored/minios.c
index 0779efbf91..4f48f63083 100644
--- a/tools/xenstored/minios.c
+++ b/tools/xenstored/minios.c
@@ -20,14 +20,6 @@
 #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)
+{
+}
diff --git a/tools/xenstored/posix.c b/tools/xenstored/posix.c
index 7e03dd982d..9463ef5c8d 100644
--- a/tools/xenstored/posix.c
+++ b/tools/xenstored/posix.c
@@ -20,14 +20,17 @@
 #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();
+}
--
generated by git-patchbot for /home/xen/git/xen.git#master



 


Rackspace

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