CTWM
Loading...
Searching...
No Matches
/usr/src/RPM/BUILD/ctwm-4.1.0/signals.c
Go to the documentation of this file.
1/*
2 * Signal handlers
3 */
4
5#include "ctwm.h"
6
7#include <signal.h>
8#include <stdio.h>
9#include <stdlib.h>
10#include <unistd.h>
11
12#include "ctwm_shutdown.h"
13#include "signals.h"
14
15
16/* Our backends */
17static void sh_restart(int signum);
18static void sh_shutdown(int signum);
19
20
21// Internal flags for which signals have called us
22static bool sig_restart = false;
23static bool sig_shutdown = false;
24
25// External flag for whether some signal handler has set a flag that
26// needs to trigger an action.
27bool SignalFlag = false;
28
29
30/**
31 * Setup signal handlers (run during startup)
32 */
33void
35{
36 // INT/QUIT/TERM: shutdown
37 // XXX Wildly unsafe handler; to be reworked
41
42 // SIGHUP: restart
44
45 // We don't use alarm(), but if we get the stray signal we shouldn't
46 // die...
48
49 // This should be set by default, but just in case; explicitly don't
50 // leave zombies.
52
53 return;
54}
55
56
57/**
58 * Handle stuff set by a signal flag. Could be a Restart, could be a
59 * Shutdown...
60 */
61void
63{
64 // Restarting?
65 if(sig_restart) {
66 // In case it fails, don't loop
67 sig_restart = false;
68
69 // Handle
70 DoRestart(t);
71
72 // Shouldn't return, but exec() might fail...
73 return;
74 }
75
76 // Shutting down?
77 if(sig_shutdown) {
78 // Doit
79 DoShutdown();
80
81 // Can't return!
82 fprintf(stderr, "%s: DoShutdown() shouldn't return!\n", ProgramName);
83 exit(1);
84 }
85
86 // ???
87 fprintf(stderr, "%s: Internal error: unexpected signal flag.\n",
89 return;
90}
91
92
93
94/*
95 * Internal backend bits
96 */
97
98/**
99 * Set flag to restart. Backend for SIGHUP.
100 */
101static void
103{
104 // Signal handler; stdio isn't async-signal-safe, write(2) is
105 const char srf[] = ": signal received, setting restart flag\n";
107 write(2, srf, sizeof(srf));
108
109 SignalFlag = sig_restart = true;
110}
111
112/**
113 * Set flag to shutdown. Backend for SIGTERM etc.
114 */
115static void
117{
118 // Signal handler; stdio isn't async-signal-safe, write(2) is
119 const char srf[] = ": signal received, setting shutdown flag\n";
121 write(2, srf, sizeof(srf));
122
123 SignalFlag = sig_shutdown = true;
124}
125
static int PlaceX
Definition add_window.c:82
char * ProgramName
Definition ctwm_main.c:146
size_t ProgramNameLen
Definition ctwm_main.c:147
void DoShutdown(void)
Cleanup and exit ctwm.
void DoRestart(Time t)
exec() ourself to restart.
static void sh_shutdown(int signum)
Set flag to shutdown.
Definition signals.c:116
void setup_signal_handlers(void)
Setup signal handlers (run during startup)
Definition signals.c:34
static void sh_restart(int signum)
Set flag to restart.
Definition signals.c:102
static bool sig_shutdown
Definition signals.c:23
static bool sig_restart
Definition signals.c:22
bool SignalFlag
Some signal flag has been set.
Definition signals.c:27
void handle_signal_flag(Time t)
Handle stuff set by a signal flag.
Definition signals.c:62