Move SIGCHLD handler to "src/main.c"

This commit is contained in:
Alex Kotov 2021-11-21 09:03:58 +05:00
parent e5f195bb03
commit 6b8d87d1ae
Signed by: kotovalexarian
GPG Key ID: 553C0EBBEB5D5F08
2 changed files with 21 additions and 13 deletions

View File

@ -10,11 +10,9 @@
#include "unit.h"
#include "util.h"
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/wait.h>
#include <unistd.h>
#include <X11/cursorfont.h>
#include <X11/keysym.h>
@ -202,7 +200,6 @@ static void setmfact(const Arg *arg);
static bool setup();
static void seturgent(Client *c, bool is_urgent);
static void showhide(Client *c);
static void sigchld(int unused);
static void spawn(const Arg *arg);
static void spawn_callback();
static void tagmon(const Arg *arg);
@ -1623,9 +1620,6 @@ bool setup()
{
XSetWindowAttributes wa;
/* clean up any zombies immediately */
sigchld(0);
if (!(global_unit = unit_new(UNIT_GLOBAL, NULL))) return false;
/* init screen */
@ -1751,13 +1745,6 @@ void showhide(Client *c)
}
}
void sigchld(__attribute__((unused)) int unused)
{
if (signal(SIGCHLD, sigchld) == SIG_ERR)
fatal_perror("can't install SIGCHLD handler");
while (0 < waitpid(-1, NULL, WNOHANG));
}
void spawn(const Arg *arg)
{
const char *const command_name = arg->v;

View File

@ -3,14 +3,18 @@
#include "dwm.h"
#include <locale.h>
#include <signal.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/wait.h>
#define PROGRAM_NAME "polytreewm"
static void signal_callback(int signo);
static void logger(const char *level, const char *fmt, ...);
static void logger_perror(const char *level, const char *fmt, ...);
@ -36,9 +40,26 @@ int main(int argc, char *argv[])
}
#endif // __OpenBSD__
{
struct sigaction action;
memset(&action, 0, sizeof(action));
action.sa_handler = signal_callback;
if (sigaction(SIGCHLD, &action, NULL) != 0) {
fatal_perror("can't install SIGCHLD handler");
}
}
exit(dwm_main(argc, argv));
}
void signal_callback(const int signo)
{
if (signo != SIGCHLD) return;
// Clean up any zombies immediately.
while (waitpid(-1, NULL, WNOHANG) > 0);
}
void logger(const char *const level, const char *const fmt, ...)
{
fprintf(stderr, PROGRAM_NAME": %s: ", level);