Loading fs_mgr/libsnapshot/snapuserd/Android.bp +32 −15 Original line number Diff line number Diff line Loading @@ -72,7 +72,7 @@ cc_defaults { cflags: [ "-Wall", "-Werror" "-Werror", ], static_libs: [ Loading @@ -89,14 +89,7 @@ cc_defaults { "liburing", ], include_dirs: ["bionic/libc/kernel"], } cc_binary { name: "snapuserd", defaults: ["snapuserd_defaults"], init_rc: [ "snapuserd.rc", ], system_shared_libs: [], // snapuserd is started during early boot by first-stage init. At that // point, /system is mounted using the "dm-user" device-mapper kernel Loading @@ -105,16 +98,40 @@ cc_binary { // faults for its code pages. static_executable: true, system_shared_libs: [], ramdisk_available: true, vendor_ramdisk_available: true, recovery_available: true, // Snapuserd segfaults with ThinLTO // http://b/208565717 lto: { never: true, }, } cc_binary { name: "snapuserd", defaults: ["snapuserd_defaults"], init_rc: [ "snapuserd.rc", ], ramdisk_available: false, vendor_ramdisk_available: true, recovery_available: true, } // This target will install to /system/bin/snapuserd_ramdisk // It will also create a symblink on /system/bin/snapuserd that point to // /system/bin/snapuserd_ramdisk . // This way, init can check if generic ramdisk copy exists. cc_binary { name: "snapuserd_ramdisk", defaults: ["snapuserd_defaults"], init_rc: [ "snapuserd.rc", ], // This target is specifically for generic ramdisk, therefore we set // vendor_ramdisk_available to false. ramdisk_available: true, vendor_ramdisk_available: false, ramdisk: true, symlinks: ["snapuserd"], } cc_test { Loading init/first_stage_init.cpp +15 −9 Original line number Diff line number Diff line Loading @@ -119,19 +119,14 @@ static void Copy(const char* src, const char* dst) { // Move snapuserd before switching root, so that it is available at the same path // after switching root. void PrepareSwitchRoot() { constexpr const char* src = "/system/bin/snapuserd"; constexpr const char* dst = "/first_stage_ramdisk/system/bin/snapuserd"; static constexpr const auto& snapuserd = "/system/bin/snapuserd"; static constexpr const auto& snapuserd_ramdisk = "/system/bin/snapuserd_ramdisk"; static constexpr const auto& dst = "/first_stage_ramdisk/system/bin/snapuserd"; if (access(dst, X_OK) == 0) { LOG(INFO) << dst << " already exists and it can be executed"; return; } if (access(src, F_OK) != 0) { PLOG(INFO) << "Not moving " << src << " because it cannot be accessed"; return; } auto dst_dir = android::base::Dirname(dst); std::error_code ec; if (access(dst_dir.c_str(), F_OK) != 0) { Loading @@ -139,7 +134,18 @@ void PrepareSwitchRoot() { LOG(FATAL) << "Cannot create " << dst_dir << ": " << ec.message(); } } Copy(src, dst); // prefer the generic ramdisk copy of snapuserd, because that's on system side of treble // boundary, and therefore is more likely to be updated along with the Android platform. // The vendor ramdisk copy might be under vendor freeze, or vendor might choose not to update // it. if (access(snapuserd_ramdisk, F_OK) == 0) { LOG(INFO) << "Using generic ramdisk copy of snapuserd " << snapuserd_ramdisk; Copy(snapuserd_ramdisk, dst); } else if (access(snapuserd, F_OK) == 0) { LOG(INFO) << "Using vendor ramdisk copy of snapuserd " << snapuserd; Copy(snapuserd, dst); } } } // namespace Loading Loading
fs_mgr/libsnapshot/snapuserd/Android.bp +32 −15 Original line number Diff line number Diff line Loading @@ -72,7 +72,7 @@ cc_defaults { cflags: [ "-Wall", "-Werror" "-Werror", ], static_libs: [ Loading @@ -89,14 +89,7 @@ cc_defaults { "liburing", ], include_dirs: ["bionic/libc/kernel"], } cc_binary { name: "snapuserd", defaults: ["snapuserd_defaults"], init_rc: [ "snapuserd.rc", ], system_shared_libs: [], // snapuserd is started during early boot by first-stage init. At that // point, /system is mounted using the "dm-user" device-mapper kernel Loading @@ -105,16 +98,40 @@ cc_binary { // faults for its code pages. static_executable: true, system_shared_libs: [], ramdisk_available: true, vendor_ramdisk_available: true, recovery_available: true, // Snapuserd segfaults with ThinLTO // http://b/208565717 lto: { never: true, }, } cc_binary { name: "snapuserd", defaults: ["snapuserd_defaults"], init_rc: [ "snapuserd.rc", ], ramdisk_available: false, vendor_ramdisk_available: true, recovery_available: true, } // This target will install to /system/bin/snapuserd_ramdisk // It will also create a symblink on /system/bin/snapuserd that point to // /system/bin/snapuserd_ramdisk . // This way, init can check if generic ramdisk copy exists. cc_binary { name: "snapuserd_ramdisk", defaults: ["snapuserd_defaults"], init_rc: [ "snapuserd.rc", ], // This target is specifically for generic ramdisk, therefore we set // vendor_ramdisk_available to false. ramdisk_available: true, vendor_ramdisk_available: false, ramdisk: true, symlinks: ["snapuserd"], } cc_test { Loading
init/first_stage_init.cpp +15 −9 Original line number Diff line number Diff line Loading @@ -119,19 +119,14 @@ static void Copy(const char* src, const char* dst) { // Move snapuserd before switching root, so that it is available at the same path // after switching root. void PrepareSwitchRoot() { constexpr const char* src = "/system/bin/snapuserd"; constexpr const char* dst = "/first_stage_ramdisk/system/bin/snapuserd"; static constexpr const auto& snapuserd = "/system/bin/snapuserd"; static constexpr const auto& snapuserd_ramdisk = "/system/bin/snapuserd_ramdisk"; static constexpr const auto& dst = "/first_stage_ramdisk/system/bin/snapuserd"; if (access(dst, X_OK) == 0) { LOG(INFO) << dst << " already exists and it can be executed"; return; } if (access(src, F_OK) != 0) { PLOG(INFO) << "Not moving " << src << " because it cannot be accessed"; return; } auto dst_dir = android::base::Dirname(dst); std::error_code ec; if (access(dst_dir.c_str(), F_OK) != 0) { Loading @@ -139,7 +134,18 @@ void PrepareSwitchRoot() { LOG(FATAL) << "Cannot create " << dst_dir << ": " << ec.message(); } } Copy(src, dst); // prefer the generic ramdisk copy of snapuserd, because that's on system side of treble // boundary, and therefore is more likely to be updated along with the Android platform. // The vendor ramdisk copy might be under vendor freeze, or vendor might choose not to update // it. if (access(snapuserd_ramdisk, F_OK) == 0) { LOG(INFO) << "Using generic ramdisk copy of snapuserd " << snapuserd_ramdisk; Copy(snapuserd_ramdisk, dst); } else if (access(snapuserd, F_OK) == 0) { LOG(INFO) << "Using vendor ramdisk copy of snapuserd " << snapuserd; Copy(snapuserd, dst); } } } // namespace Loading