Post Reply Subscribe to Thread Email Thread

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

5th August 2014, 07:45 AM |#11  
7175's Avatar
OP Senior Member
Thanks Meter: 441
 
309 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.
The Following User Says Thank You to 7175 For This Useful Post: [ View ]
5th August 2014, 09:14 AM |#12  
mirabilos's Avatar
Junior Member
Thanks Meter: 8
 
25 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 2 Users Say 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,961
 
1,401 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.
The Following User Says Thank You to E:V:A For This Useful Post: [ View ]
18th August 2014, 06:35 AM |#14  
7175's Avatar
OP Senior Member
Thanks Meter: 441
 
309 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.
The Following User Says Thank You to 7175 For This Useful Post: [ View ]
15th March 2015, 08:54 PM |#15  
alanthehat's Avatar
Junior Member
Thanks Meter: 6
 
24 posts
Join Date:Joined: Jan 2013
More
Info 2 R50e is released
R50e is released -- see https://www.mirbsd.org/mksh.htm#clog
The Following User Says Thank You to alanthehat For This Useful Post: [ View ]
17th March 2015, 10:53 PM |#16  
Reinkaos's Avatar
Senior Member
Thanks Meter: 195
 
268 posts
Join Date:Joined: Jan 2014
More
Hi @7175, good stuffs here man
I've been using your modded mkshrc, and I can see a hell of a lot of work you put into it. Looks really cool. Plus it's really a good place to learn for someone like me, I definitely had learnt a lot for the past few days. Tons of aliases too, and I'm getting used to using it now. I really appreciate your stuffs here, hope to see more of it
The Following User Says Thank You to Reinkaos For This Useful Post: [ View ]
18th March 2015, 07:22 PM |#17  
7175's Avatar
OP Senior Member
Thanks Meter: 441
 
309 posts
Join Date:Joined: Feb 2013
More
Quote:
Originally Posted by alanthehat

R50e is released -- see https://www.mirbsd.org/mksh.htm#clog

Thanks for the heads up. Updated the binaries posted in the 2nd OP to mksh R50e.

Quote:
Originally Posted by Reinkaos

Hi @7175, good stuffs here man
I've been using your modded mkshrc, and I can see a hell of a lot of work you put into it. Looks really cool. Plus it's really a good place to learn for someone like me, I definitely had learnt a lot for the past few days. Tons of aliases too, and I'm getting used to using it now. I really appreciate your stuffs here, hope to see more of it

Thanks for the feedback man! Glad it's been a good learning experience like it has been for me.
The Following 2 Users Say Thank You to 7175 For This Useful Post: [ View ]
18th March 2015, 09:32 PM |#18  
Reinkaos's Avatar
Senior Member
Thanks Meter: 195
 
268 posts
Join Date:Joined: Jan 2014
More
Quote:
Originally Posted by 7175

Thanks for the feedback man! Glad it's been a good learning experience like it has been for me.

Well, thanks for the updated binary! Anyway, anything you can recommend me to read other than the man page in OP? And I have one more question, what's the difference between the busybox (I got one from your other thread) and yours busybox.ndk?
18th March 2015, 09:40 PM |#19  
mirabilos's Avatar
Junior Member
Thanks Meter: 8
 
25 posts
Join Date:Joined: Dec 2010
Donate to Me
While I’m the upstream developer of mksh, hacking it has also been a good learning experience for me.

So it is for a friend of mine, who has taken some fundamental script frameworks I wrote, and extended it to an impressive management system, learning to code good shell while doing so.

I’m always happy when my stuff helps other people, and they share their joy! ☺

By the way: new mksh release announcements are sent over the miros-mksh mailing list (send an eMail to postmaster at mirbsd dot either org or de to subscribe).

---------- Post added at 08:40 PM ---------- Previous post was at 08:34 PM ----------

Well, we have https://www.mirbsd.org/ksh-chan.htm which collects lots of Korn Shell-related resources, although most of it is for AT&T ksh93 (the “original” Korn Shell), much also applies to mksh, though the Android OS has some special handling (especially caused by the different user-space tooling) obviously.

The shell itself behaves exactly the same across *all* supported platforms though, so (once you have set $TMPDIR to something writable for your current user) you can write Pure mksh code exactly like on Unix or Cygwin or the Macintosh or even Haiku.
The Following User Says Thank You to mirabilos For This Useful Post: [ View ]
18th March 2015, 11:01 PM |#20  
Reinkaos's Avatar
Senior Member
Thanks Meter: 195
 
268 posts
Join Date:Joined: Jan 2014
More
Quote:
Originally Posted by mirabilos

While I’m the upstream developer of mksh, hacking it has also been a good learning experience for me.

So it is for a friend of mine, who has taken some fundamental script frameworks I wrote, and extended it to an impressive management system, learning to code good shell while doing so.

I’m always happy when my stuff helps other people, and they share their joy!

By the way: new mksh release announcements are sent over the miros-mksh mailing list (send an eMail to postmaster at mirbsd dot either org or de to subscribe).

---------- Post added at 08:40 PM ---------- Previous post was at 08:34 PM ----------

Well, we have https://www.mirbsd.org/ksh-chan.htm which collects lots of Korn Shell-related resources, although most of it is for AT&T ksh93 (the “original” Korn Shell), much also applies to mksh, though the Android OS has some special handling (especially caused by the different user-space tooling) obviously.

The shell itself behaves exactly the same across *all* supported platforms though, so (once you have set $TMPDIR to something writable for your current user) you can write Pure mksh code exactly like on Unix or Cygwin or the Macintosh or even Haiku.

Thanks for the link, and for your works on mksh too! I'm really new to shell, I'm not even that familiar with unix/linux either. But I always have been interested in shell scripting, so I'm glad that I stumbled upon this thread
Whew, that's a lot of stuff in that link you gave, definitely gonna make use of it, thanks again!

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