The fvwm manual notes the potential for race conditions when using the
Exec command, and I stumbled across this recently when trying to put more
of my X startup under fvwm's control (the xrdb command didn't complete
before xclock started). So I added an ExecWait command for running
programs synchronously. It's OK as it is for short-lived programs, but
for use with longer-lived things it needs support for the EscapeFunc
mechanism.

--- ChangeLog   2002/06/21 05:35:43     1.1847
+++ ChangeLog   2002/06/21 10:16:03
@@ -1,3 +1,13 @@
+2002-06-21  Tony Finch <[EMAIL PROTECTED]>
+
+       * fvwm/builtins.c:
+       * fvwm/commands.h:
+       * fvwm/functable.c:
+       * fvwm/fvwm.1:
+       Add an ExecWait command for running a program in a blocking
+       fashion, in order to avoid race conditions of the kind mentioned
+       in the manual under the Exec command.
+
 2002-06-21  olicha  <[EMAIL PROTECTED]>
 
        * fvwm/fvwm.1: 
--- fvwm/builtins.c     2002/06/19 14:11:27     1.359
+++ fvwm/builtins.c     2002/06/21 10:16:03
@@ -1816,6 +1816,28 @@
        return;
 }
 
+void CMD_ExecWait(F_CMD_ARGS)
+{
+  pid_t pid;
+  char *cmd;
+
+  switch (pid = fork())
+  {
+  case -1:
+    fvwm_msg(ERR,"ExecWait","fork failed (%s)",strerror(errno));
+    break;
+  case 0:
+    cmd = safestrdup(action);
+    execl(exec_shell_name, exec_shell_name, "-c", cmd, NULL);
+    fvwm_msg(ERR,"ExecWait","execl failed (%s)",strerror(errno));
+    exit(100);
+  default:
+    waitpid(pid, NULL, 0);
+    break;
+  }
+  return;
+}
+
 void CMD_Refresh(F_CMD_ARGS)
 {
        refresh_window(Scr.Root, True);
--- fvwm/commands.h     2002/06/19 14:11:27     1.21
+++ fvwm/commands.h     2002/06/21 10:16:03
@@ -75,6 +75,7 @@
        F_EWMH_NUMBER_OF_DESKTOPS,
        F_EXEC,
        F_EXEC_SETUP,
+       F_EXEC_WAIT,
        F_FAKE_CLICK,
        F_FUNCTION,
        F_GLOBAL_OPTS,
@@ -265,6 +266,7 @@
 void CMD_EwmhNumberOfDesktops(F_CMD_ARGS);
 void CMD_Exec(F_CMD_ARGS);
 void CMD_ExecUseShell(F_CMD_ARGS);
+void CMD_ExecWait(F_CMD_ARGS);
 void CMD_FakeClick(F_CMD_ARGS);
 void CMD_FlipFocus(F_CMD_ARGS);
 void CMD_Focus(F_CMD_ARGS);
--- fvwm/functable.c    2002/06/19 14:12:45     1.1
+++ fvwm/functable.c    2002/06/21 10:16:03
@@ -125,6 +125,7 @@
                  F_EWMH_NUMBER_OF_DESKTOPS, 0),
        CMD_ENTRY("exec", CMD_Exec, F_EXEC, 0),
        CMD_ENTRY("execuseshell", CMD_ExecUseShell, F_EXEC_SETUP, 0),
+       CMD_ENTRY("execwait", CMD_ExecWait, F_EXEC_WAIT, 0),
        CMD_ENTRY("fakeclick", CMD_FakeClick, F_FAKE_CLICK, 0),
        CMD_ENTRY("flipfocus", CMD_FlipFocus, F_FLIP_FOCUS, FUNC_NEEDS_WINDOW),
        CMD_ENTRY("focus", CMD_Focus, F_FOCUS, FUNC_NEEDS_WINDOW),
--- fvwm/fvwm.1 2002/06/21 05:35:44     1.21
+++ fvwm/fvwm.1 2002/06/21 10:16:03
@@ -8145,6 +8145,17 @@
 Read /tmp/file
 .EE
 do not work reliably.
+Use the
+.B ExecWait
+command instead.
+
+.TP
+.BI "ExecWait " command
+Executes
+.IR command
+and waits for it to complete.
+Do not use this for programs that are going to run for any significant
+length of time because fvwm is unresponsive while waiting.
 
 .TP
 .BI "ExecUseShell [" shell "]"


Tony.
-- 
f.a.n.finch <[EMAIL PROTECTED]> http://dotat.at/
SHANNON ROCKALL: SOUTHERLY VEERING WESTERLY 4 OR 5. RAIN OR SHOWERS. MODERATE
OR GOOD.
--
Visit the official FVWM web page at <URL:http://www.fvwm.org/>.
To unsubscribe from the list, send "unsubscribe fvwm-workers" in the
body of a message to [EMAIL PROTECTED]
To report problems, send mail to [EMAIL PROTECTED]

Reply via email to