forked from EnderUNIX/Aget
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Signal.c
66 lines (52 loc) · 1.01 KB
/
Signal.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <pthread.h>
#include <unistd.h>
#include "Signal.h"
#include "Data.h"
#include "Resume.h"
#include "Misc.h"
extern int nthreads;
extern struct thread_data *wthread;
extern struct request *req;
extern int bwritten;
extern pthread_mutex_t bwritten_mutex;
void * signal_waiter(void *arg)
{
int signal;
arg = NULL;
pthread_sigmask(SIG_UNBLOCK, &signal_set, NULL);
while(1) {
#ifdef SOLARIS
sigwait(&signal_set);
#else
sigwait(&signal_set, &signal);
#endif
switch(signal) {
case SIGINT:
sigint_handler();
break;
case SIGALRM:
sigalrm_handler();
break;
}
}
}
void sigint_handler(void)
{
int i;
printf("^C caught, saving download job...\n");
for (i = 0; i < nthreads; i++) {
pthread_cancel(wthread[i].tid);
wthread[i].status &= STAT_INT; /* Interrupted download */
}
save_log();
exit(0);
}
void sigalrm_handler(void)
{
printf("Signal Alarm came\n");
updateProgressBar(bwritten, req->clength);
alarm(1);
}