~ubuntu-branches/ubuntu/wily/morse/wily-proposed

« back to all changes in this revision

Viewing changes to .pc/01alarm_time_t.patch/morse.d/alarm.c

  • Committer: Package Import Robot
  • Author(s): Nanakos Chrysostomos
  • Date: 2015-06-10 11:26:20 UTC
  • mfrom: (7.1.3 sid)
  • Revision ID: package-import@ubuntu.com-20150610112620-q00v2tou9427gf42
Tags: 2.5-1
* New upstream release.
* Bump S-V to 3.9.6.
* Clean Lintian messages.
* Fix AlarmSet declaration and definition match (Closes: Bug#749420).
* Update watch file (Closes: Bug#784861).
* Fix build (omit morseALSA and morseLinux) for non-Linux arches
  - drop 02makefile.patch, build and install via debian/rules
* Fix -X crash (Closes: #716099, #716111, #716218, #716298)
* Adjust Maintainer/Uploaders fields

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* alarm.c -- wakeup calls */
 
2
 
 
3
/*
 
4
-- Implementation of alarm.h
 
5
*/
 
6
 
 
7
#include <stdio.h>
 
8
#include <stdlib.h>
 
9
#include <signal.h>
 
10
#include <time.h>
 
11
#include <sys/time.h>
 
12
 
 
13
static int alarmPending = 0;  /* Nonzero when the alarm is set. */
 
14
 
 
15
static void ualarm();
 
16
static void AlarmHandler();
 
17
 
 
18
void AlarmSet(time)
 
19
    int time;
 
20
{
 
21
    struct sigaction handler;
 
22
 
 
23
    alarmPending = 1;
 
24
    handler.sa_handler = AlarmHandler;
 
25
    sigemptyset(&handler.sa_mask);
 
26
    handler.sa_flags = 0;
 
27
    sigaction(SIGALRM, &handler, NULL);
 
28
    ualarm(1000 * time, 0);
 
29
}
 
30
 
 
31
/*
 
32
-- If an alarm signal is lurking (due to a prior call to SetAlarm), then
 
33
-- pause until it arrives.  This procedure could have simply been written:
 
34
--   if (alarmPending) pause();
 
35
-- but that allows a potential race condition.
 
36
*/
 
37
void AlarmWait()
 
38
{
 
39
    sighold(SIGALRM);
 
40
    if (alarmPending)
 
41
      sigpause(SIGALRM);
 
42
    sigrelse(SIGALRM);
 
43
}
 
44
 
 
45
 
 
46
static void ualarm(us)
 
47
    unsigned us;
 
48
{
 
49
    struct itimerval rttimer, old_rttimer;
 
50
 
 
51
    rttimer.it_value.tv_sec  = us / 1000000;
 
52
    rttimer.it_value.tv_usec = us % 1000000;
 
53
    rttimer.it_interval.tv_sec  = 0;
 
54
    rttimer.it_interval.tv_usec = 0;
 
55
    if (setitimer(ITIMER_REAL, &rttimer, &old_rttimer)) {
 
56
        perror("ualarm");
 
57
        exit(1);
 
58
    }
 
59
}
 
60
 
 
61
 
 
62
static void AlarmHandler()
 
63
{
 
64
    alarmPending = 0;
 
65
}