Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 122975
b: refs/heads/master
c: 3b1ec9f
h: refs/heads/master
i:
  122973: e0df9a9
  122971: 3161c8c
  122967: 4760967
  122959: afdedf3
  122943: 867cc92
v: v3
  • Loading branch information
Sally, Gene authored and Sam Ravnborg committed Dec 3, 2008
1 parent 985e676 commit 37473c2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: efddd79512cc582675004bfdf7e66585198b38f9
refs/heads/master: 3b1ec9fb8197197d5e3bcca3a05e82d4f50f11bc
28 changes: 27 additions & 1 deletion trunk/usr/gen_init_cpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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;
Expand All @@ -439,6 +464,7 @@ void usage(const char *prog)
"\n"
"<name> name of the file/dir/nod/etc in the archive\n"
"<location> location of the file in the current filesystem\n"
" expands shell variables quoted with ${}\n"
"<target> link target\n"
"<mode> mode/permissions of the file\n"
"<uid> user id (0=root)\n"
Expand Down

0 comments on commit 37473c2

Please sign in to comment.