A tiling window manager

actions: cmd_execw: new exec command waits for forked proc to exit (#49)

Normally it is not possible to sequence rcfile commands that run
programs, because 'exec' forks and does not wait for completion before
moving on to the next statement in rcfile. This patch adds an 'execw'
command that will wait indefinitely for the shell to exit. User should
use timeout(1) if they don't want to hang their window manager.

authored by

Scott Mcdermott and committed by jcs.org 3de8b742 b46bb98d

+27
+15
actions.c
··· 194 194 static cmdret *cmd_exec(int interactive, struct cmdarg **args); 195 195 static cmdret *cmd_execa(int interactive, struct cmdarg **args); 196 196 static cmdret *cmd_execf(int interactive, struct cmdarg **args); 197 + static cmdret *cmd_execw(int interactive, struct cmdarg **args); 197 198 static cmdret *cmd_fdump(int interactive, struct cmdarg **args); 198 199 static cmdret *cmd_focusdown(int interactive, struct cmdarg **args); 199 200 static cmdret *cmd_focuslast(int interactive, struct cmdarg **args); ··· 444 445 "/bin/sh -c ", arg_SHELLCMD); 445 446 add_command("execf", cmd_execf, 2, 2, 2, 446 447 "frame to execute in:", arg_FRAME, 448 + "/bin/sh -c ", arg_SHELLCMD); 449 + add_command("execw", cmd_execw, 1, 1, 1, 447 450 "/bin/sh -c ", arg_SHELLCMD); 448 451 add_command("fdump", cmd_fdump, 1, 0, 0, 449 452 "", arg_NUMBER); ··· 2767 2770 { 2768 2771 spawn(ARG_STRING(0), current_frame(rp_current_vscreen)); 2769 2772 return cmdret_new(RET_SUCCESS, NULL); 2773 + } 2774 + 2775 + cmdret * 2776 + cmd_execw(int interactive, struct cmdarg **args) 2777 + { 2778 + int status = -1; 2779 + pid_t pid = spawn(ARG_STRING(0), current_frame(rp_current_vscreen)); 2780 + if (waitpid(pid, &status, 0) == -1) 2781 + perror("cmd_execw"); 2782 + else 2783 + status = WEXITSTATUS(status); 2784 + return cmdret_new(status == 0? RET_SUCCESS: RET_FAILURE, NULL); 2770 2785 } 2771 2786 2772 2787 cmdret *
+12
sdorfehs.1
··· 343 343 .Ar shell\-command , 344 344 showing _NET_WM_PID supporting programs in the given frame instead of 345 345 the frame selected when this program is run. 346 + .It Ic execw Ar shell\-command 347 + Spawn a shell executing 348 + .Ar shell\-command , 349 + but wait for it to finish. This should behave the same as 350 + .Ar exec 351 + but will wait for completion. Use timeout(1) if it might hang, or 352 + .Nm 353 + will hang itself waiting for completion. Use the 'exec' shell builtin as the 354 + first word in the command string to get similar behavior to 355 + .Ar execa 356 + owing to the forked pid remaining stable and known to 357 + .Nm . 346 358 .It Ic fdump Op Ar screenno 347 359 Output the defining data for all frames of the current screen, or 348 360 for screen number