diff src/noffle.c @ 270:d6fedc09b052 noffle

[svn] * src/noffle.c: Rearrange initialisation so that a requested usage message will be output before Noffle can fail due to misconfiguration. Introduce routine (currently stub) for checking file ownership and permissions on startup - I suspect a lot of reported errors are due to ownership problems.
author bears
date Sun, 10 Nov 2002 11:30:40 +0000
parents 52f467c7213b
children 5eece4dfd945
line wrap: on
line diff
--- a/src/noffle.c	Fri Oct 25 12:04:57 2002 +0100
+++ b/src/noffle.c	Sun Nov 10 11:30:40 2002 +0000
@@ -10,7 +10,7 @@
   received for some seconds (to allow multiple clients connect at the same
   time).
 
-  $Id: noffle.c 387 2002-06-26 13:15:44Z bears $
+  $Id: noffle.c 402 2002-11-10 11:30:40Z bears $
 */
 
 #if HAVE_CONFIG_H
@@ -553,6 +553,16 @@
 }
 
 /*
+  Check file ownership and permissions.
+  This assumes we have cd'd to the spool directory.
+ */
+static Bool
+checkFileOwnership( void )
+{
+    return TRUE;
+}
+
+/*
   Allow core files: Change core limit and change working directory
   to spool directory, where news has write permissions.
 */
@@ -573,12 +583,6 @@
         return;
     }
     Log_dbg( LOG_DBG_NOFFLE, "Core limit set to %i", lim.rlim_max );
-    if ( chdir( Cfg_spoolDir() ) != 0 )
-    {
-         Log_err( "Cannot change to directory '%s'", Cfg_spoolDir() );
-         return;
-    }
-    Log_dbg( LOG_DBG_NOFFLE, "Changed to directory '%s'", Cfg_spoolDir() );
 }
 
 static Bool
@@ -587,6 +591,18 @@
     Log_init( "noffle", noffle.lockAtStartup, LOG_NEWS );
     Cfg_read();
     Log_dbg( LOG_DBG_NOFFLE, "NOFFLE version %s", Cfg_version() );
+
+    /* cd to the spool directory */
+    if ( chdir( Cfg_spoolDir() ) != 0 )
+    {
+         Log_err( "Cannot change to directory '%s'", Cfg_spoolDir() );
+         return FALSE;
+    }
+    Log_dbg( LOG_DBG_NOFFLE, "Changed to directory '%s'", Cfg_spoolDir() );
+
+    if ( ! checkFileOwnership() )
+	return FALSE;
+
     if ( noffle.lockAtStartup )
         if ( ! Lock_openDatabases() )
             return FALSE;
@@ -667,7 +683,7 @@
 doInews( int argc, char **argv )
 {
     int result;
-    int flags;
+    unsigned flags;
     FILE *f;
 
     UNUSED( argc );
@@ -818,6 +834,17 @@
     }
 
     noffle.lockAtStartup = ! ( c == 'r' || c == 'h' );
+
+    /*
+      If they asked for help, give it before there's a possibility
+      we could fail on init.
+     */
+    if ( c == 'h' )
+    {
+        printUsage();
+	return EXIT_SUCCESS;
+    }
+
     if ( ! initNoffle() )
         return EXIT_FAILURE;
     result = EXIT_SUCCESS;