aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--usr/gen_init_cpio.c28
1 files changed, 27 insertions, 1 deletions
diff --git a/usr/gen_init_cpio.c b/usr/gen_init_cpio.c
index 7abc07f0fcd2..f1d3fe34176a 100644
--- a/usr/gen_init_cpio.c
+++ b/usr/gen_init_cpio.c
@@ -370,6 +370,30 @@ error:
370 return rc; 370 return rc;
371} 371}
372 372
373static char *cpio_replace_env(char *new_location)
374{
375 char expanded[PATH_MAX + 1];
376 char env_var[PATH_MAX + 1];
377 char *start;
378 char *end;
379
380 for (start = NULL; (start = strstr(new_location, "${")); ) {
381 end = strchr(start, '}');
382 if (start < end) {
383 *env_var = *expanded = '\0';
384 strncat(env_var, start + 2, end - start - 2);
385 strncat(expanded, new_location, start - new_location);
386 strncat(expanded, getenv(env_var), PATH_MAX);
387 strncat(expanded, end + 1, PATH_MAX);
388 strncpy(new_location, expanded, PATH_MAX);
389 } else
390 break;
391 }
392
393 return new_location;
394}
395
396
373static int cpio_mkfile_line(const char *line) 397static int cpio_mkfile_line(const char *line)
374{ 398{
375 char name[PATH_MAX + 1]; 399 char name[PATH_MAX + 1];
@@ -415,7 +439,8 @@ static int cpio_mkfile_line(const char *line)
415 } else { 439 } else {
416 dname = name; 440 dname = name;
417 } 441 }
418 rc = cpio_mkfile(dname, location, mode, uid, gid, nlinks); 442 rc = cpio_mkfile(dname, cpio_replace_env(location),
443 mode, uid, gid, nlinks);
419 fail: 444 fail:
420 if (dname_len) free(dname); 445 if (dname_len) free(dname);
421 return rc; 446 return rc;
@@ -439,6 +464,7 @@ void usage(const char *prog)
439 "\n" 464 "\n"
440 "<name> name of the file/dir/nod/etc in the archive\n" 465 "<name> name of the file/dir/nod/etc in the archive\n"
441 "<location> location of the file in the current filesystem\n" 466 "<location> location of the file in the current filesystem\n"
467 " expands shell variables quoted with ${}\n"
442 "<target> link target\n" 468 "<target> link target\n"
443 "<mode> mode/permissions of the file\n" 469 "<mode> mode/permissions of the file\n"
444 "<uid> user id (0=root)\n" 470 "<uid> user id (0=root)\n"