aboutsummaryrefslogtreecommitdiffstats
path: root/tools/xenstore/xenstored_core.c
diff options
context:
space:
mode:
authorDaniel De Graaf <dgdegra@tycho.nsa.gov>2012-02-09 18:33:34 +0000
committerDaniel De Graaf <dgdegra@tycho.nsa.gov>2012-02-09 18:33:34 +0000
commitf5f38f9f51d3dcf214d1035f8c23b2c2004243eb (patch)
tree3d04dae6798afdeb923a105f7999dfee2130c473 /tools/xenstore/xenstored_core.c
parent47a365c7f287dd670b95f3ac206a815c3043d5fe (diff)
downloadxen-f5f38f9f51d3dcf214d1035f8c23b2c2004243eb.tar.gz
xen-f5f38f9f51d3dcf214d1035f8c23b2c2004243eb.tar.bz2
xen-f5f38f9f51d3dcf214d1035f8c23b2c2004243eb.zip
xenstored: support running in minios stubdom
A previous versions of this patch has been sent to xen-devel. See http://lists.xensource.com/archives/html/xen-devel/2009-03/msg01655.html Signed-off-by: Diego Ongaro <diego.ongaro@citrix.com> Signed-off-by: Alex Zeffertt <alex.zeffertt@eu.citrix.com> Signed-off-by: Daniel De Graaf <dgdegra@tycho.nsa.gov> Acked-by: Ian Campbell <ian.campbell@citrix.com> Cc: Ian Jackson <ian.jackson@eu.citrix.com> Cc: Stefano Stabellini <stefano.stabellini@eu.citrix.com> Committed-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
Diffstat (limited to 'tools/xenstore/xenstored_core.c')
-rw-r--r--tools/xenstore/xenstored_core.c88
1 files changed, 10 insertions, 78 deletions
diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_core.c
index 4b12cf27cc..a762db714f 100644
--- a/tools/xenstore/xenstored_core.c
+++ b/tools/xenstore/xenstored_core.c
@@ -224,7 +224,6 @@ static void reopen_log(void)
}
}
-
static bool write_messages(struct connection *conn)
{
int ret;
@@ -327,7 +326,8 @@ static int initialize_set(fd_set *inset, fd_set *outset, int sock, int ro_sock,
set_fd(sock, inset, &max);
if (ro_sock != -1)
set_fd(ro_sock, inset, &max);
- set_fd(reopen_log_pipe[0], inset, &max);
+ if (reopen_log_pipe[0] != -1)
+ set_fd(reopen_log_pipe[0], inset, &max);
if (xce_handle != NULL)
set_fd(xc_evtchn_fd(xce_handle), inset, &max);
@@ -1664,53 +1664,6 @@ static void corrupt(struct connection *conn, const char *fmt, ...)
}
-static void write_pidfile(const char *pidfile)
-{
- char buf[100];
- int len;
- int fd;
-
- fd = open(pidfile, O_RDWR | O_CREAT, 0600);
- if (fd == -1)
- barf_perror("Opening pid file %s", pidfile);
-
- /* We exit silently if daemon already running. */
- if (lockf(fd, F_TLOCK, 0) == -1)
- exit(0);
-
- len = snprintf(buf, sizeof(buf), "%ld\n", (long)getpid());
- if (write(fd, buf, len) != len)
- barf_perror("Writing pid file %s", pidfile);
-}
-
-/* Stevens. */
-static void daemonize(void)
-{
- pid_t pid;
-
- /* Separate from our parent via fork, so init inherits us. */
- if ((pid = fork()) < 0)
- barf_perror("Failed to fork daemon");
- if (pid != 0)
- exit(0);
-
- /* Session leader so ^C doesn't whack us. */
- setsid();
-
- /* Let session leader exit so child cannot regain CTTY */
- if ((pid = fork()) < 0)
- barf_perror("Failed to fork daemon");
- if (pid != 0)
- exit(0);
-
- /* Move off any mount points we might be in. */
- if (chdir("/") == -1)
- barf_perror("Failed to chdir");
-
- /* Discard our parent's old-fashioned umask prejudices. */
- umask(0);
-}
-
#ifdef NO_SOCKETS
static void init_sockets(int **psock, int **pro_sock)
{
@@ -1874,20 +1827,10 @@ int main(int argc, char *argv[])
reopen_log();
- /* make sure xenstored directory exists */
- if (mkdir(xs_daemon_rundir(), 0755)) {
- if (errno != EEXIST) {
- perror("error: mkdir daemon rundir");
- exit(-1);
- }
- }
-
- if (mkdir(xs_daemon_rootdir(), 0755)) {
- if (errno != EEXIST) {
- perror("error: mkdir daemon rootdir");
- exit(-1);
- }
- }
+ /* make sure xenstored directories exist */
+ /* Errors ignored here, will be reported when we open files */
+ mkdir(xs_daemon_rundir(), 0755);
+ mkdir(xs_daemon_rootdir(), 0755);
if (dofork) {
openlog("xenstored", 0, LOG_DAEMON);
@@ -1904,10 +1847,7 @@ int main(int argc, char *argv[])
signal(SIGPIPE, SIG_IGN);
init_sockets(&sock, &ro_sock);
-
- if (pipe(reopen_log_pipe)) {
- barf_perror("pipe");
- }
+ init_pipe(reopen_log_pipe);
/* Setup the database */
setup_structure();
@@ -1925,16 +1865,8 @@ int main(int argc, char *argv[])
}
/* redirect to /dev/null now we're ready to accept connections */
- if (dofork) {
- int devnull = open("/dev/null", O_RDWR);
- if (devnull == -1)
- barf_perror("Could not open /dev/null\n");
- dup2(devnull, STDIN_FILENO);
- dup2(devnull, STDOUT_FILENO);
- dup2(devnull, STDERR_FILENO);
- close(devnull);
- xprintf = trace;
- }
+ if (dofork)
+ finish_daemonize();
signal(SIGHUP, trigger_reopen_log);
@@ -1957,7 +1889,7 @@ int main(int argc, char *argv[])
barf_perror("Select failed");
}
- if (FD_ISSET(reopen_log_pipe[0], &inset)) {
+ if (reopen_log_pipe[0] != -1 && FD_ISSET(reopen_log_pipe[0], &inset)) {
char c;
if (read(reopen_log_pipe[0], &c, 1) != 1)
barf_perror("read failed");