~ubuntu-branches/debian/squeeze/ntp/squeeze-201010051545

« back to all changes in this revision

Viewing changes to libntp/iosignal.c

  • Committer: Bazaar Package Importer
  • Author(s): Matt Zimmerman
  • Date: 2004-10-11 16:10:27 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20041011161027-icyjbji8ujym633o
Tags: 1:4.2.0a-10ubuntu2
Use ntp.ubuntulinux.org instead of pool.ntp.org

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * ntp_io.c - input/output routines for ntpd.   The socket-opening code
 
2
 * iosignal.c - input/output routines for ntpd. The socket-opening code
3
3
 *                 was shamelessly stolen from ntpd.
4
4
 */
5
5
 
6
 
#include "ntp_machine.h"
7
 
#include "ntpd.h"
8
 
#include "ntp_io.h"
9
 
#include "ntp_if.h"
10
 
#include "ntp_stdlib.h"
11
 
#include "iosignal.h"
 
6
/*
 
7
 * [Bug 158]
 
8
 * Do the #includes differently, as under some versions of Linux
 
9
 * sys/param.h has a #undef CONFIG_PHONE line in it.
 
10
 *
 
11
 * As we have ~40 CONFIG_ variables, I don't feel like renaming them
 
12
 * every time somebody adds a new macro to some system header.
 
13
 */
 
14
 
 
15
#ifdef HAVE_CONFIG_H
 
16
# include <config.h>
 
17
#endif
12
18
 
13
19
#include <stdio.h>
14
20
#include <signal.h>
25
31
# include <ifaddrs.h>
26
32
#endif
27
33
 
 
34
#include "ntp_machine.h"
 
35
#include "ntpd.h"
 
36
#include "ntp_io.h"
 
37
#include "ntp_if.h"
 
38
#include "ntp_stdlib.h"
 
39
#include "iosignal.h"
 
40
 
28
41
#if defined(HAVE_SIGNALED_IO)
29
42
static int sigio_block_count = 0;
 
43
# if defined(HAVE_SIGACTION)
 
44
/*
 
45
 * If sigaction() is used for signal handling and a signal is
 
46
 * pending then the kernel blocks the signal before it calls
 
47
 * the signal handler.
 
48
 *
 
49
 * The variable below is used to take care that the SIGIO signal
 
50
 * is not unintentionally unblocked inside the sigio_handler()
 
51
 * if the handler executes a piece of code that is normally
 
52
 * bracketed by BLOCKIO()/UNBLOCKIO() calls.
 
53
 */
 
54
static int sigio_handler_active = 0;
 
55
# endif
30
56
extern  void    input_handler   P((l_fp *));
31
57
 
32
58
/*
37
63
 * Some systems (MOST) define SIGPOLL == SIGIO, others SIGIO == SIGPOLL, and
38
64
 * a few have separate SIGIO and SIGPOLL signals.  This code checks for the
39
65
 * SIGIO == SIGPOLL case at compile time.
40
 
 * Do not defined USE_SIGPOLL or USE_SIGIO.
41
 
 * these are interal only to ntp_io.c!
 
66
 * Do not define USE_SIGPOLL or USE_SIGIO.
 
67
 * these are interal only to iosignal.c!
42
68
 */
43
69
# if defined(USE_SIGPOLL)
44
70
#  undef USE_SIGPOLL
55
81
#  define USE_SIGIO
56
82
# endif
57
83
 
 
84
# ifdef __QNXNTO__
 
85
#  include <fcntl.h>
 
86
#  include <unix.h>
 
87
#  define FNDELAY O_NDELAY
 
88
# endif
 
89
 
58
90
# if defined(USE_SIGIO) && defined(USE_SIGPOLL)
59
91
#  if SIGIO == SIGPOLL
60
92
#       define USE_SIGIO
282
314
        l_fp ts;
283
315
 
284
316
        get_systime(&ts);
 
317
 
 
318
# if defined(HAVE_SIGACTION)
 
319
        sigio_handler_active++;
 
320
        if (sigio_handler_active != 1)  /* This should never happen! */
 
321
            msyslog(LOG_ERR, "sigio_handler: sigio_handler_active != 1");
 
322
# endif
 
323
 
285
324
        (void)input_handler(&ts);
 
325
 
 
326
# if defined(HAVE_SIGACTION)
 
327
        sigio_handler_active--;
 
328
        if (sigio_handler_active != 0)  /* This should never happen! */
 
329
            msyslog(LOG_ERR, "sigio_handler: sigio_handler_active != 0");
 
330
# endif
 
331
 
286
332
        errno = saved_errno;
287
333
}
288
334
 
326
372
void
327
373
block_sigio(void)
328
374
{
329
 
        sigset_t set;
330
 
 
331
 
        ++sigio_block_count;
332
 
        if (sigio_block_count > 1)
333
 
            msyslog(LOG_INFO, "block_sigio: sigio_block_count > 1");
334
 
        if (sigio_block_count < 1)
335
 
            msyslog(LOG_INFO, "block_sigio: sigio_block_count < 1");
336
 
 
337
 
        if (sigemptyset(&set))
338
 
            msyslog(LOG_ERR, "block_sigio: sigemptyset() failed: %m");
339
 
#  if defined(USE_SIGIO)
340
 
        if (sigaddset(&set, SIGIO))
341
 
            msyslog(LOG_ERR, "block_sigio: sigaddset(SIGIO) failed: %m");
342
 
#  endif
343
 
#  if defined(USE_SIGPOLL)
344
 
        if (sigaddset(&set, SIGPOLL))
345
 
            msyslog(LOG_ERR, "block_sigio: sigaddset(SIGPOLL) failed: %m");
346
 
#  endif
347
 
 
348
 
        if (sigprocmask(SIG_BLOCK, &set, NULL))
349
 
            msyslog(LOG_ERR, "block_sigio: sigprocmask() failed: %m");
 
375
        if ( sigio_handler_active == 0 )  /* not called from within signal handler */
 
376
        {
 
377
                sigset_t set;
 
378
 
 
379
                ++sigio_block_count;
 
380
                if (sigio_block_count > 1)
 
381
                    msyslog(LOG_INFO, "block_sigio: sigio_block_count > 1");
 
382
                if (sigio_block_count < 1)
 
383
                    msyslog(LOG_INFO, "block_sigio: sigio_block_count < 1");
 
384
 
 
385
                if (sigemptyset(&set))
 
386
                    msyslog(LOG_ERR, "block_sigio: sigemptyset() failed: %m");
 
387
#       if defined(USE_SIGIO)
 
388
                if (sigaddset(&set, SIGIO))
 
389
                    msyslog(LOG_ERR, "block_sigio: sigaddset(SIGIO) failed: %m");
 
390
#       endif
 
391
#       if defined(USE_SIGPOLL)
 
392
                if (sigaddset(&set, SIGPOLL))
 
393
                    msyslog(LOG_ERR, "block_sigio: sigaddset(SIGPOLL) failed: %m");
 
394
#       endif
 
395
 
 
396
                if (sigprocmask(SIG_BLOCK, &set, NULL))
 
397
                    msyslog(LOG_ERR, "block_sigio: sigprocmask() failed: %m");
 
398
        }
350
399
}
351
400
 
352
401
void
375
424
void
376
425
unblock_sigio(void)
377
426
{
378
 
        sigset_t unset;
379
 
 
380
 
        --sigio_block_count;
381
 
        if (sigio_block_count > 0)
382
 
            msyslog(LOG_INFO, "unblock_sigio: sigio_block_count > 0");
383
 
        if (sigio_block_count < 0)
384
 
            msyslog(LOG_INFO, "unblock_sigio: sigio_block_count < 0");
385
 
 
386
 
        if (sigemptyset(&unset))
387
 
            msyslog(LOG_ERR, "unblock_sigio: sigemptyset() failed: %m");
388
 
 
389
 
#  if defined(USE_SIGIO)
390
 
        if (sigaddset(&unset, SIGIO))
391
 
            msyslog(LOG_ERR, "unblock_sigio: sigaddset(SIGIO) failed: %m");
392
 
#  endif
393
 
#  if defined(USE_SIGPOLL)
394
 
        if (sigaddset(&unset, SIGPOLL))
395
 
            msyslog(LOG_ERR, "unblock_sigio: sigaddset(SIGPOLL) failed: %m");
396
 
#  endif
397
 
 
398
 
        if (sigprocmask(SIG_UNBLOCK, &unset, NULL))
399
 
            msyslog(LOG_ERR, "unblock_sigio: sigprocmask() failed: %m");
 
427
        if ( sigio_handler_active == 0 )  /* not called from within signal handler */
 
428
        {
 
429
                sigset_t unset;
 
430
 
 
431
                --sigio_block_count;
 
432
                if (sigio_block_count > 0)
 
433
                    msyslog(LOG_INFO, "unblock_sigio: sigio_block_count > 0");
 
434
                if (sigio_block_count < 0)
 
435
                    msyslog(LOG_INFO, "unblock_sigio: sigio_block_count < 0");
 
436
 
 
437
                if (sigemptyset(&unset))
 
438
                    msyslog(LOG_ERR, "unblock_sigio: sigemptyset() failed: %m");
 
439
 
 
440
#       if defined(USE_SIGIO)
 
441
                if (sigaddset(&unset, SIGIO))
 
442
                    msyslog(LOG_ERR, "unblock_sigio: sigaddset(SIGIO) failed: %m");
 
443
#       endif
 
444
#       if defined(USE_SIGPOLL)
 
445
                if (sigaddset(&unset, SIGPOLL))
 
446
                    msyslog(LOG_ERR, "unblock_sigio: sigaddset(SIGPOLL) failed: %m");
 
447
#       endif
 
448
 
 
449
                if (sigprocmask(SIG_UNBLOCK, &unset, NULL))
 
450
                    msyslog(LOG_ERR, "unblock_sigio: sigprocmask() failed: %m");
 
451
        }
400
452
}
401
453
 
402
454
void