gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r737 - in GNUnet: contrib src/conf


From: durner
Subject: [GNUnet-SVN] r737 - in GNUnet: contrib src/conf
Date: Thu, 5 May 2005 12:48:15 -0700 (PDT)

Author: durner
Date: 2005-05-05 12:47:57 -0700 (Thu, 05 May 2005)
New Revision: 737

Added:
   GNUnet/contrib/server-user.in
Modified:
   GNUnet/contrib/config-user.in
   GNUnet/contrib/config.in
   GNUnet/src/conf/confdata.c
Log:


Modified: GNUnet/contrib/config-user.in
===================================================================
--- GNUnet/contrib/config-user.in       2005-05-05 11:50:49 UTC (rev 736)
+++ GNUnet/contrib/config-user.in       2005-05-05 19:47:57 UTC (rev 737)
@@ -1,29 +1,30 @@
 mainmenu "GNUnet user configuration"
 
+menu "User specific configuration" ""
 menu "Meta-configuration" "Meta"
-  config ADVANCED
-  bool "Show options for advanced users"
-  
-  config RARE
-  bool "Show rarely used options"
-  
-  config CONF_DEF_DIR
+  config config-user.in_CONF_DEF_DIR
   string "Default configuration directory"
-  depends on RARE
+  depends on RARE-CLIENT
   default "/etc/"
   help
        This is the directory where gnunet-setup will store the configuration
        file by default.
-       Default: CONF_DEF_DIR                   = ~/.gnunet/
+       Default: config-user.in_CONF_DEF_DIR                    = ~/.gnunet/
   
-  config CONF_DEF_FILE
+  config config-user.in_CONF_DEF_FILE
   string "Default configuration file"
-  depends on RARE
+  depends on RARE-CLIENT
   default "gnunet-user.conf"
   help
        This is the filename under which gnunet-setup will store the 
configuration
        by default.
-       Default: CONF_DEF_FILE          = gnunet-user.conf
+       Default: config-user.in_CONF_DEF_FILE           = gnunet-user.conf
+
+  config ADVANCED-CLIENT
+  bool "Show options for advanced users"
+  
+  config RARE-CLIENT
+  bool "Show rarely used options"  
 endmenu
 
 menu "General settings" "GNUNET"
@@ -38,7 +39,7 @@
        config LOGLEVEL
        string "What kinds of (debug) output should be printed"
        default "WARNING"
-       depends on Meta::ADVANCED
+       depends on Meta::ADVANCED-CLIENT
        help
                What kinds of (debug) output should be printed? You can 
                use NOTHING, FATAL, ERROR, FAILURE, WARNING, MESSAGE, INFO, 
DEBUG, 
@@ -49,7 +50,7 @@
        config LOGFILE
        string "Where to write the messages"
        default "$GNUNET_HOME/logs"
-       depends on Meta::ADVANCED
+       depends on Meta::ADVANCED-CLIENT
        help
                Where to write the messages? Leave the entry unspecified (as
                default) to make the clients print their messages to stderr.
@@ -57,17 +58,17 @@
 endmenu
 
 menu "Network options for the clients" "NETWORK"
-       config PORT
+       config CLIENT-PORT
        int "Port to use to talk to gnunetd"
        default 2087
-       depends on Meta::ADVANCED
+       depends on Meta::ADVANCED-CLIENT
        help
                Port to use to talk to gnunetd, default is 2087
 
        config HOST
        string "On which machine runs gnunetd (for clients)"
        default "localhost"
-       depends on Meta::ADVANCED
+       depends on Meta::ADVANCED-CLIENT
        help
                On which machine runs gnunetd (for clients) This is equivalent 
to
                the -H option.  Default is localhost.
@@ -78,7 +79,7 @@
        config INSERT-PRIORITY
        int "Default priority for locally inserted content"
        default 50
-       depends on Meta::RARE
+       depends on Meta::RARE-CLIENT
        help
                Default priority for locally inserted content
                Default: 50
@@ -86,7 +87,7 @@
        config INSERT-EXPIRATION
        int "Default expiration time for locally inserted content"
        default 36500
-       depends on Meta::RARE
+       depends on Meta::RARE-CLIENT
        help
                Default expiration time for locally inserted content, in days
                Default is 36500 (100 years)
@@ -94,7 +95,7 @@
        config SEARCHTIMEOUT
        int "How long should gnunet-search try to get an answer to a query"
        default 3000
-       depends on Meta::ADVANCED
+       depends on Meta::ADVANCED-CLIENT
        help
                How long should gnunet-search try to get an answer to a query 
before
                timing out (in seconds).  Default is "3000", which should be 
enough
@@ -103,28 +104,28 @@
        config ANONYMITY-RECEIVE
        int "Anonymity level for receiving data (default)"
        default 1
-       depends on Meta::ADVANCED
+       depends on Meta::ADVANCED-CLIENT
        help
                Anonymity level for receiving data (default)
 
        config ANONYMITY-SEND
        int "Anonymity level for sharing data (default)"
        default 1
-       depends on Meta::ADVANCED
+       depends on Meta::ADVANCED-CLIENT
        help
                Anonymity level for sharing data (default)
 
        config MAXRESULTS
        int "Default limit for the number of search results"
        default 0
-       depends on Meta::ADVANCED
+       depends on Meta::ADVANCED-CLIENT
        help
                Default limit for the number of search results (0 for unlimited)
 
        config SEARCHTIMEOUT
        int "Default timeout for searches"
        default 300
-       depends on Meta::ADVANCED
+       depends on Meta::ADVANCED-CLIENT
        help
                Default timeout for searches
 
@@ -132,7 +133,7 @@
        config EXTRACTORS
        string "Specify which additional extractor libraries should be used"
        default 
"libextractor_filename:-libextractor_split:-libextractor_lower:-libextractor_thumbnail"
-       depends on Meta::RARE
+       depends on Meta::RARE-CLIENT
        help
                Specify which additional extractor libraries should be used.
                gnunet-insert uses libextractor to extract keywords from files.
@@ -156,7 +157,7 @@
        config DISABLE-SYMLINK
        bool "Disable symlinking"
        default y
-       depends on Meta::RARE
+       depends on Meta::RARE-CLIENT
        help
                Disable symlinking.  When set to YES, GNUnet will always make
                a copy of the file when files are indexed.  The default is to
@@ -191,7 +192,7 @@
                Default: "my nickname"
 endmenu
 
-if Meta:RARE
+if Meta:RARE-CLIENT
 menu "Defaults for gnunet-tracekit" GNUNET-TRACEKIT
        config WAIT
        int "How long to wait for replies"
@@ -237,3 +238,5 @@
                Default is http://ovmj.org/GNUnet/testbed/
 endmenu
 endif
+
+endmenu

Modified: GNUnet/contrib/config.in
===================================================================
--- GNUnet/contrib/config.in    2005-05-05 11:50:49 UTC (rev 736)
+++ GNUnet/contrib/config.in    2005-05-05 19:47:57 UTC (rev 737)
@@ -1,6 +1,25 @@
 mainmenu "GNUnet Configuration"
 
+menu "Server configuration" ""
 menu "Meta-configuration" "Meta"
+  config config.in_CONF_DEF_DIR
+  string "Default configuration directory"
+  depends on RARE
+  default "/etc/"
+  help
+       This is the directory where gnunet-setup will store the configuration
+       file by default.
+       Default: config.in_CONF_DEF_DIR                 = /etc/
+  
+  config config.in_CONF_DEF_FILE
+  string "Default configuration file"
+  depends on RARE
+  default "gnunet.conf"
+  help
+       This is the filename under which gnunet-setup will store the 
configuration
+       by default.
+       Default: config.in_CONF_DEF_FILE                = gnunet.conf
+
   config EXPERIMENTAL
   bool "Prompt for development and/or incomplete code"
   help
@@ -24,24 +43,6 @@
   
   config RARE
   bool "Show rarely used options"
-  
-  config CONF_DEF_DIR
-  string "Default configuration directory"
-  depends on RARE
-  default "/etc/"
-  help
-       This is the directory where gnunet-setup will store the configuration
-       file by default.
-       Default: CONF_DEF_DIR                   = /etc/
-  
-  config CONF_DEF_FILE
-  string "Default configuration file"
-  depends on RARE
-  default "gnunet.conf"
-  help
-       This is the filename under which gnunet-setup will store the 
configuration
-       by default.
-       Default: CONF_DEF_FILE          = gnunet.conf
 endmenu
 
 menu "General settings" "GNUNETD"
@@ -857,3 +858,5 @@
        endif
        
 endmenu
+       
+endmenu

Added: GNUnet/contrib/server-user.in
===================================================================
--- GNUnet/contrib/server-user.in       2005-05-05 11:50:49 UTC (rev 736)
+++ GNUnet/contrib/server-user.in       2005-05-05 19:47:57 UTC (rev 737)
@@ -0,0 +1,4 @@
+mainmenu "GNUnet user configuration"
+
+source "/etc/config.in"
+source "/etc/config-user.in"

Modified: GNUnet/src/conf/confdata.c
===================================================================
--- GNUnet/src/conf/confdata.c  2005-05-05 11:50:49 UTC (rev 736)
+++ GNUnet/src/conf/confdata.c  2005-05-05 19:47:57 UTC (rev 737)
@@ -215,69 +215,139 @@
 
 int conf_write(const char *name)
 {
-       FILE *out;
+       FILE *out = NULL;
        struct symbol *sym;
        struct menu *menu;
        const char *basename;
-       char dirname[128], tmpname[128], dstname[128], newname[128];
+       char dirname[128], tmpname[128], newname[128];
        int type;
        const char *str;
-       struct symbol *confDefFn;
+       const char *cur_tmpl = NULL;
+       char **tempfiles = NULL;
+       int num_tempfiles = 0;
+       int idx;
 
   sym_clear_all_valid();
 
-       confDefFn = sym_find("CONF_DEF_FILE", "Meta");
-       sym_calc_value_ext(confDefFn, 1);       
-
-       dirname[0] = 0;
-       if (name && name[0]) {
-               char *slash = strrchr(name, DIR_SEPARATOR);
-               if (slash) {
-                       int size = slash - name + 1;
-                       memcpy(dirname, name, size);
-                       dirname[size] = 0;
-                       if (slash[1])
-                               basename = slash + 1;
-                       else
-                               basename = sym_get_string_value(confDefFn);
-               } else
-                       basename = name;
-       } else
-               basename = sym_get_string_value(confDefFn);
-
-       if (! dirname[0]) {
-               struct symbol *confDefDir;
-               
-               confDefDir = sym_find("CONF_DEF_DIR", "Meta");
-               sym_calc_value_ext(confDefDir, 1);
-               
-               strcpy(dirname, sym_get_string_value(confDefDir));
-       }
-
-       sprintf(newname,
-               "%s.tmpconfig.%u",
-               dirname,
-               (unsigned int) getpid());
-       out = FOPEN(newname, "w");
-       if (!out)
-               return 1;
-
-  fprintf(out, "#%s"
-                              "# Automatically generated by gnunet-setup%s"
-                              "#%s", NEWLINE, NEWLINE, NEWLINE);
-
        menu = rootmenu.list;
        while (menu) {
 
                sym = menu->sym;
+               
                if (!sym) {
 
                        str = menu_get_prompt(menu);
-                       if (str && strlen(str) > 0)
+                       if (str && strlen(str) > 0) {                   
+                               /* First of all, we have to determine where to 
write the menu's settings to.
+                                * There are two possibilites:
+                                *      1. There's a setting 
$prefix_CONF_DEF_FILE that defines the file
+                                *               (this is useful if independent 
.in files with different
+                                *     destination files are included 
together). $prefix is the name
+                                *     of the template file.
+                                *  2. We use conf_def_filename. */
+                               if (!out || (cur_tmpl == NULL || 
strcmp(cur_tmpl, menu->file->name) != 0)) {
+                                       char key[251];
+                                       struct symbol *fn_sym;
+                                       int registered;
+                                       char *prefix;
+                                       struct stat stat_cf;
+                                       int exists;
+                                       
+                                       /* This setting's destination file is 
different from the previous
+                                        * one's. */
+                                       if (out)
+                                               fclose(out);
+                                       
+                                       cur_tmpl = menu->file->name;
+                                       prefix = cur_tmpl + strlen(cur_tmpl);
+                                       while(*prefix != '/' && *prefix != '\\')
+                                               prefix--;
+                                       prefix++;
+                                       
+                                       /* Determine destination */
+                                       SNPRINTF(key, 250, "%s_CONF_DEF_FILE", 
prefix);
+                                       fn_sym = sym_find(key, "Meta");
+                                       
+                                       if (! fn_sym) {
+                                               /* Default filename */
+                                               strncpy(newname, 
conf_def_filename, 127);
+                                               newname[127] = 0;
+                                               basename = conf_def_filename;
+                                               strcpy(dirname, "/etc/");
+                                       }
+                                       else
+                                       {
+                                               sym_calc_value_ext(fn_sym, 1);
+               
+                                               dirname[0] = 0;
+                                               if (name && name[0]) {
+                                                       char *slash = 
strrchr(name, '/'); /* the path is always '/' delimited */
+                                                       if (slash) {
+                                                               int size = 
slash - name + 1;
+                                                               memcpy(dirname, 
name, size);
+                                                               dirname[size] = 
0;
+                                                               if (slash[1])
+                                                                       
basename = slash + 1;
+                                                               else
+                                                                       
basename = sym_get_string_value(fn_sym);
+                                                       } else
+                                                               basename = name;
+                                               } else
+                                                       basename = 
sym_get_string_value(fn_sym);
+                                       
+                                               if (! dirname[0]) {
+                                                       SNPRINTF(key, 250, 
"%s_CONF_DEF_DIR", prefix);
+                                                       fn_sym = sym_find(key, 
"Meta");
+                                                       
+                                                       if (fn_sym) {
+                                                               
sym_calc_value_ext(fn_sym, 1);
+                                                               strcpy(dirname, 
sym_get_string_value(fn_sym));
+                                                       }
+                                                       else
+                                                               strcpy(dirname, 
"/etc/");
+                                               }
+                                       }
+                                       
+                                       /* Create a temporary filename */
+                                       sprintf(newname,
+                                               "%s%s-%u.tmp",
+                                               dirname,
+                                               basename,
+                                               (unsigned int) getpid());
+               
+                                       exists = STAT(newname, &stat_cf);
+                                       
+                                       out = FOPEN(newname, "a");
+                                       
+                                       if (!out)
+                                               return 1;
+               
+                                       if (exists == -1)
+                                         fprintf(out, "#%s"
+                                                                        "# 
Automatically generated by gnunet-setup%s"
+                                                                        "#%s", 
NEWLINE, NEWLINE, NEWLINE);
+               
+                                       /* Save the temporary filename to 
rename it later */
+                                       registered = 0;
+                                       for (idx=0; idx < num_tempfiles; idx++) 
{
+                                               if (strcmp(tempfiles[idx], 
newname) == 0)
+                                                       registered = 1;
+                                       }
+                                       if (! registered) {
+                                               if (num_tempfiles == 0)
+                                                       tempfiles = 
malloc(sizeof(char **));
+                                               else
+                                                       tempfiles = 
realloc(tempfiles, (num_tempfiles + 1) * sizeof(char **));
+                                               tempfiles[num_tempfiles] = 
strdup(newname);
+                                               num_tempfiles++;
+                                       }
+                               }
+
                                fprintf(out, "%s"
                                        "#%s"
                                        "# %s%s"
                                        "#%s", NEWLINE, NEWLINE, str, NEWLINE, 
NEWLINE);
+                       }
                        if (menu->section && strlen(menu->section) > 0)
                                fprintf(out, "[%s]%s", menu->section, NEWLINE);
                } else if (!(sym->flags & SYMBOL_CHOICE)) {
@@ -333,17 +403,44 @@
                        }
                }
        }
-       fclose(out);
        
-       sprintf(tmpname, "%s%s.old", dirname, basename);
-       UNLINK(tmpname);
-       sprintf(dstname, "%s%s", dirname, basename);
-       RENAME(dstname, tmpname);
+       if (out)
+               fclose(out);
+       
+       for (idx=0; idx < num_tempfiles; idx++) {
+               char *dstname, *tempfile;
+               int dstlen;
+               
+               /* Get real destination name. The temporary name has the form
+                *              name-pid.tmp */
+               tempfile = tempfiles[idx];
+               dstlen = strlen(tempfile);
+               while (tempfile[dstlen] != '-')
+                       dstlen--;
+               
+               dstname = malloc(dstlen + 1);
+               strncpy(dstname, tempfile, dstlen);
+               dstname[dstlen] = 0;
+               
+               sprintf(tmpname, "%s.old", dstname);
+               UNLINK(tmpname);
+               RENAME(dstname, tmpname);
 
-       if (RENAME(newname, dstname))
-               return 1;
+               if (RENAME(tempfile, dstname)) {
+                       free(dstname);
+                       free(tempfile);
+
+                       return 1;
+               }
                
-       UNLINK(newname);
+               UNLINK(tempfile);
+               
+               free(dstname);
+               free(tempfile);
+       }
+       
+       if (tempfiles)
+               free(tempfiles);
 
        sym_change_count = 0;
 





reply via email to

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