[Kernel, init.d] flawed init.d support stemming from doomlord kernels - Sony Ericsson Xperia Mini, Mini Pro, Xperia Pro, A

It seems that all Xperia Kernels that stem back to the DoomLord kernel start the init.d execution twice. While you may think "better twice than never" the nearly parallel execution of scripts can create problems if they concurrently manipulate CPU related tables - or fail to do so due to security mechanisms built in. I was hunting the problem that cpu-clock manipulation from init.d did not work for the scripts generated by System Tuner - finally resulting in this finding.
I checked for sirkay 587c and 587d and for fly-kernel 0.8 as the latest of their breed, quite sure nobody has ever cared about this quirk.
The duplicate execution could be tracked back to the init.rc entries:
Code:
[COLOR=SeaGreen]#DooMLoRD: init.d scripts support
start sysinitsupport
class_start core
class_start main
#DooMLoRD: new init.d scripts support
service sysinitsupport /sbin/sysinitsupport.sh
class main
disabled
oneshot[/COLOR]
Which does:
Code:
#!/sbin/sh
# DooMLoRD: init.d support script (v1)
# [START] setting up
echo "[START] remounting system" > /data/local/tmp/sysinitsupportlog.txt
/sbin/busybox mount -o remount,rw /system >> /data/local/tmp/sysinitsupportlog.txt
# make init.d directory
echo "
[*] make init.d directory" >> /data/local/tmp/sysinitsupportlog.txt
/sbin/busybox mkdir -p /system/etc/init.d >> /data/local/tmp/sysinitsupportlog.txt
# correcting permissions of files in init.d directory
echo "
[*] correcting permissions of files in init.d directory" >> /data/local/tmp/sysinitsupportlog.txt
/sbin/busybox chmod 777 /system/etc/init.d/*
# [COLOR=DarkOrchid]make [/COLOR]init.d directory
echo "
[*] [COLOR=DarkOrchid]make [/COLOR]init.d directory" >> /data/local/tmp/sysinitsupportlog.txt
[COLOR=Red]/system/bin/logwrapper /sbin/busybox run-parts /system/etc/init.d[/COLOR]
# [DONE] all done exiting
echo "[DONE] all done exiting" >> /data/local/tmp/sysinitsupportlog.txt
And later also in init.rc:
Code:
[COLOR=SeaGreen]#DooMLoRD: run my mods
service mymods /sbin/execute_mods.sh
class main
oneshot[/COLOR]
Which then does:
Code:
#!/sbin/sh
# starting
echo "[ START ]" > /data/local/tmp/log_doom-mods.log
echo "" >> /data/local/tmp/log_doom-mods.log
[COLOR=Red]# execute tweaks
/system/bin/logwrapper /sbin/busybox run-parts /etc/init.d[/COLOR]
# execute FPS limit remove
/sbin/mount -t debugfs debugfs /sys/kernel/debug
/sbin/echo '0' > /sys/kernel/debug/msm_fb/0/vsync_enable
/sbin/umount /sys/kernel/debug
echo "FPS limit successfully removed " >> /data/local/tmp/log_doom-mods.log
# DONE
echo "" >> /data/local/tmp/log_doom-mods.log
echo "[ DONE ]" >> /data/local/tmp/log_doom-mods.log
You see that the execution of
Code:
[COLOR=Red]/system/bin/logwrapper /sbin/busybox run-parts /etc/init.d[/COLOR]
is actually done twice - from sysinitsupport.sh first and then again from execute_mods.sh
Also mind that the log-entry in the first is leading in the wrong direction (copy error from above). It should better read "execute init.d directory"
The related logs are found in \data\local\tmp.
You can check yourself with this little script in \etc\init.d:
Code:
#!/system/bin/sh
echo [] > /data/local/tmp/$PPID-exec-done
echo $PPID "init.d executed" >> /data/local/tmp/$PPID-exec-done
date >> /data/local/tmp/$PPID-exec-done
Mind the $PPID which is the parent PID of the executing command (the busybox "run-parts"). Per boot you should just get 1 file <PPID>-exec-done containing the timestamp if you get 2 then you know why...
I have attached the script wrapped in a zip file. Unpack it, copy to \etc\init.d (or if not sym-linked to \system\etc\init.d) and change attributes to "777". Reboot and look what you get in \data\local\tmp.
Once you know, remove the script again and delete the created files in \data\local\tmp.
Mind that the scripts referenced from init.rc are copied over again from the kernel part so any change of the scripts in the \system\sbin folder is useless. The kernel has to fix that, no way out here.

I've been looking into this issue as well with the help of dk_zero_cool (mounts2sd amongst other things) as no matter what I tried I could not get m2sd to run in anything other than Safe Mode because init.d was being run as a service and not being executed in full before the init continued. So far I have edited init.rc to remove the second instance you quote above, and edited the first instance to:
Code:
exec /sbin/sysinitsupport.sh
so it executes rather than running a service. I then edited sysinitsupport.sh to contain just this:
Code:
#!/system/bin/sh
export PATH=/sbin:/system/sbin:/system/bin:/system/xbin
/system/bin/logwrapper busybox run-parts /system/etc/init.d
and also removed the line in execute_mods.sh that relates to init.d, so now theoretically the only thing that should happen in relation to init.d is that the exec command runs sysinitsupport.sh which in turn runs the init.d scripts before anything else in init.rc happens. IN THEORY!!! Because even with all of that done (and I have searched through the whole ramdisk, plus looked at the git for the init binary used in the Lupus ICS kernel I am using to make sure I haven't missed anything) the m2sd init.d script is still running in Safe Mode because it is detecting /system/bin/servicemanager running at the point it tries to execute. So something somewhere is still starting before the execution of init.d. I even tried with the init binary from the latest CM9 build for the Ray to rule out something wrong in there too.
I have sent all my files to dk_zero_cool to see if he can shed any further light on what else may be wrong. I have checked four different Ray kernels and they all use the same DoomLord methods so I doubt whether there are any Ray kernels that are running init.d correctly. It would be great to find a fix for this. Hope more people chip in!
Thanks for opening the discussion

As I understood, you have made some changes in the kernel assembly (not the code) to circumvent the effects you have outlined. I admit that I have not fully understood YOUR concern - but for my double execution of the "run-parts" the deactivation of the relevant line in either of the 2 scripts should do it, or not?
Is your concern related to the situation that init.d cannot do "everything" at the time it is executing and so it cannot achieve what some scripts intend to?
I am far too little educated in the details of kernel execution privileges so cannot further comment on that

Yeah, pretty much - to avoid possible issues with the m2sd script moving stuff around while something else is trying to make use of it the first thing it does is check if servicemanager is running, and if it is it disables the ability to move things like /data and dalvik-cache to sd-ext. The changes that we made in the scripts SHOULD have changed the init.d implementation from it running as a service whilst the rest of the init process carried on, to being executed as a command allowing any init.d scripts to be executed prior to any other service being started - as I understand it this is how init.d was intended to be used (ie the user scripts in /etc/init.d are run fully before anything else). However as I said, even with these changes and everything else relating to init.d having been removed something is still starting servicemanager, and until the source of that can be isolated scripts like m2sd cannot run fully/safely.

I guess the strategy to check on servicemanager is not right here. This is a process that starts several services and should not depend on anything in the init.d. So if you say that the boot sequence would have init.d completed BEFORE any service is started via servicemanager - THEN this could be a flaw in the kernel.
However is that really true? Is there no option to check if certain "dangerous" (for your move purposes) services are active already instead of checking on the servicemanager? I had found a nice overview on the Linux boot process here and I think that somewhere as part of the various init.x excuted scripts the servicemanager simply MUST be started - init.d is just a part of init - and for sure not the first part of it.
Off Topic:
I wonder where I can get some more insight in the Xperia Kernels and how they are assembled - especially which trace of that is noticeable in the filesystem. I noticed that the ICS Kernel have roughly 340MB for the user space while the JB Kernel has 360MB. Device should have 512 MB RAM, then some MB go away for radio and possibly video buffer, but his should be the same for all (accross ICS/JB). So what kind of memory tweaking makes this 20MB difference? I have not found a good place to discuss this - where could I go to?

tobbbie said:
It seems that all Xperia Kernels that stem back to the DoomLord kernel start the init.d execution twice. While you may think "better twice than never" the nearly parallel execution of scripts can create problems if they concurrently manipulate CPU related tables - or fail to do so due to security mechanisms built in. I was hunting the problem that cpu-clock manipulation from init.d did not work for the scripts generated by System Tuner - finally resulting in this finding.
Click to expand...
Click to collapse
How about Radeon kernel? Is there an issue like you said?
Sent from my ST18i using Tapatalk 2

frogerra said:
How about Radeon kernel? Is there an issue like you said?
Sent from my ST18i using Tapatalk 2
Click to expand...
Click to collapse
Just try out (see the guide on 01test.zip) - nothing you can harm doing that.

kernel behaviour trick
I noticed some kernels (GB and ICS) do overwrite settings from /etc/init.d ....
So if you make an init.d script with specific cpu values, or VM settings...some kernel overwrite these with their compiled/preferred values "after" init.d scripts are executed. This way it looks as if your script is not completely accepted by the rom...but the truth is that the kernel applies its own preferred values afterwards.
Thats why my init.d script contains a wait of 60 seconds in the beginning of the scripts......how ? add:
sleep 60
So your script looks like this (example):
#!/system/bin/sh
# this init.d script is for when you apply doomlord kernel supplied with repack 2013
sleep 60
That will run your init.d goodies after one minute.
As you see I'm working on a revived repack4pda 2013 (GB) , which will be released soon in repack4pda thread.
Br.
Michel

I guess that these kernels may be doing the same what you are proposing - just sleep the shell process before action starts. So you need to lookup the call tree from the init process along the various init.*.rc scripts if this is the case. For duplicate execution of init.d content any timed scripts willl not help - the duplicate execution will just happen later as the same script will pause the same amount of time.
Not sure if the init process script execution is synchronous or not - so if you create scripts which sleep, the final signal for "boot completed" may just also delay and the whole boot process may take longer by that sleep time. As well would you just stack the delays after each other and so nothing is gained finally. Synchronous execution would make it impossible that a part of the init process could postpone beyond boot completed.
It may differ if you run the scripts via the "exec" command or let it execute via the servicemanager. I guess the latter may run them asynchronously - not sure here as well.

Related

[Q] Modifying install-recovery.sh

I am trying to run Link2SD (Motorola Droid with Bugless Beast: GPA17)and Chevy No 1 1Ghz Lv kernel)
Link2SD attempts to mount the partition at boot using /etc/install-recovery.sh but it is not working (M boot loop, kernel panic, then boots)
Trying to debug this, I modified the install-recovery.sh by adding the word TEST to the first line of the LOG:
LOG=/data/link2sd-install-recovery.log
echo "$(date) TEST mounting..." > $LOG
...
I do not see a log file with that name but there are two other log files (/data/link2sd-debuggerd.log & /data/link2sd-boot-receiver.log). In neither of these, do I see my trace statement.
So, are there additional steps that I need to perform in order to modify the script and have it run?
Thanks!

[SOLVED]/etc/init.d/99tweaks not executing in Eclipse 2.2?

First off, I followed the instructions to a tee on installing Eclipse 2.2, including using Pete's Motorola One-Click and NOT Zergrush root. I used voodoo rootkeeper, kept the backup, installed the 2.3.5 Build 418 update, re-enabled root, deleted the back and then flashed Eclipse 2.2.
I then installed the Latest V6 Supercharger scripts which worked under Eclipse 2.1. I can get the Lag Nullifier option to work. However, when I try to get the memory settings to stick, they don't. It keeps reverting back to the default Eclipse values. I've tried local.prop and build.prop and nothing seems to make it work.
I have gone and modified the /etc/init.d/99tweaks script and commented out the minfree values line:
Code:
# minfree values
#echo 2560,4096,6144,17408,19456,23552 > /sys/module/lowmemorykiller/parameters/minfree
I've tried also sticking it in build.prop or local.prop and neither option works.
What's funny is, it appears NONE of the scripts in /etc/init.d are running at all. My SD cache is at 128, not 2048 as it is listed in the file:
Code:
# sd card speed boost
if [ -e /sys/devices/virtual/bdi/179:0/read_ahead_kb ]; then
echo 2048 > /sys/devices/virtual/bdi/179:0/read_ahead_kb
fi
Is something broken?
UPDATE 5/11/2012 10:40 AM Eastern
Okay, I did a factory reset, wiped cache, wiped dalvik and reflashed Eclipse 2.2. Upon rebooting, I checked the read_ahead_kb file and the init.d_log_test.txt file. This is what I found:
# cat /sys/devices/virtual/bdi/179:0/read_ahead_kb
cat /sys/devices/virtual/bdi/179:0/read_ahead_kb
128
# ls -l /data/local/tmp/init.d_log_test.txt
ls -l /data/local/tmp/init.d_log_test.txt
/data/local/tmp/init.d_log_test.txt: No such file or directory
So, the 99tweaks file either didn't run in /etc/init.d or it can't write to the /data/local/tmp and /sys/devices/virtual/bdi/170:0 directories.
Has anyone else noticed this issue? I guess my next thing to try is to sbf back to 2.3.4, re-apply the 418 update and flash again and see what happens.
Thanks!
BTW, I went and ran the 99tweaks script myself at the shell prompt and it seems to have worked. So, it definitely appears to be that the 99tweaks file (and any OTHER scripts in the /etc/init.d directory) are NOT getting executed after the phone is powered on or rebooted.
Here's the output from my run (deleted a bunch of the link_image errors or else my post was too long):
# sh 99tweaks
sh 99tweaks
vm.dirty_ratio = 90
vm.dirty_background_ratio = 70
vm.vfs_cache_pressure = 25
vm.oom_kill_allocating_task = 1
vm.min_free_kbytes = 4096
link_image[1964]: 3295 could not load needed library 'libncurses.so' for 'sqlite3' (load_library[1106]: Library 'libncu
rses.so' not found)CANNOT LINK EXECUTABLE
...
...
link_image[1964]: 3351 could not load needed library 'libncurses.so' for 'sqlite3' (load_library[1106]: Library 'libnc
urses.so' not found)CANNOT LINK EXECUTABLE
#
Click to expand...
Click to collapse
Could it be the 2.3.5 update broke the init.d process?
UPDATE: 05/11/2012 1:48 PM Eastern Time
Okay, I went and placed my OWN script in the /etc/init.d directory that echoed the string "Hello World" to a file in the /data/local/tmp directory named HelloWorld.txt. The file NEVER gets created when I reboot. If I run the script interactively, then it gets created, so definitely the process that runs the scripts in the /etc/init.d directory IS broken with the 2.3.5 update.
Okay, after days of banging my head against the wall and SBFing, rooting, voodoo rerooting, etc, it of course ended up being SO damned simple!
I finally decided to look at the files for the init.d hack. Lo and behold, I found that the /etc/install-recovery.sh script was NOT set to execute. It was read/write permissions only.
I also checked the /system/load_pia.sh and it was fine.
Using root explorer, I mounted /etc to read/write. I then changed the permissions of the /etc/install-recovery.sh script to be 0755. I then remounted the /etc directory r/o and rebooted. And what do you know - the 99tweaks file ran.
So, I would suggest everyone go and look at their /etc/install-recovery.sh script and ENSURE it's set to execute permissions. If not, nothing in /etc/init.d will execute since the install-recovery.sh script is the cog that does all the work.
work for me
changed permissions for /system/etc/install-recovery.sh
with root browser to
[x] [x] [x]
[x] [ ] [x]
[x] [ ] [x]
thanks

[Q] Symlinked scripts in init.d?

The rom I'm running (PARANOIDANDROID for HTC Desire) has a script in init.d to create symlinks for files contained in /sd-ext/gapps onto /system. This allows Desire users to have gapps on a ROM which would otherwise use up almost all of the space on /system.
I'm attempting to add a script to /sd-ext/gapps/system/etc/init.d so that it will be symlinked into /system/etc/init.d and be run on boot. I've confirmed that the file is indeed symlinked correctly (and that all permissions are set appropriately), but when it comes to execution of the script, something goes wrong.
The error I get is:
Code:
I/run-parts( 80): run-parts: /system/etc/init.d/25marketcache2sdext: No such file or directory
This indicates to me that run-parts doesn't like symlinked files. Is there any other way of going about this, or perhaps making run-parts work nicely with my script? I've tried some googling but I've found little that applied to Android, and even less that I actually understood.

[Q] init.d support on Cyanogenmod 12.1

Hi,
I'm trying to run a custom init.d script on my HTC One (m7) which is running on Cyanogemod 12.1 (The problem existed already in 12.0). The problem is that none of the scripts are executed at boot time.
Looking at the "init.cm.rc" script i found the following snippets that look like the "sysinit" command should be triggered at boot time.
Code:
[...]
on post-fs-data
[...]
# Run sysinit
start sysinit
[...]
# sysinit (/system/etc/init.d)
service sysinit /system/bin/sysinit
user root
oneshot
disabled
I even tried removing the "disabled" parameter but the "sysinit" command is still not executed at boot time.
If I run the "sysinit" command on a root shell the scripts are executed as the should.
Anybody an idea what I'm missing?
Thanks in advance!
Hi.
I am also running CM12.1 on a w7dsn device, and init.d wasn't working. I was able to get it running by using the init.sh script as described here:
http://techtrickz.com/how-to/fix-xposed-framework-installation-issue-on-nexus-6/
I've just downloaded the script and run it from my sdcard, no other steps are necessary.
lfom said:
Hi.
I am also running CM12.1 on a w7dsn device, and init.d wasn't working. I was able to get it running by using the init.sh script as described here:
http://techtrickz.com/how-to/fix-xposed-framework-installation-issue-on-nexus-6/
I've just downloaded the script and run it from my sdcard, no other steps are necessary.
Click to expand...
Click to collapse
I am trying to get init.d working on d2vzw, and no luck. The script you linked to works by replacing /system/etc/install-recovery.sh, but my build has no such file. What a drag with CM...
galets said:
I am trying to get init.d working on d2vzw, and no luck. The script you linked to works by replacing /system/etc/install-recovery.sh, but my build has no such file. What a drag with CM...
Click to expand...
Click to collapse
Mine didn't have either, but after installing the script (and creating install-recovery.sh) then my scripts in init.d started to be run after every boot.
You must turn off selinux in order for init.d to work
Sent from my LG-LS980 using XDA Free mobile app
I'm using CyanogenMod 12.1 ROM on my phone, to enable the init.d you have to remove the /system/bin/sysinit then recreate the similar filename with the same content and permissions (755, root, shell).
Code:
#!/system/bin/sh
export PATH=/sbin:/system/sbin:/system/bin:/system/xbin
run-parts /system/etc/init.d
Was it the init.rc from the boot.img initrd, or the one from the rootfs /boot.img?
Just change the permissions of all files in /etc/init.d folder to 755.
Also if you use the /data/local/userinit.sh change that to 755.
Leave the /system/bin/sysinit file as it is.
Code:
#!/system/bin/sh
export PATH=/sbin:/system/sbin:/system/bin:/system/xbin
for i in /system/etc/init.d/*; do
if [ -x $i ]; then
/system/bin/log -t sysinit Running $i
$i
fi
done
Cheers

init.d doesn't work

Hi,
I've followed this how-to: http://forum.xda-developers.com/showthread.php?t=1933849 to enable init.d support on my phone (GT-S5570i, Android 2.3.6, stock rom)
I have installed BusyBox (standard install, not smart install), then, after installing and launch Uni-init, i get "SUCCESS ! You have init.d support !"
Well, so I went into init.d folder and I manually launch the script "00test" to see if I am able to run scripts on my phone: ok: inside /data folder i see the test.log file! Then I delete this test file to see if my phone is really able to execute this script from the init.d folder at the boot.
Well, after reboot I go in /data but I don't see any test.log file.
Why? Uni-init told me that I have init.d support, but this don't seems true. The permissions on init.d folder and scripts are ok (rwxr-xr-x). I've also tried to change the ownership to 0 (root) and to 1000 (system) to the test script, and I've also tried another init.d activator, this one: http://download.apks.org/?apkid=com.broodplank.initdtoggler&ver=1.3&server=apk-s#.VbluDvldLcc bot no luck again.
Then I've found this solution: http://forum.xda-developers.com/showthread.php?t=2725680 which, differently from the other solutions, has inserted the runinit script inside /bin. Well: so I rebooted again, but the init scripts aren't still able to run at boot.
If i start the runinit script from a shell window, ok: scripts from init.d folder are properly executed, but again, when I boot my phone, these scripts aren't executed. Maybe I should tell to some system files to execute runinit at the boot time? I miss something?
Many thanks.
In another discussion I've read the following statement:
- the boot process calls install-recovery.sh while executing init.rc
- the install-recovery.sh calls sysinit script
- the sysinit script runs /system/etc/init.d/* in order
Click to expand...
Click to collapse
But I've found that my init.rc exclude the install-recovery.sh script:
Code:
#service flash_recovery /system/etc/install-recovery.sh
# oneshot
So, I don't have any chance to implement the init.d solution?

Categories

Resources