X-Git-Url: http://git.archive.openwrt.org/?p=project%2Ffstools.git;a=blobdiff_plain;f=libfstools%2Fextroot.c;h=418df9494f7f4ba0a59f4efa3963c34c424d4f39;hp=45cc3f51bf27e6d36dfa8d8cf0b2121d6c1a1105;hb=de6b026d685670fbb10279c4a75a9227d94f22d2;hpb=35056038c02a7cbd18b57a5f46a373d564c69693 diff --git a/libfstools/extroot.c b/libfstools/extroot.c index 45cc3f5..418df94 100644 --- a/libfstools/extroot.c +++ b/libfstools/extroot.c @@ -19,6 +19,7 @@ #include #include #include +#include #include "libfstools.h" @@ -39,19 +40,37 @@ int mount_extroot(void) if (!extroot_prefix) return -1; - sprintf(ldlib_path, "%s/lib", extroot_prefix); - sprintf(block_path, "%s/sbin/block", extroot_prefix); + /* try finding the library directory */ + snprintf(ldlib_path, sizeof(ldlib_path), "%s/upper/lib", extroot_prefix); - if (stat(block_path, &s)) + if (stat(ldlib_path, &s) || !S_ISDIR(s.st_mode)) + snprintf(ldlib_path, sizeof(ldlib_path), "%s/lib", extroot_prefix); + + /* try finding the block executable */ + snprintf(block_path, sizeof(block_path), "%s/upper/sbin/block", extroot_prefix); + + if (stat(block_path, &s) || !S_ISREG(s.st_mode)) + snprintf(block_path, sizeof(block_path), "%s/sbin/block", extroot_prefix); + + if (stat(block_path, &s) || !S_ISREG(s.st_mode)) + snprintf(block_path, sizeof(block_path), "/sbin/block"); + + if (stat(block_path, &s) || !S_ISREG(s.st_mode)) return -1; - sprintf(kmod_loader, "/sbin/kmodloader %s/etc/modules-boot.d/ %s", extroot_prefix, extroot_prefix); - system(kmod_loader); + /* set LD_LIBRARY_PATH env var and load kmods from overlay if we found a lib directory there */ + if (!stat(ldlib_path, &s) && S_ISDIR(s.st_mode)) { + ULOG_INFO("loading kmods from internal overlay\n"); + setenv("LD_LIBRARY_PATH", ldlib_path, 1); + snprintf(kmod_loader, sizeof(kmod_loader), + "/sbin/kmodloader %s/etc/modules-boot.d/", dirname(ldlib_path)); + if (system(kmod_loader)) + ULOG_ERR("failed to launch kmodloader from internal overlay\n"); + } pid = fork(); if (!pid) { mkdir("/tmp/extroot", 0755); - setenv("LD_LIBRARY_PATH", ldlib_path, 1); execl(block_path, block_path, "extroot", NULL); exit(-1); } else if (pid > 0) { @@ -69,10 +88,10 @@ int mount_extroot(void) mkdir("/tmp/extroot/mnt/rom", 0755); if (mount_move("/tmp/extroot", "", "/mnt")) { - fprintf(stderr, "moving pivotroot failed - continue normal boot\n"); + ULOG_ERR("moving pivotroot failed - continue normal boot\n"); umount("/tmp/extroot/mnt"); } else if (pivot("/mnt", "/rom")) { - fprintf(stderr, "switching to pivotroot failed - continue normal boot\n"); + ULOG_ERR("switching to pivotroot failed - continue normal boot\n"); umount("/mnt"); } else { umount("/tmp/overlay"); @@ -83,10 +102,10 @@ int mount_extroot(void) } } else if (find_mount("/tmp/extroot/overlay")) { if (mount_move("/tmp/extroot", "", "/overlay")) { - fprintf(stderr, "moving extroot failed - continue normal boot\n"); + ULOG_ERR("moving extroot failed - continue normal boot\n"); umount("/tmp/extroot/overlay"); } else if (fopivot("/overlay", "/rom")) { - fprintf(stderr, "switching to extroot failed - continue normal boot\n"); + ULOG_ERR("switching to extroot failed - continue normal boot\n"); umount("/overlay"); } else { umount("/tmp/overlay");