Fix aliases so that aliases are applied to the profile name as well as

the entries

Add rewrite as an alternative alias keyword
This commit is contained in:
John Johansen 2009-06-10 20:26:31 +00:00
parent 5a2b875b81
commit 3850ede5cf
4 changed files with 32 additions and 7 deletions

View file

@ -260,7 +260,7 @@ extern void dump_expanded_symtab(void);
/* parser_alias.c */
extern int new_alias(const char *from, const char *to);
extern void replace_aliases(void *list);
extern void replace_aliases(struct codomain *cod);
extern void free_aliases(void);
/* parser_merge.c */

View file

@ -114,7 +114,6 @@ static char *do_alias(struct alias_rule *alias, const char *target)
}
static struct cod_entry *target_list;
static void process_entries(const void *nodep, VISIT value, int __unused level)
{
struct alias_rule **t = (struct alias_rule **) nodep;
@ -147,10 +146,36 @@ static void process_entries(const void *nodep, VISIT value, int __unused level)
}
}
void replace_aliases(void *list)
static struct codomain *target_cod;
static void process_name(const void *nodep, VISIT value, int __unused level)
{
target_list = list;
twalk(alias_table, process_entries);
struct alias_rule **t = (struct alias_rule **) nodep;
struct codomain *cod = target_cod;
int len;
if (value == preorder || value == endorder)
return;
len = strlen((*t)->from);
if (cod->name && strncmp((*t)->from, cod->name, len) == 0) {
char *new = do_alias(*t, cod->name);
if (!new)
return;
free(cod->name);
cod->name = new;
}
}
void replace_aliases(struct codomain *cod)
{
target_cod = cod;
twalk(alias_table, process_name);
if (cod->entries) {
target_list = cod->entries;
twalk(alias_table, process_entries);
}
}
static void free_alias(void *nodep)

View file

@ -71,6 +71,7 @@ static struct keyword_table keyword_table[] = {
{"set", TOK_SET},
{"rlimit", TOK_RLIMIT},
{"alias", TOK_ALIAS},
{"rewrite", TOK_ALIAS},
{"ptrace", TOK_PTRACE},
/* terminate */
{NULL, 0}

View file

@ -328,8 +328,7 @@ static void __process_alias(const void *nodep, const VISIT value,
if (value == preorder || value == endorder)
return;
if ((*t)->entries)
replace_aliases((*t)->entries);
replace_aliases((*t));
if ((*t)->hat_table)
twalk((*t)->hat_table, __process_alias);