diff options
author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2023-10-24 15:49:29 +0200 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2023-10-24 15:57:18 +0200 |
commit | c4ab32879df8b5e83b0ebd091ce2c750f53f5633 (patch) | |
tree | e59eaea3361c77240f20868a5ce641ec6000982e | |
parent | 3c70940f4c1b8534e1ef547e09050d33b8187122 (diff) |
Cleanup: gensquashfs: simplify apply_xattrs
- Pass the option structure along and use it's values rather than
passing several of them individually
- free() the path ASAP, so we don't have it around anymore when we
go into the recursion step
- shorten some argument names. Together with the above changes, this
allows collapsing some multi line blocks into much simpler
constructs.
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
-rw-r--r-- | bin/gensquashfs/src/apply_xattr.c | 87 | ||||
-rw-r--r-- | bin/gensquashfs/src/mkfs.c | 4 | ||||
-rw-r--r-- | bin/gensquashfs/src/mkfs.h | 4 |
3 files changed, 35 insertions, 60 deletions
diff --git a/bin/gensquashfs/src/apply_xattr.c b/bin/gensquashfs/src/apply_xattr.c index cc03eab..a858432 100644 --- a/bin/gensquashfs/src/apply_xattr.c +++ b/bin/gensquashfs/src/apply_xattr.c @@ -121,100 +121,77 @@ fail: } #endif -static int xattr_xcan_dfs(const char *path_prefix, void *selinux_handle, - sqfs_xattr_writer_t *xwr, bool scan_xattr, void *xattr_map, - tree_node_t *node) +static int apply_dfs(const options_t *opt, sqfs_xattr_writer_t *xwr, + void *sehnd, void *maphnd, tree_node_t *n) { char *path = NULL; int ret; ret = sqfs_xattr_writer_begin(xwr, 0); if (ret) { - sqfs_perror(node->name, "recoding xattr key-value pairs\n", - ret); + sqfs_perror(n->name, "recoding xattr key-value pairs\n", ret); return -1; } #ifdef HAVE_SYS_XATTR_H - if (scan_xattr) { - path = get_full_path(path_prefix, node); + if (opt->infile == NULL && opt->scan_xattr) { + path = get_full_path(opt->packdir, n); if (path == NULL) return -1; ret = xattr_from_path(xwr, path); free(path); path = NULL; - if (ret) { - ret = -1; - goto out; - } + if (ret) + return -1; } -#else - (void)path_prefix; #endif - if (selinux_handle != NULL || xattr_map != NULL) { - path = fstree_get_path(node); - + if (sehnd != NULL || maphnd != NULL) { + path = fstree_get_path(n); if (path == NULL) { perror("reconstructing absolute path"); - ret = -1; - goto out; + return -1; } } - if (xattr_map != NULL) { - ret = xattr_apply_map_file(path, xattr_map, xwr); - - if (ret) { - ret = -1; - goto out; - } - } + if (maphnd != NULL && xattr_apply_map_file(path, maphnd, xwr) != 0) + goto fail; - if (selinux_handle != NULL) { - ret = selinux_relable_node(selinux_handle, xwr, node, path); + if (sehnd != NULL && selinux_relable_node(sehnd, xwr, n, path) != 0) + goto fail; - if (ret) { - ret = -1; - goto out; - } - } + free(path); - if (sqfs_xattr_writer_end(xwr, &node->xattr_idx)) { - sqfs_perror(node->name, "completing xattr key-value pairs", - ret); - ret = -1; - goto out; + ret = sqfs_xattr_writer_end(xwr, &n->xattr_idx); + if (ret) { + sqfs_perror(n->name, "completing xattr key-value pairs", ret); + return -1; } - if (S_ISDIR(node->mode)) { - node = node->data.children; - - while (node != NULL) { - if (xattr_xcan_dfs(path_prefix, selinux_handle, xwr, - scan_xattr, xattr_map, node)) { - ret = -1; - goto out; - } - - node = node->next; + if (S_ISDIR(n->mode)) { + for (n = n->data.children; n != NULL; n = n->next) { + if (apply_dfs(opt, xwr, sehnd, maphnd, n)) + return -1; } } -out: + return 0; +fail: free(path); - return ret; + return -1; } -int apply_xattrs(fstree_t *fs, const char *path, void *selinux_handle, - void *xattr_map, sqfs_xattr_writer_t *xwr, bool scan_xattr) +int apply_xattrs(fstree_t *fs, const options_t *opt, void *sehnd, + void *maphnd, sqfs_xattr_writer_t *xwr) { if (xwr == NULL) return 0; - if (selinux_handle == NULL && !scan_xattr && xattr_map == NULL) + if (sehnd == NULL && maphnd == NULL && + !(opt->infile == NULL && opt->scan_xattr)) { return 0; + } - return xattr_xcan_dfs(path, selinux_handle, xwr, scan_xattr, xattr_map, fs->root); + return apply_dfs(opt, xwr, sehnd, maphnd, fs->root); } diff --git a/bin/gensquashfs/src/mkfs.c b/bin/gensquashfs/src/mkfs.c index 488d015..8019d24 100644 --- a/bin/gensquashfs/src/mkfs.c +++ b/bin/gensquashfs/src/mkfs.c @@ -153,10 +153,8 @@ int main(int argc, char **argv) if (fstree_post_process(&sqfs.fs)) goto out; - if (apply_xattrs(&sqfs.fs, opt.packdir, sehnd, xattrmap, - sqfs.xwr, opt.infile == NULL && opt.scan_xattr)) { + if (apply_xattrs(&sqfs.fs, &opt, sehnd, xattrmap, sqfs.xwr)) goto out; - } if (sortfile != NULL) { if (fstree_sort_files(&sqfs.fs, sortfile)) diff --git a/bin/gensquashfs/src/mkfs.h b/bin/gensquashfs/src/mkfs.h index a762966..06774df 100644 --- a/bin/gensquashfs/src/mkfs.h +++ b/bin/gensquashfs/src/mkfs.h @@ -72,8 +72,8 @@ struct XattrMap { void process_command_line(options_t *opt, int argc, char **argv); -int apply_xattrs(fstree_t *fs, const char *path, void *selinux_handle, - void *xattr_map, sqfs_xattr_writer_t *xwr, bool scan_xattr); +int apply_xattrs(fstree_t *fs, const options_t *opt, void *selinux_handle, + void *xattr_map, sqfs_xattr_writer_t *xwr); void *xattr_open_map_file(const char *path); |