Commit graph

3083 commits

Author SHA1 Message Date
TreeHugger Robot
af9240abc9 Merge "Add /mnt/androidwritable for MOUNT_EXTERNAL_ANDROID_WRITABLE apps" into rvc-dev 2020-04-21 11:08:07 +00:00
Nikita Ioffe
a840d405eb Cleanup logic in KillZramBackingDevice
Since this function is used in userspace reboot, we need to be more
diligent with error handling, e.g.:

* If init fails to read /sys/block/zram0/backing_dev, then fail and
fallback to hard reboot.
* Always call swapoff.
* Always reset zram.
* Tear down loop device only if zram is backed by a loop device.

Test: adb reboot userspace
Bug: 153917129
Change-Id: I4709da1d08cf427ad9c898cfb2506b6a29f1d680
2020-04-16 21:37:03 +01:00
Steve Muckle
2980ba4b3d first_stage_init: add hook to exec a shell script
If the first stage console is being used, attempt to run /first_stage.sh
immediately before the console is created.

Bug: 154126020
Change-Id: I8b7431e7b8219afea295b120d7ea91751804bda6
Merged-In: I8b7431e7b8219afea295b120d7ea91751804bda6
2020-04-15 14:05:05 -07:00
Ricky Wai
7f72524f9f Add /mnt/androidwritable for MOUNT_EXTERNAL_ANDROID_WRITABLE apps
Bug: 153540919
Test: Able to boot without errors
Change-Id: If206e5e3d76a7919b7468bc2d9666b3aff296b3b
2020-04-14 12:31:50 +01:00
Nikita Ioffe
6236af3d0c Fallback to hard reboot if userspace reboot hasn't started in time
Similarly to other recovery mechanisms, timeout is controlled by a
read-only property that can be configured per-device.

Test: adb root
Test: adb shell setprop init.userspace_reboot.started.timeoutmillis 2
Test: adb reboot userspace
Bug: 152803929
Change-Id: Id70710b46da798945ac5422ef7d69265911ea5ef
Merged-In: Id70710b46da798945ac5422ef7d69265911ea5ef
(cherry picked from commit d05535485f)
2020-04-14 00:21:41 +01:00
Steve Muckle
ae317c716b first_stage_init: load modules in modules.load.recovery in recovery
In recovery mode, load modules from modules.load.recovery if it
exists. Otherwise load from modules.load as usual.

Bug: 150825361
Change-Id: I7636bb5958ed10ae9a66015f04f168129618272f
Merged-In: I7636bb5958ed10ae9a66015f04f168129618272f
2020-04-08 10:49:13 -07:00
Will Mcvicker
51ae53fa1c Merge "first_stage_init: increase serial console tries to 50" into rvc-dev 2020-04-07 20:24:02 +00:00
Dan Shi
12c7aa8ace Remove vts10 tests from vts suite
The tests are only needed in vts10 suite, as they are part of CTS
package and no longer needed in vts 11.

Bug: 151896491
Test: local build
Exempt-From-Owner-Approval: This CL removes vts10 tests from vts suite.
It won't change test logic or behavior.

Change-Id: I4d468be075b54213b56c7e1aa94af94f2bdce9ff
Merged-In: I4d468be075b54213b56c7e1aa94af94f2bdce9ff
2020-04-06 14:25:10 -07:00
Will McVicker
283128f26a first_stage_init: increase serial console tries to 50
tl,dr;
Increase the attempts to 50 to reduce the chances of failing
to load the serial console. This will only happen if the cmdline
parameter "androidboot.first_stage_console=1" is enabled.

Details:
10 attempts only amounts to about 1 second of trying to open the serial
console. I tested booting an ACK GKI image 5x with 20 vendor modules and
found the serial console loaded on attempt 17 for all five boot
tests.

Bug: 153354917
Test: boot ACK image 5x and verify serial console comes up
Change-Id: I161a4176b2c6cf7b0bc1eefe072ff38b894add5d
2020-04-06 19:49:00 +00:00
Tom Cherry
27311fd844 Merge "init: don't sync() before shutting down services" into rvc-dev 2020-04-03 02:40:17 +00:00
Tom Cherry
6288212ac3 init: don't sync() before shutting down services
Devices in the lab are hitting an issue where they're getting stuck
likely in the sync() call in DoReboot() before we start the reboot
monitor thread and before we shut down services.

It's possible that concurrent writing to RW file systems is causing
this sync() call to take essentially forever.  To protect against
this, we need to remove this sync().  Note that we will still call
sync() after shutting down services.

Note that the service shutdown code has a timeout and there is a
reboot monitor thread that will shutdown the device if more than 30
seconds pass above that timeout.  This change increases that timeout
to 300 seconds to give the final sync() calls explicitly more time to
finish.

Bug: 150863651
Test: reboot functions normally
Test: put an infinite loop in DoReboot and the the reboot monitor thread
      triggers and shuts down the device appropriately
Merged-In: I6fd7d3a25d3225081388e39a14c9fdab21b592ba
Change-Id: I6fd7d3a25d3225081388e39a14c9fdab21b592ba
(cherry picked from commit 10615eb397)
2020-04-02 12:51:36 -07:00
Nikita Ioffe
6bd3bc8d01 Properly fail userspace reboot if it's not supported
Previously, after `adb reboot userspace` is called on a device that
doesn't suppor it, init would've logged an error and quietly exit the
shutdown sequence. This was leaving adb handing forever.

With this approach, init will fail setprop
"sys.powerctl=reboot,userspace" in case userspace reboot is not
supported.

Test: adb root
Test: adb setprop init.userspace_reboot.is_supported 0
Test: adb reboot userspace
Test: atest CtsInitTestCases
Bug: 146639622
Change-Id: I1264078f53ed3ff54638c7f3b6846b7437f98ee5
Merged-In: I1264078f53ed3ff54638c7f3b6846b7437f98ee5
(cherry picked from commit 92116e4129)
2020-04-02 17:25:48 +01:00
Nikita Ioffe
9fd393f430 Make init.userspace_reboot.is_supported a rw property
General recommendation is to avoid read-only properties, and instead control
"read-onlines" by only allowing init/vendor_init to set the property.

Since ro.init.userspace_reboot.is_supported was added in this release, and
nobody outside of the platform is querying it directly, it should be fine to
simply rename it.

Test: adb shell getprop init.userspace_reboot.is_supported
Test: atest CtsUserspaceRebootHostSideTestCases
Bug: 152803929
Change-Id: I7552d5ccc6e9b750a6081947eef8fcb027be13e1
Merged-In: I7552d5ccc6e9b750a6081947eef8fcb027be13e1
(cherry picked from commit 663cd35030)
2020-04-01 18:24:57 +01:00
TreeHugger Robot
d456db6d50 Merge "init: require root for oneshot_on test" into rvc-dev 2020-03-31 15:33:51 +00:00
Tom Cherry
5b1c316a1f init: require root for oneshot_on test
Bug: 152630580
Bug: 152637928
Bug: 152662041
Bug: 152662652
Test: this test is skipped when run as non-root
Merged-In: I7118025cc20081a200000bf484a08c9ed0b0d3ec
Change-Id: I7118025cc20081a200000bf484a08c9ed0b0d3ec
(cherry picked from commit 14f4afd2f2)
2020-03-30 18:52:44 -07:00
Tom Cherry
495a394fd3 init: do not handle control messages after shutdown
We already stop queue'ing new control messages, but we forgot to stop
handling those control messages that are already queued.  This CL
fixes that.

Bug: 150863651
Test: CF reboots appropriately
Merged-In: Ifea07a30b868de23eb735db10d8bae410e1b98bb
Change-Id: Ifea07a30b868de23eb735db10d8bae410e1b98bb
(cherry picked from commit 22d6348845)
2020-03-28 12:17:40 -07:00
Tom Cherry
43374ce9c1 init: fix StopSendingMessages()
A typo made this function a no-op.

Bug: 150863651
Test: CF responds to messages appropriately
Merged-In: Iaae0264fae3f2b899ceb5ba0364a4773df1f7ca3
Change-Id: Iaae0264fae3f2b899ceb5ba0364a4773df1f7ca3
(cherry picked from commit 68855276a1)
2020-03-28 12:17:30 -07:00
Tom Cherry
9c83185c1e init: use an eventfd instead of socketpair to wake the main loop
eventfd is a more suitable mechanism.

Bug: 150863651
Test: boot CF, ctl.start services, reboot CF
Merged-In: Ie5c3b0c048afdd7afa4bfc4cba26bec3225925e5
Change-Id: Ie5c3b0c048afdd7afa4bfc4cba26bec3225925e5
(cherry picked from commit 40463336a8)
2020-03-27 16:17:57 -07:00
David Anderson
b9123e5bce init: Forcefully mount system_ext on DAP devices if not present in fstab.
Bug: 150315914
Test: cuttlefish boots with system_ext missing from fstab
Change-Id: I99f292a070678b8a98500258af98129fbd81dfa7
Merged-In: I99f292a070678b8a98500258af98129fbd81dfa7
2020-03-26 17:25:54 -07:00
David Anderson
d8f032ee93 init: Factor out first-stage uevent handling into a separate class.
This will make it possible to re-use in second-stage init.

Bug: 150315914
Test: first-stage init boots
Change-Id: I6a0f13d5c71ab5529a76751f68ac0f15834323d1
Merged-In: I6a0f13d5c71ab5529a76751f68ac0f15834323d1
2020-03-26 17:25:49 -07:00
David Anderson
620e5d48db init: Remove special-case hacks for the super partition.
Rather than special-casing super in the uevent listener, call Realpath()
after we've generated its symlink. This allows us to generalize the
uevent listener code.

Also, rename "metadata partition" to "super partition" in a few places,
as this terminology is a bit dated.

Bug: 150315914
Test: first-stage init boots
Change-Id: I2bf3bebf3360f097582df7fba95f3c1753feb2e2
Merged-In: I2bf3bebf3360f097582df7fba95f3c1753feb2e2
2020-03-26 17:25:45 -07:00
Nikita Ioffe
f0ab5b17f6 Use properties for various userspace reboot timeouts
Test: adb reboot userspace
Bug: 146560409
Change-Id: I435e4f93a8769ff7d30cf781e0b48fa3e96121ef
Merged-In: I435e4f93a8769ff7d30cf781e0b48fa3e96121ef
(cherry picked from commit 7b41a1558d)
2020-03-25 21:40:45 +00:00
TreeHugger Robot
5eb308766e Merge "Remove use of static libdexfile to avoid linking in ART internal code." into rvc-dev 2020-03-25 20:29:25 +00:00
TreeHugger Robot
3553c5ea4c Merge "init: add missing TEMP_FAILURE_RETRY" into rvc-dev 2020-03-25 15:40:26 +00:00
Tom Cherry
494cffb26c init: add missing TEMP_FAILURE_RETRY
Bug: 150863651
Test: boot
Change-Id: I09e86e08a716c2c2933e090d57818a9aad6486f8
2020-03-24 18:17:53 -07:00
Martin Stjernholm
ae695c9fad Remove use of static libdexfile to avoid linking in ART internal code.
- Create a static library libunwindstack_no_dex without DEX support.
- Use it in libdebuggerd_handler_fallback, whose only use is in the
  linker, which shouldn't need that support.
- Use it in init_first_stage, which doesn't need DEX support either.
- Also need a libbacktrace_no_dex since it's in the dependency chain
  from init_first_stage to libunwindstack_no_dex.

Also restrict the *_no_dex libs and libdebuggerd_handler_fallback as
much as possible to avoid inadvertent use of these reduced
functionality libs.

Test: m init_first_stage on Cuttlefish
  where BOARD_BUILD_SYSTEM_ROOT_IMAGE=false
Test: m system_image com.android.runtime
Test: Build & boot
Test: atest linker-unit-tests libunwindstack_unit_test debuggerd_test
Bug: 142944931
Bug: 151466650
Change-Id: Iaacb29bfe602f3ca12a00a712e2a64c45ff0118b
Merged-In: Iaacb29bfe602f3ca12a00a712e2a64c45ff0118b
2020-03-24 21:48:00 +00:00
Tom Cherry
c297d6034d init: add ctl.oneshot_on/ctl.oneshot_off
Some services are lazy HALs on some platforms and not lazy HALs on
others; this is known at runtime by hwservicemanager, so this change
adds these properties to allow hwservicemanager to turn one oneshot
(for lazy HALs).  It may also be required to make a lazy HAL not lazy
anymore, and oneshot_off is provided for this.

Bug: 147841742
Test: new unit test that turn on and off oneshot on a service (bootanim)
      and observes that it follows the expected behavior
Merged-In: I79524e2c9a5008f90c8d3bc40920fde00602a439
Change-Id: I79524e2c9a5008f90c8d3bc40920fde00602a439
(cherry picked from commit bdbf5047c9)
2020-03-23 08:03:01 -07:00
Tom Cherry
2bf886afc2 init: use a no-op signal handler instead of SIG_IGN for SIGPIPE
We want to ignore SIGPIPE within init, but if we use SIG_IGN, that
would be inherited by child processes through exec(), which we do not
want to have happen.  We instead set up a real signal handler with a
no-op handler function, that will ignore SIGPIPE within init, but will
not be inherited across exec().

This fixes c29c2baa69 ("init: Add support for native service
registration with lmkd"), when SIG_IGN was introduced.
Note that we caught this issue before shipping a release with that
change, so the major motivation here is to not cause a behavior change
in init.

Bug: 151581751
Test: children of init that don't explicitly block SIGPIPE exit when
      sent SIGPIPE
Test: children of init that do explicitly block SIGPIPE do not exit
      when sent SIGPIPE
Test: init does not exit when sent SIGPIPE
Test: init exits when sent SIGABRT
Merged-In: Ieda8555fd03836bcd672a422fe673a8369ad9beb
Change-Id: Ieda8555fd03836bcd672a422fe673a8369ad9beb
(cherry picked from commit fd470e87cc)
2020-03-18 09:42:56 -07:00
David Anderson
054e6a388e init: Fix restorecon for /metadata.
Since new files can be introduced to /metadata after the initial
restorecon, we need to skip hashing.

Bug: 150907679
Test: rollback, ls -lZ /metadata/ota
Change-Id: I1f928f519ae2c75aeedb74b70d513743e86bcf2b
Merged-In: I1f928f519ae2c75aeedb74b70d513743e86bcf2b
2020-03-16 14:00:54 -07:00
Tom Cherry
0c19d6c99f init: handle property messages asynchronously #2
A previous change moved property_service into its own thread, since
there was otherwise a deadlock whenever a process called by init would
try to set a property.  This new thread, however, would send a message
via a blocking socket to init for each property that it received,
since init may need to take action depending on which property it is.
Unfortunately, this means that the deadlock is still possible, the
only difference is the socket's buffer must be filled before init deadlocks.

This change, therefore, adds the following:
1) A lock for instructing init to reboot
2) A lock for waiting on properties
3) A lock for queueing new properties

A previous version of this change was reverted and added locks around
all service operations and allowed the property thread to spawn
services directly.  This was complex due to the fact that this code
was not designed to be multi-threaded.  It was reverted due to
apparent issues during reboot.  This change keeps a queue of processes
pending control messages, which it will then handle in the future.  It
is less flexible but safer.

Bug: 146877356
Bug: 148236233
Bug: 150863651
Bug: 151251827
Test: multiple reboot tests, safely restarting hwservicemanager
Merged-In: Ice773436e85d3bf636bb0a892f3f6002bdf996b6
Change-Id: Ice773436e85d3bf636bb0a892f3f6002bdf996b6
(cherry picked from commit 802864c782)
2020-03-16 09:21:18 -07:00
Tom Cherry
0188274148 Revert "init: handle property service callbacks asynchronously"
This is apparently causing problems with reboot.

This reverts commit d2dab830d3.

Bug: 150863651
Test: build
Merged-In: Ib8a4835cdc8358a54c7acdebc5c95038963a0419
Change-Id: Ib8a4835cdc8358a54c7acdebc5c95038963a0419
2020-03-16 09:20:22 -07:00
Tom Cherry
0c3d4843de Revert "Stop & Resume property service when switching to bootstrap namespace"
Dependent change was reverted.

This reverts commit 352ae2d225.

Bug: 150863651
Test: build
Merged-In: I2e11b782fcd2b7baded133a841fdcf519f702b84
Change-Id: I2e11b782fcd2b7baded133a841fdcf519f702b84
2020-03-10 16:38:44 -07:00
Yifan Hong
dd4e7ef6ce init: restorecon libsnapshot rollback indicator
The rollback indicator is created during first stage init and
is unlabeled. Need to restorecon it properly so that it can
be properly deleted by update_engine later.

Bug: 149956852
Bug: 150907679
Test: apply OTA, reboot, look at serial console
Change-Id: Ie954023b557865691fec2ae378145596bf1973a9
2020-03-05 21:56:03 -08:00
David Anderson
960a81f4a1 init: Make sure ImageManager status files are labelled.
adb remount and snapshot-based updates use ImageManager in first-stage
init. This creates status files, which need to be labelled.

Bug: 148834619
Test: manual test
Change-Id: I72949fca2889f9e5612049844a78bf9355b48797
Merged-In: I72949fca2889f9e5612049844a78bf9355b48797
2020-03-05 21:55:12 -08:00
PO HUNG CHEN
7fc6052fd3 Merge "Refine the exported DSU status" into rvc-dev 2020-03-06 02:25:21 +00:00
Howard Chen
026adf0864 Refine the exported DSU status
The new exported DSU status removes the need to make blocking binder
calls out of system server during device boot.

Bug: 149790245
Bug: 149716497
Test: adb shell am start-activity \
    -n com.android.dynsystem/com.android.dynsystem.VerificationActivity \
    -a android.os.image.action.START_INSTALL \
    -d file:///storage/emulated/0/Download/system.raw.gz \
    --el KEY_SYSTEM_SIZE $(du -b system.raw|cut -f1) \
    --el KEY_USERDATA_SIZE 8589934592
Change-Id: I27fae316214498407a73474ca8b93aec3518e4b5
Merged-In: I27fae316214498407a73474ca8b93aec3518e4b5
(cherry picked from commit 2e1c6b26a1)
2020-03-04 18:24:00 +08:00
Nikita Ioffe
352ae2d225 Stop & Resume property service when switching to bootstrap namespace
Test: atest CtsUserspaceRebootHostSideTestCases
Bug: 148236233
Bug: 149745936
Merged-In: I9d30b75f4b4177175ce086c3b6a7c0bba9a17396
Change-Id: I9d30b75f4b4177175ce086c3b6a7c0bba9a17396
(cherry picked from commit 6963f81a2b)
2020-03-02 11:09:42 -08:00
Tom Cherry
d2dab830d3 init: handle property service callbacks asynchronously
A previous change moved property_service into its own thread, since
there was otherwise a deadlock whenever a process called by init would
try to set a property.  This new thread, however, would send a message
via a blocking socket to init for each property that it received,
since init may need to take action depending on which property it is.
Unfortunately, this means that the deadlock is still possible, the
only difference is the socket's buffer must be filled before init deadlocks.

There are possible partial solutions here: the socket's buffer may be
increased or property_service may only send messages for the
properties that init will take action on, however all of these
solutions still lead to eventual deadlock.  The only complete solution
is to handle these messages asynchronously.

This change, therefore, adds the following:
1) A lock for instructing init to reboot
2) A lock for waiting on properties
3) A lock for queueing new properties
4) A lock for any actions with ServiceList or any Services, enforced
   through thread annotations, particularly since this code was not
   designed with the intention of being multi-threaded.

Bug: 146877356
Bug: 148236233
Test: boot
Test: kill hwservicemanager without deadlock
Merged-In: I84108e54217866205a48c45e8b59355012c32ea8
Change-Id: I84108e54217866205a48c45e8b59355012c32ea8
(cherry picked from commit 7205c62933)
2020-03-02 11:08:50 -08:00
Tom Cherry
eb04526a1e Refactor libinit_test_utils to not use libinit and expose its libraries
Users of libinit_test_utils must include all libraries that it uses.
If it uses libinit, then there is a large number of libraries that
must be included.  To avoid this, make libinit_test_utils only use
init_common_sources and the small number of required libraries that go
along with those sources.  Additionally, expose these sources as a
default for users of libinit_test_utils.

Bug: 148236233
Test: build
Merged-In: I224fa7e0590d073e4cd40412b5dcb6f72a64b6bf
Change-Id: I224fa7e0590d073e4cd40412b5dcb6f72a64b6bf
(cherry picked from commit a2f9136b2c)
2020-03-02 11:08:26 -08:00
Nikita Ioffe
284d0cf746 Reset post_data_ and services_update_finished_ on userspace reboot
Test: adb reboot userspace
Bug: 143970043
Change-Id: I77d47a8460b1526337a318547a59141334e11cdd
Merged-In: I77d47a8460b1526337a318547a59141334e11cdd
(cherry picked from commit 3ad292025c)
2020-02-29 13:18:39 +00:00
Nikita Ioffe
dffbb4f148 If userspace reboot watchdog triggers, don't store reason in persistent property
If init is wedged, then the write will never succeed and reboot won't
happen.

Also, in case of normal reboot, move call to PersistRebootReason to the
top of DoReboot() function, to make sure we persist it even if /data is
not mounted.

Test: builds
Test: adb shell svc power reboot userspace
Test: atest CtsUserspaceRebootHostSideTestCases
Bug: 148767783
Change-Id: I4ae40e1f6fdc41cc0bcae57020fa3d3385dda1b4
Merged-In: I4ae40e1f6fdc41cc0bcae57020fa3d3385dda1b4
2020-02-28 11:40:10 +00:00
Howard Yen
446c4fbed0 init: prevent persist.sys.usb.config initalized as none,adb
Prevent appending ",adb" to persist.sys.usb.config if "none" is
explicitly defined in default prop.

Bug: 150130503
Test: persist.sys.usb.config initalized correctly
Change-Id: I3b5de6fd102e252019e843f39f0875f5aaea7486
2020-02-26 22:02:08 +08:00
Nikita Ioffe
d0bc0b6f1e Store reason in case of userspace-reboot watchdog reboot
Test: adb reboot userspace
Bug: 148767783
Change-Id: I58cf103fd5ce47eadae334376109492d0cc1c1c6
2020-02-19 20:12:07 +00:00
Mark Salyzyn
ee016ce0b3 bootstat: enhance last reboot reason property with file backing
Helps with support of recovery and rollback boot reason history, by
also using /metadata/bootstat/persist.sys.boot.reason to file the
reboot reason.

Test: manual
Bug: 129007837
Change-Id: Id1d21c404067414847bef14a0c43f70cafe1a3e2
2020-02-14 13:24:16 -08:00
Bowgo Tsai
196cc58781 Preserving /avb/* keys to /metadata
Those keys will be used for key revocation check by DSU installation
service. Note that failing to copy those keys to /metadata is NOT fatal,
because it is auxiliary to perform public key matching prior to booting
into DSU images on next boot. The actual key matching will still be done
on next DSU boot.

Bug: 146910547
Test: boot device, checks the avb keys are copied to /metadata/gsi/dsu/avb/.
Change-Id: I25a4eba82e84288bac7a859205c920628a063651
2020-02-13 15:15:20 +08:00
Steven Moreland
504e6647ff libinit_test_utils: -= libhidl-gen-utils header
Bug: N/A
Test: N/A
Change-Id: Idd558c395dfe19af9fe654941cd77bc94d3d74f4
2020-02-10 10:41:29 -08:00
Steven Moreland
579e4b3d2b Merge "libinit_test_utils: don't assume interface format" 2020-02-10 17:44:05 +00:00
Nikita Ioffe
15e4f6fe5a Merge "Don't log userspace_reboot.started/finished properties from init" 2020-02-10 17:22:03 +00:00
Tom Cherry
2157b2065e Merge "init: group source files better in Android.bp" 2020-02-10 14:49:02 +00:00
Steven Moreland
bb44cd6ea1 libinit_test_utils: don't assume interface format
These can be AIDL or HIDL interfaces. Avoiding assuming the format here.

Bug: 141008902
Test: vts_ibase_test
Change-Id: If60367e3a46c74a1d28548379655f5e211f58b73
2020-02-07 13:39:35 -08:00