From: Daniel Ottavio Date: Mon, 29 Aug 2005 03:24:25 +0000 (+0000) Subject: * amd/sun_map.c (sun_entry2amd) : Wipe out any trailing white X-Git-Tag: before-clocktime-fixes~9 X-Git-Url: https://git.fsl.cs.stonybrook.edu/?a=commitdiff_plain;h=c41ee89149e82909a8bd5f00d7e508788944b950;p=am-utils-6.0.git * amd/sun_map.c (sun_entry2amd) : Wipe out any trailing white spaces or 'n' before passing strings to the parser. --- diff --git a/ChangeLog b/ChangeLog index 286eac5..e98a616 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2005-08-28 Daniel P. Ottavio + + * amd/sun_map.c (sun_entry2amd) : Wipe out any trailing white + spaces or '\n' before passing strings to the parser. + 2005-08-27 Erez Zadok * libamu/xutil.c: amd_program_number is a u_long now. diff --git a/amd/amd.h b/amd/amd.h index 8967323..b2b8915 100644 --- a/amd/amd.h +++ b/amd/amd.h @@ -351,6 +351,7 @@ struct mnt_map { kv *kvhash[NKVHASH]; /* Cached data */ cf_map_t *cfm; /* pointer to per-map amd.conf opts, if any */ void *map_data; /* Map data black box */ + mnt_map *include; /* list of included maps */ }; /* @@ -572,6 +573,7 @@ extern int background(void); extern void deslashify(char *); extern void do_task_notify(void); extern int eval_fs_opts(am_opts *, char *, char *, char *, char *, char *); +extern char **file_search_include(char *); extern int file_read_line(char *, int, FILE *); extern void forcibly_timeout_mp(am_node *); extern void free_map(am_node *); diff --git a/amd/info_file.c b/amd/info_file.c index c672509..44cd5e2 100644 --- a/amd/info_file.c +++ b/amd/info_file.c @@ -53,10 +53,15 @@ #include +/* max number of include lines a map file can have */ +#define MAX_INCLUDE_LINES 16 + + /* forward declarations */ int file_init_or_mtime(mnt_map *m, char *map, time_t *tp); int file_reload(mnt_map *m, char *map, void (*fn) (mnt_map *, char *, char *)); int file_search(mnt_map *m, char *map, char *key, char **pval, time_t *tp); +static FILE *file_open(char *map, time_t *tp); int @@ -90,6 +95,55 @@ file_read_line(char *buf, int size, FILE *fp) return done; } +char ** +file_search_include(char *map) { + + char line_buff[INFO_MAX_LINE_LEN]; + FILE *mapf = NULL; + char **retval = NULL, *tmp; + int count = 0; + size_t len = 0; + + if ((mapf = fopen(map, "r")) == NULL) { + plog(XLOG_ERROR, "could not read file %s", map); + goto err; + } + + len = MAX_INCLUDE_LINES * sizeof(char*); + retval = (char **)xmalloc(len); + memset(retval, 0, len); + + memset(line_buff, 0, sizeof(line_buff)); + + while ((len = file_read_line(line_buff, sizeof(line_buff), mapf)) > 0) { + if (line_buff[0] == '+') { + if(count <= MAX_INCLUDE_LINES) { + tmp = &line_buff[1]; + if(*tmp) { + /* remove any trailing white spaces and '\n' */ + int ws = strlen(tmp) - 1; + while (ws >= 0 && (isspace(tmp[ws]) || tmp[ws] == '\n')) { + tmp[ws--] = '\0'; + } + + retval[count++] = strdup(tmp); + } + } + else { + plog(XLOG_WARNING, "too many include lines in map %s", map); + } + } + memset(line_buff, 0, sizeof(line_buff)); + } + + if(count == 0) { + /* If there are no include lines, pass back NULL */ + XFREE(retval); + } + + err: + return retval; +} /* * Try to locate a key in a file @@ -160,6 +214,7 @@ file_search_or_reload(mnt_map *m, * Return a copy of the data */ char *dc; + printf("key :%s\n", kp); if (m->cfm->cfm_flags & CFM_SUN_MAP_SYNTAX) dc = sun_entry2amd(kp, cp); else diff --git a/amd/mapc.c b/amd/mapc.c index 206287c..5155787 100644 --- a/amd/mapc.c +++ b/amd/mapc.c @@ -541,6 +541,16 @@ search_map(mnt_map *m, char *key, char **valp) plog(XLOG_MAP, "Re-synchronizing cache for map %s", m->map_name); mapc_sync(m); } + if (rc < 0) { + /* Try to search any included maps. */ + mnt_map *inc; + for (inc = m->include; inc != NULL; inc = NEXT(mnt_map, inc)) { + rc = (*inc->search) (m, m->map_name, key, valp, &m->modify); + if (rc > 0) { + break; + } + } + } } while (rc < 0); return rc; @@ -575,7 +585,7 @@ mapc_reload_map(mnt_map *m) int error; kv *maphash[NKVHASH], *tmphash[NKVHASH]; time_t t; - + error = (*m->mtime) (m, m->map_name, &t); if (error) { t = m->modify; @@ -1001,6 +1011,35 @@ mapc_sync(mnt_map *m) */ mapc_find_wildcard(m); } + + if (strchr(m->map_name, (int)'/') != NULL) { + /* + * Look for include lines in the map file. If the map name + * contains a '/' than we assume that it is a file map type. + */ + char **include; + int k; + + /* serch for a list of include lines */ + include = file_search_include(m->map_name); + if (include != NULL) { + /* + * For each include line create a mnt_map and add it to the + * list of included maps. + */ + mnt_map *map; + for (k = 0; include[k] != NULL; k++) { + map = mapc_create(include[k], + "mapdefault", + "file", + m->cfm->cfm_dir); + /* Add the new map to the list of included maps. */ + ((qelem *)map)->q_forw = (qelem *)(m->include); + m->include = map; + } + XFREE(include); + } + } } } diff --git a/amd/sun_map.c b/amd/sun_map.c index 8c1d69d..d71d41c 100644 --- a/amd/sun_map.c +++ b/amd/sun_map.c @@ -516,6 +516,7 @@ sun_entry2amd(const char *key, const char *s_entry_str) { char *retval = NULL; char line_buff[INFO_MAX_LINE_LEN]; + int ws; struct sun_entry *s_entry = NULL; /* For now the key should no be NULL. */ @@ -528,9 +529,16 @@ sun_entry2amd(const char *key, const char *s_entry_str) plog(XLOG_ERROR,"Sun entry value was null"); goto err; } - + + /* Make sure there are no trailing white spaces or '\n'. */ + xstrlcpy(line_buff, s_entry_str, sizeof(line_buff)); + ws = strlen(line_buff) - 1; + while (ws >= 0 && (isspace(line_buff[ws]) || line_buff[ws] == '\n')) { + line_buff[ws--] = '\0'; + } + /* Parse the sun entry line. */ - s_entry = sun_map_parse_read(s_entry_str); + s_entry = sun_map_parse_read(line_buff); if (s_entry == NULL) { plog(XLOG_ERROR,"could not parse Sun style map"); goto err; diff --git a/amd/sun_map_parse.y b/amd/sun_map_parse.y index 2ee7a8a..0ec3412 100644 --- a/amd/sun_map_parse.y +++ b/amd/sun_map_parse.y @@ -219,6 +219,9 @@ entry : locations { /* Add this entry to the entry list. */ sun_list_add(get_sun_entry_list(), (qelem *)entry); } + +/* We need to allow include lines, but we do not handle them here. */ +| '+' WORD ; mountpoints : mountpoint