diff options
author | Michal Marek <mmarek@suse.cz> | 2011-03-31 17:16:42 -0400 |
---|---|---|
committer | Michal Marek <mmarek@suse.cz> | 2011-04-18 08:27:52 -0400 |
commit | a8b8017c34fefcb763d8b06c294b58d1c480b2e4 (patch) | |
tree | 61f638af2d7e5ad95990055414788f6f9c0a82dc /usr | |
parent | 53e6892c0411006848882eacfcfea9e93681b55d (diff) |
initramfs: Use KBUILD_BUILD_TIMESTAMP for generated entries
gen_init_cpio gets the current time and uses it for each symlink,
special file, and directory. Grab the current time once and make it
possible to override it with the KBUILD_BUILD_TIMESTAMP variable for
reproducible builds.
Signed-off-by: Michal Marek <mmarek@suse.cz>
Diffstat (limited to 'usr')
-rw-r--r-- | usr/gen_init_cpio.c | 53 |
1 files changed, 40 insertions, 13 deletions
diff --git a/usr/gen_init_cpio.c b/usr/gen_init_cpio.c index 7f06884ecd41..af0f22fb1ef7 100644 --- a/usr/gen_init_cpio.c +++ b/usr/gen_init_cpio.c | |||
@@ -22,6 +22,7 @@ | |||
22 | 22 | ||
23 | static unsigned int offset; | 23 | static unsigned int offset; |
24 | static unsigned int ino = 721; | 24 | static unsigned int ino = 721; |
25 | static time_t default_mtime; | ||
25 | 26 | ||
26 | struct file_handler { | 27 | struct file_handler { |
27 | const char *type; | 28 | const char *type; |
@@ -102,7 +103,6 @@ static int cpio_mkslink(const char *name, const char *target, | |||
102 | unsigned int mode, uid_t uid, gid_t gid) | 103 | unsigned int mode, uid_t uid, gid_t gid) |
103 | { | 104 | { |
104 | char s[256]; | 105 | char s[256]; |
105 | time_t mtime = time(NULL); | ||
106 | 106 | ||
107 | if (name[0] == '/') | 107 | if (name[0] == '/') |
108 | name++; | 108 | name++; |
@@ -114,7 +114,7 @@ static int cpio_mkslink(const char *name, const char *target, | |||
114 | (long) uid, /* uid */ | 114 | (long) uid, /* uid */ |
115 | (long) gid, /* gid */ | 115 | (long) gid, /* gid */ |
116 | 1, /* nlink */ | 116 | 1, /* nlink */ |
117 | (long) mtime, /* mtime */ | 117 | (long) default_mtime, /* mtime */ |
118 | (unsigned)strlen(target)+1, /* filesize */ | 118 | (unsigned)strlen(target)+1, /* filesize */ |
119 | 3, /* major */ | 119 | 3, /* major */ |
120 | 1, /* minor */ | 120 | 1, /* minor */ |
@@ -152,7 +152,6 @@ static int cpio_mkgeneric(const char *name, unsigned int mode, | |||
152 | uid_t uid, gid_t gid) | 152 | uid_t uid, gid_t gid) |
153 | { | 153 | { |
154 | char s[256]; | 154 | char s[256]; |
155 | time_t mtime = time(NULL); | ||
156 | 155 | ||
157 | if (name[0] == '/') | 156 | if (name[0] == '/') |
158 | name++; | 157 | name++; |
@@ -164,7 +163,7 @@ static int cpio_mkgeneric(const char *name, unsigned int mode, | |||
164 | (long) uid, /* uid */ | 163 | (long) uid, /* uid */ |
165 | (long) gid, /* gid */ | 164 | (long) gid, /* gid */ |
166 | 2, /* nlink */ | 165 | 2, /* nlink */ |
167 | (long) mtime, /* mtime */ | 166 | (long) default_mtime, /* mtime */ |
168 | 0, /* filesize */ | 167 | 0, /* filesize */ |
169 | 3, /* major */ | 168 | 3, /* major */ |
170 | 1, /* minor */ | 169 | 1, /* minor */ |
@@ -242,7 +241,6 @@ static int cpio_mknod(const char *name, unsigned int mode, | |||
242 | unsigned int maj, unsigned int min) | 241 | unsigned int maj, unsigned int min) |
243 | { | 242 | { |
244 | char s[256]; | 243 | char s[256]; |
245 | time_t mtime = time(NULL); | ||
246 | 244 | ||
247 | if (dev_type == 'b') | 245 | if (dev_type == 'b') |
248 | mode |= S_IFBLK; | 246 | mode |= S_IFBLK; |
@@ -259,7 +257,7 @@ static int cpio_mknod(const char *name, unsigned int mode, | |||
259 | (long) uid, /* uid */ | 257 | (long) uid, /* uid */ |
260 | (long) gid, /* gid */ | 258 | (long) gid, /* gid */ |
261 | 1, /* nlink */ | 259 | 1, /* nlink */ |
262 | (long) mtime, /* mtime */ | 260 | (long) default_mtime, /* mtime */ |
263 | 0, /* filesize */ | 261 | 0, /* filesize */ |
264 | 3, /* major */ | 262 | 3, /* major */ |
265 | 1, /* minor */ | 263 | 1, /* minor */ |
@@ -460,7 +458,7 @@ static int cpio_mkfile_line(const char *line) | |||
460 | static void usage(const char *prog) | 458 | static void usage(const char *prog) |
461 | { | 459 | { |
462 | fprintf(stderr, "Usage:\n" | 460 | fprintf(stderr, "Usage:\n" |
463 | "\t%s <cpio_list>\n" | 461 | "\t%s [-t <timestamp>] <cpio_list>\n" |
464 | "\n" | 462 | "\n" |
465 | "<cpio_list> is a file containing newline separated entries that\n" | 463 | "<cpio_list> is a file containing newline separated entries that\n" |
466 | "describe the files to be included in the initramfs archive:\n" | 464 | "describe the files to be included in the initramfs archive:\n" |
@@ -491,7 +489,11 @@ static void usage(const char *prog) | |||
491 | "nod /dev/console 0600 0 0 c 5 1\n" | 489 | "nod /dev/console 0600 0 0 c 5 1\n" |
492 | "dir /root 0700 0 0\n" | 490 | "dir /root 0700 0 0\n" |
493 | "dir /sbin 0755 0 0\n" | 491 | "dir /sbin 0755 0 0\n" |
494 | "file /sbin/kinit /usr/src/klibc/kinit/kinit 0755 0 0\n", | 492 | "file /sbin/kinit /usr/src/klibc/kinit/kinit 0755 0 0\n" |
493 | "\n" | ||
494 | "<timestamp> is time in seconds since Epoch that will be used\n" | ||
495 | "as mtime for symlinks, special files and directories. The default\n" | ||
496 | "is to use the current time for these entries.\n", | ||
495 | prog); | 497 | prog); |
496 | } | 498 | } |
497 | 499 | ||
@@ -529,17 +531,42 @@ int main (int argc, char *argv[]) | |||
529 | char *args, *type; | 531 | char *args, *type; |
530 | int ec = 0; | 532 | int ec = 0; |
531 | int line_nr = 0; | 533 | int line_nr = 0; |
534 | const char *filename; | ||
535 | |||
536 | default_mtime = time(NULL); | ||
537 | while (1) { | ||
538 | int opt = getopt(argc, argv, "t:h"); | ||
539 | char *invalid; | ||
532 | 540 | ||
533 | if (2 != argc) { | 541 | if (opt == -1) |
542 | break; | ||
543 | switch (opt) { | ||
544 | case 't': | ||
545 | default_mtime = strtol(optarg, &invalid, 10); | ||
546 | if (!*optarg || *invalid) { | ||
547 | fprintf(stderr, "Invalid timestamp: %s\n", | ||
548 | optarg); | ||
549 | usage(argv[0]); | ||
550 | exit(1); | ||
551 | } | ||
552 | break; | ||
553 | case 'h': | ||
554 | case '?': | ||
555 | usage(argv[0]); | ||
556 | exit(opt == 'h' ? 0 : 1); | ||
557 | } | ||
558 | } | ||
559 | |||
560 | if (argc - optind != 1) { | ||
534 | usage(argv[0]); | 561 | usage(argv[0]); |
535 | exit(1); | 562 | exit(1); |
536 | } | 563 | } |
537 | 564 | filename = argv[optind]; | |
538 | if (!strcmp(argv[1], "-")) | 565 | if (!strcmp(filename, "-")) |
539 | cpio_list = stdin; | 566 | cpio_list = stdin; |
540 | else if (! (cpio_list = fopen(argv[1], "r"))) { | 567 | else if (!(cpio_list = fopen(filename, "r"))) { |
541 | fprintf(stderr, "ERROR: unable to open '%s': %s\n\n", | 568 | fprintf(stderr, "ERROR: unable to open '%s': %s\n\n", |
542 | argv[1], strerror(errno)); | 569 | filename, strerror(errno)); |
543 | usage(argv[0]); | 570 | usage(argv[0]); |
544 | exit(1); | 571 | exit(1); |
545 | } | 572 | } |