On Thu, 18 Oct 2012 18:20:24 +0200
Rob Hoelz <r...@hoelz.ro> wrote:

> Hello tmux users and developers!
> 
> I found an interesting issue on tmux 1.7.  I have the following
> snippet at the end of my tmux.conf:
> 
> if-shell "[[ -e ~/.tmux.local.conf ]]" \
>     "source-file ~/.tmux.local.conf"
> 
> In tmux.local.conf, I set certain environment variables, depending on
> the machine.
> 
> However, when I start up the tmux server process by using new-session,
> the environment variables are not correctly set.  This is because the
> if-shell job is still running in the background when the session is
> created.
> 
> Attached is a patch to fix this; please let me know if there's
> anything I can do to improve it!
> 
> Thanks,
> Rob

Ok, I'm going to try sending this patch in again; I was able to view it
fine in my mail reader last time, but it didn't render properly in the
SF web view.  I have also improved the patch a bit; it should now more
closely conform to the style guidelines.

Thanks,
Rob
diff --git a/server.c b/server.c
index 4da0739..bdf9b0e 100644
--- a/server.c
+++ b/server.c
@@ -53,6 +53,7 @@ struct event	 server_ev_second;
 struct paste_stack global_buffers;
 
 int		 server_create_socket(void);
+void		 server_loop_once(void)
 void		 server_loop(void);
 int		 server_should_shutdown(void);
 void		 server_send_shutdown(void);
@@ -110,6 +111,7 @@ server_start(int lockfd, char *lockfile)
 	char			*cause;
 	struct timeval		 tv;
 	u_int			 i;
+	char			 dummy;
 
 	/* The first client is special and gets a socketpair; create it. */
 	if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, pair) != 0)
@@ -122,6 +124,7 @@ server_start(int lockfd, char *lockfile)
 		break;
 	default:
 		close(pair[1]);
+		read(pair[0], &dummy, 1);
 		return (pair[0]);
 	}
 	close(pair[0]);
@@ -200,22 +203,32 @@ server_start(int lockfd, char *lockfile)
 	evtimer_add(&server_ev_second, &tv);
 
 	set_signals(server_signal_callback);
+	/* wait for any jobs started by the configuration file to finish */
+	while(!LIST_EMPTY(&all_jobs) && !server_should_shutdown())
+		server_loop_once();
+	write(pair[1], "a", 1);
 	server_loop();
 	exit(0);
 }
 
+void
+server_loop_once(void)
+{
+	event_loop(EVLOOP_ONCE);
+
+	server_window_loop();
+	server_client_loop();
+
+	key_bindings_clean();
+	server_clean_dead();
+}
+
 /* Main server loop. */
 void
 server_loop(void)
 {
 	while (!server_should_shutdown()) {
-		event_loop(EVLOOP_ONCE);
-
-		server_window_loop();
-		server_client_loop();
-
-		key_bindings_clean();
-		server_clean_dead();
+		server_loop_once();
 	}
 }
 
------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_sfd2d_oct
_______________________________________________
tmux-users mailing list
tmux-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tmux-users

Reply via email to