[patch] don't resume terminal-stopped slave sessions

Scott <[email protected]>
Newsgroups gmane.comp.web.links
Message-ID <[email protected]>
I have made this patch to avoid having to fg-suspend-fg to get a slave
session back if I have initially suspended it for longer than one
second.  I also find this behavior unpleasant because elinks loses its place in
my shell's job control queue as being the default process to foreground
without specifying a job number (because it is running in the background,
even though I did not tell it to do that).

It seems to me that automatically continuing suspended elinks sessions
unrequested behind the back of the user is a bit mysterious and initially
inexplicable for the naive user (like me ;)  The following patch allows this
behavior to affect the master only, and be configurable even in that
case.  Please let me know what you think.  Thanks.

diff -ur elinks-0.12-20071028/src/config/options.inc
elinks-nosusp/src/config/options.inc
--- elinks-0.12-20071028/src/config/options.inc	2007-10-27
15:40:03.000000000 -0700
+++ elinks-nosusp/src/config/options.inc	2007-11-02 22:33:29.000000000 -0700
@@ -1280,6 +1280,17 @@
 		"sessions", OPT_SORT,
 		N_("Sessions settings.")),

+#if defined (SIGCONT) && defined(SIGTTOU)
+	/* XXX see comment in signals.c to understand this */
+	INIT_OPT_BOOL("ui.sessions", N_("Keep session master running"),
+		"keep_master_running", 0, 0,
+		N_("Cause a master suspended instance to revive itself\n"
+		"after 1s.  Be aware that unsetting this option will\n"
+		"put the onus on the user to either keep the master\n"
+		"session running or start it in the background\n"
+		"and hangup the terminal.\n")),
+#endif
+
 	INIT_OPT_BOOL("ui.sessions", N_("Keep session active"),
 		"keep_session_active", 0, 0,
 		N_("Keep the session active even if the last terminal exits.")),
diff -ur elinks-0.12-20071028/src/osdep/signals.c
elinks-nosusp/src/osdep/signals.c
--- elinks-0.12-20071028/src/osdep/signals.c	2007-10-27 15:40:03.000000000 -0700
+++ elinks-nosusp/src/osdep/signals.c	2007-11-02 22:27:07.000000000 -0700
@@ -74,16 +74,40 @@
 	pid_t pid = getpid();

 	block_itrm();
+
 #if defined (SIGCONT) && defined(SIGTTOU)
-	if (!fork()) {
-		sleep(1);
-		kill(pid, SIGCONT);
-		/* Use _exit() rather than exit(), so that atexit
-		 * functions are not called, and stdio output buffers
-		 * are not flushed.  Any such things must have been
-		 * inherited from the parent process, which will take
-		 * care of them when appropriate.  */
-		_exit(0);
+	/*
+	 * If the master session is suspended, all slave
+	 * instances will block waiting for it to resume.
+	 * The following code is intended to prevent this by
+	 * causing any terminal-stopped instance to be
+	 * resumed after one second by a short-lived child
+	 * that continues its parent.  This is really only
+	 * needed by the session master, but we do it
+	 * unconditionally based on the setting of the
+	 * config option.
+	 *
+	 * This works out fine because load_config() is
+	 * never called from slave instances, so they will
+	 * only use the compiled-in default for the option;
+	 * slaves can be suspended happily without blocking
+	 * any other instances, so it shouldn't ever be
+	 * needed to enable this behavior in slave
+	 * instances.
+	 */
+	if (get_opt_bool("ui.sessions.keep_master_running")) {
+		if (!fork()) {
+			sleep(1);
+			kill(pid, SIGCONT);
+			/* Use _exit() rather than exit(),
+			 * so that atexit functions are not
+			 * called, and stdio output buffers
+			 * are not flushed.  Any such things
+			 * must have been inherited from the
+			 * parent process, which will take
+			 * care of them when appropriate.  */
+			_exit(0);
+		}
 	}
 #endif
 	raise(SIGSTOP);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.