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

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