~ubuntu-branches/ubuntu/vivid/postfix/vivid-proposed

« back to all changes in this revision

Viewing changes to src/util/watchdog.c

  • Committer: Bazaar Package Importer
  • Author(s): LaMont Jones
  • Date: 2011-02-22 05:26:41 UTC
  • mto: (33.1.4 natty) (39.1.4 oneiric)
  • mto: This revision was merged to the branch mainline in revision 36.
  • Revision ID: james.westby@ubuntu.com-20110222052641-9kcxe1gt157c31j9
Tags: upstream-2.8.0
ImportĀ upstreamĀ versionĀ 2.8.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
119
119
  */
120
120
static WATCHDOG *watchdog_curr;
121
121
 
 
122
 /*
 
123
  * Workaround for systems where the alarm signal does not wakeup the event
 
124
  * machinery, and therefore does not restart the watchdog timer in the
 
125
  * single_server etc. skeletons. The symptom is that programs abort when the
 
126
  * watchdog timeout is less than the max_idle time.
 
127
  */
 
128
#ifdef USE_WATCHDOG_PIPE
 
129
#include <errno.h>
 
130
#include <iostuff.h>
 
131
#include <events.h>
 
132
 
 
133
static int watchdog_pipe[2];
 
134
 
 
135
/* watchdog_read - read event pipe */
 
136
 
 
137
static void watchdog_read(int unused_event, char *unused_context)
 
138
{
 
139
    char    ch;
 
140
 
 
141
    while (read(watchdog_pipe[0], &ch, 1) > 0)
 
142
         /* void */ ;
 
143
}
 
144
 
 
145
#endif                                  /* USE_WATCHDOG_PIPE */
 
146
 
122
147
/* watchdog_event - handle timeout event */
123
148
 
124
149
static void watchdog_event(int unused_sig)
137
162
    if (msg_verbose > 1)
138
163
        msg_info("%s: %p %d", myname, (void *) wp, wp->trip_run);
139
164
    if (++(wp->trip_run) < WATCHDOG_STEPS) {
 
165
#ifdef USE_WATCHDOG_PIPE
 
166
        int     saved_errno = errno;
 
167
 
 
168
        /* Wake up the events(3) engine. */
 
169
        if (write(watchdog_pipe[1], "", 1) != 1)
 
170
            msg_warn("%s: write watchdog_pipe: %m", myname);
 
171
        errno = saved_errno;
 
172
#endif
140
173
        alarm(wp->timeout);
141
174
    } else {
142
175
        if (wp->action)
177
210
        msg_fatal("%s: sigaction(SIGALRM): %m", myname);
178
211
    if (msg_verbose > 1)
179
212
        msg_info("%s: %p %d", myname, (void *) wp, timeout);
 
213
#ifdef USE_WATCHDOG_PIPE
 
214
    if (watchdog_curr == 0) {
 
215
        if (pipe(watchdog_pipe) < 0)
 
216
            msg_fatal("%s: pipe: %m", myname);
 
217
        non_blocking(watchdog_pipe[0], NON_BLOCKING);
 
218
        non_blocking(watchdog_pipe[1], NON_BLOCKING);
 
219
        event_enable_read(watchdog_pipe[0], watchdog_read, (char *) 0);
 
220
    }
 
221
#endif
180
222
    return (watchdog_curr = wp);
181
223
}
182
224
 
193
235
    if (wp->saved_time)
194
236
        alarm(wp->saved_time);
195
237
    myfree((char *) wp);
 
238
#ifdef USE_WATCHDOG_PIPE
 
239
    if (watchdog_curr == 0) {
 
240
        event_disable_readwrite(watchdog_pipe[0]);
 
241
        (void) close(watchdog_pipe[0]);
 
242
        (void) close(watchdog_pipe[1]);
 
243
    }
 
244
#endif
196
245
    if (msg_verbose > 1)
197
246
        msg_info("%s: %p", myname, (void *) wp);
198
247
}