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