Post Reply

[Shell][mksh][Scripting]::mksh-R50d-static-FULL+mkshrc_mods:::

OP 7175

5th August 2014, 07:45 AM   |  #11  
7175's Avatar
OP Senior Member
Thanks Meter: 330
 
254 posts
Join Date:Joined: Feb 2013
More
@E:V:A : Glad the first execution you mentioned worked. I would try messing with quotes/double quotes around the shell command, i.e. ssh ... -T su -c 'exec ...' or try ssh ... -T su -c exec "...", as something to test out further. This can make a lot of difference.

The ulimit shell function can control all sorts of performance related stuff, priority, max niceness, etc. You can see all values with "ulimit -a".

I understand your hesitance about the libc.so replacement. I would keep a copy of the old one and twrp backup before trying out a new one. I get what you're saying about statically linked binaries. I just fixed my i7 desktop that had a blown power supply, so I'll be looking into this. Thanks for the linaro link!

@mirabilos : Thanks for taking a look at this and providing us with mksh! I updated my OP with the specifics about the rebinds for "control I" and "control U" that you mentioned, and I added a suffix to the beginning comments of the file. Something like:
Code:
# $MirOS: src/bin/mksh/dot.mkshrc,v 1.88 2014/01/11 18:09:39 tg Exp $Android_mod by 7175@xda-developers.com 2014/08/04$
Not sure if that's what you wanted me to add in. I included an extra zip to download in the 2nd post that contains the official mkshrc 2014/01/11, my personal mkshrc, and a "diff -ur" patch (also attached to this post).

I will look into getting a statically linked mksh compiled, that sounds like something really handy to keep around.

edit: Here's basically what I added to the beginning and end of PS1 to trim down its "set -x" verbosity to 3 lines. I'd like to get it down more but haven't figured it out.
Code:
PS1=$'\001\r'; PS1+='${|
	local e=$?
	[[ -o -x ]] && set +x && global -x XTR_DBG=1 || global -x XTR_DBG=0
...
...
...
 (( XTR_DBG )) && set -x
	return ${e}
} '
Last edited by 7175; 5th August 2014 at 07:48 AM.
5th August 2014, 09:14 AM   |  #12  
mirabilos's Avatar
Junior Member
Thanks Meter: 6
 
22 posts
Join Date:Joined: Dec 2010
Donate to Me
Angry
Quote:
Originally Posted by 7175

@mirabilos : Thanks for taking a look at this and providing us with mksh!

You’re welcome!

Quote:
Originally Posted by 7175

Not sure if that's what you wanted me to add in.

Ah, so you did not patch the mksh binary, only the mkshrc file?
But then, that’s okay as you wrote, sure.

Quote:
Originally Posted by 7175

I included an extra zip to download in the 2nd post that contains the official mkshrc 2014/01/11, my personal mkshrc, and a "diff -ur" patch (also attached to this post).

OK, thanks. Will have a look at it within the next weeks (August is going to be a busy month for me).
I’m assuming you are okay with me adding some of your changes back to main mksh?

Quote:
Originally Posted by 7175

I will look into getting a statically linked mksh compiled, that sounds like something really handy to keep around.

Indeed, it is.

The first mksh run on Android actually was statically compiled against µClibc, though that’s cheating. (Also, dietlibc and klibc are better than µClibc). I think it should work against Bionic, too.

Quote:
Originally Posted by 7175

edit: Here's basically what I added to the beginning and end of PS1 to trim down its "set -x" verbosity to 3 lines. I'd like to get it down more but haven't figured it out.

I don’t think it works in less, considering you have to save the previous $?. There are a few handy tricks around. I tried these four:

#1 is:

Code:
	local e=$?
	[[ -o -x ]]; local x=$?; set +x

	(( e )) && REPLY+="$e|"
[…]
	(( x )) || set -x
	return $e
This is about what you did. #2 is:

Code:
	local e=$? x=$([[ -o -x ]]; echo $?); set +x

	(( e )) && REPLY+="$e|"
[…]
	(( x )) || set -x
	return $e
This only looks different (I’d prefer #1 over this.) #3 is:

Code:
	set +x $? $([[ -o -x ]]; echo $?)

	(( $1 )) && REPLY+="$1|"
[…]
	(( $2 )) || set -x
	return $1
This reduces visual clutter. #4 is:

Code:
	set +x $? $([[ -o -x ]]; echo $?)

	(( $1 )) && REPLY+="$1|"
[…]
	(( $2 )) && return $1
	(( $1 )) && set -x && return $1
	set -x
This reduces visual clutter even more, in that, when $? is 0, one line less is shown. But it makes the number of lines shown be not always the same. YMMV on whether to use this, #3 or #1.

This could be made even nicer *iff* mksh had the EXIT trap when leaving a function. The manpage says it’s TODO. This part of the manpage is from 1999 or older. (I started mksh in late 2002, early 2003.) Go figure… But now I have a reason to add it ☺

Another thing you could do is “set +o inherit-xtrace”, which makes functions not run with “set -x” when the main body runs with it. But wait, I see now that it does not affect ${|…;} blocks. This is a bug, which I’ll fix ☻
Last edited by mirabilos; 5th August 2014 at 09:17 AM. Reason: more info
The Following User Says Thank You to mirabilos For This Useful Post: [ View ]
5th August 2014, 08:04 PM   |  #13  
E:V:A's Avatar
Recognized Developer
Flag -∇ϕ
Thanks Meter: 1,813
 
1,354 posts
Join Date:Joined: Dec 2011
@mirabilos:
Quote:

You Wrote:

Quote:

1. Would you have any clue to what's going on HERE?

You are annoying me. I've told you times and times again to disable SEAndroid, or to fix its SELinux policies.

Well, you can be as annoyed as you like. First of all, that question was not aimed at you, and second, as I have also said repeatedly, I have already tried using SELinux in Permissive mode and it doesn't work either. In addition, your suggestion to "fix its SELinux policies" is rather ridiculous as there are no tools available to do so. At least nothing out of the box and no available binaries anywhere, and surely no instructions how to do so. So if you know how to do it, why don't you just explain for us how to do so. (My policies are updated to latest according Androids policy update tools.)

In addition there is no such thing as "disable SEAndroid". It's either in Permissive or Enforced mode. That is, unless you flash a new custom FW, which is out of the question. In addition, ATE works just fine, in Enforcing mode.

So believe me, I am far more annoyed by Googles lack of SELinux/SEAndroid developer support, than you will ever be from me asking these questions.

Thanks for explaining and helping with everything else above.

@7175:
Quote:

The ulimit shell function can control all sorts of performance related stuff, priority, max niceness, etc. You can see all values with "ulimit -a".

Yes, I know about all those things, but I was asking why you think they need to be tweaked? The defaults, seem to work just fine.
Last edited by E:V:A; 7th August 2014 at 11:25 PM.
18th August 2014, 06:35 AM   |  #14  
7175's Avatar
OP Senior Member
Thanks Meter: 330
 
254 posts
Join Date:Joined: Feb 2013
More
@mirabilos : Thank you for your detailed replies, and I would be more than happy to contribute if you see anything from the content I posted.

It is interesting to see the other possibilities for turning off xtrace within the PS1. I didn't even realize you could set positional parameters after the set -x... I think I like that one the most. It just seems more array-like and streamlined, although I guess the same number of variables is still used. I look forward to seeing what updates you'll have on the exit trap and localization. This is something I'd like to toy around with.

I took your advice and set out to get a mksh static built. I ended up compiling with GCC, running "LDSTATIC=-static ./Build.sh" in the mksh source directory. I'm pretty new to cross compiling, so I didn't really get that far or try that hard before chrooting to a fresh Ubuntu terminal on my Nexus, installing GCC, and compiling there. The only thing I changed in the source code was ${ENV:-~/.mkshrc} to ${ENV:-/system/etc/mkshrc} in the "main.c" source file. I can include this in the OP though as you mentioned before. (edit: just saw this as a compiler option with Build.sh)

Edit: I see the option now in the Build.sh for changing the mkshrc path. Also, got R50 rebuilt static with klibc. Damn that got the size way down from using glibc, 684K to 204K.
Last edited by 7175; 24th August 2014 at 05:54 AM.
Post Reply Subscribe to Thread

Tags
busybox, grep, ksh, mksh, shell
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Top Threads in Android Software and Hacking General [Developers Only] by ThreadRank