Blame SOURCES/autofs-5.0.8-fix-macro_addvar-and-move-init-to-main-thread.patch

304803
autofs-5.0.8 - fix macro_addvar() and move init to main thread
304803
304803
From: Ian Kent <raven@themaw.net>
304803
304803
- move macro table initialization to the main thread.
304803
- change to using malloc() instead of realloc() in macro_global_addvar()
304803
  and macro_addvar().
304803
- fix possible incorrect return from macro_addvar().
304803
---
304803
 CHANGELOG           |    1 +
304803
 daemon/automount.c  |   16 ++++++++++++++++
304803
 lib/macros.c        |   25 ++++++++++++++++++++-----
304803
 modules/parse_sun.c |    9 ---------
304803
 4 files changed, 37 insertions(+), 14 deletions(-)
304803
304803
--- autofs-5.0.7.orig/CHANGELOG
304803
+++ autofs-5.0.7/CHANGELOG
304803
@@ -89,6 +89,7 @@
304803
 - fix symlink expire.
304803
 - fix master map type check.
304803
 - fix bad mkdir permission on create.
304803
+- fix macro_addvar() and move init to main thread.
304803
 
304803
 25/07/2012 autofs-5.0.7
304803
 =======================
304803
--- autofs-5.0.7.orig/daemon/automount.c
304803
+++ autofs-5.0.7/daemon/automount.c
304803
@@ -2129,6 +2129,9 @@ int main(int argc, char *argv[])
304803
 			program);
304803
 #endif
304803
 
304803
+	/* Get processor information for predefined escapes */
304803
+	macro_init();
304803
+
304803
 	if (dumpmaps) {
304803
 		struct master_mapent *entry;
304803
 		struct list_head *head, *p;
304803
@@ -2152,6 +2155,7 @@ int main(int argc, char *argv[])
304803
 			master_list = master_new(master, timeout, ghost);
304803
 		if (!master_list) {
304803
 			printf("%s: can't create master map", program);
304803
+			macro_free_global_table();
304803
 			exit(1);
304803
 		}
304803
 
304803
@@ -2163,6 +2167,7 @@ int main(int argc, char *argv[])
304803
 		if (!nc) {
304803
 			printf("%s: failed to init null map cache for %s",
304803
 				program, master_list->name);
304803
+			macro_free_global_table();
304803
 			exit(1);
304803
 		}
304803
 		master_list->nc = nc;
304803
@@ -2187,6 +2192,7 @@ int main(int argc, char *argv[])
304803
 			master_free_mapent(entry);
304803
 		}
304803
 		master_kill(master_list);
304803
+		macro_free_global_table();
304803
 
304803
 		exit(0);
304803
 	}
304803
@@ -2198,6 +2204,7 @@ int main(int argc, char *argv[])
304803
 
304803
 	if (!master_list) {
304803
 		printf("%s: can't create master map %s", program, argv[0]);
304803
+		macro_free_global_table();
304803
 		exit(1);
304803
 	}
304803
 
304803
@@ -2209,6 +2216,7 @@ int main(int argc, char *argv[])
304803
 		res = write(start_pipefd[1], pst_stat, sizeof(*pst_stat));
304803
 		close(start_pipefd[1]);
304803
 		release_flag_file();
304803
+		macro_free_global_table();
304803
 		exit(1);
304803
 	}
304803
 
304803
@@ -2218,6 +2226,7 @@ int main(int argc, char *argv[])
304803
 		res = write(start_pipefd[1], pst_stat, sizeof(*pst_stat));
304803
 		close(start_pipefd[1]);
304803
 		release_flag_file();
304803
+		macro_free_global_table();
304803
 		exit(1);
304803
 	}
304803
 
304803
@@ -2228,6 +2237,7 @@ int main(int argc, char *argv[])
304803
 		res = write(start_pipefd[1], pst_stat, sizeof(*pst_stat));
304803
 		close(start_pipefd[1]);
304803
 		release_flag_file();
304803
+		macro_free_global_table();
304803
 		exit(1);
304803
 	}
304803
 
304803
@@ -2239,6 +2249,7 @@ int main(int argc, char *argv[])
304803
 		res = write(start_pipefd[1], pst_stat, sizeof(*pst_stat));
304803
 		close(start_pipefd[1]);
304803
 		release_flag_file();
304803
+		macro_free_global_table();
304803
 		exit(1);
304803
 	}
304803
 #endif
304803
@@ -2257,6 +2268,7 @@ int main(int argc, char *argv[])
304803
 		res = write(start_pipefd[1], pst_stat, sizeof(*pst_stat));
304803
 		close(start_pipefd[1]);
304803
 		release_flag_file();
304803
+		macro_free_global_table();
304803
 		exit(1);
304803
 	}
304803
 
304803
@@ -2268,6 +2280,7 @@ int main(int argc, char *argv[])
304803
 		res = write(start_pipefd[1], pst_stat, sizeof(*pst_stat));
304803
 		close(start_pipefd[1]);
304803
 		release_flag_file();
304803
+		macro_free_global_table();
304803
 		exit(1);
304803
 	}
304803
 
304803
@@ -2277,6 +2290,7 @@ int main(int argc, char *argv[])
304803
 		res = write(start_pipefd[1], pst_stat, sizeof(*pst_stat));
304803
 		close(start_pipefd[1]);
304803
 		release_flag_file();
304803
+		macro_free_global_table();
304803
 		exit(1);
304803
 	}
304803
 
304803
@@ -2299,6 +2313,7 @@ int main(int argc, char *argv[])
304803
 		res = write(start_pipefd[1], pst_stat, sizeof(*pst_stat));
304803
 		close(start_pipefd[1]);
304803
 		release_flag_file();
304803
+		macro_free_global_table();
304803
 		exit(3);
304803
 	}
304803
 
304803
@@ -2323,6 +2338,7 @@ int main(int argc, char *argv[])
304803
 	}
304803
 	closelog();
304803
 	release_flag_file();
304803
+	macro_free_global_table();
304803
 
304803
 #ifdef TIRPC_WORKAROUND
304803
 	if (dh_tirpc)
304803
--- autofs-5.0.7.orig/lib/macros.c
304803
+++ autofs-5.0.7/lib/macros.c
304803
@@ -35,6 +35,7 @@ static struct substvar
304803
 };
304803
 
304803
 static struct substvar *system_table = &sv_osvers;
304803
+static unsigned int macro_init_done = 0;
304803
 
304803
 static pthread_mutex_t table_mutex = PTHREAD_MUTEX_INITIALIZER;
304803
 static pthread_mutex_t macro_mutex = PTHREAD_MUTEX_INITIALIZER;
304803
@@ -62,6 +63,12 @@ void dump_table(struct substvar *table)
304803
 /* Get processor information for predefined macro definitions */
304803
 void macro_init(void)
304803
 {
304803
+	macro_lock();
304803
+	if (macro_init_done) {
304803
+		macro_unlock();
304803
+		return;
304803
+	}
304803
+
304803
 	uname(&un;;
304803
 	/*
304803
 	 * uname -p is not defined on Linux.  Make it the same as
304803
@@ -71,6 +78,10 @@ void macro_init(void)
304803
 	if (processor[0] == 'i' && processor[1] >= '3' &&
304803
 		!strcmp(processor + 2, "86"))
304803
 		processor[1] = '3';
304803
+
304803
+	macro_init_done = 1;
304803
+	macro_unlock();
304803
+	return;
304803
 }
304803
 
304803
 int macro_is_systemvar(const char *str, int len)
304803
@@ -118,10 +129,11 @@ int macro_global_addvar(const char *str,
304803
 	}
304803
 
304803
 	if (sv && !sv->readonly) {
304803
-		char *this = realloc(sv->val, strlen(value) + 1);
304803
+		char *this = malloc(strlen(value) + 1);
304803
 		if (!this)
304803
 			goto done;
304803
-		strcat(this, value);
304803
+		strcpy(this, value);
304803
+		free(sv->val);
304803
 		sv->val = this;
304803
 		ret = 1;
304803
 	} else {
304803
@@ -213,13 +225,16 @@ macro_addvar(struct substvar *table, con
304803
 	}
304803
 
304803
 	if (lv) {
304803
-		char *this = realloc(lv->val, strlen(value) + 1);
304803
+		char *this = malloc(strlen(value) + 1);
304803
 		if (!this) {
304803
 			lv = table;
304803
 			goto done;
304803
 		}
304803
-		strcat(this, value);
304803
+		strcpy(this, value);
304803
+		free(lv->val);
304803
 		lv->val = this;
304803
+		if (lv != table)
304803
+			lv = table;
304803
 	} else {
304803
 		struct substvar *new;
304803
 		char *def, *val;
304803
@@ -413,7 +428,7 @@ macro_findvar(const struct substvar *tab
304803
 	etmp[len]='\0';
304803
 
304803
 	if ((value=getenv(etmp)) != NULL) {
304803
-		lv_var = macro_addvar(table, str, len, value);
304803
+		lv_var = macro_addvar((struct substvar *) table, str, len, value);
304803
 		return(lv_var);
304803
 	}
304803
 #endif
304803
--- autofs-5.0.7.orig/modules/parse_sun.c
304803
+++ autofs-5.0.7/modules/parse_sun.c
304803
@@ -41,7 +41,6 @@ int parse_version = AUTOFS_PARSE_VERSION
304803
 
304803
 static struct mount_mod *mount_nfs = NULL;
304803
 static int init_ctr = 0;
304803
-static int macro_init_done = 0;
304803
 static pthread_mutex_t instance_mutex = PTHREAD_MUTEX_INITIALIZER;
304803
 
304803
 static void instance_mutex_lock(void)
304803
@@ -243,14 +242,6 @@ int parse_init(int argc, const char *con
304803
 	int i, bval;
304803
 	unsigned int append_options;
304803
 
304803
-	/* Get processor information for predefined escapes */
304803
-	macro_lock();
304803
-	if (!macro_init_done) {
304803
-		macro_init_done = 1;
304803
-		macro_init();
304803
-	}
304803
-	macro_unlock();
304803
-
304803
 	/* Set up context and escape chain */
304803
 
304803
 	if (!(ctxt = (struct parse_context *) malloc(sizeof(struct parse_context)))) {