diff options
-rw-r--r-- | bin/gensquashfs/mkfs.c | 38 | ||||
-rw-r--r-- | bin/gensquashfs/mkfs.h | 5 | ||||
-rw-r--r-- | bin/gensquashfs/options.c | 23 |
3 files changed, 30 insertions, 36 deletions
diff --git a/bin/gensquashfs/mkfs.c b/bin/gensquashfs/mkfs.c index 4120242..2885d84 100644 --- a/bin/gensquashfs/mkfs.c +++ b/bin/gensquashfs/mkfs.c @@ -6,39 +6,6 @@ */ #include "mkfs.h" -static int set_working_dir(options_t *opt) -{ - const char *ptr; - char *path; - - if (opt->packdir != NULL) { - if (chdir(opt->packdir)) { - perror(opt->packdir); - return -1; - } - return 0; - } - - ptr = strrchr(opt->infile, '/'); - if (ptr == NULL) - return 0; - - path = strndup(opt->infile, ptr - opt->infile); - if (path == NULL) { - perror("constructing input directory path"); - return -1; - } - - if (chdir(path)) { - perror(path); - free(path); - return -1; - } - - free(path); - return 0; -} - static int pack_files(sqfs_block_processor_t *data, fstree_t *fs, options_t *opt) { @@ -52,8 +19,10 @@ static int pack_files(sqfs_block_processor_t *data, fstree_t *fs, int flags; int ret; - if (set_working_dir(opt)) + if (opt->packdir != NULL && chdir(opt->packdir) != 0) { + perror(opt->packdir); return -1; + } for (fi = fs->files; fi != NULL; fi = fi->next) { if (fi->input_file == NULL) { @@ -224,5 +193,6 @@ out: sqfs_writer_cleanup(&sqfs, status); if (sehnd != NULL) selinux_close_context_file(sehnd); + free(opt.packdir); return status; } diff --git a/bin/gensquashfs/mkfs.h b/bin/gensquashfs/mkfs.h index e1e4e1b..c43c10a 100644 --- a/bin/gensquashfs/mkfs.h +++ b/bin/gensquashfs/mkfs.h @@ -42,10 +42,13 @@ typedef struct { sqfs_writer_cfg_t cfg; unsigned int dirscan_flags; const char *infile; - const char *packdir; const char *selinux; bool no_tail_packing; + /* copied from command line or constructed from infile argument + if not specified. Must be free'd. */ + char *packdir; + unsigned int force_uid_value; unsigned int force_gid_value; bool force_uid; diff --git a/bin/gensquashfs/options.c b/bin/gensquashfs/options.c index 9153265..ec2263c 100644 --- a/bin/gensquashfs/options.c +++ b/bin/gensquashfs/options.c @@ -267,7 +267,12 @@ void process_command_line(options_t *opt, int argc, char **argv) opt->infile = optarg; break; case 'D': - opt->packdir = optarg; + free(opt->packdir); + opt->packdir = strdup(optarg); + if (opt->packdir == NULL) { + perror(optarg); + exit(EXIT_FAILURE); + } break; #ifdef WITH_SELINUX case 's': @@ -316,8 +321,24 @@ void process_command_line(options_t *opt, int argc, char **argv) fputs("Unknown extra arguments specified.\n", stderr); goto fail_arg; } + + /* construct packdir if not specified */ + if (opt->packdir == NULL && opt->infile != NULL) { + const char *split = strrchr(opt->infile, '/'); + + if (split != NULL) { + opt->packdir = strndup(opt->infile, + split - opt->infile); + + if (opt->packdir == NULL) { + perror("constructing input directory path"); + exit(EXIT_FAILURE); + } + } + } return; fail_arg: fputs("Try `gensquashfs --help' for more information.\n", stderr); + free(opt->packdir); exit(EXIT_FAILURE); } |