OK, so what we were previously trying to do is this:
Code:
# open /Applications/MyApp.app
this used to work in 10.0, but now in 10.1 if you do it, the app opens, but not as root. rather as whoever has window server and the GUI and such. it is exactly as though that user had double clicked that app.
i went fishing through the running processes, looking to see what process was associated with TextEdit.app when it was running, thinking that i would just start the process manually from the command line, instead of simulating a double-click with open. this approach works like magic! what you will discover if you look at the processes is this:
Code:
#ps -aujx
USER PID %CPU %MEM VSZ RSS TT STAT TIME PPID PGID SESS JOBC COMMAND
lethe 1373 0.0 0.4 88640 3868 ?? S 0:00.71 69 69 292af70 0 /Applications/TextEdit.app/Contents/MacOS/TextEdit -psn_0_7340033
now, you see that the running process is not /Applications/TextEdit.app, but rather /Applications/TextEdit.app/Contents/MacOS/TextEdit. this makes sense, because in UNIX a program is just a file filled with executable code. it can t really be a directory, the way a .app bundle is.
there is a funny argument there associated with that (-psn_0_7340033 in this example.) just ignore it. i have no idea what that is. testuser, any idea? anyway it s not important.
so instead of open (equivalent to double click) /Applications/TextEdit, we actually launch the process that goes with it instead. then according to the rules of UNIX, the child process inherits the properties of its parent. so if we are root when we launch this program, it launches as root:
Code:
# pwd
/private/var/root
# touch testfile
# chmod 600 testfile
# /Applications/TextEdit.app/Contents/MacOS/TextEdit /private/var/root/testfile
and now the file will open and you can read/write it with textedit. no more sudo vi for you!
if you try this:
Code:
# open -e /private/var/root/testfile
it will fail. try it and see!
OK so i hope this cleared it up for you.