gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r36615 - gnunet-gtk/src/setup


From: gnunet
Subject: [GNUnet-SVN] r36615 - gnunet-gtk/src/setup
Date: Wed, 28 Oct 2015 14:37:31 +0100

Author: grothoff
Date: 2015-10-28 14:37:31 +0100 (Wed, 28 Oct 2015)
New Revision: 36615

Modified:
   gnunet-gtk/src/setup/gnunet-setup.c
Log:
give proper error message when we cannot write config file (#3675)

Modified: gnunet-gtk/src/setup/gnunet-setup.c
===================================================================
--- gnunet-gtk/src/setup/gnunet-setup.c 2015-10-28 13:21:36 UTC (rev 36614)
+++ gnunet-gtk/src/setup/gnunet-setup.c 2015-10-28 13:37:31 UTC (rev 36615)
@@ -517,7 +517,7 @@
  * Try elevating user priviledges to run as user 'gnunet' or 'root'.
  *
  * @param username user gnunet-setup should be run as
- * @return GNUNET_OK on success
+ * @return #GNUNET_OK on success
  */
 static int
 try_gksu (const char *username)
@@ -595,7 +595,6 @@
   uid_t my_uid;
   struct passwd *gnunet_pw;
 
-
   my_uid = getuid ();
   gnunet_pw = getpwnam ("gnunet");
   if ( (0 != do_gksu) &&
@@ -620,6 +619,39 @@
     (void) GNUNET_CONFIGURATION_load (cfg, option_cfg_name);
   else
     (void) GNUNET_CONFIGURATION_load (cfg, NULL);
+  if (0 != ACCESS (option_cfg_name,
+                   W_OK))
+  {
+    if (ENOENT == errno)
+    {
+      char *dirname;
+      size_t len;
+
+      (void) GNUNET_DISK_directory_create_for_file (option_cfg_name);
+      dirname = GNUNET_strdup (option_cfg_name);
+      len = strlen (dirname) - 1;
+      while ((len > 0) && (dirname[len] != DIR_SEPARATOR))
+        len--;
+      dirname[len] = '\0';
+      if (0 != ACCESS (dirname,
+                       X_OK | W_OK | R_OK))
+      {
+        if (ENOENT == errno)
+          errno = EACCES; /* really means somewhere access was denied */
+      }
+      else
+        errno = ENOENT; /* all good now */
+    }
+    if (ENOENT != errno)
+    {
+      fprintf (stderr,
+               "Refusing to start as I will be unable to write configuration 
file `%s': %s\n",
+               option_cfg_name,
+               STRERROR (errno));
+      GNUNET_GTK_main_loop_quit (ml);
+      return;
+    }
+  }
   main_window = GTK_WIDGET (GNUNET_SETUP_get_object ("GNUNET_setup_dialog"));
   main_window = GNUNET_GTK_plug_me ("GNUNET_FS_GTK_PLUG",
                                     main_window);




reply via email to

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