Merge "Make mksquashfs generate a fs_config-friendly root entry"

This commit is contained in:
Treehugger Robot 2018-02-27 16:24:21 +00:00 committed by Gerrit Code Review
commit 3d4fb4e335
2 changed files with 19 additions and 3 deletions

View File

@ -2480,7 +2480,7 @@ endif
# $1: root directory
# $2: add prefix
define fs_config
(cd $(1); find . -type d | sed 's,$$,/,'; find . \! -type d) | cut -c 3- | sort | sed 's,^,$(2),' | $(HOST_OUT_EXECUTABLES)/fs_config -C -D $(TARGET_OUT) -S $(SELINUX_FC)
(cd $(1); find . -type d | sed 's,$$,/,'; find . \! -type d) | cut -c 3- | sort | sed 's,^,$(2),' | $(HOST_OUT_EXECUTABLES)/fs_config -C -D $(TARGET_OUT) -S $(SELINUX_FC) -R "$(2)"
endef
# Depending on the various images guarantees that the underlying

View File

@ -67,17 +67,18 @@ static struct selabel_handle* get_sehnd(const char* context_file) {
}
static void usage() {
fprintf(stderr, "Usage: fs_config [-D product_out_path] [-S context_file] [-C]\n");
fprintf(stderr, "Usage: fs_config [-D product_out_path] [-S context_file] [-R root] [-C]\n");
}
int main(int argc, char** argv) {
char buffer[1024];
const char* context_file = NULL;
const char* product_out_path = NULL;
char* root_path = NULL;
struct selabel_handle* sehnd = NULL;
int print_capabilities = 0;
int opt;
while((opt = getopt(argc, argv, "CS:D:")) != -1) {
while((opt = getopt(argc, argv, "CS:R:D:")) != -1) {
switch(opt) {
case 'C':
print_capabilities = 1;
@ -85,6 +86,9 @@ int main(int argc, char** argv) {
case 'S':
context_file = optarg;
break;
case 'R':
root_path = optarg;
break;
case 'D':
product_out_path = optarg;
break;
@ -98,6 +102,14 @@ int main(int argc, char** argv) {
sehnd = get_sehnd(context_file);
}
if (root_path != NULL) {
size_t root_len = strlen(root_path);
/* Trim any trailing slashes from the root path. */
while (root_len && root_path[--root_len] == '/') {
root_path[root_len] = '\0';
}
}
while (fgets(buffer, 1023, stdin) != NULL) {
int is_dir = 0;
int i;
@ -122,6 +134,10 @@ int main(int argc, char** argv) {
unsigned uid = 0, gid = 0, mode = 0;
uint64_t capabilities;
fs_config(buffer, is_dir, product_out_path, &uid, &gid, &mode, &capabilities);
if (root_path != NULL && strcmp(buffer, root_path) == 0) {
/* The root of the filesystem needs to be an empty string. */
strcpy(buffer, "");
}
printf("%s %d %d %o", buffer, uid, gid, mode);
if (sehnd != NULL) {