Another copy of my dotfiles. Because I don't completely trust GitHub.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
1.8 KiB

  1. diff --git a/dwmblocks.c b/dwmblocks.c
  2. index 7d7a564..e2c5dd0 100644
  3. --- a/dwmblocks.c
  4. +++ b/dwmblocks.c
  5. @@ -34,8 +34,6 @@ static int screen;
  6. static Window root;
  7. static char statusbar[LENGTH(blocks)][CMDLENGTH] = {0};
  8. static char statusstr[2][256];
  9. -static char exportstring[CMDLENGTH + 22] = "export BLOCK_BUTTON=-;";
  10. -static int button = 0;
  11. static int statusContinue = 1;
  12. static void (*writestatus) () = setroot;
  13. @@ -55,21 +53,8 @@ void getcmd(const Block *block, char *output)
  14. output[0] = block->signal;
  15. output++;
  16. }
  17. - char* cmd;
  18. - FILE *cmdf;
  19. - if (button)
  20. - {
  21. - cmd = strcat(exportstring, block->command);
  22. - cmd[20] = '0' + button;
  23. - button = 0;
  24. - cmdf = popen(cmd,"r");
  25. - cmd[22] = '\0';
  26. - }
  27. - else
  28. - {
  29. - cmd = block->command;
  30. - cmdf = popen(cmd,"r");
  31. - }
  32. + char *cmd = block->command;
  33. + FILE *cmdf = popen(cmd,"r");
  34. if (!cmdf)
  35. return;
  36. fgets(output, CMDLENGTH, cmdf);
  37. @@ -117,6 +102,7 @@ void setupsignals()
  38. sa.sa_sigaction = buttonhandler;
  39. sa.sa_flags = SA_SIGINFO;
  40. sigaction(SIGUSR1, &sa, NULL);
  41. + signal(SIGCHLD, SIG_IGN);
  42. }
  43. #endif
  44. @@ -179,9 +165,29 @@ void sighandler(int signum)
  45. void buttonhandler(int sig, siginfo_t *si, void *ucontext)
  46. {
  47. - button = si->si_value.sival_int & 0xff;
  48. - getsigcmds(si->si_value.sival_int >> 8);
  49. + int button = si->si_value.sival_int & 0xff;
  50. + sig = si->si_value.sival_int >> 8;
  51. + getsigcmds(sig);
  52. writestatus();
  53. + if (fork() == 0)
  54. + {
  55. + static char exportstring[CMDLENGTH + 22] = "export BLOCK_BUTTON=-;";
  56. + const Block *current;
  57. + int i;
  58. + for (i = 0; i < LENGTH(blocks); i++)
  59. + {
  60. + current = blocks + i;
  61. + if (current->signal == sig)
  62. + break;
  63. + }
  64. + char *cmd = strcat(exportstring, blocks[i].command);
  65. + cmd[20] = '0' + button;
  66. + char *command[] = { "/bin/sh", "-c", cmd, NULL };
  67. + setsid();
  68. + execvp(command[0], command);
  69. + exit(EXIT_SUCCESS);
  70. + cmd[22] = '\0';
  71. + }
  72. }
  73. #endif