Sometimes I see the following logcat output such as that below:
<3>[ 283.152845] init: untracked pid 4217 exited
<3>[ 283.162185] init: untracked pid 4078 exited
<3>[ 283.173691] init: untracked pid 1504 exited
<3>[ 283.177018] init: untracked pid 1468 exited
What is the meaning of the log of init: untracked pid xxxx exited?
use logcat and read the huge log carefully. You might find the program that crashes all the time.
There may be many different reasons, one of them is that android init trying to
initialize services specified by init.rc failed.
You can try to bisect the services started from init.rc first, and once you find
the errornous service, then try to fix the specific service start up errors, which
may be the kernel driver error, or android hal driver error, library fault, or
sometimes android framework error.
Technically, this message (modern version of which is "Untracked pid XXX exited with status YY") means that Android init sees a child process exit (that is, receives SIGCHLD signal and then gets its pid with waitpid()), but it can't associate that process with any of configured services (see this question on Android init service configuration).
This in turn opens up a question of what can daemonize itself in Android environment and how to find it. But I don't think that I can answer that, the only suggestion that I have is getting root access and checking processes.
Related
There is a persistent process which I desire to persistently kill.
To do so, I made a very simple python script:
import os
import signal
While True:
os.system("ps >> /sdcard/newdata.txt")
file = open("/sdcard/newdata.txt","r")
for x in file:
if (len(x.split())<9):
continue
elif (x.split()[8] == "/system/bin/XXXX"):
pid = int(x.split()[1])
os.kill(pid, signal.SIGKILL)
break
file.close()
the XXXX represents the name of the binary of the file which triggers the process.
In my specific case this binary, XXXX, is a good way of recognizing the process I want to kill.
I think it should work, but instead it returns an error:
"ProcessLookupError: [Errno 3] No such process"
I printed the pid and ran the script multiple times.
The pid is fixed which should mean the process didn't respawn, still it always returns an error as if the pid is wrong.
Can anyone explain this?
Following the example given in this post, I added these lines to /init.rc:
on property:dev.bootcomplete=1
start boot_handler
service boot_handler /system/bin/bc_handler.sh
class main
user root
group root
disabled
oneshot
And this /system/bin/bc_handler.sh:
#!/system/bin/sh
echo hi > /data/local/hi.txt
I'm building Android 8.0 for the emulator. When the system starts, I can see that the script didn't run, and this message is seen in the logs:
[ 217.280853] init: service boot_handler does not have a SELinux domain defined
I tried changing my service to look like this:
service boot_handler /system/bin/sh /system/bin/bc_handler.sh
class main
user root
group root
disabled
oneshot
seclabel u:r:shell:s0
and now the error is
init: Service 'boot_handler' (pid 1729) killed by signal 1
Is there any documentation on how one adds a new service to Android under SELinux? Or documentation on how to disable SELinux on Android? I've been googling for hours, and all of the information I'm finding seems to be obsolete.
You can disable SELinux by setting permissive mode on your running platform
In permissive mode, selinux will only dump warning message
By default, it's in enforcing mode, where any SELinux violation will be denied.
To add a service, you should add file context in file_context, and write a .te file for your service
Here is a basic example and you can dig into more about SELinux
I am trying to add a native service written in C++ to the AOSP build.
The first thing I did was to create a native service and client to the AOSP build.
This worked as expected. I could start the service within an adb shell and call it via binder on a adb shell.
The trouble started when I wanted to start my service with init.
I added a .rc file to my build
service myp /system/bin/myp_service
class main
This did the the trick so that init tried to start it but it failed because of SELinux policies.
So I added a file_contexts to my device tree and added:
/system/bin/myp_service u:object_r:myp_exec:s0
Next I added a myp.te file and added:
type myp, domain;
type myp_exec, exec_type, file_type;
type myp_service, service_manager_type;
init_daemon_domain(myp)
net_domain(myp)
binder_use(myp)
binder_service(myp)
add_service(myp, myp_service)
binder_call(myp, binderservicedomain)
binder_call(myp, appdomain)
allow myp myp_service:service_manager add;
And finally I added a service_contexts file with:
myp u:object_r:myp_service:s0
This finally made my service successfully start at boot time.
Unfortunalty I cannot use binder against this service. When I try to connect to the service with my client the call
defaultServiceManager()->getService(String16("Demo"))
returns a null pointer.
I cannot find any hints in the dmesg.
So I assume I am still missing something for the SElinux but I have no clue what I am missing.
If I shutdown the SELinux with setenforce and restart the service then it works fine.
Can anyone give me a hint what I am missing for SELinux or where I can get more information about which policy blocked something?
You could see the denials like this:
adb logcat | grep "SELinux : avc" > /tmp/logs
Get sepolicy current file. (Can be taken from device this way adb pull sepolicy.
Using audit2allow (located in AOSP source code: external/selinux/prebuilts/bin/audit2allow or in SDK tools. Do this: cat /tmp/logs | .external/selinux/prebuilts/bin/audit2allow -p sepolicy
The audit2allow tool will tell you what permission you are missing for the logcat extracted and the current sepolicy file, watch-out because you could need to do this several times since fixing some permissions will show the next ones required.
If you have a userdebug kind of build you could get setenforce 0, logcat with it and all the denials will be in logcat even if you will be permited to do the operation desired. This will leave the audit2allow iterations required in 1.
For anyone who came across this problem, please make sure your service_contexts file is successfully merged with stock service_contexts file. If you're building your service for Android O or later, please put this file inside a folder and refer to it in your Makefile by BOARD_PLAT_PRIVATE_SEPOLICY_DIR1. And you don't need to add allow myp default_android_service:service_manager add if the build system does pick up your service_contexts.
Also, about the domain.te violation problem, you probably want to attach one of the coredomain or appdomain attribute to your domain 2 with typeattribute <your_domain> <attribute>;.
Finally, please double check the following built files to make sure you don't leave any sepolicy configurations out in the final build:
$(AOSP_ROOT)/out/target/product//obj/ETC/file_contexts.bin_intermediates/file_contexts.*
$(AOSP_ROOT)/out/target/product/potter/obj/ETC/plat_service_contexts_intermediates/service_contexts.*
$(AOSP_ROOT)/out/target/product/potter/obj/ETC/sepolicy_neverallows_intermediates/policy.conf
I am currently trying to insmod a kernel module during the end of the boot process, and so I've created the following entries in init.rc:
on post_late_start
start myscript
on nonencrypted
class_start late_start
trigger post_late_start
on property:void.decrypt=trigger_restart_framework
class_start main
class_start late_start
trigger post_late_start
service myscript /data/my_sh.sh
disabled
oneshot
Then in my /data directory my_sh.sh has the following:
#!/system/bin/sh
log -t mytag -p V "Hello World!"
insmod mymodule.ko mod_parameter=arg
But when I run -- sometimes I do not see the "Hello World" tag when I logcat -s "mytag" and of course, the insmodded module is not installed either.
What is the proper way of late-inserting a kernel module (it needs to go in after network is up and /data is mounted). And further -- how do I get the output of insmod into the log so that I can debug? Any help is appreciated and I can post more details if necessary.
At least since Froyo and still in Lollipop, Android init implements insmod in system/core/init/buildin.c. It is supposed to work directly in an init*.rc file:
on boot
insmod /system/lib/modules/your-module.ko.
However, at least in Lollipop 5.1, it no longer works, as SELinux rules are enforced. init does not have the required sys_module permission. Therefore the underlying init_module system call returns EPERM. This is never reported to anywhere. The only symptom is that insmod commands now fail to load the module, always.
I opened an AOSP issue on this. According to Google, this works as intended. If you want to use kernel modules when SELinux is enforced (which they strongly advice against), you must yourself add the required SELinux permission to init.
I am not sure about your log, but to insmod you need to give the exact path to the module, because I dont think you will be having mymodule.ko residing in the same place as init.rc is there. So try to give the full path of your ko file.
Generally it resides in /lib/modules/youdrivername.ko
so check it here first.
I am doing kernel configuration for ICS. I needed to enable Posix message queue as it is required in one of our applications. But enabling this option resulted in error. The make was successfull. But the image could not be loaded. The dmesg was:-
disagrees about version of symbol module_layout.
init: untracked pid 2038 exited.
logcat :-
mknod : '/dev/nexus_proxy' failed
NEXUS_Platform_Join [CONSTRUCTOR] failed.
Looks like you rebuilt only the kernel.
You need to build any kernel-modules (*.ko files) and
update them onto the filesystem.
Here is a detailed discussion on the disagrees about version of symbol error.