gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r5753 - in GNUnet/src: server util/boot util/loggers


From: gnunet
Subject: [GNUnet-SVN] r5753 - in GNUnet/src: server util/boot util/loggers
Date: Sat, 24 Nov 2007 20:45:14 -0700 (MST)

Author: grothoff
Date: 2007-11-24 20:45:13 -0700 (Sat, 24 Nov 2007)
New Revision: 5753

Modified:
   GNUnet/src/server/gnunetd.c
   GNUnet/src/util/boot/startup.c
   GNUnet/src/util/loggers/file.c
Log:
fixing mantis 1291

Modified: GNUnet/src/server/gnunetd.c
===================================================================
--- GNUnet/src/server/gnunetd.c 2007-11-24 23:00:11 UTC (rev 5752)
+++ GNUnet/src/server/gnunetd.c 2007-11-25 03:45:13 UTC (rev 5753)
@@ -87,20 +87,6 @@
           _("`%s' is shutting down.\n"), "gnunetd");
 }
 
-
-static int
-post_detach ()
-{
-  if (GNUNET_OK != changeUser (ectx, cfg))
-    return GNUNET_SYSERR;
-  if (GNUNET_OK != checkPermissions (ectx, cfg))
-    return GNUNET_SYSERR;
-  mon = GNUNET_network_monitor_create (ectx, cfg);
-  if (mon == NULL)
-    return GNUNET_SYSERR;
-  return GNUNET_OK;
-}
-
 /**
  * The main method of gnunetd.
  */
@@ -115,7 +101,7 @@
     return GNUNET_SYSERR;
   if (GNUNET_NO != debug_flag)
     GNUNET_pid_file_write (ectx, cfg, (unsigned int) getpid ());
-  if (GNUNET_OK != post_detach ())
+  if (NULL == (mon = GNUNET_network_monitor_create (ectx, cfg)))
     {
       if (GNUNET_NO == debug_flag)
         GNUNET_terminal_detach_complete (ectx, filedes, GNUNET_NO);
@@ -156,7 +142,6 @@
   waitForSignalHandler (ectx);
   disableCoreProcessing ();
   GNUNET_cron_stop (cron);
-  GNUNET_pid_file_delete (ectx, cfg);
   stopTCPServer ();
   unloadApplicationModules ();
   doneConnection ();
@@ -235,6 +220,17 @@
       GNUNET_fini (ectx, cfg);
       return 1;
     }
+  GNUNET_pid_file_write(ectx, cfg, getpid());
+  if (GNUNET_OK != changeUser (ectx, cfg)) {
+    GNUNET_pid_file_delete(ectx, cfg);
+    GNUNET_fini (ectx, cfg);
+    return 1;
+  }
+  if (GNUNET_OK != checkPermissions (ectx, cfg)) {
+    GNUNET_pid_file_delete (ectx, cfg);
+    GNUNET_fini (ectx, cfg);
+    return 1;
+  }
   if (GNUNET_YES == debug_flag)
     {
       int dev;
@@ -271,6 +267,7 @@
               _
               ("Configuration or GNUnet version changed.  You need to run 
`%s'!\n"),
               "gnunet-update");
+      GNUNET_pid_file_delete (ectx, cfg);
       GNUNET_fini (ectx, cfg);
       return 1;
     }
@@ -288,6 +285,7 @@
   else
 #endif
     ret = gnunet_main ();
+  GNUNET_pid_file_delete (ectx, cfg);
   GNUNET_fini (ectx, cfg);
   if (ret != GNUNET_OK)
     return 1;

Modified: GNUnet/src/util/boot/startup.c
===================================================================
--- GNUnet/src/util/boot/startup.c      2007-11-24 23:00:11 UTC (rev 5752)
+++ GNUnet/src/util/boot/startup.c      2007-11-25 03:45:13 UTC (rev 5753)
@@ -69,12 +69,17 @@
   struct GE_Context *tetx;
   unsigned long long logrotate;
   int dev;
-  char *user;
+  char * user;
+  char * rdir;
+  size_t len;
+  size_t pos;
 
   nctx = NULL;
   admin_log_file = NULL;
   admin_log_level = NULL;
   user_log_level = NULL;
+  user = NULL;
+  GC_get_configuration_value_string (cfg, "GNUNETD", "USER", NULL, &user);
   logrotate = 7;
   if (-1 == GC_get_configuration_value_number (cfg,
                                                "GNUNETD",
@@ -86,7 +91,29 @@
                                        "LOGFILE",
                                        VAR_DAEMON_DIRECTORY "/logs",
                                        &admin_log_file);
-  GNUNET_disk_directory_create_for_file (*ectx, admin_log_file);
+  if (user != NULL) {
+    rdir = GNUNET_expand_file_name (NULL, admin_log_file);
+    GE_ASSERT(NULL, rdir != NULL);
+    len = strlen (rdir);
+    pos = 1;
+    while (pos < len) {
+      if (rdir[pos] == DIR_SEPARATOR) {
+       rdir[pos] = '\0';
+       if (mkdir(rdir, S_IRUSR | S_IWUSR| S_IXUSR) == 0) {
+         GNUNET_file_change_owner(nctx,
+                                  rdir,
+                                  user);
+       } else if (errno != EEXIST) {
+         GE_LOG_STRERROR_FILE (NULL,
+                               GE_ERROR | GE_USER | GE_BULK,
+                               "mkdir", rdir);      
+       }
+       rdir[pos] = DIR_SEPARATOR;
+      } 
+      pos++;
+    }
+    GNUNET_free(rdir);
+  }
   GC_get_configuration_value_string (cfg,
                                      "LOGGING",
                                      "ADMIN-LEVEL",
@@ -95,8 +122,6 @@
                                      "LOGGING",
                                      "USER-LEVEL",
                                      "WARNING", &user_log_level);
-  user = NULL;
-  GC_get_configuration_value_string (cfg, "GNUNETD", "USER", NULL, &user);
   dev =
     GC_get_configuration_value_yesno (cfg, "LOGGING", "DEVELOPER", GNUNET_NO);
   all = convertLogLevel (admin_log_level);
@@ -130,6 +155,7 @@
       else
         nctx = GE_create_context_multiplexer (nctx, tetx);
     }
+  GNUNET_free_non_null(user);
   GE_setDefaultContext (nctx);
   GE_free_context (*ectx);
   *ectx = nctx;

Modified: GNUnet/src/util/loggers/file.c
===================================================================
--- GNUnet/src/util/loggers/file.c      2007-11-24 23:00:11 UTC (rev 5752)
+++ GNUnet/src/util/loggers/file.c      2007-11-25 03:45:13 UTC (rev 5753)
@@ -333,6 +333,8 @@
       GNUNET_free (name);
       return NULL;              /* ERROR! */
     }
+  if (owner != NULL)
+    GNUNET_file_change_owner (NULL, name, owner);
   fctx = GNUNET_malloc (sizeof (FileContext));
   fctx->first_start = GNUNET_YES;
   fctx->logdate = logDate;





reply via email to

[Prev in Thread] Current Thread [Next in Thread]