ia64/xen-unstable
changeset 6089:d74e320900fd
merge
author | kaf24@firebug.cl.cam.ac.uk |
---|---|
date | Wed Aug 10 09:50:15 2005 +0000 (2005-08-10) |
parents | e87001315978 66e6479d9ab8 |
children | 50e57636bdd8 |
files | linux-2.6-xen-sparse/arch/xen/configs/xenU_defconfig_x86_32 linux-2.6-xen-sparse/arch/xen/configs/xenU_defconfig_x86_64 linux-2.6-xen-sparse/arch/xen/i386/kernel/pci-dma.c linux-2.6-xen-sparse/arch/xen/x86_64/kernel/pci-dma.c tools/console/daemon/io.c tools/console/daemon/utils.c tools/misc/xend tools/xenstore/utils.c tools/xenstore/utils.h tools/xenstore/xenstored_core.c xen/common/page_alloc.c |
line diff
5.1 --- a/tools/console/daemon/io.c Wed Aug 10 09:50:05 2005 +0000 5.2 +++ b/tools/console/daemon/io.c Wed Aug 10 09:50:15 2005 +0000 5.3 @@ -231,6 +231,7 @@ static void handle_tty_read(struct domai 5.4 5.5 if (!write_sync(xcs_data_fd, &msg, sizeof(msg))) { 5.6 dolog(LOG_ERR, "Write to xcs failed: %m"); 5.7 + exit(1); 5.8 } 5.9 } else { 5.10 close(dom->tty_fd); 5.11 @@ -262,6 +263,7 @@ static void handle_xcs_msg(int fd) 5.12 5.13 if (!read_sync(fd, &msg, sizeof(msg))) { 5.14 dolog(LOG_ERR, "read from xcs failed! %m"); 5.15 + exit(1); 5.16 } else if (msg.type == XCS_REQUEST) { 5.17 struct domain *dom; 5.18
6.1 --- a/tools/console/daemon/utils.c Wed Aug 10 09:50:05 2005 +0000 6.2 +++ b/tools/console/daemon/utils.c Wed Aug 10 09:50:15 2005 +0000 6.3 @@ -59,6 +59,8 @@ bool _read_write_sync(int fd, void *data 6.4 6.5 if (len < 1) { 6.6 if (len == -1 && (errno == EAGAIN || errno == EINTR)) { 6.7 + continue; 6.8 + } else { 6.9 return false; 6.10 } 6.11 } else {
7.1 --- a/tools/misc/xend Wed Aug 10 09:50:05 2005 +0000 7.2 +++ b/tools/misc/xend Wed Aug 10 09:50:15 2005 +0000 7.3 @@ -24,6 +24,7 @@ import sys 7.4 import socket 7.5 import signal 7.6 import time 7.7 +import commands 7.8 7.9 XCS_PATH = "/var/lib/xen/xcs_socket" 7.10 XCS_EXEC = "/usr/sbin/xcs" 7.11 @@ -116,8 +117,7 @@ def stop_xcs(): 7.12 return 7.13 7.14 def start_xenstored(): 7.15 - if os.fork() == 0: 7.16 - os.execvp('/usr/sbin/xenstored', ['/usr/sbin/xenstored']); 7.17 + s,o = commands.getstatusoutput("/usr/sbin/xenstored --pid-file=/var/run/xenstore.pid"); 7.18 7.19 def start_consoled(): 7.20 if os.fork() == 0:
8.1 --- a/tools/xenstore/utils.c Wed Aug 10 09:50:05 2005 +0000 8.2 +++ b/tools/xenstore/utils.c Wed Aug 10 09:50:15 2005 +0000 8.3 @@ -80,30 +80,6 @@ void *malloc_nofail(size_t size) 8.4 barf("malloc of %zu failed", size); 8.5 } 8.6 8.7 -/* Stevens. */ 8.8 -void daemonize(void) 8.9 -{ 8.10 - pid_t pid; 8.11 - 8.12 - /* Separate from our parent via fork, so init inherits us. */ 8.13 - if ((pid = fork()) < 0) 8.14 - barf_perror("Failed to fork daemon"); 8.15 - if (pid != 0) 8.16 - exit(0); 8.17 - 8.18 - close(STDIN_FILENO); 8.19 - close(STDOUT_FILENO); 8.20 - close(STDERR_FILENO); 8.21 - 8.22 - /* Session leader so ^C doesn't whack us. */ 8.23 - setsid(); 8.24 - /* Move off any mount points we might be in. */ 8.25 - chdir("/"); 8.26 - /* Discard our parent's old-fashioned umask prejudices. */ 8.27 - umask(0); 8.28 -} 8.29 - 8.30 - 8.31 /* This version adds one byte (for nul term) */ 8.32 void *grab_file(const char *filename, unsigned long *size) 8.33 {
9.1 --- a/tools/xenstore/utils.h Wed Aug 10 09:50:05 2005 +0000 9.2 +++ b/tools/xenstore/utils.h Wed Aug 10 09:50:15 2005 +0000 9.3 @@ -40,9 +40,6 @@ void barf_perror(const char *fmt, ...) _ 9.4 void *grab_file(const char *filename, unsigned long *size); 9.5 void release_file(void *data, unsigned long size); 9.6 9.7 -/* For writing daemons, based on Stevens. */ 9.8 -void daemonize(void); 9.9 - 9.10 /* Signal handling: returns fd to listen on. */ 9.11 int signal_to_fd(int signal); 9.12 void close_signal(int fd);
10.1 --- a/tools/xenstore/xenstored_core.c Wed Aug 10 09:50:05 2005 +0000 10.2 +++ b/tools/xenstore/xenstored_core.c Wed Aug 10 09:50:15 2005 +0000 10.3 @@ -1540,10 +1540,49 @@ static void setup_structure(void) 10.4 xs_daemon_transactions()); 10.5 } 10.6 10.7 +static void write_pidfile(const char *pidfile) 10.8 +{ 10.9 + char buf[100]; 10.10 + int len; 10.11 + int fd; 10.12 + 10.13 + fd = open(pidfile, O_RDWR | O_CREAT, 0600); 10.14 + if (fd == -1) 10.15 + barf_perror("Opening pid file %s", pidfile); 10.16 + 10.17 + /* We exit silently if daemon already running. */ 10.18 + if (lockf(fd, F_TLOCK, 0) == -1) 10.19 + exit(0); 10.20 + 10.21 + len = sprintf(buf, "%d\n", getpid()); 10.22 + write(fd, buf, len); 10.23 +} 10.24 + 10.25 +/* Stevens. */ 10.26 +static void daemonize(void) 10.27 +{ 10.28 + pid_t pid; 10.29 + 10.30 + /* Separate from our parent via fork, so init inherits us. */ 10.31 + if ((pid = fork()) < 0) 10.32 + barf_perror("Failed to fork daemon"); 10.33 + if (pid != 0) 10.34 + exit(0); 10.35 + 10.36 + /* Session leader so ^C doesn't whack us. */ 10.37 + setsid(); 10.38 + /* Move off any mount points we might be in. */ 10.39 + chdir("/"); 10.40 + /* Discard our parent's old-fashioned umask prejudices. */ 10.41 + umask(0); 10.42 +} 10.43 + 10.44 + 10.45 static struct option options[] = { { "no-fork", 0, NULL, 'N' }, 10.46 { "verbose", 0, NULL, 'V' }, 10.47 { "output-pid", 0, NULL, 'P' }, 10.48 { "trace-file", 1, NULL, 'T' }, 10.49 + { "pid-file", 1, NULL, 'F' }, 10.50 { NULL, 0, NULL, 0 } }; 10.51 10.52 int main(int argc, char *argv[]) 10.53 @@ -1553,6 +1592,7 @@ int main(int argc, char *argv[]) 10.54 fd_set inset, outset; 10.55 bool dofork = true; 10.56 bool outputpid = false; 10.57 + const char *pidfile = NULL; 10.58 10.59 while ((opt = getopt_long(argc, argv, "DVT:", options, NULL)) != -1) { 10.60 switch (opt) { 10.61 @@ -1572,11 +1612,20 @@ int main(int argc, char *argv[]) 10.62 optarg); 10.63 write(tracefd, "\n***\n", strlen("\n***\n")); 10.64 break; 10.65 + case 'F': 10.66 + pidfile = optarg; 10.67 } 10.68 } 10.69 if (optind != argc) 10.70 barf("%s: No arguments desired", argv[0]); 10.71 10.72 + if (dofork) { 10.73 + openlog("xenstored", 0, LOG_DAEMON); 10.74 + daemonize(); 10.75 + } 10.76 + if (pidfile) 10.77 + write_pidfile(pidfile); 10.78 + 10.79 talloc_enable_leak_report_full(); 10.80 10.81 /* Create sockets for them to listen to. */ 10.82 @@ -1623,19 +1672,18 @@ int main(int argc, char *argv[]) 10.83 /* Restore existing connections. */ 10.84 restore_existing_connections(); 10.85 10.86 - /* Debugging: daemonize() closes standard fds, so dup here. */ 10.87 - tmpout = dup(STDOUT_FILENO); 10.88 - if (dofork) { 10.89 - openlog("xenstored", 0, LOG_DAEMON); 10.90 - daemonize(); 10.91 - } 10.92 - 10.93 if (outputpid) { 10.94 char buffer[20]; 10.95 sprintf(buffer, "%i\n", getpid()); 10.96 write(tmpout, buffer, strlen(buffer)); 10.97 } 10.98 - close(tmpout); 10.99 + 10.100 + /* close stdin/stdout now we're ready to accept connections */ 10.101 + if (dofork) { 10.102 + close(STDIN_FILENO); 10.103 + close(STDOUT_FILENO); 10.104 + close(STDERR_FILENO); 10.105 + } 10.106 10.107 #ifdef TESTING 10.108 signal(SIGUSR1, stop_failtest);