[PATCH RFC] Terminate the log with one last message.

Peter Hutterer peter.hutterer at who-t.net
Tue Jul 19 20:17:43 PDT 2011


Instead of just closing the log when everything is done, put one more
message in stating that we're actually terminating. Users or scripts that
look at the Xorg.log will then know that a) the server has terminated
properly and b) why the server terminated (to some degree, given that most
real-world errors will be caused by AbortServer()).

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
Admittedly the error codes are a bit bolted on, but I'd be happy with just
one terminating line. It would make thinks like 
http://patchwork.freedesktop.org/patch/6461/
easier to detect with scripts.

suggestions welcome.

 dix/main.c                        |    2 +-
 doc/Xserver-spec.xml              |    4 ++--
 hw/dmx/dmxinit.c                  |    6 +++---
 hw/kdrive/src/kdrive.c            |    6 +++---
 hw/vfb/InitOutput.c               |    6 +++---
 hw/xfree86/common/xf86Configure.c |    2 +-
 hw/xfree86/common/xf86Helper.c    |    4 ++--
 hw/xfree86/common/xf86Init.c      |    8 ++++----
 hw/xfree86/common/xf86Priv.h      |    2 +-
 hw/xfree86/common/xf86ShowOpts.c  |    2 +-
 hw/xnest/Init.c                   |    6 +++---
 hw/xquartz/darwin.c               |    4 ++--
 hw/xwin/InitOutput.c              |    6 +++---
 include/os.h                      |   13 ++++++++++---
 os/log.c                          |    6 ++++--
 15 files changed, 43 insertions(+), 34 deletions(-)

diff --git a/dix/main.c b/dix/main.c
index 955b7ea..16575ce 100644
--- a/dix/main.c
+++ b/dix/main.c
@@ -347,7 +347,7 @@ int main(int argc, char *argv[], char *envp[])
 
 	if (dispatchException & DE_TERMINATE)
 	{
-	    ddxGiveUp();
+	    ddxGiveUp(EXIT_NO_ERROR);
 	    break;
 	}
 
diff --git a/doc/Xserver-spec.xml b/doc/Xserver-spec.xml
index 7d7f915..b14e489 100644
--- a/doc/Xserver-spec.xml
+++ b/doc/Xserver-spec.xml
@@ -4680,8 +4680,8 @@ An Example implementation is miPushPixels() in Xserver/mi/mipushpxl.c.</para>
   <title>Shutdown Procedures</title>
 <para>
 <blockquote><programlisting>
-	void AbortDDX()
-	void ddxGiveUp()
+	void AbortDDX(enum ExitCode error)
+	void ddxGiveUp(enum ExitCode error)
 </programlisting></blockquote>
 Some hardware may require special work to be done before the server
 exits so that it is not left in an intermediate state.  As explained
diff --git a/hw/dmx/dmxinit.c b/hw/dmx/dmxinit.c
index 74b3582..bc1509b 100644
--- a/hw/dmx/dmxinit.c
+++ b/hw/dmx/dmxinit.c
@@ -821,7 +821,7 @@ static void dmxSetDefaultFontPath(char *fp)
 /** This function is called in Xserver/os/utils.c from \a AbortServer().
  * We must ensure that backend and console state is restored in the
  * event the server shutdown wasn't clean. */
-void AbortDDX(void)
+void AbortDDX(enum ExitCode error)
 {
     int i;
 
@@ -842,9 +842,9 @@ void ddxBeforeReset(void)
 /** This function is called in Xserver/dix/main.c from \a main() when
  * dispatchException & DE_TERMINATE (which is the only way to exit the
  * main loop without an interruption. */
-void ddxGiveUp(void)
+void ddxGiveUp(enum ExitCode error)
 {
-    AbortDDX();
+    AbortDDX(error);
 }
 
 /** This function is called in Xserver/os/osinit.c from \a OsInit(). */
diff --git a/hw/kdrive/src/kdrive.c b/hw/kdrive/src/kdrive.c
index f034ce4..8dd039e 100644
--- a/hw/kdrive/src/kdrive.c
+++ b/hw/kdrive/src/kdrive.c
@@ -232,7 +232,7 @@ KdProcessSwitch (void)
 }
 
 void
-AbortDDX(void)
+AbortDDX(enum ExitCode error)
 {
     KdDisableScreens ();
     if (kdOsFuncs)
@@ -249,9 +249,9 @@ AbortDDX(void)
 }
 
 void
-ddxGiveUp (void)
+ddxGiveUp (enum ExitCode error)
 {
-    AbortDDX ();
+    AbortDDX (error);
 }
 
 Bool	kdDumbDriver;
diff --git a/hw/vfb/InitOutput.c b/hw/vfb/InitOutput.c
index 53f82f9..31ed505 100644
--- a/hw/vfb/InitOutput.c
+++ b/hw/vfb/InitOutput.c
@@ -150,7 +150,7 @@ vfbBitsPerPixel(int depth)
 }
 
 void
-ddxGiveUp(void)
+ddxGiveUp(enum ExitCode error)
 {
     int i;
 
@@ -201,9 +201,9 @@ ddxGiveUp(void)
 }
 
 void
-AbortDDX(void)
+AbortDDX(enum ExitCode error)
 {
-    ddxGiveUp();
+    ddxGiveUp(error);
 }
 
 #ifdef __APPLE__
diff --git a/hw/xfree86/common/xf86Configure.c b/hw/xfree86/common/xf86Configure.c
index 9752669..ab07515 100644
--- a/hw/xfree86/common/xf86Configure.c
+++ b/hw/xfree86/common/xf86Configure.c
@@ -749,7 +749,7 @@ DoConfigure(void)
 
 bail:
     OsCleanup(TRUE);
-    AbortDDX();
+    AbortDDX(EXIT_ERR_CONFIGURE);
     fflush(stderr);
     exit(0);
 }
diff --git a/hw/xfree86/common/xf86Helper.c b/hw/xfree86/common/xf86Helper.c
index 3cdffdb..f8e6c8b 100644
--- a/hw/xfree86/common/xf86Helper.c
+++ b/hw/xfree86/common/xf86Helper.c
@@ -1198,9 +1198,9 @@ xf86LogInit(void)
 }
 
 void
-xf86CloseLog(void)
+xf86CloseLog(enum ExitCode error)
 {
-    LogClose();
+    LogClose(error);
 }
 
 
diff --git a/hw/xfree86/common/xf86Init.c b/hw/xfree86/common/xf86Init.c
index 22f0f0a..f39ce87 100644
--- a/hw/xfree86/common/xf86Init.c
+++ b/hw/xfree86/common/xf86Init.c
@@ -900,7 +900,7 @@ OsVendorInit(void)
  */
 
 void
-ddxGiveUp(void)
+ddxGiveUp(enum ExitCode error)
 {
     int i;
 
@@ -927,7 +927,7 @@ ddxGiveUp(void)
     if (xorgHWOpenConsole)
 	xf86CloseConsole();
 
-    xf86CloseLog();
+    xf86CloseLog(error);
 
     /* If an unexpected signal was caught, dump a core for debugging */
     if (xf86Info.caughtSignal)
@@ -944,7 +944,7 @@ ddxGiveUp(void)
  */
 
 void
-AbortDDX(void)
+AbortDDX(enum ExitCode error)
 {
   int i;
 
@@ -977,7 +977,7 @@ AbortDDX(void)
    * This is needed for an abnormal server exit, since the normal exit stuff
    * MUST also be performed (i.e. the vt must be left in a defined state)
    */
-  ddxGiveUp();
+  ddxGiveUp(error);
 }
 
 void
diff --git a/hw/xfree86/common/xf86Priv.h b/hw/xfree86/common/xf86Priv.h
index 5d91ab3..1fe3d7e 100644
--- a/hw/xfree86/common/xf86Priv.h
+++ b/hw/xfree86/common/xf86Priv.h
@@ -140,7 +140,7 @@ extern _X_EXPORT pmWait (*xf86PMConfirmEventToOs)(int fd,pmEvent event);
 
 /* xf86Helper.c */
 extern _X_EXPORT void xf86LogInit(void);
-extern _X_EXPORT void xf86CloseLog(void);
+extern _X_EXPORT void xf86CloseLog(enum ExitCode error);
 
 /* xf86Init.c */
 extern _X_EXPORT Bool xf86LoadModules(char **list, pointer *optlist);
diff --git a/hw/xfree86/common/xf86ShowOpts.c b/hw/xfree86/common/xf86ShowOpts.c
index c0fa80a..a805916 100644
--- a/hw/xfree86/common/xf86ShowOpts.c
+++ b/hw/xfree86/common/xf86ShowOpts.c
@@ -124,7 +124,7 @@ void DoShowOptions (void) {
 	}
 	bail:
 	OsCleanup (TRUE);                             
-	AbortDDX ();                                                           
+	AbortDDX (EXIT_ERR_DRIVERS);
 	fflush (stderr);                        
 	exit (0);
 }
diff --git a/hw/xnest/Init.c b/hw/xnest/Init.c
index ea0669a..af57518 100644
--- a/hw/xnest/Init.c
+++ b/hw/xnest/Init.c
@@ -114,16 +114,16 @@ CloseInput(void)
 /*
  * DDX - specific abort routine.  Called by AbortServer().
  */
-void AbortDDX(void)
+void AbortDDX(enum ExitCode error)
 {
   xnestDoFullGeneration = True;
   xnestCloseDisplay();
 }
 
 /* Called by GiveUp(). */
-void ddxGiveUp(void)
+void ddxGiveUp(enum ExitCode error)
 {
-  AbortDDX();
+  AbortDDX(error);
 }
 
 #ifdef __APPLE__
diff --git a/hw/xquartz/darwin.c b/hw/xquartz/darwin.c
index 73685b0..a946448 100644
--- a/hw/xquartz/darwin.c
+++ b/hw/xquartz/darwin.c
@@ -766,7 +766,7 @@ void ddxUseMsg( void )
  * ddxGiveUp --
  *      Device dependent cleanup. Called by dix before normal server death.
  */
-void ddxGiveUp( void )
+void ddxGiveUp( enum ExitCode error )
 {
     ErrorF( "Quitting Xquartz\n" );
 }
@@ -779,7 +779,7 @@ void ddxGiveUp( void )
  *      are closed.
  */
 _X_NORETURN
-void AbortDDX( void ) {
+void AbortDDX( enum ExitCode error ) {
     ErrorF( "   AbortDDX\n" );
     OsAbort();
 }
diff --git a/hw/xwin/InitOutput.c b/hw/xwin/InitOutput.c
index 22ef8da..756fcd3 100644
--- a/hw/xwin/InitOutput.c
+++ b/hw/xwin/InitOutput.c
@@ -191,7 +191,7 @@ ddxBeforeReset (void)
 
 /* See Porting Layer Definition - p. 57 */
 void
-ddxGiveUp (void)
+ddxGiveUp (enum ExitCode error)
 {
   int		i;
 
@@ -258,12 +258,12 @@ ddxGiveUp (void)
 
 /* See Porting Layer Definition - p. 57 */
 void
-AbortDDX (void)
+AbortDDX (enum ExitCode error)
 {
 #if CYGDEBUG
   winDebug ("AbortDDX\n");
 #endif
-  ddxGiveUp ();
+  ddxGiveUp (error);
 }
 
 #ifdef __CYGWIN__
diff --git a/include/os.h b/include/os.h
index 506dc5d..a553f57 100644
--- a/include/os.h
+++ b/include/os.h
@@ -459,8 +459,15 @@ typedef struct {
 /* stuff for FlushCallback */
 extern _X_EXPORT CallbackListPtr FlushCallback;
 
-extern _X_EXPORT void AbortDDX(void);
-extern _X_EXPORT void ddxGiveUp(void);
+enum ExitCode {
+    EXIT_NO_ERROR	= 0,
+    EXIT_ERR_ABORT	= 1,
+    EXIT_ERR_CONFIGURE	= 2,
+    EXIT_ERR_DRIVERS	= 3,
+};
+
+extern _X_EXPORT void AbortDDX(enum ExitCode error);
+extern _X_EXPORT void ddxGiveUp(enum ExitCode error);
 extern _X_EXPORT int TimeSinceLastInputEvent(void);
 
 /* strcasecmp.c */
@@ -508,7 +515,7 @@ typedef enum {
 } MessageType;
 
 extern _X_EXPORT const char *LogInit(const char *fname, const char *backup);
-extern _X_EXPORT void LogClose(void);
+extern _X_EXPORT void LogClose(enum ExitCode error);
 extern _X_EXPORT Bool LogSetParameter(LogParameter param, int value);
 extern _X_EXPORT void LogVWrite(int verb, const char *f, va_list args) _X_ATTRIBUTE_PRINTF(2,0);
 extern _X_EXPORT void LogWrite(int verb, const char *f, ...) _X_ATTRIBUTE_PRINTF(2,3);
diff --git a/os/log.c b/os/log.c
index 4a310e6..f519762 100644
--- a/os/log.c
+++ b/os/log.c
@@ -231,9 +231,11 @@ LogInit(const char *fname, const char *backup)
 }
 
 void
-LogClose(void)
+LogClose(enum ExitCode error)
 {
     if (logFile) {
+	ErrorF("Server terminated %s (%d). Closing log file.\n",
+		(error == EXIT_NO_ERROR) ? "successfully" : "with error", error);
 	fclose(logFile);
 	logFile = NULL;
     }
@@ -411,7 +413,7 @@ AbortServer(void)
     CloseWellKnownConnections();
     OsCleanup(TRUE);
     CloseDownDevices();
-    AbortDDX();
+    AbortDDX(EXIT_ERR_ABORT);
     fflush(stderr);
     if (CoreDump)
 	OsAbort();
-- 
1.7.6



More information about the xorg-devel mailing list