statuscmd programs forked
This commit is contained in:
parent
a0ebcc3f54
commit
ff41f8e71e
2 changed files with 102 additions and 19 deletions
44
dwmblocks.c
44
dwmblocks.c
|
@ -36,8 +36,6 @@ static int screen;
|
||||||
static Window root;
|
static Window root;
|
||||||
static char statusbar[LENGTH(blocks)][CMDLENGTH] = {0};
|
static char statusbar[LENGTH(blocks)][CMDLENGTH] = {0};
|
||||||
static char statusstr[2][256];
|
static char statusstr[2][256];
|
||||||
static char exportstring[CMDLENGTH + 22] = "export BLOCK_BUTTON=-;";
|
|
||||||
static int button = 0;
|
|
||||||
static int statusContinue = 1;
|
static int statusContinue = 1;
|
||||||
static void (*writestatus) () = setroot;
|
static void (*writestatus) () = setroot;
|
||||||
|
|
||||||
|
@ -71,21 +69,8 @@ void getcmd(const Block *block, char *output)
|
||||||
output++;
|
output++;
|
||||||
}
|
}
|
||||||
strcpy(output, block->icon);
|
strcpy(output, block->icon);
|
||||||
char* cmd;
|
char *cmd = block->command;
|
||||||
FILE *cmdf;
|
FILE *cmdf = popen(cmd,"r");
|
||||||
if (button)
|
|
||||||
{
|
|
||||||
cmd = strcat(exportstring, block->command);
|
|
||||||
cmd[20] = '0' + button;
|
|
||||||
button = 0;
|
|
||||||
cmdf = popen(cmd,"r");
|
|
||||||
cmd[22] = '\0';
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
cmd = block->command;
|
|
||||||
cmdf = popen(cmd,"r");
|
|
||||||
}
|
|
||||||
if (!cmdf)
|
if (!cmdf)
|
||||||
return;
|
return;
|
||||||
char c;
|
char c;
|
||||||
|
@ -136,6 +121,7 @@ void setupsignals()
|
||||||
sa.sa_sigaction = buttonhandler;
|
sa.sa_sigaction = buttonhandler;
|
||||||
sa.sa_flags = SA_SIGINFO;
|
sa.sa_flags = SA_SIGINFO;
|
||||||
sigaction(SIGUSR1, &sa, NULL);
|
sigaction(SIGUSR1, &sa, NULL);
|
||||||
|
signal(SIGCHLD, SIG_IGN);
|
||||||
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -198,9 +184,29 @@ void sighandler(int signum)
|
||||||
|
|
||||||
void buttonhandler(int sig, siginfo_t *si, void *ucontext)
|
void buttonhandler(int sig, siginfo_t *si, void *ucontext)
|
||||||
{
|
{
|
||||||
button = si->si_value.sival_int & 0xff;
|
int button = si->si_value.sival_int & 0xff;
|
||||||
getsigcmds(si->si_value.sival_int >> 8);
|
sig = si->si_value.sival_int >> 8;
|
||||||
|
getsigcmds(sig);
|
||||||
writestatus();
|
writestatus();
|
||||||
|
if (fork() == 0)
|
||||||
|
{
|
||||||
|
static char exportstring[CMDLENGTH + 22] = "export BLOCK_BUTTON=-;";
|
||||||
|
const Block *current;
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < LENGTH(blocks); i++)
|
||||||
|
{
|
||||||
|
current = blocks + i;
|
||||||
|
if (current->signal == sig)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
char *cmd = strcat(exportstring, blocks[i].command);
|
||||||
|
cmd[20] = '0' + button;
|
||||||
|
char *command[] = { "/bin/sh", "-c", cmd, NULL };
|
||||||
|
setsid();
|
||||||
|
execvp(command[0], command);
|
||||||
|
exit(EXIT_SUCCESS);
|
||||||
|
cmd[22] = '\0';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
77
patches/dwmblocks-statuscmd-fork.diff
Normal file
77
patches/dwmblocks-statuscmd-fork.diff
Normal file
|
@ -0,0 +1,77 @@
|
||||||
|
diff --git a/dwmblocks.c b/dwmblocks.c
|
||||||
|
index 7d7a564..e2c5dd0 100644
|
||||||
|
--- a/dwmblocks.c
|
||||||
|
+++ b/dwmblocks.c
|
||||||
|
@@ -34,8 +34,6 @@ static int screen;
|
||||||
|
static Window root;
|
||||||
|
static char statusbar[LENGTH(blocks)][CMDLENGTH] = {0};
|
||||||
|
static char statusstr[2][256];
|
||||||
|
-static char exportstring[CMDLENGTH + 22] = "export BLOCK_BUTTON=-;";
|
||||||
|
-static int button = 0;
|
||||||
|
static int statusContinue = 1;
|
||||||
|
static void (*writestatus) () = setroot;
|
||||||
|
|
||||||
|
@@ -55,21 +53,8 @@ void getcmd(const Block *block, char *output)
|
||||||
|
output[0] = block->signal;
|
||||||
|
output++;
|
||||||
|
}
|
||||||
|
- char* cmd;
|
||||||
|
- FILE *cmdf;
|
||||||
|
- if (button)
|
||||||
|
- {
|
||||||
|
- cmd = strcat(exportstring, block->command);
|
||||||
|
- cmd[20] = '0' + button;
|
||||||
|
- button = 0;
|
||||||
|
- cmdf = popen(cmd,"r");
|
||||||
|
- cmd[22] = '\0';
|
||||||
|
- }
|
||||||
|
- else
|
||||||
|
- {
|
||||||
|
- cmd = block->command;
|
||||||
|
- cmdf = popen(cmd,"r");
|
||||||
|
- }
|
||||||
|
+ char *cmd = block->command;
|
||||||
|
+ FILE *cmdf = popen(cmd,"r");
|
||||||
|
if (!cmdf)
|
||||||
|
return;
|
||||||
|
fgets(output, CMDLENGTH, cmdf);
|
||||||
|
@@ -117,6 +102,7 @@ void setupsignals()
|
||||||
|
sa.sa_sigaction = buttonhandler;
|
||||||
|
sa.sa_flags = SA_SIGINFO;
|
||||||
|
sigaction(SIGUSR1, &sa, NULL);
|
||||||
|
+ signal(SIGCHLD, SIG_IGN);
|
||||||
|
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
@@ -179,9 +165,29 @@ void sighandler(int signum)
|
||||||
|
|
||||||
|
void buttonhandler(int sig, siginfo_t *si, void *ucontext)
|
||||||
|
{
|
||||||
|
- button = si->si_value.sival_int & 0xff;
|
||||||
|
- getsigcmds(si->si_value.sival_int >> 8);
|
||||||
|
+ int button = si->si_value.sival_int & 0xff;
|
||||||
|
+ sig = si->si_value.sival_int >> 8;
|
||||||
|
+ getsigcmds(sig);
|
||||||
|
writestatus();
|
||||||
|
+ if (fork() == 0)
|
||||||
|
+ {
|
||||||
|
+ static char exportstring[CMDLENGTH + 22] = "export BLOCK_BUTTON=-;";
|
||||||
|
+ const Block *current;
|
||||||
|
+ int i;
|
||||||
|
+ for (i = 0; i < LENGTH(blocks); i++)
|
||||||
|
+ {
|
||||||
|
+ current = blocks + i;
|
||||||
|
+ if (current->signal == sig)
|
||||||
|
+ break;
|
||||||
|
+ }
|
||||||
|
+ char *cmd = strcat(exportstring, blocks[i].command);
|
||||||
|
+ cmd[20] = '0' + button;
|
||||||
|
+ char *command[] = { "/bin/sh", "-c", cmd, NULL };
|
||||||
|
+ setsid();
|
||||||
|
+ execvp(command[0], command);
|
||||||
|
+ exit(EXIT_SUCCESS);
|
||||||
|
+ cmd[22] = '\0';
|
||||||
|
+ }
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in a new issue