From 37473c2b9cf67a7453d173ff7da765efe9a0de5e Mon Sep 17 00:00:00 2001 From: "Sally, Gene" Date: Wed, 29 Oct 2008 09:54:17 -0400 Subject: [PATCH] --- yaml --- r: 122975 b: refs/heads/master c: 3b1ec9fb8197197d5e3bcca3a05e82d4f50f11bc h: refs/heads/master i: 122973: e0df9a91fe022489eb3cbb6d19ffe9b75e15d7a9 122971: 3161c8c4172b6128991dcb4d26c5c7e032b0ad5a 122967: 47609679d91d6a5dfaa4a32e1d3c664e9bbc316a 122959: afdedf3ec6f2453c65814fefe6cc2170ec2ee6e7 122943: 867cc92ecf534157ff8bd84f189a6a556ff8e088 v: v3 --- [refs] | 2 +- trunk/usr/gen_init_cpio.c | 28 +++++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/[refs] b/[refs] index 4295923f8ade..0aa2b5c9ebe0 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: efddd79512cc582675004bfdf7e66585198b38f9 +refs/heads/master: 3b1ec9fb8197197d5e3bcca3a05e82d4f50f11bc diff --git a/trunk/usr/gen_init_cpio.c b/trunk/usr/gen_init_cpio.c index 7abc07f0fcd2..f1d3fe34176a 100644 --- a/trunk/usr/gen_init_cpio.c +++ b/trunk/usr/gen_init_cpio.c @@ -370,6 +370,30 @@ static int cpio_mkfile(const char *name, const char *location, 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"