summaryrefslogtreecommitdiff
path: root/zwgc/main.c
diff options
context:
space:
mode:
authorGravatar Richard Basch <probe@mit.edu>1993-09-24 17:30:34 +0000
committerGravatar Richard Basch <probe@mit.edu>1993-09-24 17:30:34 +0000
commitaee56099e7f608361812cd1509e1f2449057ca21 (patch)
tree25716479944a24c35c416aaed3a4f666145d9fa3 /zwgc/main.c
parentdbf89848ca8a80725ed27326fb5c8f7465fe46c8 (diff)
Changed bzero/bcopy to _BZERO/_BCOPY (defined in <zephyr/zephyr_conf.h>)
Added POSIX signal handling
Diffstat (limited to 'zwgc/main.c')
-rw-r--r--zwgc/main.c71
1 files changed, 52 insertions, 19 deletions
diff --git a/zwgc/main.c b/zwgc/main.c
index cc17790..14e04b9 100644
--- a/zwgc/main.c
+++ b/zwgc/main.c
@@ -17,10 +17,10 @@ static char rcsid_main_c[] = "$Id$";
#endif
#include <zephyr/mit-copyright.h>
+#include <zephyr/zephyr.h>
#include <stdio.h>
#include <signal.h>
-#include <zephyr/zephyr.h>
#include "new_memory.h"
#include "zwgc.h"
#include "parser.h"
@@ -46,7 +46,7 @@ static void setup_signals(), detach();
int zwgc_debug = 0;
#endif
-static char *zwgc_version_string = "0.4.5";
+static char *zwgc_version_string = "0.4.6";
/*
* description_filename_override - <<<>>>
@@ -85,7 +85,7 @@ static void fake_startup_packet()
var_set_variable("version", zwgc_version_string);
- bzero(&notice, sizeof(notice));
+ _BZERO(&notice, sizeof(notice));
notice.z_version = "";
notice.z_class = "WG_CTL_CLASS";
@@ -355,7 +355,7 @@ static void signal_exit()
multiple SIGCHLD's at once, and don't process in time. */
static void signal_child()
{
-#if defined(NO_UNION_WAIT) || defined(_POSIX_SOURCE)
+#if defined(POSIX)
int status;
#else
union wait status;
@@ -364,7 +364,11 @@ static void signal_child()
int pid, old_errno = errno;
do {
+#ifdef POSIX
+ pid = waitpid(-1, &status, WNOHANG);
+#else
pid = wait3(&status, WNOHANG, (struct rusage *)0);
+#endif
} while (pid != 0 && pid != -1);
errno = old_errno;
}
@@ -372,21 +376,50 @@ static void signal_child()
static void setup_signals(dofork)
int dofork;
{
- if (dofork) {
- /* Ignore keyboard signals if forking. Bad things will happen. */
- signal(SIGINT, SIG_IGN);
- signal(SIGTSTP, SIG_IGN);
- signal(SIGQUIT, SIG_IGN);
- } else {
- /* clean up on SIGINT. exiting on logout is the user's problem, now. */
- signal(SIGINT, signal_exit);
- }
-
- /* behavior never changes */
- signal(SIGTERM, signal_exit);
- signal(SIGHUP, signal_exit);
- signal(SIGCHLD, signal_child);
- signal(SIGPIPE, SIG_IGN); /* so that Xlib gets an error */
+#ifdef POSIX
+ struct sigaction sa;
+
+ sigemptyset(&sa.sa_mask);
+ sa.sa_flags = 0;
+
+ if (dofork) {
+ sa.sa_handler = SIG_IGN;
+ sigaction(SIGINT, &sa, (struct sigaction *)0);
+ sigaction(SIGTSTP, &sa, (struct sigaction *)0);
+ sigaction(SIGQUIT, &sa, (struct sigaction *)0);
+ } else {
+ /* clean up on SIGINT; exiting on logout is the user's problem, now. */
+ sa.sa_handler = signal_exit;
+ sigaction(SIGINT, &sa, (struct sigaction *)0);
+ }
+
+ /* behavior never changes */
+ sa.sa_handler = signal_exit;
+ sigaction(SIGTERM, &sa, (struct sigaction *)0);
+ sigaction(SIGHUP, &sa, (struct sigaction *)0);
+
+ sa.sa_handler = signal_child;
+ sigaction(SIGCHLD, &sa, (struct sigaction *)0);
+
+ sa.sa_handler = SIG_IGN;
+ sigaction(SIGPIPE, &sa, (struct sigaction *)0);
+#else
+ if (dofork) {
+ /* Ignore keyboard signals if forking. Bad things will happen. */
+ signal(SIGINT, SIG_IGN);
+ signal(SIGTSTP, SIG_IGN);
+ signal(SIGQUIT, SIG_IGN);
+ } else {
+ /* clean up on SIGINT; exiting on logout is the user's problem, now. */
+ signal(SIGINT, signal_exit);
+ }
+
+ /* behavior never changes */
+ signal(SIGTERM, signal_exit);
+ signal(SIGHUP, signal_exit);
+ signal(SIGCHLD, signal_child);
+ signal(SIGPIPE, SIG_IGN); /* so that Xlib gets an error */
+#endif
}
/* detach() taken from old zwgc, with lots of stuff ripped out */