Merge pull request #23 from danbyl/forkbefore

Update status after forking and export with setenv
This commit is contained in:
Luke Smith 2020-05-26 07:26:42 -04:00 committed by GitHub
commit 6d75ac1b00
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 11 deletions

View file

@ -42,5 +42,5 @@ scripts in response to click events. See the above linked scripts for examples
of this using the `$BLOCK_BUTTON` variable. of this using the `$BLOCK_BUTTON` variable.
For this feature to work, you need the appropriate patch in dwm as well. See For this feature to work, you need the appropriate patch in dwm as well. See
[here](https://gist.github.com/danbyl/54f7c1d57fc6507242a95b71c3d8fdea). [here](https://dwm.suckless.org/patches/statuscmd/).
Credit for those patches goes to Daniel Bylinka (daniel.bylinka@gmail.com). Credit for those patches goes to Daniel Bylinka (daniel.bylinka@gmail.com).

View file

@ -184,29 +184,25 @@ void sighandler(int signum)
void buttonhandler(int sig, siginfo_t *si, void *ucontext) void buttonhandler(int sig, siginfo_t *si, void *ucontext)
{ {
int button = si->si_value.sival_int & 0xff; char button[2] = {'0' + si->si_value.sival_int & 0xff, '\0'};
sig = si->si_value.sival_int >> 8; sig = si->si_value.sival_int >> 8;
getsigcmds(sig);
writestatus();
if (fork() == 0) if (fork() == 0)
{ {
static char exportstring[CMDLENGTH + 22] = "export BLOCK_BUTTON=-;";
const Block *current; const Block *current;
int i; for (int i = 0; i < LENGTH(blocks); i++)
for (i = 0; i < LENGTH(blocks); i++)
{ {
current = blocks + i; current = blocks + i;
if (current->signal == sig) if (current->signal == sig)
break; break;
} }
char *cmd = strcat(exportstring, blocks[i].command); char *command[] = { "/bin/sh", "-c", current->command, NULL };
cmd[20] = '0' + button; setenv("BLOCK_BUTTON", button, 1);
char *command[] = { "/bin/sh", "-c", cmd, NULL };
setsid(); setsid();
execvp(command[0], command); execvp(command[0], command);
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
cmd[22] = '\0';
} }
getsigcmds(sig);
writestatus();
} }
#endif #endif