summaryrefslogtreecommitdiff
path: root/zwgc
diff options
context:
space:
mode:
authorGravatar Greg Hudson <ghudson@mit.edu>2004-06-23 22:27:34 +0000
committerGravatar Greg Hudson <ghudson@mit.edu>2004-06-23 22:27:34 +0000
commit90881ab99434e9a49e0238b8c7df5c429ff9bd0a (patch)
treeab50176895d7ba2caf4f8835e91a8f7aca17e021 /zwgc
parent7ca14878db2542986e5128baa020773f5d2f4a20 (diff)
Rewrite the wgfile on SIGUSR1.
Diffstat (limited to 'zwgc')
-rw-r--r--zwgc/main.c10
-rw-r--r--zwgc/zephyr.c37
-rw-r--r--zwgc/zephyr.h1
-rw-r--r--zwgc/zwgc.17
4 files changed, 41 insertions, 14 deletions
diff --git a/zwgc/main.c b/zwgc/main.c
index 83413da..52b9e7a 100644
--- a/zwgc/main.c
+++ b/zwgc/main.c
@@ -461,6 +461,12 @@ static RETSIGTYPE signal_child()
errno = old_errno;
}
+/* rewrite the wgfile in case it has gone away */
+static RETSIGTYPE signal_usr1()
+{
+ write_wgfile();
+}
+
static void setup_signals(dofork)
int dofork;
{
@@ -493,6 +499,9 @@ static void setup_signals(dofork)
sa.sa_handler = signal_child;
sigaction(SIGCHLD, &sa, (struct sigaction *)0);
+ sa.sa_handler = signal_usr1;
+ sigaction(SIGUSR1, &sa, (struct sigaction *)0);
+
#else /* !POSIX */
if (dofork) {
/* Ignore keyboard signals if forking. Bad things will happen. */
@@ -510,6 +519,7 @@ static void setup_signals(dofork)
signal(SIGHUP, signal_exit);
signal(SIGCHLD, signal_child);
signal(SIGPIPE, SIG_IGN); /* so that Xlib gets an error */
+ signal(SIGUSR1, signal_usr1);
#endif
}
diff --git a/zwgc/zephyr.c b/zwgc/zephyr.c
index c3276e5..9ad8dbe 100644
--- a/zwgc/zephyr.c
+++ b/zwgc/zephyr.c
@@ -43,6 +43,9 @@ static const char rcsid_zephyr_c[] = "$Id$";
extern int zwgc_debug;
#endif /* DEBUG */
+static int zephyr_inited = 0;
+static unsigned short zephyr_port = 0;
+
/*
* Internal Routine:
*
@@ -70,6 +73,25 @@ static string get_zwgc_port_number_filename()
}
/*
+ * Write out the port number to the wg file.
+ */
+
+void write_wgfile()
+{
+ char *name = get_zwgc_port_number_filename();
+ FILE *port_file;
+
+ port_file = fopen(name, "w");
+ if (port_file) {
+ fprintf(port_file, "%d\n", zephyr_port);
+ fclose(port_file);
+ } else {
+ fprintf(stderr, "zwgc: error while opening %s for writing: ", name);
+ perror("");
+ }
+}
+
+/*
*
*/
@@ -98,8 +120,6 @@ static void handle_zephyr_input(notice_handler)
}
}
-static int zephyr_inited = 0;
-
/*
*
*/
@@ -107,7 +127,6 @@ static int zephyr_inited = 0;
void zephyr_init(notice_handler)
void (*notice_handler)();
{
- unsigned short port = 0; /* Use any old port */
char *temp;
char *exposure;
char *tty = NULL;
@@ -117,14 +136,13 @@ void zephyr_init(notice_handler)
* Initialize zephyr. If error, print error message & exit.
*/
FATAL_TRAP( ZInitialize(), "while initializing Zephyr" );
- FATAL_TRAP( ZOpenPort(&port), "while opening Zephyr port" );
+ FATAL_TRAP( ZOpenPort(&zephyr_port), "while opening Zephyr port" );
/*
* Save away our port number in a special place so that zctl and
* other clients can send us control messages: <<<>>>
*/
temp = get_zwgc_port_number_filename();
- errno = 0;
port_file = fopen(temp, "r");
if (port_file) {
fprintf(stderr, "zwgc: windowgram file already exists. If you are\n");
@@ -132,14 +150,7 @@ void zephyr_init(notice_handler)
fprintf(stderr, "zwgc: and try again.\n");
exit(1);
}
- port_file = fopen(temp, "w");
- if (port_file) {
- fprintf(port_file, "%d\n", port);
- fclose(port_file);
- } else {
- fprintf(stderr, "zwgc: error while opening %s for writing: ", temp);
- perror("");
- }
+ write_wgfile();
/* Set hostname and tty for locations. If we support X, use the
* display string for the default tty name. */
diff --git a/zwgc/zephyr.h b/zwgc/zephyr.h
index d2e3735..98265df 100644
--- a/zwgc/zephyr.h
+++ b/zwgc/zephyr.h
@@ -19,5 +19,6 @@
extern void zephyr_init();
extern void finalize_zephyr();
+extern void write_wgfile();
#endif
diff --git a/zwgc/zwgc.1 b/zwgc/zwgc.1
index 48ab388..880d2ad 100644
--- a/zwgc/zwgc.1
+++ b/zwgc/zwgc.1
@@ -963,7 +963,12 @@ SIGINT, SIGQUIT, and SIGTSTP are ignored because they can be sent
inadvertently, and bizarre side-effects can result. If you want them
to be acted on, then run
.I zwgc -nofork &
-
+.PP
+If
+.I zwgc
+receives a SIGUSR1, it will rewrite the file used to store the
+WindowGram port number ($WGFILE or /tmp/wg.\fIuid\fR), in the event
+that the file has been lost.
.SH CONTROL MESSAGES
In order to allow some special user controls over the behavior of
.IR zwgc ,