WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] Attached are

# HG changeset patch
# User kaf24@xxxxxxxxxxxxxxxxxxxx
# Node ID 61cbf8f977ef85724fb76f2421218ec3f670ea9c
# Parent  ebf05456ee11174c1a28aa678a438af56c8c1fb4
Attached are 
three patches to fix a problem with Xend starting consoled.  consoled 
depends on xenstored to be running and xenstored is started on demand in 
Xend.  The patches change xenstored to manage its own pidfile, and have 
xend start actually start up xenstored.

diff -r ebf05456ee11 -r 61cbf8f977ef tools/misc/xend
--- a/tools/misc/xend   Thu Aug  4 17:37:09 2005
+++ b/tools/misc/xend   Thu Aug  4 18:51:55 2005
@@ -114,6 +114,14 @@
         xcs_pidfile.close()
     except:
        return    
+
+def start_xenstored():
+    if os.fork() == 0:
+        os.execvp('/usr/sbin/xenstored', ['/usr/sbin/xenstored']);
+
+def start_consoled():
+    if os.fork() == 0:
+        os.execvp('/usr/sbin/consoled', ['/usr/sbin/consoled']);
             
 def main():
     try:
@@ -130,11 +138,13 @@
         return status >> 8
     elif sys.argv[1] == 'start':
         start_xcs()
-        if os.fork() == 0:
-            os.execvp('/usr/sbin/consoled', ['/usr/sbin/consoled']);
+        start_xenstored()
+        start_consoled()
         return daemon.start()
     elif sys.argv[1] == 'trace_start':
         start_xcs()
+        start_xenstored()
+        start_consoled()
         return daemon.start(trace=1)
     elif sys.argv[1] == 'stop':
         stop_xcs()
@@ -142,6 +152,8 @@
     elif sys.argv[1] == 'restart':
         stop_xcs()
         start_xcs()
+        start_xenstored()
+        start_consoled()
         return daemon.stop() or daemon.start()
     elif sys.argv[1] == 'status':
         return daemon.status()
diff -r ebf05456ee11 -r 61cbf8f977ef tools/python/xen/xend/server/SrvDaemon.py
--- a/tools/python/xen/xend/server/SrvDaemon.py Thu Aug  4 17:37:09 2005
+++ b/tools/python/xen/xend/server/SrvDaemon.py Thu Aug  4 18:51:55 2005
@@ -126,12 +126,8 @@
     def cleanup_xend(self, kill=False):
         return self.cleanup_process(XEND_PID_FILE, "xend", kill)
 
-    def cleanup_xenstored(self, kill=False):
-        return self.cleanup_process(XENSTORED_PID_FILE, "xenstored", kill)
-
     def cleanup(self, kill=False):
         self.cleanup_xend(kill=kill)
-        #self.cleanup_xenstored(kill=kill)
 
     def status(self):
         """Returns the status of the xend daemon.
@@ -167,31 +163,6 @@
             pidfile.write(str(pid))
             pidfile.close()
         return pid
-
-    def start_xenstored(self):
-        """Fork and exec xenstored, writing its pid to XENSTORED_PID_FILE.
-        """
-        def mkdirs(p):
-            try:
-                os.makedirs(p)
-            except:
-                pass
-        mkdirs(XENSTORED_RUN_DIR)
-        mkdirs(XENSTORED_LIB_DIR)
-        
-        pid = self.fork_pid(XENSTORED_PID_FILE)
-        if pid:
-            # Parent
-            log.info("Started xenstored, pid=%d", pid)
-        else:
-            # Child
-            if XEND_DAEMONIZE:
-                self.daemonize()
-            if XENSTORED_DEBUG:
-                os.execl("/usr/sbin/xenstored", "xenstored", "--no-fork",
-                         "-T", "/var/log/xenstored-trace.log")
-            else:
-                os.execl("/usr/sbin/xenstored", "xenstored", "--no-fork")
 
     def daemonize(self):
         if not XEND_DAEMONIZE: return
@@ -223,14 +194,10 @@
         4  Insufficient privileges
         """
         xend_pid = self.cleanup_xend()
-        xenstored_pid = self.cleanup_xenstored()
 
         if self.set_user():
             return 4
         os.chdir("/")
-
-        if xenstored_pid == 0:
-            self.start_xenstored()
 
         if xend_pid > 0:
             # Trying to run an already-running service is a success.
diff -r ebf05456ee11 -r 61cbf8f977ef tools/xenstore/utils.c
--- a/tools/xenstore/utils.c    Thu Aug  4 17:37:09 2005
+++ b/tools/xenstore/utils.c    Thu Aug  4 18:51:55 2005
@@ -84,6 +84,9 @@
 void daemonize(void)
 {
        pid_t pid;
+       int fd;
+       size_t len;
+       char buf[100];
 
        /* Separate from our parent via fork, so init inherits us. */
        if ((pid = fork()) < 0)
@@ -101,6 +104,18 @@
        chdir("/");
        /* Discard our parent's old-fashioned umask prejudices. */
        umask(0);
+
+       fd = open("/var/run/xenstored.pid", O_RDWR | O_CREAT);
+       if (fd == -1) {
+               exit(1);
+       }
+
+       if (lockf(fd, F_TLOCK, 0) == -1) {
+               exit(1);
+       }
+
+       len = sprintf(buf, "%d\n", getpid());
+       write(fd, buf, len);
 }
 
 

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] Attached are, Xen patchbot -unstable <=