public inbox for util-linux@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] setsid: add option "-c" to set the controlling terminal
@ 2012-03-14  9:07 harald
  2012-03-20  8:29 ` Karel Zak
  0 siblings, 1 reply; 2+ messages in thread
From: harald @ 2012-03-14  9:07 UTC (permalink / raw)
  To: util-linux; +Cc: Harald Hoyer

From: Harald Hoyer <harald@redhat.com>

---
 sys-utils/setsid.1 |    4 ++++
 sys-utils/setsid.c |   18 ++++++++++++++++--
 2 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/sys-utils/setsid.1 b/sys-utils/setsid.1
index 0d9580e..eff7948 100644
--- a/sys-utils/setsid.1
+++ b/sys-utils/setsid.1
@@ -11,6 +11,10 @@ setsid \- run a program in a new session
 .SH DESCRIPTION
 .B setsid
 runs a program in a new session.
+.SH OPTIONS
+.TP
+\fB\-c\fP, \fB\-\-ctty\fP
+Set the controlling terminal to the current one.
 .SH "SEE ALSO"
 .BR setsid (2)
 .SH AUTHOR
diff --git a/sys-utils/setsid.c b/sys-utils/setsid.c
index efd20e6..bcbba6e 100644
--- a/sys-utils/setsid.c
+++ b/sys-utils/setsid.c
@@ -15,6 +15,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <termio.h>
 
 #include "c.h"
 #include "nls.h"
@@ -25,6 +26,9 @@ static void __attribute__ ((__noreturn__)) usage(FILE * out)
 	fprintf(out, _(" %s [options] <program> [arguments ...]\n"),
 		program_invocation_short_name);
 	fprintf(out, USAGE_OPTIONS);
+	fprintf(out, _(
+		" -c, --ctty \tset the controlling terminal to the current one\n"
+		));
 	fprintf(out, USAGE_HELP);
 	fprintf(out, USAGE_VERSION);
 	fprintf(out, USAGE_MAN_TAIL("setsid(1)"));
@@ -34,7 +38,10 @@ static void __attribute__ ((__noreturn__)) usage(FILE * out)
 int main(int argc, char **argv)
 {
 	int ch;
+	int ctty = 0;
+
 	static const struct option longopts[] = {
+		{"ctty", no_argument, NULL, 'c'},
 		{"version", no_argument, NULL, 'V'},
 		{"help", no_argument, NULL, 'h'},
 		{NULL, 0, NULL, 0}
@@ -44,11 +51,14 @@ int main(int argc, char **argv)
 	bindtextdomain(PACKAGE, LOCALEDIR);
 	textdomain(PACKAGE);
 
-	while ((ch = getopt_long(argc, argv, "+Vh", longopts, NULL)) != -1)
+	while ((ch = getopt_long(argc, argv, "+Vhc", longopts, NULL)) != -1)
 		switch (ch) {
 		case 'V':
 			printf(UTIL_LINUX_VERSION);
 			return EXIT_SUCCESS;
+		case 'c':
+			ctty=1;
+			break;
 		case 'h':
 			usage(stdout);
 		default:
@@ -74,6 +84,10 @@ int main(int argc, char **argv)
 		/* cannot happen */
 		err(EXIT_FAILURE, _("setsid failed"));
 
-	execvp(argv[1], argv + 1);
+	if (ctty) {
+		if (ioctl (0, TIOCSCTTY, 1))
+			warn(_("failed to set the controlling terminal"));
+	}
+	execvp(argv[optind], argv + optind + 1);
 	err(EXIT_FAILURE, _("execvp failed"));
 }
-- 
1.7.9.3


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] setsid: add option "-c" to set the controlling terminal
  2012-03-14  9:07 [PATCH v2] setsid: add option "-c" to set the controlling terminal harald
@ 2012-03-20  8:29 ` Karel Zak
  0 siblings, 0 replies; 2+ messages in thread
From: Karel Zak @ 2012-03-20  8:29 UTC (permalink / raw)
  To: harald; +Cc: util-linux

On Wed, Mar 14, 2012 at 10:07:18AM +0100, harald@redhat.com wrote:
>  sys-utils/setsid.1 |    4 ++++
>  sys-utils/setsid.c |   18 ++++++++++++++++--
>  2 files changed, 20 insertions(+), 2 deletions(-)

 Applied, thanks.


-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-03-20  8:29 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-03-14  9:07 [PATCH v2] setsid: add option "-c" to set the controlling terminal harald
2012-03-20  8:29 ` Karel Zak

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox