------------------------------------------------------------------------------- Ctrl-C terminates Su, not the running command. Problem... A Ctrl-C in a SU started interactive sub-shell terminates the SU session but does not kill the shell, OR any running command that shell started. IE it kills the SU, not the running command I am trying to kill. It also screws up the TTY, so half the commands goes to a sub-program (if it was running) and leaves the TTY in 'raw' mode, until reset. Solution... Make sure the su runs the shell as a full login shell and NOT a sub-shell. Bash makes this easy by providing a '--login' command line option. Better still use sudo which is better (though it also has its flaws) ------------------------------------------------------------------------------- Su always leaves behind a extra process exec su user -c program A "ps" from another terminal shows two processes su user -c program program How can you get su to replace itself with the program? Possible solutions... These are tiny su replacments, though they were more about the TTY and interupt problem above than process replacing... gosu su-exec ------------------------------------------------------------------------------- A 'become root' shell function (added to ".bashrc" or equivelent) # Start a root login shell in my own HOME root_su() { # Su with environment preserve (fails for solaris) echo "Root (su)..." history -w # write shell history for read by ROOT shell /bin/su -m root # do not use -l as on fedora it changes HOME history -a # restore history performed while we were root } root_su_env() { # SU running a login shell for my HOME (su has no -m or -p option) echo "Root (su path)..." history -w # write history for read by ROOT shell /bin/su root -c "exec env PATH=$PATH HOME=$HOME bash --login" history -a # restore history performed while we were root } root_perl() { # SU using a perl script to launch a full login shell! (with a '-' prefix) echo "Root (perl non-bash shell)..." history -w # write history for read by ROOT shell /bin/su root -c "exec env PATH=$PATH HOME=$HOME \ perl -e '\$shell=\"sh\"; exec(\$shell \"-\$shell\")'" history -a # restore history performed while we were root } root_sudo() { echo "Root (sudo) type your own password..." # Use sudo to start a root shell with my HOME environment history -w # write history for read by ROOT shell #sudo -E bash --login # only works is sudo passes the env! sudo bash -c "HOME=$HOME exec bash --login" history -a } alias root root_sudo ------------------------------------------------------------------------------- Note I start SU, using a command, not a direct login shell. This allows me to control the environment of the root shell, passing specific environment varables in as I want and not what sudo allows. I do NOT want to use su -m -shell=/bin/bash As, 1 my shell completely sets up the environment and 2 I don't want to pass any extra environment I may have set. -------------------- New FC5 version 5.96 Using -m -l -s, behaves correctly Ctrl-C does not exit shell, but the logout command does. suspend -f does suspend shell and I can resume the shell. But it does not run my shell setup, as environment was NOT preserved. /bin/su -m -l -s /bin/bash Process Tree... ps xajww PPID PID PGID SID TTY TPGID STAT UID TIME COMMAND 31360 31362 31362 31362 pts/3 31596 Ss 501 0:00 -bash 31362 31519 31519 31362 pts/3 31596 S 0 0:00 /bin/su -m -l -s /bin/bash 31519 31523 31523 31362 pts/3 31596 S 0 0:00 -bash 31523 31596 31596 31362 pts/3 31596 R+ 0 0:00 ps xajfww ----------------------- Pre FC5 notes... Using -m -s, behaves correctly It does use my environment, so my Root shell settings are in place, and everything else works. Of course it could pass 'unknown' environment settings I did not want to pass to root! /bin/su -m -s /bin/bash Process Tree... ps xajww PPID PID PGID SID TTY TPGID STAT UID TIME COMMAND 31360 31362 31362 31362 pts/3 31728 Ss 501 0:00 -bash 31362 31622 31622 31362 pts/3 31728 S 0 0:00 /bin/su -m -s /bin/bash 31622 31626 31626 31362 pts/3 31728 S 0 0:00 bash 31626 31728 31728 31362 pts/3 31728 R+ 0 0:00 ps xajww But use a command to start a shell does NOT work. /bin/su root -c "exec env PATH=$ROOT_PATH HOME=$ROOT_HOME bash --login"; Process Tree... ps xajww PPID PID PGID SID TTY TPGID STAT UID TIME COMMAND 31360 31362 31362 31362 pts/3 31771 Ss 501 0:00 -bash 31362 31771 31771 31362 pts/3 31771 S+ 0 0:00 /bin/su root -c exec env PATH=... HOME=... bash --login 31771 31774 31774 31774 ? -1 Ss 0 0:00 bash --login 31774 31928 31928 31774 ? -1 R 0 0:00 ps xajww Now Ctrl-C kills the su... Session terminated, killing shell... ...killed. But any sub-commands continue to run, and terminal settings have been screwed up, with half the characters going to the sub-program and half to the prompt. As you can see the SID and TPGID changed in this case! SU does not do this under FC4, or on any other UNIX machine I have previously used. Removing the -login makes no difference, except make bash run ".bash_profile", rather than ".bashrc" in the home it is using. ------------------- Old FC4 version 5.2.1 Run under FC5 does not behave the same as on FC4 either. This shows that the problem may not be a SU problem but some library problem. -------------------------------------------------------------------------------