[Zope-Checkins] CVS: Zope/lib/python/Controller - Main.py:1.1.2.2

Chris McDonough chrism@zope.com
Tue, 3 Sep 2002 03:44:16 -0400


Update of /cvs-repository/Zope/lib/python/Controller
In directory cvs.zope.org:/tmp/cvs-serv3114/lib/python/Controller

Modified Files:
      Tag: chrism-install-branch
	Main.py 
Log Message:
Merge of head into installer-branch.  Sorry.  :-(


=== Zope/lib/python/Controller/Main.py 1.1.2.1 => 1.1.2.2 ===
--- Zope/lib/python/Controller/Main.py:1.1.2.1	Mon Sep  2 03:35:09 2002
+++ Zope/lib/python/Controller/Main.py	Tue Sep  3 03:43:45 2002
@@ -123,41 +123,16 @@
         # do not set a pidfile (the pid is already written into the Z2.pid
         # file if we're not in readonly mode).
         zdaemon.run(sys.argv, pidfile='')
-        
-    # lock_file is used for the benefit of zctl, so it can tell whether
-    # Zope is already running before attempting to fire it off again.
-    # We aren't concerned about locking the file to protect against
-    # other Zope instances running from our CLIENT_HOME, we just
-    # try to lock the file to signal that zctl should not try to
-    # start Zope if *it* can't lock the file; we don't panic
-    # if we can't lock it.
-    if not READ_ONLY:
-        if os.path.exists(PID_FILE):
-            os.unlink(PID_FILE)
-        pf = open(PID_FILE, 'w')
-        try:
-            lock_file(pf)
-        except:
-            pass
-        pid=str(os.getpid())
-        try: pid=str(os.getppid())+' '+pid
-        except: pass
-        pf.write(pid)
-        pf.flush()
-        # hold on to the pidfile while its locked (we will clean it up later)
-        hold(pf)
 
     # set up our various loggers
     import zLOG
     import ZLogger
 
-    if READ_ONLY:
-        if hasattr(zLOG, '_set_stupid_dest'):
-            zLOG._set_stupid_dest(sys.stderr)
-        else:
-            zLOG._stupid_dest = sys.stderr
+    # log to stderr until we suid
+    if hasattr(zLOG, '_set_stupid_dest'):
+        zLOG._set_stupid_dest(sys.stderr)
     else:
-        zLOG.log_write = ZLogger.ZLogger.log_write
+        zLOG._stupid_dest = sys.stderr
 
     if DETAILED_LOG_FILE is not None:
         from ZServer import DebugLogger
@@ -408,11 +383,17 @@
             try:
                 import initgroups
             except:
-                raise SystemExit, 'initgroups is required to safely setuid'
+                msg = ('the "initgroups" module is required for a safe '
+                       'setuid.  Check your Zope installation for the '
+                       'initgroups.so module')
+                zLOG.LOG('z2', zLOG.PANIC, msg)
+                raise SystemExit, msg
             if UID == None:
-                raise SystemExit, ('A user was not specified to setuid '
-                                   'to; fix this to start as root (see '
-                                   'doc/SETUID.txt)')
+                msg = ('A user was not specified to setuid to; fix this to '
+                       'start as root (change the effective_user directive '
+                       'in zope.conf)')
+                zLOG.LOG('z2', zLOG.PANIC, msg)
+                raise SystemExit, msg
             import stat
             client_home_stat = os.stat(CLIENT_HOME)
             client_home_faults = []
@@ -424,7 +405,8 @@
                 client_home_faults.append('fix this to start as root (see '
                                           'doc/SETUID.txt)')
                 err = '%s %s' % (CLIENT_HOME, ', '.join(client_home_faults))
-                raise SystemExit, err
+                zLOG.LOG('z2', zLOG.PANIC, err)
+                #raise SystemExit, err
 
             try:
                 try:    UID = string.atoi(UID)
@@ -449,6 +431,8 @@
                         except OSError:
                             pass
                     os.setuid(uid)
+                    zLOG.LOG("Z2", zLOG.INFO,
+                             'Set effective user to "%s"' % UID)
                 except OSError:
                     pass
             except KeyError:
@@ -470,6 +454,33 @@
                 'your Zope data, it is recommended you use 077' % current_umask
                 ))
 
+    # lock_file is used for the benefit of zctl, so it can tell whether
+    # Zope is already running before attempting to fire it off again.
+    # We aren't concerned about locking the file to protect against
+    # other Zope instances running from our CLIENT_HOME, we just
+    # try to lock the file to signal that zctl should not try to
+    # start Zope if *it* can't lock the file; we don't panic
+    # if we can't lock it.
+    if not READ_ONLY:
+        if os.path.exists(PID_FILE):
+            os.unlink(PID_FILE)
+        pf = open(PID_FILE, 'w')
+        try:
+            lock_file(pf)
+        except:
+            pass
+        pid=str(os.getpid())
+        try: pid=str(os.getppid())+' '+pid
+        except: pass
+        pf.write(pid)
+        pf.flush()
+        # hold on to the pidfile while its locked (we will clean it up later)
+        hold(pf)
+
+    # move this to after setuid once we figure it out.
+    if not READ_ONLY:
+        zLOG.log_write = ZLogger.ZLogger.log_write
+
     # Start Medusa, Ye Hass!
     sys.ZServerExitCode=0
     try:
@@ -568,6 +579,7 @@
     pass
 
 def _warn_nobody():
+    import zLOG
     zLOG.LOG("z2", zLOG.INFO, ("Running Zope as 'nobody' can compromise "
                                "your Zope files; consider using a "
                                "dedicated user account for Zope"))