Commit graph

384 commits

Author SHA1 Message Date
Bart Van Assche
97047b54e9 init: Combine two global sigchld_fd variables into one
Remove the Service::SetSigchldFd() method. Make the Service::GetSigchldFd()
create a signalfd for SIGCHLD. This makes it possible to use a SIGCHLD
signalfd in unit tests.

Change-Id: I0b41caa8f46c79f4d400e49aaba5227fad53c251
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2023-11-20 09:32:59 -08:00
Akilesh Kailash
76b553c93b init: Start snapuserd_proxy after early-init
When service is started prior to early init and if per-app memcg is enabled, service start will fail as the required directories for memcg isn't present viz /dev/memcg/apps.

Bug: 308818430
Test: th and CF OTA test with per-app memcg enabled
Change-Id: Ic65e8d179fbfb8e2135f2de5cc7c77d6c29ea7d2
Signed-off-by: Akilesh Kailash <akailash@google.com>
2023-11-08 15:07:57 +00:00
Bart Van Assche
a75f210398 init: Make WaitToBeReaped() wait less long
Reduce the time spent in WaitToBeReaped() by waiting for SIGCHLD instead
of waiting for 50 ms.

Bug: 308687042
Change-Id: I5e259fdd22dec68e45d27205def2fc6463c06ca3
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2023-11-07 10:52:26 -08:00
Bart Van Assche
43323a7e7a init: Create different file descriptors for SIGCHLD and SIGTERM
This change will allow a later CL to wait for SIGCHLD without discarding
the SIGTERM information.

Bug: 308687042
Change-Id: I5b9ab4562060455573cd816cc48bf90576b39ab9
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2023-11-06 10:38:20 -08:00
Bart Van Assche
ac8b5bd0bc init: Fix a compiler warning
Fix the following compiler warning:

system/core/init/init.cpp:754:57: warning: ISO C++ requires field designators to be specified in declaration order; field '' will be initialized after field 'sa_flags' [-Wreorder-init-list]
    const struct sigaction act { .sa_handler = SIG_DFL, .sa_flags = SA_NOCLDSTOP };
                                                        ^~~~~~~~~~~~~~~~~~~~~~~~
system/core/init/init.cpp:754:34: note: previous initialization for field '' is here
    const struct sigaction act { .sa_handler = SIG_DFL, .sa_flags = SA_NOCLDSTOP };
                                 ^~~~~~~~~~~~~~~~~~~~~

Change-Id: I29e2d51dfdff85212a33eebfd51b241268cdfe9a
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2023-11-02 13:06:22 -07:00
Jooyung Han
55ef3d6104 Skip bootstrap APEX RC files for the second round
Reading .rc files from bootstrap APEXes causes "double loading".
This works for services because init just ignores duplicates. But it
emits error logs, which can mislead even though there's no actual
errors. Besides, for actions, duplicates can cause a problem when
commands are not idempotent.

So, when loading RC files from APEXes for the second time, we'd better
skip those bootstrap APEXes.

Bug: 290148081
Test: VendorApexHostTestCases
Change-Id: Ia630dbd14046064b5e5c612c01ebacf57091c8d4
2023-08-11 10:02:08 +09:00
Jooyung Han
566c65239f Use /bootstrap-apex for bootstrap APEXes
This new directory is bind-mounted to /apex in the bootstrap mount
namespace so that apexd-bootstrap mounts bootstrap APEXes there via
/apex.

The directory is shared between two mount namespaces, hence visible
in the default mount namespace.

Bug: 290148078
Test: VendorApexHostTestCases
Change-Id: I841480e41be8def5a4c6a4aa874c4e21465a71d3
2023-08-09 17:27:39 +09:00
Jooyung Han
840691be71 Revert "Use /bootstrap-apex for bootstrap APEXes"
Revert submission 2666915-share-bootstrap

Reason for revert: b/293949266 vold_prepare_subdirs fails to create apexdata directories.

Reverted changes: /q/submissionid:2666915-share-bootstrap

Change-Id: I3e97e8511755844de4b54f51ff20afc154bd8e74
2023-08-01 09:06:47 +00:00
Jooyung Han
201801ce8e Use /bootstrap-apex for bootstrap APEXes
This new directory is bind-mounted to /apex in the bootstrap mount
namespace so that apexd-bootstrap mounts bootstrap APEXes there via
/apex.

The directory is detached from /apex in the default mount namespace but
still visible in case bootstrap APEXes are needed.

However, there are (mostly, virtual) devices which don't need two mount
namespaces. Those devices don't need to make /bootstrap-apex directory
at all.

Bug: 290148078
Test: atest VendorApexHostTestCases
Test: atest MicrodroidTests
Change-Id: I541cec71d9970b14971d46e01e4808b23590dbed
2023-07-31 18:16:46 +09:00
JW Wang
a37c4d2796 Export active dsu slot to system prop
The prop can be consumed by init scripts to do customized setup:

on property:ro.gsid.dsu_slot=oemtest
    # Do setup for test
on property:ro.gsid.dsu_slot=oemdemo
    # Do setup for demo

Bug: 277691885
Test: m
Change-Id: I7bd78b9ba31021b27d57c6f092dad5d7ebf6e59b
2023-05-15 09:48:59 +08:00
Bart Van Assche
071dbc1729 init: Combine the CheckShutdown() and set_do_shutdown() methods
Let the CheckShutdown() method clear the do_shutdown_ member instead of
clearing that member separately from calling CheckShutdown().

Bug: 266255006
Change-Id: Ifc1cff2be92a45db7f91be2fdb812930d2fd1ad5
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2023-03-03 13:27:17 -08:00
Bart Van Assche
b4b1b75a35 init: Remove the DebugRebootLogging() function
The DebugRebootLogging() function was introduced to help with
root-causing b/150863651. Remove this function since this logging
functionality is no longer needed. Also remove the functions and methods
that are only used by DebugRebootLogging().

Change-Id: Ia150604c6cd70f42b13d655ba43b95445a55b6e2
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2023-03-03 13:26:58 -08:00
Bart Van Assche
1fdbf8d0f8 init: Combine two if-statements
Combine two if-statements. This change is fine because:
* The code between the two if-statements does not queue actions.
* If an action is queued from another thread then WakeMainInitThread()
  is called after the action has been queued.

Bug: 266255006
Change-Id: Id4b9565ff4fdb3ee2a2bbca316c8c78e0f2d38dd
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2023-03-03 13:26:58 -08:00
Bart Van Assche
b6b7ccc24f init: Document the locking strategy used in class PropWaiterState
Let the compiler verify that lock_ is held when any of the data members
are accessed.

Bug: 266255006
Change-Id: I71b341815d84ab530627d934ad4d4681b652b9d8
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2023-02-17 13:55:11 -08:00
Bart Van Assche
68a59e1c72 init: Document the locking strategy in class ShutdownState
Let the compiler verify that shutdown_command_lock_ is held when
shutdown_command_ is accessed.

Bug: 266255006
Change-Id: Ibd05137ab65e20f247f35bbb2bb1865e05f51f41
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2023-02-17 13:55:11 -08:00
Alex Hong
057b94215a Reland "Set the log callback earlier for showing system property set denials"
PropertyInit loads the build.prop files and set the system properties.
Set the SELinux log callback before that to show the avc denials for debugging.

Test: $ make init_system
      Push this module and ensure system property set denials are shown during boot
Bug: 185920634
Bug: 211547922
Change-Id: If9f34d469d3da2ebdfe64bb611de85a3ca37e000
2023-01-31 22:11:16 +08:00
Bart Van Assche
29d8a42d14 Revert "init: Add more diagnostics for signalfd hangs."
Revert commit 14f9c15e05 ("init: Add more diagnostics for signalfd
hangs") because:
* That commit was intented to help with root-causing b/223076262.
* The root cause of b/223076262 has been fixed (not blocking SIGCHLD
  in all threads in the init process).

Test: Treehugger
Change-Id: I586663ec0588e74a9d58512f7f31155398cf4f52
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2022-11-30 09:17:16 -08:00
Shen Lin
63ae3fdd9d init: Amend code format for DoLoadApex
Test: m init
Change-Id: I9d873cdf067ea586f75e62ff8a39cb753151f9ec
2022-11-02 11:01:04 +08:00
Bart Van Assche
1a5b59386d init: Fix HandleSignalFd()
There are two bugs in HandleSignalFd():
* If the one_off argument is true and if no data is read from the
  signalfd, 'siginfo' is left uninitialized and used in the switch
  statement in HandleSignalFd().
* The PLOG() statement in the switch statement should be a LOG()
  statement since it does not report a failed system call.

This CL has been tested by changing kDiagnosticTimeout locally from 10s
into 100ms.

Change-Id: I0e488dd95bc13e1befaef770c0748d1d47f6e431
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2022-10-27 08:07:26 -07:00
Nikita Ioffe
537ab23872 Merge "init: skip cgroup/task_profiles configuration if cgroups are disabled" 2022-10-24 07:14:12 +00:00
Nikita Ioffe
c2b1654c11 init: skip cgroup/task_profiles configuration if cgroups are disabled
We are planning to remove cgroups from the Micrdroid kernel, since the
entire VM belongs exclusively to a single owner, and is in the control
of the cgroups on the host side.

This patch expoxes CgroupAvailable API from libprocessgroup, and changes
init to query the CgroupAvailable API before doing any
cgroups/task_profiles related work.

Bug: 239367015
Test: run MicrodroidDemoApp
Test: atest --test-mapping packages/modules/Virtualization:avf-presubmit
Change-Id: I82787141cd2a7f9309a4e9b24acbd92ca21c145b
2022-10-21 13:14:23 +01:00
Bart Van Assche
bc5c4a4659 init/epoll: Make Epoll::Wait() easier to use
Invoke the callback functions from inside Epoll::Wait() instead of
returning a vector with pointers to callback functions. Remove handlers
after handler invocation finished to prevent that self-removal triggers
a use-after-free.

The CL that made Epoll::Wait() return a vector is available at
https://android-review.googlesource.com/c/platform/system/core/+/1112042.

Bug: 213617178
Change-Id: I52c6ade5746a911510746f83802684f2d9cfb429
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2022-10-20 09:32:51 -07:00
Bart Van Assche
4842650043 init: Improve readability of the code in SecondStageMain()
Change the type of epoll_timeout from
std::optional<std::chrono:milliseconds> into std::chrono::milliseconds.
No functionality is changed.

Bug: 213617178
Change-Id: Ieb150e0aeabdb79c8da4649875ea3ed59297343b
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2022-10-20 09:32:51 -07:00
Bart Van Assche
a2c160449b init: Introduce Epoll::SetFirstCallback()
Prepare for optimizing Epoll::Wait() by moving the
ReapAnyOutstandingChildren() call into Epoll::Wait(). No functionality
is changed.

Bug: 213617178
Change-Id: I280ea0069ed29cf323e4177ec500b30b900f7c8d
Signed-off-by: Bart Van Assche <bvanassche@google.com>
2022-10-18 09:17:55 -07:00
Jooyung Han
c69bcd4a6d Merge "Removed property init.apex.<apex-name>.load/unload." 2022-09-02 06:46:54 +00:00
Deyao Ren
259b63d71c Removed property init.apex.<apex-name>.load/unload.
Bug: 240533726
Test: atest CtsInitTestCases ApexTestCases
Change-Id: I7ed149f24dc4b116865320c85389ffe7bae6ae0d
2022-09-01 16:14:00 +00:00
Deyao Ren
e37c15e9b0 Merge changes from topic "vapex_stop_service"
* changes:
  Remove and add service and action during apex load and unload
  Stop services when unload an apex
2022-08-31 16:09:43 +00:00
Deyao Ren
238e909349 Remove and add service and action during apex load and unload
Bug: 232114573
Test: atest CtsInitTestCases ApexTestCases
Change-Id: I1f91ada1d44ac2380e2faf8fc25e0a521cc1a826
2022-08-30 17:31:00 +00:00
Deyao Ren
07595e198c Stop services when unload an apex
Bug: 238854102
Test: atest CtsInitTestCases ApexTestCases
Change-Id: I3b9df9424f7841c42bd1bde27cd0e0750615bd6c
2022-08-24 06:22:57 +00:00
Deyao Ren
aebf88191b Merge "Add apex name to service" am: ec73481e58
Original change: https://android-review.googlesource.com/c/platform/system/core/+/2155014

Change-Id: I3c44c321568173fa11588c2d6c69a43ad48c63f9
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-07-22 23:09:19 +00:00
Deyao Ren
df40ed1be1 Add apex name to service
Passed apex file name to service. The file name will be parsed
to determine 1) whether the service is from an apex; 2) apex name

Bug: 236090201

Change-Id: I2c292c0c067f4bf44bb25b1f80e4f972b94f7258
2022-07-22 04:00:30 +00:00
Jooyung Han
6bfcefca0a Merge "Update linker configuration when loading apex" am: 11e757c9cc
Original change: https://android-review.googlesource.com/c/platform/system/core/+/2155096

Change-Id: Ife9943c015595c8d1381716fede99ad0fce2fab1
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-07-18 23:59:47 +00:00
Jooyung Han
626be07153 Update linker configuration when loading apex
On ctl.apex_load <apex_name> control message, init invokes linkerconfig
to update linker configuration for the updated apex.

Bug: 232173613
Test: CtsInitTestCases
Test: VendorApexHostTestCases
Change-Id: I01d975849c3f4efe74205a7b04ebbd6864ba1121
2022-07-18 17:45:15 +09:00
Jooyung Han
db126b9a4e Merge "Return Result<T> from Do(Un)LoadApex()" am: 46fa45d82c
Original change: https://android-review.googlesource.com/c/platform/system/core/+/2155095

Change-Id: Ib73a4ed9cfb73ebd26cd03d2c3119aab5f17c5e2
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-07-16 03:19:31 +00:00
Jooyung Han
a2fe3e577e Return Result<T> from Do(Un)LoadApex()
For consistent error message. This is a preparation step for the
follow-up change: to generate linker configuration in DoLoadApex()

Bug: 232173613
Test: CtsInitTestCases
Change-Id: I27954ae2429e82da1bde1925ef62b277c24129d3
2022-07-16 08:37:06 +09:00
Treehugger Robot
e03286ac40 Merge "Add ctl.apex_(un)load properties to (un)load apex" am: e271146ec8
Original change: https://android-review.googlesource.com/c/platform/system/core/+/2146970

Change-Id: I26a3865aaaae2ded31c84e701a0a6fe3592b65a1
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-07-13 04:20:59 +00:00
Jooyung Han
678f0b4828 Add ctl.apex_(un)load properties to (un)load apex
These props are supposed to be used by apexd when installing an apex
without reboot. During the installation, apexd will unmount the current
one and mount the new one. Since the path and its contents will be
replaced, anything loaded from the apex should be unloaded before
unmounting. After apexd mounts the apex again, then init should re-read
.rc files from the apex.

This change only addes required properties:
- ctl.apex_load <apex_name>
- ctl.apex_unload <apex_name>
- init.apex.<apex_name> = loaded | unloaded

Bug: 232114573
Bug: 232173613
Test: atest CtsInitTestCases
Change-Id: I4a8942d67912e2f11acc51bec756c4e3c218179a
2022-07-07 15:58:33 +09:00
Kean Mariotti
7772fc84f5 Merge "Revert "Set the log callback earlier for showing system property set denials"" am: 526fbe2a37 am: c0e0892a5a
Original change: https://android-review.googlesource.com/c/platform/system/core/+/2118487

Change-Id: I351a3a385c5d1be27258343db342910c5ec0291f
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-06-08 09:50:51 +00:00
Kean Mariotti
526fbe2a37 Merge "Revert "Set the log callback earlier for showing system property set denials"" 2022-06-08 09:07:42 +00:00
Kean Mariotti
3a6040eb71 Revert "Set the log callback earlier for showing system property set denials"
This reverts commit 8c224faa24.

Reason for revert: 235312897

Change-Id: I80684c80bb6f97853449d429bbf948c07d4cb651
2022-06-08 07:57:53 +00:00
Alex Hong
c0b9b5f2d3 Merge "Set the log callback earlier for showing system property set denials" am: af74368a36 am: 219306f683
Original change: https://android-review.googlesource.com/c/platform/system/core/+/1684665

Change-Id: Ic880afd4b9393b6d5e0516c914d00c5ec27de55c
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-06-08 06:11:38 +00:00
Alex Hong
af74368a36 Merge "Set the log callback earlier for showing system property set denials" 2022-06-08 05:37:22 +00:00
Jooyung Han
4a8d564a5e Merge changes from topics "action-in-apex-config", "apex-ready-event", "subcontext-for-vendor-apex" am: ec76b5cb4e am: 364bc73186
Original change: https://android-review.googlesource.com/c/platform/system/core/+/2093006

Change-Id: I3f9f6446af71094526e3c5a2ff2034ba25495c7a
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-05-13 03:55:45 +00:00
Jooyung Han
03baf470dc APEX configs support 'on' as well am: badb7de1a2 am: bc3ec37dad
Original change: https://android-review.googlesource.com/c/platform/system/core/+/2093004

Change-Id: I6b656e0e9de265f1532406236d38578e2a99cf7f
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-05-13 03:55:36 +00:00
Christopher Ferris
3863195506 Merge "Use new AndroidUnwinder object." am: dbe14f2f73 am: 32cfdb4be7
Original change: https://android-review.googlesource.com/c/platform/system/core/+/2095788

Change-Id: I18b4dfda04db0fadf49fa9ce9112e1205c3c21ad
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-05-12 05:08:43 +00:00
Jooyung Han
38e8e74550 Use subcontext for APEX configs from /{vendor, odm}
Instead of using config file path, use APEX's preinstalled path to
determine whether to use subcontext or not for APEX configs.

Bug: 232021354
Test: CtsInitTestCases, CtsBluetoothTestCases
Change-Id: Iba603f09602f0bec3113e2be3d15c62055c09e72
2022-05-12 13:37:19 +09:00
Jooyung Han
badb7de1a2 APEX configs support 'on' as well
APEX configs have supported only 'service' definitions. For those
services relying on 'on' trigger actions, we had to have separate config
files installed in read-only partitions (e.g. /system/etc/init).

This was suboptimal because even though APEXes are updatable, read-only
partitions are not.

Now, 'on' is supported in APEX configs. Putting 'on' trigger actions
near to service definitions makes APEX more self-contained.

'on' trigger actions loaded from APEX configs are not sticky. So, events
happens before loading APEX configs can't trigger actions. For example,
'post-fs-data' is where APEX configs are loaded for now, so 'on
post-fs-data' in APEX configs can't be triggerd.

Bug: 202731768
Test: atest CtsInitTestCases
Change-Id: I5a01d9c7c57b07955b829d6cc157e7f0c91166f9
2022-05-12 13:37:13 +09:00
Christopher Ferris
d2bd6c5f13 Use new AndroidUnwinder object.
Replace libbacktrace with the new AndroidUnwinder object.

Bug: 120606663

Test: Ran unit tests.
Test: Added call of UnwindMainThreadStack() in DebugRebootLogging()
Test: and verified unwind data is logged properly.
Change-Id: Ia724f9485377d6d2c894283242a3c5653bf82768
2022-05-11 15:39:20 -07:00
Akilesh Kailash
071d75052b Merge "libsnapshot: Remove invalid snapshot metadata" am: e3cca4a0d1 am: d2611d1c1c am: 0d701c13b6
Original change: https://android-review.googlesource.com/c/platform/system/core/+/2061835

Change-Id: Ica6ad814de0853722fd2e5d4ab41670a29f3f36e
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-04-17 00:25:11 +00:00
Akilesh Kailash
f86fca236f libsnapshot: Remove invalid snapshot metadata
If there are snapshot metadata persisting in /metadata/ota/snapshots,
remove them before applying a new update. Make sure that
the snapshots are indeed invalid before removing them.

On a sidenote, add a comment in init.cpp related to
b/223076262.

Bug: 228250473
Test: 1: Apply OTA in recovery through adb sideload
2: Reboot
3: Apply OTA OTA again through update_device.py
4: Re-run Full OTA updates just from update_device.py

Signed-off-by: Akilesh Kailash <akailash@google.com>
Change-Id: I116bbafae09042b9c391ccd58c102704571c214e
2022-04-16 16:43:35 +00:00