mirror of
https://github.com/xen-project/xen.git
synced 2026-10-29 10:40:03 +01:00
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@suse.com> Reviewed-by: Jason Andryuk <jandryuk@gmail.com> Reviewed-by: Julien Grall <jgrall@amazon.com>
This commit is contained in:
1 parent
1c2c7f7901
commit
e767a98f04
4 files changed
+38
-41
No files matched your search
+3
-27
@@ -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. */
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
}
|
||||
+29
-2
@@ -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();
|
||||
}
|
||||