annotate lib-src/=timer.c @ 9539:164a7cb8d0ea

(shell-command, shell-command-on-region): Rename arg FLAG to OUTPUT-BUFFER and allow it to be a buffer.
author Richard M. Stallman <rms@gnu.org>
date Sat, 15 Oct 1994 10:16:09 +0000
parents dd3b83e4ceb0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
998
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
1 /* timer.c --- daemon to provide a tagged interval timer service
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
2
5634
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
3 This little daemon runs forever waiting for commands to schedule events.
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
4 SIGALRM causes
998
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
5 it to check its queue for events attached to the current second; if
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
6 one is found, its label is written to stdout. SIGTERM causes it to
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
7 terminate, printing a list of pending events.
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
8
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
9 This program is intended to be used with the lisp package called
5634
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
10 timer.el. The first such program was written anonymously in 1990.
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
11 This version was documented and rewritten for portability by
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
12 esr@snark.thyrsus.com, Aug 7 1992. */
998
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
13
45
a55a3ac41924 Initial revision
root <root>
parents:
diff changeset
14 #include <stdio.h>
a55a3ac41924 Initial revision
root <root>
parents:
diff changeset
15 #include <signal.h>
5634
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
16 #include <errno.h>
958
cc82116a8f1c *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 621
diff changeset
17 #include <sys/types.h> /* time_t */
cc82116a8f1c *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 621
diff changeset
18
4696
1fc792473491 Include <config.h> instead of "config.h".
Roland McGrath <roland@gnu.org>
parents: 4392
diff changeset
19 #include <../src/config.h>
5634
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
20 #undef read
45
a55a3ac41924 Initial revision
root <root>
parents:
diff changeset
21
3392
0cab056764c8 [LINUX]: #undef signal.
Richard M. Stallman <rms@gnu.org>
parents: 2820
diff changeset
22 #ifdef LINUX
0cab056764c8 [LINUX]: #undef signal.
Richard M. Stallman <rms@gnu.org>
parents: 2820
diff changeset
23 /* Perhaps this is correct unconditionally. */
0cab056764c8 [LINUX]: #undef signal.
Richard M. Stallman <rms@gnu.org>
parents: 2820
diff changeset
24 #undef signal
0cab056764c8 [LINUX]: #undef signal.
Richard M. Stallman <rms@gnu.org>
parents: 2820
diff changeset
25 #endif
5634
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
26 #ifdef _CX_UX
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
27 /* I agree with the comment above, this probably should be unconditional (it
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
28 * is already unconditional in a couple of other files in this directory),
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
29 * but in the spirit of minimizing the effects of my port, I am making it
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
30 * conditional on _CX_UX.
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
31 */
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
32 #undef signal
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
33 #endif
3392
0cab056764c8 [LINUX]: #undef signal.
Richard M. Stallman <rms@gnu.org>
parents: 2820
diff changeset
34
0cab056764c8 [LINUX]: #undef signal.
Richard M. Stallman <rms@gnu.org>
parents: 2820
diff changeset
35
45
a55a3ac41924 Initial revision
root <root>
parents:
diff changeset
36 extern int errno;
8857
76dea5c39776 Don't declare malloc.
Richard M. Stallman <rms@gnu.org>
parents: 8241
diff changeset
37 extern char *strerror ();
998
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
38 extern time_t time ();
958
cc82116a8f1c *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 621
diff changeset
39
cc82116a8f1c *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 621
diff changeset
40 /*
5634
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
41 * The field separator for input. This character shouldn't occur in dates,
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
42 * and should be printable so event strings are readable by people.
958
cc82116a8f1c *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 621
diff changeset
43 */
cc82116a8f1c *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 621
diff changeset
44 #define FS '@'
45
a55a3ac41924 Initial revision
root <root>
parents:
diff changeset
45
958
cc82116a8f1c *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 621
diff changeset
46 struct event
998
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
47 {
958
cc82116a8f1c *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 621
diff changeset
48 char *token;
cc82116a8f1c *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 621
diff changeset
49 time_t reply_at;
998
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
50 };
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
51 int events_size; /* How many slots have we allocated? */
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
52 int num_events; /* How many are actually scheduled? */
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
53 struct event *events; /* events[0 .. num_events-1] are the
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
54 valid events. */
45
a55a3ac41924 Initial revision
root <root>
parents:
diff changeset
55
5634
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
56 char *pname; /* program name for error messages */
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
57
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
58 /* This buffer is used for reading commands.
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
59 We make it longer when necessary, but we never free it. */
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
60 char *buf;
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
61 /* This is the allocated size of buf. */
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
62 int buf_size;
45
a55a3ac41924 Initial revision
root <root>
parents:
diff changeset
63
5634
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
64 /* Non-zero means don't handle an alarm now;
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
65 instead, just set alarm_deferred if an alarm happens.
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
66 We set this around parts of the program that call malloc and free. */
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
67 int defer_alarms;
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
68
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
69 /* Non-zero if an alarm came in during the reading of a command. */
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
70 int alarm_deferred;
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
71
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
72 /* Schedule one event, and arrange an alarm for it.
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
73 STR is a string of two fields separated by FS.
2813
89b1121e2d43 * timer.c: Fix mispellings of get_date function's name.
Jim Blandy <jimb@redhat.com>
parents: 2592
diff changeset
74 First field is string for get_date, saying when to wake-up.
998
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
75 Second field is a token to identify the request. */
5634
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
76
998
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
77 void
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
78 schedule (str)
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
79 char *str;
45
a55a3ac41924 Initial revision
root <root>
parents:
diff changeset
80 {
2813
89b1121e2d43 * timer.c: Fix mispellings of get_date function's name.
Jim Blandy <jimb@redhat.com>
parents: 2592
diff changeset
81 extern time_t get_date ();
998
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
82 extern char *strcpy ();
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
83 time_t now;
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
84 register char *p;
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
85 static struct event *ep;
5634
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
86
998
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
87 /* check entry format */
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
88 for (p = str; *p && *p != FS; p++)
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
89 continue;
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
90 if (!*p)
958
cc82116a8f1c *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 621
diff changeset
91 {
1751
fac61b478a41 Also, write a newline after the token.
Michael I. Bushnell <mib@gnu.org>
parents: 1750
diff changeset
92 fprintf (stderr, "%s: bad input format: %s\n", pname, str);
998
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
93 return;
958
cc82116a8f1c *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 621
diff changeset
94 }
998
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
95 *p++ = 0;
45
a55a3ac41924 Initial revision
root <root>
parents:
diff changeset
96
998
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
97 /* allocate an event slot */
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
98 ep = events + num_events;
958
cc82116a8f1c *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 621
diff changeset
99
998
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
100 /* If the event array is full, stretch it. After stretching, we know
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
101 that ep will be pointing to an available event spot. */
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
102 if (ep == events + events_size)
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
103 {
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
104 int old_size = events_size;
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
105
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
106 events_size *= 2;
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
107 events = ((struct event *)
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
108 realloc (events, events_size * sizeof (struct event)));
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
109 if (! events)
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
110 {
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
111 fprintf (stderr, "%s: virtual memory exhausted.\n", pname);
5634
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
112 /* Since there is so much virtual memory, and running out
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
113 almost surely means something is very very wrong,
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
114 it is best to exit rather than continue. */
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
115 exit (1);
998
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
116 }
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
117
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
118 while (old_size < events_size)
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
119 events[old_size++].token = NULL;
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
120 }
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
121
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
122 /* Don't allow users to schedule events in past time. */
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
123 ep->reply_at = get_date (str, NULL);
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
124 if (ep->reply_at - time (&now) < 0)
958
cc82116a8f1c *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 621
diff changeset
125 {
1751
fac61b478a41 Also, write a newline after the token.
Michael I. Bushnell <mib@gnu.org>
parents: 1750
diff changeset
126 fprintf (stderr, "%s: bad time spec: %s%c%s\n", pname, str, FS, p);
998
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
127 return;
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
128 }
45
a55a3ac41924 Initial revision
root <root>
parents:
diff changeset
129
998
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
130 /* save the event description */
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
131 ep->token = (char *) malloc ((unsigned) strlen (p) + 1);
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
132 if (! ep->token)
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
133 {
1751
fac61b478a41 Also, write a newline after the token.
Michael I. Bushnell <mib@gnu.org>
parents: 1750
diff changeset
134 fprintf (stderr, "%s: malloc %s: %s%c%s\n",
5525
1d84e80b47a4 Don't declare sys_errlist; declare strerror instead.
Roland McGrath <roland@gnu.org>
parents: 4696
diff changeset
135 pname, strerror (errno), str, FS, p);
998
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
136 return;
958
cc82116a8f1c *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 621
diff changeset
137 }
998
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
138
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
139 strcpy (ep->token, p);
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
140 num_events++;
45
a55a3ac41924 Initial revision
root <root>
parents:
diff changeset
141 }
5634
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
142
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
143 /* Print the notification for the alarmed event just arrived if any,
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
144 and schedule an alarm for the next event if any. */
45
a55a3ac41924 Initial revision
root <root>
parents:
diff changeset
145
a55a3ac41924 Initial revision
root <root>
parents:
diff changeset
146 void
998
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
147 notify ()
958
cc82116a8f1c *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 621
diff changeset
148 {
1995
f149ad4ad9d4 * timer.c (notify): Initialize waitfor properly.
Jim Blandy <jimb@redhat.com>
parents: 1751
diff changeset
149 time_t now, tdiff, waitfor = -1;
998
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
150 register struct event *ep;
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
151
5634
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
152 /* Inhibit interference with alarms while changing global vars. */
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
153 defer_alarms = 1;
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
154 alarm_deferred = 0;
2592
2e57e16282f0 (notify): Bug fix. Treat the body of this function as a critical region.
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2102
diff changeset
155
998
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
156 now = time ((time_t *) NULL);
45
a55a3ac41924 Initial revision
root <root>
parents:
diff changeset
157
998
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
158 for (ep = events; ep < events + num_events; ep++)
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
159 /* Are any events ready to fire? */
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
160 if (ep->reply_at <= now)
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
161 {
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
162 fputs (ep->token, stdout);
1750
2a92e870a448 Also, write a newline after the token.
Michael I. Bushnell <mib@gnu.org>
parents: 1749
diff changeset
163 putc ('\n', stdout);
1746
7c4fc10fde41 timer.c (notify): Flush stdout after writing message to avoid lossage
Michael I. Bushnell <mib@gnu.org>
parents: 998
diff changeset
164 fflush (stdout);
998
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
165 free (ep->token);
45
a55a3ac41924 Initial revision
root <root>
parents:
diff changeset
166
998
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
167 /* We now have a hole in the event array; fill it with the last
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
168 event. */
2592
2e57e16282f0 (notify): Bug fix. Treat the body of this function as a critical region.
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2102
diff changeset
169 ep->token = events[num_events - 1].token;
2e57e16282f0 (notify): Bug fix. Treat the body of this function as a critical region.
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2102
diff changeset
170 ep->reply_at = events[num_events - 1].reply_at;
998
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
171 num_events--;
45
a55a3ac41924 Initial revision
root <root>
parents:
diff changeset
172
998
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
173 /* We ought to scan this event again. */
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
174 ep--;
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
175 }
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
176 else
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
177 {
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
178 /* next timeout should be the soonest of any remaining */
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
179 if ((tdiff = ep->reply_at - now) < waitfor || waitfor < 0)
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
180 waitfor = (long)tdiff;
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
181 }
958
cc82116a8f1c *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 621
diff changeset
182
998
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
183 /* If there are no more events, we needn't bother setting an alarm. */
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
184 if (num_events > 0)
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
185 alarm (waitfor);
2592
2e57e16282f0 (notify): Bug fix. Treat the body of this function as a critical region.
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2102
diff changeset
186
5634
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
187 /* Now check if there was another alarm
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
188 while we were handling an explicit request. */
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
189 defer_alarms = 0;
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
190 if (alarm_deferred)
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
191 notify ();
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
192 alarm_deferred = 0;
45
a55a3ac41924 Initial revision
root <root>
parents:
diff changeset
193 }
5634
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
194
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
195 /* Read one command from command from standard input
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
196 and schedule the event for it. */
45
a55a3ac41924 Initial revision
root <root>
parents:
diff changeset
197
a55a3ac41924 Initial revision
root <root>
parents:
diff changeset
198 void
998
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
199 getevent ()
958
cc82116a8f1c *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 621
diff changeset
200 {
998
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
201 int i;
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
202
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
203 /* In principle the itimer should be disabled on entry to this
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
204 function, but it really doesn't make any important difference
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
205 if it isn't. */
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
206
5634
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
207 if (buf == 0)
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
208 {
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
209 buf_size = 80;
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
210 buf = (char *) malloc (buf_size);
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
211 }
45
a55a3ac41924 Initial revision
root <root>
parents:
diff changeset
212
998
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
213 /* Read a line from standard input, expanding buf if it is too short
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
214 to hold the line. */
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
215 for (i = 0; ; i++)
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
216 {
5634
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
217 char c;
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
218 int nread;
998
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
219
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
220 if (i >= buf_size)
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
221 {
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
222 buf_size *= 2;
5634
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
223 alarm_deferred = 0;
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
224 defer_alarms = 1;
998
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
225 buf = (char *) realloc (buf, buf_size);
5634
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
226 defer_alarms = 0;
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
227 if (alarm_deferred)
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
228 notify ();
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
229 alarm_deferred = 0;
998
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
230 }
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
231
5634
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
232 /* Read one character into c. */
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
233 while (1)
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
234 {
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
235 nread = read (fileno (stdin), &c, 1);
998
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
236
5634
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
237 /* Retry after transient error. */
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
238 if (nread < 0
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
239 && (1
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
240 #ifdef EINTR
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
241 || errno == EINTR
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
242 #endif
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
243 #ifdef EAGAIN
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
244 || errno == EAGAIN
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
245 #endif
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
246 ))
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
247 continue;
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
248
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
249 /* Report serious errors. */
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
250 if (nread < 0)
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
251 {
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
252 perror ("read");
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
253 exit (1);
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
254 }
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
255
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
256 /* On eof, exit. */
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
257 if (nread == 0)
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
258 exit (0);
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
259
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
260 break;
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
261 }
45
a55a3ac41924 Initial revision
root <root>
parents:
diff changeset
262
998
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
263 if (c == '\n')
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
264 {
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
265 buf[i] = '\0';
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
266 break;
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
267 }
45
a55a3ac41924 Initial revision
root <root>
parents:
diff changeset
268
998
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
269 buf[i] = c;
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
270 }
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
271
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
272 /* Register the event. */
5634
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
273 alarm_deferred = 0;
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
274 defer_alarms = 1;
998
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
275 schedule (buf);
5634
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
276 defer_alarms = 0;
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
277 notify ();
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
278 alarm_deferred = 0;
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
279 }
998
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
280
5634
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
281 /* Handle incoming signal SIG. */
45
a55a3ac41924 Initial revision
root <root>
parents:
diff changeset
282
2102
b11495a4ecdf * timer.c (main): Set the ownership of the stdin file descriptor
Jim Blandy <jimb@redhat.com>
parents: 1995
diff changeset
283 SIGTYPE
998
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
284 sigcatch (sig)
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
285 int sig;
958
cc82116a8f1c *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 621
diff changeset
286 {
998
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
287 struct event *ep;
45
a55a3ac41924 Initial revision
root <root>
parents:
diff changeset
288
5634
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
289 /* required on older UNIXes; harmless on newer ones */
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
290 signal (sig, sigcatch);
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
291
998
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
292 switch (sig)
958
cc82116a8f1c *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 621
diff changeset
293 {
cc82116a8f1c *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 621
diff changeset
294 case SIGALRM:
5634
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
295 if (defer_alarms)
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
296 alarm_deferred = 1;
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
297 else
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
298 notify ();
998
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
299 break;
958
cc82116a8f1c *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 621
diff changeset
300 case SIGTERM:
998
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
301 fprintf (stderr, "Events still queued:\n");
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
302 for (ep = events; ep < events + num_events; ep++)
1751
fac61b478a41 Also, write a newline after the token.
Michael I. Bushnell <mib@gnu.org>
parents: 1750
diff changeset
303 fprintf (stderr, "%d = %ld @ %s\n",
998
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
304 ep - events, ep->reply_at, ep->token);
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
305 exit (0);
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
306 break;
958
cc82116a8f1c *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 621
diff changeset
307 }
45
a55a3ac41924 Initial revision
root <root>
parents:
diff changeset
308 }
958
cc82116a8f1c *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 621
diff changeset
309
45
a55a3ac41924 Initial revision
root <root>
parents:
diff changeset
310 /*ARGSUSED*/
a55a3ac41924 Initial revision
root <root>
parents:
diff changeset
311 int
998
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
312 main (argc, argv)
45
a55a3ac41924 Initial revision
root <root>
parents:
diff changeset
313 int argc;
a55a3ac41924 Initial revision
root <root>
parents:
diff changeset
314 char **argv;
a55a3ac41924 Initial revision
root <root>
parents:
diff changeset
315 {
998
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
316 for (pname = argv[0] + strlen (argv[0]);
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
317 *pname != '/' && pname != argv[0];
45
a55a3ac41924 Initial revision
root <root>
parents:
diff changeset
318 pname--);
998
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
319 if (*pname == '/')
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
320 pname++;
45
a55a3ac41924 Initial revision
root <root>
parents:
diff changeset
321
998
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
322 events_size = 16;
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
323 events = ((struct event *) malloc (events_size * sizeof (*events)));
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
324 num_events = 0;
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
325
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
326 signal (SIGALRM, sigcatch);
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 958
diff changeset
327 signal (SIGTERM, sigcatch);
958
cc82116a8f1c *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 621
diff changeset
328
5634
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
329 /* Loop reading commands from standard input
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
330 and scheduling alarms accordingly.
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
331 The alarms are handled asynchronously, while we wait for commands. */
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
332 while (1)
e77e9d7386be Include errno.h; don't include fasync.h.
Richard M. Stallman <rms@gnu.org>
parents: 5571
diff changeset
333 getevent ();
45
a55a3ac41924 Initial revision
root <root>
parents:
diff changeset
334 }
5527
51451a050975 [! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents: 5525
diff changeset
335
51451a050975 [! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents: 5525
diff changeset
336 #ifndef HAVE_STRERROR
51451a050975 [! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents: 5525
diff changeset
337 char *
51451a050975 [! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents: 5525
diff changeset
338 strerror (errnum)
51451a050975 [! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents: 5525
diff changeset
339 int errnum;
51451a050975 [! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents: 5525
diff changeset
340 {
51451a050975 [! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents: 5525
diff changeset
341 extern char *sys_errlist[];
51451a050975 [! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents: 5525
diff changeset
342 extern int sys_nerr;
51451a050975 [! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents: 5525
diff changeset
343
51451a050975 [! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents: 5525
diff changeset
344 if (errnum >= 0 && errnum < sys_nerr)
51451a050975 [! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents: 5525
diff changeset
345 return sys_errlist[errnum];
51451a050975 [! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents: 5525
diff changeset
346 return (char *) "Unknown error";
51451a050975 [! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents: 5525
diff changeset
347 }
51451a050975 [! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents: 5525
diff changeset
348
51451a050975 [! HAVE_STRERROR] (strerror): Define the function.
Roland McGrath <roland@gnu.org>
parents: 5525
diff changeset
349 #endif /* ! HAVE_STRERROR */
958
cc82116a8f1c *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 621
diff changeset
350
8241
a16dfe068972 (xmalloc): New function.
Richard M. Stallman <rms@gnu.org>
parents: 5634
diff changeset
351 long *
a16dfe068972 (xmalloc): New function.
Richard M. Stallman <rms@gnu.org>
parents: 5634
diff changeset
352 xmalloc (size)
a16dfe068972 (xmalloc): New function.
Richard M. Stallman <rms@gnu.org>
parents: 5634
diff changeset
353 int size;
a16dfe068972 (xmalloc): New function.
Richard M. Stallman <rms@gnu.org>
parents: 5634
diff changeset
354 {
a16dfe068972 (xmalloc): New function.
Richard M. Stallman <rms@gnu.org>
parents: 5634
diff changeset
355 register long *val;
a16dfe068972 (xmalloc): New function.
Richard M. Stallman <rms@gnu.org>
parents: 5634
diff changeset
356
a16dfe068972 (xmalloc): New function.
Richard M. Stallman <rms@gnu.org>
parents: 5634
diff changeset
357 val = (long *) malloc (size);
a16dfe068972 (xmalloc): New function.
Richard M. Stallman <rms@gnu.org>
parents: 5634
diff changeset
358
a16dfe068972 (xmalloc): New function.
Richard M. Stallman <rms@gnu.org>
parents: 5634
diff changeset
359 if (!val && size)
a16dfe068972 (xmalloc): New function.
Richard M. Stallman <rms@gnu.org>
parents: 5634
diff changeset
360 {
a16dfe068972 (xmalloc): New function.
Richard M. Stallman <rms@gnu.org>
parents: 5634
diff changeset
361 fprintf (stderr, "timer: virtual memory exceeded\n");
a16dfe068972 (xmalloc): New function.
Richard M. Stallman <rms@gnu.org>
parents: 5634
diff changeset
362 exit (1);
a16dfe068972 (xmalloc): New function.
Richard M. Stallman <rms@gnu.org>
parents: 5634
diff changeset
363 }
a16dfe068972 (xmalloc): New function.
Richard M. Stallman <rms@gnu.org>
parents: 5634
diff changeset
364
a16dfe068972 (xmalloc): New function.
Richard M. Stallman <rms@gnu.org>
parents: 5634
diff changeset
365 return val;
a16dfe068972 (xmalloc): New function.
Richard M. Stallman <rms@gnu.org>
parents: 5634
diff changeset
366 }
a16dfe068972 (xmalloc): New function.
Richard M. Stallman <rms@gnu.org>
parents: 5634
diff changeset
367
958
cc82116a8f1c *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 621
diff changeset
368 /* timer.c ends here */