From aa6f5ffbdba45aa8e19e5048648fc6c7b25376d3 Mon Sep 17 00:00:00 2001 From: merge Date: Thu, 22 Jan 2009 13:55:32 +0000 Subject: MERGE-via-pending-tracking-hist-MERGE-via-stable-tracking-MERGE-via-mokopatches-tracking-fix-stray-endmenu-patch-1232632040-1232632141 pending-tracking-hist top was MERGE-via-stable-tracking-MERGE-via-mokopatches-tracking-fix-stray-endmenu-patch-1232632040-1232632141 / fdf777a63bcb59e0dfd78bfe2c6242e01f6d4eb9 ... parent commitmessage: From: merge MERGE-via-stable-tracking-hist-MERGE-via-mokopatches-tracking-fix-stray-endmenu-patch-1232632040 stable-tracking-hist top was MERGE-via-mokopatches-tracking-fix-stray-endmenu-patch-1232632040 / 90463bfd2d5a3c8b52f6e6d71024a00e052b0ced ... parent commitmessage: From: merge MERGE-via-mokopatches-tracking-hist-fix-stray-endmenu-patch mokopatches-tracking-hist top was fix-stray-endmenu-patch / 3630e0be570de8057e7f8d2fe501ed353cdf34e6 ... parent commitmessage: From: Andy Green fix-stray-endmenu.patch Signed-off-by: Andy Green --- usr/gen_init_cpio.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'usr/gen_init_cpio.c') diff --git a/usr/gen_init_cpio.c b/usr/gen_init_cpio.c index 7abc07f0fcd..f1d3fe34176 100644 --- a/usr/gen_init_cpio.c +++ b/usr/gen_init_cpio.c @@ -370,6 +370,30 @@ error: return rc; } +static char *cpio_replace_env(char *new_location) +{ + char expanded[PATH_MAX + 1]; + char env_var[PATH_MAX + 1]; + char *start; + char *end; + + for (start = NULL; (start = strstr(new_location, "${")); ) { + end = strchr(start, '}'); + if (start < end) { + *env_var = *expanded = '\0'; + strncat(env_var, start + 2, end - start - 2); + strncat(expanded, new_location, start - new_location); + strncat(expanded, getenv(env_var), PATH_MAX); + strncat(expanded, end + 1, PATH_MAX); + strncpy(new_location, expanded, PATH_MAX); + } else + break; + } + + return new_location; +} + + static int cpio_mkfile_line(const char *line) { char name[PATH_MAX + 1]; @@ -415,7 +439,8 @@ static int cpio_mkfile_line(const char *line) } else { dname = name; } - rc = cpio_mkfile(dname, location, mode, uid, gid, nlinks); + rc = cpio_mkfile(dname, cpio_replace_env(location), + mode, uid, gid, nlinks); fail: if (dname_len) free(dname); return rc; @@ -439,6 +464,7 @@ void usage(const char *prog) "\n" " name of the file/dir/nod/etc in the archive\n" " location of the file in the current filesystem\n" + " expands shell variables quoted with ${}\n" " link target\n" " mode/permissions of the file\n" " user id (0=root)\n" -- cgit v1.2.3