[Q] Read commands' output inside su process - Android Q&A, Help & Troubleshooting

Hello, maybe here someone will help me
I'm writing a file manager app and I want to allow it for browsing with root permissions.
All I have so far is creation of a Process object using Runtime.exec("su"). Then I get output stream from it and write "ls" command. And here goes the question. How to read the output of the "ls"? Getting the input stream from the process gives me stdout of the "su" which is useless.

glodos said:
Hello, maybe here someone will help me
I'm writing a file manager app and I want to allow it for browsing with root permissions.
All I have so far is creation of a Process object using Runtime.exec("su"). Then I get output stream from it and write "ls" command. And here goes the question. How to read the output of the "ls"? Getting the input stream from the process gives me stdout of the "su" which is useless.
Click to expand...
Click to collapse
Use the -c option of su:
Code:
su -c 'ls -l /system/'

I think I'm closer, but still it doesn't work
I have this:
Code:
p = Runtime.getRuntime().exec("/system/bin/su -c 'ls -d -1 "+directory.getAbsolutePath()+"/*'");
So the command for a directory /data will be:
Code:
/system/bin/su -c 'ls -d -1 /data/*'
But it gives me:
Code:
W/su (13979): request rejected (0->0 'ls)
I have tried putting the command's parts into array but then system asks for su permission on every command. For ex. ls /data needs permission and ls /system needs another permission beacuse the command is different.

Not much I can think of to do about that. I had a similar issue once upon a time and I dealt with it by using a script that read its commands from a data file. I'd write the datafile to my program's designated directory (no special permissions required), then run a single command with su and that script would read the datafile to know what to do, otherwise, I had a ****load of su requests bothering the user.

You've got a point there, but making it work with a file manager, where the commands are related to user interaction would be very difficult. Anyway I will put it into my consideration.
I wonder how all these root explorers are made but none of the developers, which I asked so far, were so kind to give me some tips

glodos said:
You've got a point there, but making it work with a file manager, where the commands are related to user interaction would be very difficult. Anyway I will put it into my consideration.
I wonder how all these root explorers are made but none of the developers, which I asked so far, were so kind to give me some tips
Click to expand...
Click to collapse
Well, I suppose you could keep a process open to a shell with root permissions and once open, keep input and output pipes routed to it and send and receive commands as needed.

Gene Poole said:
Well, I suppose you could keep a process open to a shell with root permissions and once open, keep input and output pipes routed to it and send and receive commands as needed.
Click to expand...
Click to collapse
Well, that's what I've tried to do, but as I mentioned in the first post, output pipe gives me stdout of the su process which doesn't write any output (but "ls" does).

glodos said:
Well, that's what I've tried to do, but as I mentioned in the first post, output pipe gives me stdout of the su process which doesn't write any output (but "ls" does).
Click to expand...
Click to collapse
No, I don't think you're following me. Just run su -c 'sh' and it should run a shell and keep it open. From there, you create an input stream, output stream and possibly an error stream, then write commands like "ls -l /system\n" (the \n triggers the shell to execute it) to the output stream, then read the results form the input stream. You keep doing this as needed and when you're done just send "exit\n".

Oh, I understand now. I'll try it ASAP.
Edit:
It works now, but I have problems with stopping the loop. Here is my piece of code:
Code:
String[] cmd = new String[]{"su", "-c", "/system/bin/sh"};
console = Runtime.getRuntime().exec(cmd);
BufferedWriter stdin = new BufferedWriter(new OutputStreamWriter(console.getOutputStream()));
stdin.write("ls -d -1 "+directory.getAbsolutePath()+"/*\n");
BufferedReader stdout = new BufferedReader(new InputStreamReader(console.getInputStream()));
String read;
data1 = new String();
while((read=stdout.readLine())!=null){
data1+=read + "\n";
}
The problem is, that it hangs at some point on invocation of "stdout.readLine()". I have read that it waits for some data to come and it will never be null.
Furthermore if my ls command returns nothing (which can happen) it always hangs forever on readLine().
Anyway I'll try to do something with this. Maybe there is a workaround and reading will not block.
Thank you for your effort, it was really helpful.

glodos said:
The problem is, that it hangs at some point on invocation of "stdout.readLine()". I have read that it waits for some data to come and it will never be null.
Furthermore if my ls command returns nothing (which can happen) it always hangs forever on readLine().
Anyway I'll try to do something with this. Maybe there is a workaround and reading will not block.
Thank you for your effort, it was really helpful.
Click to expand...
Click to collapse
Sorry to ressurect such an old thread. I'd been having the same problem with reads blocking using BufferedReader, InputStream and other variants. Turns out BufferedReader has a ready() method which indicates whether a read() will block. This code works for me:
Code:
String outputStr;
BufferedReader reader = new BufferedReader(new InputStreamReader(suProcess.getInputStream()));
while (reader.ready()) {
outputStr += reader.readLine();
}
Hope it helps someone from the repeating the same frustrations. Heck I hope it helps me in the future in case I forget this

Related

[GUIDE] Basic Unix/Linux command to use with ADB SHELL

So I have been reading quite a few threads here on XDA, and the one thing I noticed for noobs to linux/unix world is that they are struggling with some basic command once adb shell is gained. I decided to whip out this quick tutorial to help those noobs out to become more of an expert...like me...lol j/k
Here we go:
Prerequisites:
You must know how to invoke a adb shell command already to drop into your phone.
ALL commands in Unix/Linux are case sensitive
For more details, go to this ADB tutorial (very good one): http://forum.xda-developers.com/showthread.php?t=517874
Let's get going:
Once a shell is gained via adb, let's look at some of the basic commands you can do to navigate around the filesystem. Note: you must remove the double-quotes (") for the actual command.
Code:
"cd" = is change directory
to change to any directory, you type: cd dir_name (where dir_name is a full path)
Example: I want to go to /data/local/tmp in my phone, I would do
cd /data/local/tmp <hit ENTER>
You can also use the ".." to go UP one directory.
Example: I'm in /data/local/tmp and I want to go up to /data folder, a command would be: cd ../.. alternatively, if I do cd .. then i'll drop into /data/local folder instead.
Code:
"ls" = list files/directories
to list files/directories within a folder, the command should be:
ls <hit enter> => this will list all NON-HIDDEN file/directories within your CURRENT directory.
ls /data/local/tmp => this will list all NON-HIDDEN file/directories within /data/local/tmp directory.
ls -l => this will list all NON-HIDDEN file/directories within your CURRENT directory, plus additional details. Consider this is like a "Details" view in Windows Explorer.
ls -a => this will list all files/directories (including hidden files) within your CURRENT directory.
ls -la => this will list all files/directories (including hidden files) within your CURRENT directory, plus details.
Code:
"chmod" = change mode
Goes to wikipedia for more details: https://secure.wikimedia.org/wikipedia/en/wiki/Chmod
Most commonly used modes on android phones are:
"755" or "777".
So if you have a root.sh shell script that you downloaded from XDA, and uploaded to your phone and try to execute it with ./root.sh and it said "Permission denied". That means your script does not have the execute permission. You need to do:
chmod 755 root.sh <hit enter>
[B]IMPORTANT: There is *NO* negative sign (-) in front of the mode bit. So it is NOT chmod -755 root.sh[/B]
If you get a "File or directory not found" error, which means you are chmod-ing a file that doesn't exist in your current directory. To execute a chmod on root.sh in /data/local/tmp you do:
chmod 755 /data/local/tmp/root.sh
If you want to chmod an ENTIRE DIRECTORY and ALL files underneath it you do:
chmod -R 755 /data/local/tmp => this will set /data/local/tmp and ALL files/folders underneath it to be 755.
Code:
"chown" = change ownership
Go to wikipedia for details: https://secure.wikimedia.org/wikipedia/en/wiki/Chown
Most common used chown for android is: "root:root" or "root:shell"
Example: if you want to change ownership of root.sh to root:shell then you do:
chown root:shell root.sh
NOTE: the -R (recursive) option is also available for chown.
chown -R root:shell /data/local/tmp
Code:
"pwd" = print working directory
so when you are within a directory and you want to know which directory you are in, then you issue the command:
pwd <hit enter>
The system will reply back with the currently directory you are in.
I'll try to add more if I think of anything else useful, or if you have suggestions, please feel free to add.
so what does it mean to add adb to your path? thats holding me back from temp rooting on my mac. Im a total adb noob clearly.
hockey4life0099 said:
so what does it mean to add adb to your path? thats holding me back from temp rooting on my mac. Im a total adb noob clearly.
Click to expand...
Click to collapse
The easiest way to explain it is that you can run ADB from anywhere...do a search and you can find a more detailed (and more proper) explanation and directions on how to set it up.
hockey4life0099 said:
so what does it mean to add adb to your path? thats holding me back from temp rooting on my mac. Im a total adb noob clearly.
Click to expand...
Click to collapse
What OS are you using?
vboyz103 said:
What OS are you using?
Click to expand...
Click to collapse
mac
______________
hockey4life0099 said:
mac
______________
Click to expand...
Click to collapse
Like I said, do a search on XDA...there's a great guide on how to set up ADB properly. I'll link to it tomorrow when I get on the computer.
-- Sent from my 3VO Shooter --
hockey4life0099 said:
mac
______________
Click to expand...
Click to collapse
If you use mac, open a Terminal, and you should be at your home directory and type:
nano ~/.profile
if the .profile doesn't exist yet, then you'll see an empty.
Put this into the file
PATH=$PATH:/path/to/your/android/platform-tools
export PATH
save and exit out of Nano, and type:
source ~/.profile
then after this type adb and if adb is in your PATH then you see adb help.
Overview Of Permissions via ADB SHELL
Example = drwxrwxrwx
To Check Permission at anytime in ADB just Type:
ls -l
The First character defines the Directory, Link, Binary.
Below are some examples
Example = d---------
d = Directory
l = Link
b = Binary
The next 9 characters define the file permissions. These permissions are
given in groups of 3 each.
The first 3 characters are the permissions for the owner of the file or directory.
Example = -rwx------
The next 3 are permissions for the group that the file is owned by.
Example = ----rwx---
The final 3 characters define the access permissions for everyone not part of the group.
Example = -------rwx
There are 3 possible attributes that make up file access permissions.
r - Read permission. Whether the file may be read. In the case of a
directory, this would mean the ability to list the contents of the
directory.
w - Write permission. Whether the file may be written to or modified. For
a directory, this defines whether you can make any changes to the contents
of the directory. If write permission is not set then you will not be able
to delete, rename or create a file.
x - Execute permission. Whether the file may be executed. In the case of a
directory, this attribute decides whether you have permission to enter,
run a search through that directory or execute some program from that
directory
In addition to the file permission, you can also modify the owner and
group of the file. The chown program is used here and its syntax is very
simple. You need to be the owner of a file or root to do this.
Understanding Owner Permissions:
The first command is for owner ID, the Second Command is for Group ID.
exp. root.root ( First Root is owner, Second Root is Group ).
Chmod 644 some file, Like Build.prop For testing & then Veiw the Resulted Changes!
Refer to the table below as a quick reference.
Command Line for Both would look like this
chmod 644 build.prop = -rw-r--r--
\/
Chmod Guide
0 - ---
1 - --x
2 - -w-
3 - -wx
4 - r--
5 - r-x
6 - rw-
7 - rwx
SH Chown Guide
\/
chown root.root build.prop
root.root = Root
root.shell = Shell
Busybox SH Chown Guide
\/
chown 0.0 build.prop
0.0 = Root
0.2000 = Shell
I'll update the chmod with more with More Complex Commands Later
Side Note:Always set owner ( chown ) before Setting Permissions ( Chmod )!
Hope this Clears up things & is Helpful to everyone
~Eugene373​
Add adb to your path in Windows.
As has been explained above all it does is allowing your adb to be called out from any location.
To set it in windows you will need to add path to your adb.exe file to your PATH in widows XP or CLASSPATH in windows7.
You can find it in start->contro panel->system->advanced.
There is a tab called "Inviromental Variables".
Click on that tab and new window will pop up. New window has 2 field in it. We are interested in bottom field called "System variables".
Windows XP user should look for line with variable "Path".
Click that line and choose edit below. New pop up will apear and you can edit path line in there. You should add path to your adb.exe to that line.
Example.
I did install windows sdk in c:\android\android-sdx-windows so my adb.exe file is in that folder. I did add path to that folder in "Paht" line of system variables. Add path to your adb.exe after semicolon.
;c:\Location\of folder\where you have\adb exe file\
Save changes, apply them. Now you can use call for adb commands from any location.
Widows 7 users.
Same changed need to be appied as for Windows XP.
There is only one difference that that path in Inviromental variables in windows7 is called "CLASSPATH".
Rest is same. Just add the path to folder containing your adb.exe file to CLASSPATH line and you would be able to use adb in any location.
Hope this make sense and will help.
My mac keeps sayin no device but I can access adb from anywhere basically its in my path but won't pick up my phone
Sent from my PG86100 using XDA Premium App
snoopy1e11 said:
My mac keeps sayin no device but I can access adb from anywhere basically its in my path but won't pick up my phone
Sent from my PG86100 using XDA Premium App
Click to expand...
Click to collapse
Make sure your phone is in debugging mode.
ADB won't see phone if debugging is not enabled.
It is on
Sent from my PG86100 using XDA Premium App
I'm a windows user.
Can't think of anything else.
Sorry.
agat63 said:
Make sure your phone is in debugging mode.
ADB won't see phone if debugging is not enabled.
Click to expand...
Click to collapse
If you have USB debugging turned on, you should see a triangle with exclamation mark on task bar. Secondly, try to do this:
adb kill-server => kill off current server first
then
sudo adb devices => u need to enter password
Basically, you are running adb with escalated privilege, sometimes it needs root access.
This is Wat I got
Sent from my PG86100 using XDA Premium App
snoopy1e11 said:
This is Wat I got
Sent from my PG86100 using XDA Premium App
Click to expand...
Click to collapse
hmmm interesting...just wondering if you have your device turned on to be disk usage instead of just Charge Only?
Check on your desktop to see if you SD card had mounted, not sure if it makes a difference but worth a try. Another thought is that maybe your USB port doesn't work?? Did you check your phone to see if you have a triangle with exclamation mark in it on the task bar? (to the left)
Also, try it on a different computer if u can, and if it still doesn't work, afraid urs is defective.
I really appreciate ur help I re did the sudo command and hit "adb devices connect" and my device popped up
Sent from my PG86100 using XDA Premium App
snoopy1e11 said:
I really appreciate ur help I re did the sudo command and hit "adb devices connect" and my device popped up
Sent from my PG86100 using XDA Premium App
Click to expand...
Click to collapse
Ha, interesting cuz I never have to issue that command. Good to know you got it to work.

[howto]make hostnames work on busybox

Rooted PDAs only! Shell required!
Before doing the following steps, verify that you don't have an "/etc/resolv.conf"! I reckon none of the stock ROMs have one, but this tweak doesn't work with such a file in place.
Code:
ls -l /etc/resolv.conf || echo "ok"
If this prints some file details and you can use eg. "ping -c 3 www.google.com", you don't have the problem in the first place.
If it says "no such file..." and "ok", go ahead.
Make a file named "/mnt/sdcard/resolv.conf" containing, for example:
Code:
nameserver 8.8.8.8
nameserver 8.8.4.4
These are the IP numbers of the Google public DNS resolvers, BTW, but you can use any others.
Code:
mount -o remount,rw /system &&
ln -s /mnt/sdcard/resolv.conf /etc/
mount -o remount,ro /system
The problem: busybox and other C-programs use a library component called the "stub-resolver" to make IP-adresses from hostnames. This isn't capable of resolving by itself, so it parses "/etc/resolv.conf". The "nameserver" lines in there tell it where to send the UDP packets with questions like "what's the IP of Gmail.com?".
Java programs do this differently: they use "getprop" for the IPs of the nameservers, and vendor customized "dhcpcd" scripts populate the needed properties.
C-programs need the etc/resolv.conf for proper operation.
Q: what does this do for me?
A: first, it'll make symbolic hostnames work for C-programs like "wget", "ping", "nslookup" etc. As added benefit, you can see the names requested by Android programs if you give the IPs of some DNS-resolver you might have in a home LAN. Look at its logs!
Q: what are these '&&' combinations for?
A: well, we don't get to see them often, not even in developer scripts, but they are very useful! They logically "AND" commands. If the command or program before an '&&' fails, none of the following ones will get executed. So if the first "mount" doesn't work (a typo or whatever), the symbolic link by the "ln -s ..." won't be attempted at all, meaning less errors. POSIX requires compliant shells to do this type of short-circuit evaluation, so we can rely on it.
Q: why use a symlink ("ln -s ...") instead of a file?
A: This way you can change nameservers without remounting /system, in fact, you don't even need to be root for this. Change /sdcard/resolv.conf and you're set.
Q: which nameservers should I use?
A: with a patch to "/system/etc/dhcpcd/dhcpcd-hooks/20-dns.conf" it's possible to use the ones from your ISP provided DHCP lease. I thought a onetime manual configuration would do for the moment. You could search the web for the OpenDNS resolvers as an alternative, or use your providers resolvers (eg. from the APN config).
Although I already had resolv.conf added, your explanation for why it is needed was very informative!!! Thanks.
ino-xda said:
Make a file named "/mnt/sdcard/resolv.conf" containing, for example: ...
Click to expand...
Click to collapse
Q: will this work in etc/init.d/ scripts?
A: that depends on when they run. The symbolic link points to a file on the sdcard, thus it will work no sooner than the sdcard has been mounted, but before scanning for media files, icons etc. has finished. Once the device is fully up and running, it should work reliably.

File copy and replacing in /system directory with root permission programmatically?

Can anyone kind enough show me how to copy files from my app assets folder to /system folder? I know how to get root access and all. For example: I want to copy file from "/assets/lib/libs.so" and check if this file already exist, if it does replace it to new "/system/lib/libs.so".
I think You could create a script (its language should not be too difficult) and make it start on every boot (every scripter Can do this) But I don't know how much time it would take and if You reboot often... Try to look for an app that runs script programmatically
Sent from R'lyeh using Cthulhu app
tsirhcitna said:
I think You could create a script (its language should not be too difficult) and make it start on every boot (every scripter Can do this) But I don't know how much time it would take and if You reboot often... Try to look for an app that runs script programmatically
Sent from R'lyeh using Cthulhu app
Click to expand...
Click to collapse
Sorry I haven't been clearly state that I want to write an app that does this, like in java.
Ooops my fault! I know java for PC but I never studied it for Android (when I tried to program for android the emulator taking twenty minutes to start stopped me). I don't know how to help you but seeing nobody is answering I can suggest you to go on Stack Overflow, it's all about coding, and all the answer I've seen on it where very good (You can also look for file manipulation on some android java tutorial)
Sorry I can't help you more
tsirhcitna said:
Ooops my fault! I know java for PC but I never studied it for Android (when I tried to program for android the emulator taking twenty minutes to start stopped me). I don't know how to help you but seeing nobody is answering I can suggest you to go on Stack Overflow, it's all about coding, and all the answer I've seen on it where very good (You can also look for file manipulation on some android java tutorial)
Sorry I can't help you more
Click to expand...
Click to collapse
can u write java code that wrap around command line that copy file to system folder? this will work, cos i can get su, just need to mount rw /system/lib then copy file from my app assets folder and replace the file in /system/lib
homi3kh said:
Can anyone kind enough show me how to copy files from my app assets folder to /system folder? I know how to get root access and all. For example: I want to copy file from "/assets/lib/libs.so" and check if this file already exist, if it does replace it to new "/system/lib/libs.so".
Click to expand...
Click to collapse
I suppose you're getting Root Permission running su command with Runtime.getRuntime().exec... right?
That's fine, you now need to run another commands:
To check if /assets/lib/libs.so (or any other file) exists:
Code:
ls /assets/lib | grep libs.so
If the file exists, you'll get "libs.so" as output of that command (otherwise, you will not get anything).
To remount /system in RW mode:
Code:
mount -o rw, remount -t yaffs2 /dev/block/mtdblock4 /system
Ok, now you can copy your file (or files, I dunno):
Code:
cp /assets/lib/libs.so /system/lib/libs.so
And finally, remount /system in RO mode again:
Code:
mount -o ro, remount -t yaffs2 /dev/block/mtdblock4 /system
Pretty easy, it isn't? :highfive:
Note: I highly recommend you to use RootTools, it's a lib to run commands as root very easily
RoberGalarga said:
I suppose you're getting Root Permission running su command with Runtime.getRuntime().exec... right?
That's fine, you now need to run another commands:
To check if /assets/lib/libs.so (or any other file) exists:
Code:
ls /assets/lib | grep libs.so
If the file exists, you'll get "libs.so" as output of that command (otherwise, you will not get anything).
To remount /system in RW mode:
Code:
mount -o rw, remount -t yaffs2 /dev/block/mtdblock4 /system
Ok, now you can copy your file (or files, I dunno):
Code:
cp /assets/lib/libs.so /system/lib/libs.so
And finally, remount /system in RO mode again:
Code:
mount -o ro, remount -t yaffs2 /dev/block/mtdblock4 /system
Pretty easy, it isn't? :highfive:
Note: I highly recommend you to use RootTools, it's a lib to run commands as root very easily
Click to expand...
Click to collapse
yes this is what i'm asking for but can you wrap it with RootTools code for me too? it's a bit confusing cos I don't know much about command line.
Ok. It's kinda easy, BTW:
To grant root permissions (If you already have root permissions in other way, you don't need to do this again):
Code:
if (RootTools.isAccessGiven()) {
// your device is rooted!! The fun can begin :)
}else{
// Not rooted... no fun here :(
}
Now, an example using 1 command (you'll need to develop the rest). Checking if /assets/lib/libs.so exists:
Code:
try {
List<String> output = RootTools.sendShell("ls /assets/lib | grep libs.so",-1);
if (output.get(0).equals("libs.so")){ //output.get(0) is the way to read 1 line of the command output
//the file exist... you can continue
}else{
//something is wrong, or the file is missing... =/
}
} catch (Exception e) {
// something went wrong, deal with it here
}
Proceed in the same way to run the other commands. Note that there are ways to run several commands using RootTools, you can check them in the Usage Page (I think will be a bit easy, since you don't need to read the output of the other commands).

[q]reboot tasker

Hi!
I want to stop and start tasker by itself via a bashscript since I see no other way to do so. This works if you put in terminal line by line:
Code:
am force-stop net.dinglisch.android.taskerm
am start -a android.intent.action.MAIN -n net.dinglisch.android.taskerm/net.dinglisch.android.taskerm.Tasker
killall net.dinglisch.android.taskerm
But now I'm stock
My guess was that it would have to work if i put in a file "kst.sh" and run
Code:
sh ./kst.sh
as root. But it doesn't work and it seems to ignore the linebreaks in the file.
So here I am, knowing the commands and need to run them with one call. How do I do that?
Many thanks!!
C0qRouge said:
... it seems to ignore the linebreaks in the file...
Click to expand...
Click to collapse
That error is caused by the windows linebreaks, you need to use any word editor that let you change the linebreak style to Unix (Notepad++ is a popular choice), or write your script from your device directly (any editor for android should work).

[Q] Trouble with CM10's su and Android Terminal Emulator

I am having a hard time getting certain interactive features of any shell to work with Android Terminal Emulator as soon i acquire superuser privileges by issuing the "su" command. I am no longer able to cycle through the command history which is otherwise done by pressing the volume down key (provided you have the vol. down key bound to the Ctrl key via Terminal Emulator's settings) and then the p key. It will simply display the "^P" control sequence instead of displaying the last entered command. It only becomes an issue once the su command is entered. Does anyone know of any possible workarounds?
bsimpson1 said:
I am having a hard time getting certain interactive features of any shell to work with Android Terminal Emulator as soon i acquire superuser privileges by issuing the "su" command. I am no longer able to cycle through the command history which is otherwise done by pressing the volume down key (provided you have the vol. down key bound to the Ctrl key via Terminal Emulator's settings) and then the p key. It will simply display the "^P" control sequence instead of displaying the last entered command. It only becomes an issue once the su command is entered. Does anyone know of any possible workarounds?
Click to expand...
Click to collapse
Quick answer: install Chainfire's SuperSU and don't look back
Just saw this post searching for some terminal stuff and had to reply cause this was driving me crazy trying to figure it out / fix it. The issue is with the CWM su binary. I never could exactly figure out the exact problem, and I wasn't willing to grep through its source code. I know that the permissions weren't (still might not be) configured correctly at installation. /system/xbin/su should be -srwx 06755 and Owner:Group 0:0 aka root:root at installation but the -s--- 06000 sticky-bit should not persist after installation and remounting /system, i.e., /system/xbin/su should be -rwx 0755 in the AOS. CWM's su has been re-chmod'ing the user-specific sticky-bit when I try changing it.. I'm pretty sure this is at least part of the problem with console/shell/terminal output not being (re)directed correctly with CWM-su executed processes.
Another thing to mention is the "security context" (SELinux additional file permissions) which labels the file with an "object" and "role" among other things. I know that it's set correctly during installation with SuperSU, but I didn't see a command for it in the installation zip's script for CWM-su NOV-17-beta. I'm never really sure what's going on with CWM's giant su binary these days lol This is a pretty important permission setting not to forget, especially if you're running enforced SELinux which is Android 4.4's SELinux' default security. Note: SELinux denies unconfigured files by default, and otherwise configured only allows minimum access to function when called. It then makes sense that if su doesn't have the correct security context, then it's children, shell executions might not either.
So I'm pretty sure the shortcuts (ctrl + c,x,z; esc + ...) stopped functioning correctly as a results of one or both of these issues. I checked almost all the suspects like libncurses.so (cursor library), libjackpal*[2-4].so (term library for execution of scripts), other terminals (same results in: better terminal emulator, connectbot, connectbot VX, Script Manager, JuiceSSH, Server Auditor, and a fresh Terminal IDE installation - could just take over the system with this beast if I had time). The ONLY place CWM su'd cursor works is recovery, flashing AromaFM. There's no SELinux here in this bootstrapped utopia of simplicity.
Chainfire's SuperSU recovery-installation-zip does all of the above mentioned correctly, so the cursor works everywhere(includes su binary and Superuser, and it yields complete removal of CWM's superuser files), the security context that's set to su, deamonsu, *all files that are added or modified* during installation is ubject_r:system_file:s0 via
Code:
chcon u:object_r:system_file:s0 file
. Also you can check SELinux security context with id -Z or maybe ls -Z, depends on those binaries and whether called by busybox, etc..
edit: CWM's su actually isn't used in TWRP; a supersu package is used
7175 said:
Quick answer: install Chainfire's SuperSU and don't look back
Just saw this post searching for some terminal stuff and had to reply cause this was driving me crazy trying to figure it out / fix it. The issue is with the CWM su binary. I never could exactly figure out the exact problem, and I wasn't willing to grep through its source code. I know that the permissions weren't (still might not be) configured correctly at installation. /system/xbin/su should be -srwx 06755 and Owner:Group 0:0 aka root:root at installation but the -s--- 06000 sticky-bit should not persist after installation and remounting /system, i.e., /system/xbin/su should be -rwx 0755 in the AOS. CWM's su has been re-chmod'ing the user-specific sticky-bit when I try changing it.. I'm pretty sure this is at least part of the problem with console/shell/terminal output not being (re)directed correctly with CWM-su executed processes.
Another thing to mention is the "security context" (SELinux additional file permissions) which labels the file with an "object" and "role" among other things. I know that it's set correctly during installation with SuperSU, but I didn't see a command for it in the installation zip's script for CWM-su NOV-17-beta. I'm never really sure what's going on with CWM's giant su binary these days lol This is a pretty important permission setting not to forget, especially if you're running enforced SELinux which is Android 4.4's SELinux' default security. Note: SELinux denies unconfigured files by default, and otherwise configured only allows minimum access to function when called. It then makes sense that if su doesn't have the correct security context, then it's children, shell executions might not either.
So I'm pretty sure the shortcuts (ctrl + c,x,z; esc + ...) stopped functioning correctly as a results of one or both of these issues. I checked almost all the suspects like libncurses.so (cursor library), libjackpal*[2-4].so (term library for execution of scripts), other terminals (same results in: better terminal emulator, connectbot, connectbot VX, Script Manager, JuiceSSH, Server Auditor, and a fresh Terminal IDE installation - could just take over the system with this beast if I had time). The ONLY place CWM su'd cursor works is recovery, flashing AromaFM. There's no SELinux here in this bootstrapped utopia of simplicity.
Chainfire's SuperSU recovery-installation-zip does all of the above mentioned correctly, so the cursor works everywhere(includes su binary and Superuser, and it yields complete removal of CWM's superuser files), the security context that's set to su, deamonsu, *all files that are added or modified* during installation is ubject_r:system_file:s0 via
Code:
chcon u:object_r:system_file:s0 file
. Also you can check SELinux security context with id -Z or maybe ls -Z, depends on those binaries and whether called by busybox, etc..
Click to expand...
Click to collapse
Thanks for such a detailed reply. It's nice to know that the problem wasn't on my end. I can finally stop desperately editing my bashrc file, adding all sorts of obscure environment variables and crossing my fingers.
bsimpson1 said:
Thanks for such a detailed reply. It's nice to know that the problem wasn't on my end. I can finally stop desperately editing my bashrc file, adding all sorts of obscure environment variables and crossing my fingers.
Click to expand...
Click to collapse
Man I'm right there with you. lol yeah my 1MB of cursor-fix bashrc and mksh edits are now resting in peace, blasted that tar.gz coffin out to space with my "working-key-signal" su'd ssh terminal the other day like Spock in The Wrath of Khan, oh yeah. I'm glad to know I wasn't the only person who cared about this so much.

Categories

Resources