Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Blogs > rainbowsally
User Name


Rate this Entry

So you'd like to run apps from the commandline as su or user

Posted 01-14-2012 at 11:24 PM by rainbowsally
Updated 01-15-2012 at 07:42 AM by rainbowsally

So you'd like to run apps from the commandline as su or user

In case it's not clear, and it probably isn't, this modification (openSUSE version so far):

[x] Allows users to run gui apps (such as kate or kwrite, konqueror or dolphin) and non-gui apps with the same syntax, no wrappers. I.e., makes kde work WITH linux instead of against it.

[x] Allows uniform syntax for calling script-based programs which may now call gui apps or not and run without crashing, whether run as user or superuser.

[x] superuser handling done once, programatically instead requiring recurring wrapper call every time you run a gui app (which WILL crash in kde without this modification if you are already superuser).

Try this without the modification. It will demonstrate half the reason this modification (or something like it) is necessary.
su # enter password
kdesu kwrite

Here's the finished version for openSUSE. The code for kubuntu is still not quite finished.

# For openSUSE, run apps as user or 'su' 
# without kdesu/xdg-su or any other su 
# wrapper.
# Integrates gui and terminal apps the way 
# you'd expect them to be.
# How:
# add this to, or create /root/(dot)bashrc 
# containing this code.

function _su_check_connected
  dbus-send --dest=org.freedesktop /org/freedesktop org.freedesktop.Hello 2>/dev/null

function _su_check
  if [ "$USER" != "root" ]; then
    for i in /root/.dbus/session-bus/*; do
      source $i
      if _su_check_connected ; then
        # we are now connected to the first dbus-daemon that worked
    # if no files contain a valid address, we'll just create one.
    export $(dbus-launch)
    # if root logs in before su does, root's daemon will get reused
    # otherwise there will be one for su and one for root.
    # two daemons is tolerable.  600+ is not.

The above is tested and bug-free for openSUSE 11.4. (At least it is for me and I've been using it for several months.)

Kubuntu Note:

The kubuntu code will be forthcoming soon but may require some help from some of the old timers around here because we need to catch and handle relaying a SIGHUP to root's 'knotify' in order to prevent SUDO_USER hanging in the dimmed state when trying to logout or shutdown.

Root's knotify can be looked up using 'pgrep knotify -u root' and sent the signal (kill -s 15 <PID>) as superuser in order to clear the stuff that hangs, but that shouldn't be necessary.

That *should* be handled programmatically too.
Posted in Uncategorized
Views 1062 Comments 0
« Prev     Main     Next »
Total Comments 0




All times are GMT -5. The time now is 12:13 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration