Closed Bug 916809 Opened 11 years ago Closed 11 years ago

"su" does not work as expected in recent builds

Categories

(Firefox OS Graveyard :: General, defect)

x86_64
Linux
defect
Not set
normal

Tracking

(Not tracked)

RESOLVED INVALID

People

(Reporter: wlach, Unassigned)

References

Details

Some automation we have is shared between Android and FirefoxOS. On Android, sometimes we need to run certain shell commands as root, otherwise they will fail due to insufficient permissions.

It seems like on FirefoxOS the "su" utility does not do shell escaping as expected. e.g. if I do:

su -c 'dd if=/mnt/sdcard/foo of=/data/local/bar'

It'll say:

su: exec failed for dd if=/mnt/sdcard/foo of=/data/local/bar Error:No such file or directory

If I just copy "sh" over "su" (maintaining the privilege bits), things will then work as I expect. I'm not sure what kind of busted version of "su" is now included with FirefoxOS, but could we revert to using the old one (and/or just copying sh over su at some point)?
I'm going to needinfo :mwu on this. I'm not sure if he's the right person to ask about this, but if not I wager he knows who. :)
Flags: needinfo?(mwu)
Does adb root work for you? Any engineering build will give you root by default, and userdebug builds will allow adb root to give you root.

We haven't touched "su" btw. I think we just use the stock version provided by ICS or JB MR2.

Also, dd isn't a good command to use if you're only using it to copy files and block devices. Use "cat srcpath > dstpath". (dd can give poor performance if the blocksize isn't configured correctly)
Flags: needinfo?(mwu)
(In reply to Michael Wu [:mwu] from comment #2)
> Does adb root work for you? Any engineering build will give you root by
> default, and userdebug builds will allow adb root to give you root.
> 
> We haven't touched "su" btw. I think we just use the stock version provided
> by ICS or JB MR2.
> 
> Also, dd isn't a good command to use if you're only using it to copy files
> and block devices. Use "cat srcpath > dstpath". (dd can give poor
> performance if the blocksize isn't configured correctly)

I'm 95% certain "su" used to work the way I expect. Certainly I didn't start seeing this type of problem until recently (e.g. bug 895153). If you're not sure, I suppose I could dig and check.

To be clear, my problem isn't that I somehow need a way of running commands as superuser. I know there are many ways of doing that with eng builds that work fine, and that su is not required. My problem is that lots of automation is written that uses the shellCheckOutput call in mozdevice, which in turn calls "su" if the root=True argument is specified (because that's always worked on Android). 

Making "su" a symbolic link to "sh" would I think be the easiest and most universal way of making sure that things work how we expect on both platforms. We wouldn't even need to give it special permissions, since both the adb console and negatus are running as root by default in eng builds.
I took a look at the Android su source code (found in system/extras/su.c), and it doesn't take a -c argument.

It expects the command line to look like:
  su UID command command arguments

so something like:
  su root ls -l

and not
  su root 'ls -l'

which would try to execute the command ls -l.

I think that what you want is:
  su root sh -c 'dd if=/mnt/sdcard/foo of=/data/local/bar'

This doesn't follow the standard linux su syntax (for which your invocation would work).
The Android su parses -c as the username, and due to lack of checking, this winds up being intepreted as 0.

so: su -c 'dd if=/mnt/sdcard/foo of=/data/local/bar'

is treated the same as: su root 'dd if=/mnt/sdcard/foo of=/data/local/bar'
su root dd if=/mnt/sdcard/foo of=/data/local/bar

should also work.
Ok, it sounds like things are actually working as expected here. Sorry for the confusion!
Status: NEW → RESOLVED
Closed: 11 years ago
Resolution: --- → INVALID
See Also: → 895153
You need to log in before you can comment on or make changes to this bug.