[Spread-users] Re: [PATCH] spread_params.h configuration via spread.conf

Daniel Rall dlr at finemaltcoding.com
Tue Aug 27 18:03:17 EDT 2002


A thousand pardons.  I included the wrong version of the patch for
configuration.c.  The following version correctly free()'s previously
malloc()'d memory when the set_param_if_valid() is called more than
once.

So you can either use (last patch - its configuration.c section) +
this patch, or I can resend in its entirety if that is preferable.

                             Thanks, Dan

Index: configuration.c
===================================================================
RCS file: /storage/cvsroot/spread/daemon/configuration.c,v
retrieving revision 1.3
diff -u -u -r1.3 configuration.c
--- configuration.c	27 Aug 2002 01:10:52 -0000	1.3
+++ configuration.c	27 Aug 2002 21:59:31 -0000
@@ -68,6 +68,7 @@
 #endif	/* ARCH_PC_WIN95 */
 
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h> 
 #include <assert.h>
 
@@ -78,6 +79,7 @@
 #undef  ext_conf_body
 
 #include "alarm.h"
+#include "spread_params.h"
 
 static	proc		My;
 
@@ -89,6 +91,12 @@
 
 static  port_reuse SocketPortReuse = port_reuse_auto;
 
+static  char    *RuntimeDir = NULL;
+
+static	char	*User = NULL;
+
+static	char	*Group = NULL;
+
 static  int     Link_Protocol;
 
 int		Conf_init( char *file_name, char *my_name )
@@ -546,4 +554,61 @@
                 return;
         }
         SocketPortReuse = state;
+}
+
+static void set_param_if_valid(char **param, char *value, char *description)
+{
+        if (value != NULL && *value != '\0')
+        {
+                int len = strlen(value);
+                char *old_value = *param;
+                char *buf = malloc(len + 1);
+                if (buf == NULL)
+                {
+                        Alarm(EXIT, "Spread: Out of memory");
+                }
+                strncpy(buf, value, len);
+                buf[len] = '\0';
+
+                *param = buf;
+                if (old_value != NULL)
+                {
+                    free(old_value);
+                }
+                Alarm(PRINT, "Set %s to '%s'\n", description, value);
+        }
+        else
+        {
+                Alarm(DEBUG, "Ignored invalid %s\n", description);
+        }
+}
+
+char    *Conf_get_runtime_dir(void)
+{
+        return (RuntimeDir != NULL ? RuntimeDir : SP_RUNTIME_DIR);
+}
+
+void    Conf_set_runtime_dir(char *dir)
+{
+        set_param_if_valid(&RuntimeDir, dir, "runtime directory");
+}
+
+char    *Conf_get_user(void)
+{
+        return (User != NULL ? User : SP_USER);
+}
+
+void    Conf_set_user(char *user)
+{
+        set_param_if_valid(&User, user, "user name");
+}
+
+char    *Conf_get_group(void)
+{
+        return (Group != NULL ? Group : SP_GROUP);
+}
+
+void    Conf_set_group(char *group)
+{
+        set_param_if_valid(&Group, group, "group name");
 }




More information about the Spread-users mailing list