9170895
diff -urNp coreutils-8.6-orig/src/su.c coreutils-8.6/src/su.c
9170895
--- coreutils-8.6-orig/src/su.c	2010-11-03 13:56:11.679069689 +0100
9170895
+++ coreutils-8.6/src/su.c	2010-11-03 13:56:45.304325661 +0100
9170895
@@ -153,6 +153,9 @@ static bool simulate_login;
9f2386c
 /* If true, change some environment vars to indicate the user su'd to.  */
9f2386c
 static bool change_environment;
9f2386c
 
9f2386c
+/* If true, then don't call setsid() with a command. */
9f2386c
+int same_session = 0;
9f2386c
+
9170895
 #ifdef USE_PAM
9170895
 static bool _pam_session_opened;
9170895
 static bool _pam_cred_established;
9170895
@@ -161,6 +164,7 @@ static bool _pam_cred_established;
9f2386c
 static struct option const longopts[] =
9f2386c
 {
9f2386c
   {"command", required_argument, NULL, 'c'},
9f2386c
+  {"session-command", required_argument, NULL, 'C'},
9f2386c
   {"fast", no_argument, NULL, 'f'},
9f2386c
   {"login", no_argument, NULL, 'l'},
9f2386c
   {"preserve-environment", no_argument, NULL, 'p'},
9170895
@@ -335,14 +339,27 @@ create_watching_parent (void)
9170895
       sigemptyset (&action.sa_mask);
9170895
       action.sa_flags = 0;
9170895
       sigemptyset (&ourset);
9170895
-      if (sigaddset (&ourset, SIGTERM)
9170895
-	  || sigaddset (&ourset, SIGALRM)
9170895
-	  || sigaction (SIGTERM, &action, NULL)
9170895
-	  || sigprocmask (SIG_UNBLOCK, &ourset, NULL))
9170895
-	{
9f2386c
+    if (!same_session)
eb20fc6
+      {
2505178
+        if (sigaddset(&ourset, SIGINT) || sigaddset(&ourset, SIGQUIT))
2505178
+          {
9170895
+            error (0, errno, _("cannot set signal handler"));
9170895
+            caught_signal = true;
2505178
+          }
eb20fc6
+      }
9170895
+    if (!caught_signal && (sigaddset(&ourset, SIGTERM)
2505178
+                    || sigaddset(&ourset, SIGALRM)
2505178
+                    || sigaction(SIGTERM, &action, NULL)
2505178
+                    || sigprocmask(SIG_UNBLOCK, &ourset, NULL))) {
9170895
 	  error (0, errno, _("cannot set signal handler"));
9170895
 	  caught_signal = true;
9170895
 	}
9170895
+    if (!caught_signal && !same_session && (sigaction(SIGINT, &action, NULL)
2505178
+                                     || sigaction(SIGQUIT, &action, NULL)))
eb20fc6
+      {
9170895
+        error (0, errno, _("cannot set signal handler"));
9170895
+        caught_signal = true;
eb20fc6
+      }
9170895
     }
9170895
   if (!caught_signal)
9170895
     {
9170895
@@ -627,6 +644,8 @@ Change the effective user id and group i
9f2386c
 \n\
9f2386c
   -, -l, --login               make the shell a login shell\n\
d66c4db
   -c, --command=COMMAND        pass a single COMMAND to the shell with -c\n\
9f2386c
+  --session-command=COMMAND    pass a single COMMAND to the shell with -c\n\
9f2386c
+                               and do not create a new session\n\
9f2386c
   -f, --fast                   pass -f to the shell (for csh or tcsh)\n\
9f2386c
   -m, --preserve-environment   do not reset environment variables\n\
9f2386c
   -p                           same as -m\n\
9170895
@@ -649,6 +668,7 @@ main (int argc, char **argv)
9f2386c
   int optc;
9f2386c
   const char *new_user = DEFAULT_USER;
9f2386c
   char *command = NULL;
9f2386c
+  int request_same_session = 0;
9f2386c
   char *shell = NULL;
9f2386c
   struct passwd *pw;
9f2386c
   struct passwd pw_copy;
9170895
@@ -674,6 +694,11 @@ main (int argc, char **argv)
2505178
           command = optarg;
2505178
           break;
9f2386c
 
2505178
+        case 'C':
2505178
+          command = optarg;
2505178
+          request_same_session = 1;
2505178
+          break;
9f2386c
+
2505178
         case 'f':
2505178
           fast_startup = true;
2505178
           break;
9170895
@@ -743,6 +768,9 @@ main (int argc, char **argv)
9f2386c
     }
9f2386c
 #endif
9f2386c
 
9f2386c
+  if (request_same_session || !command || !pw->pw_uid)
9f2386c
+    same_session = 1;
9f2386c
+
9f2386c
   if (!shell && !change_environment)
9f2386c
     shell = getenv ("SHELL");
9f2386c
   if (shell && getuid () != 0 && restricted_shell (pw->pw_shell))
9170895
@@ -764,6 +792,8 @@ main (int argc, char **argv)
9170895
 #endif
9170895
 
9170895
   change_identity (pw);
9170895
+  if (!same_session)
9170895
+    setsid ();
9170895
 
9170895
   /* Set environment after pam_open_session, which may put KRB5CCNAME
9170895
      into the pam_env, etc.  */