|
1 /***************************************************************************** |
|
2 * Copyright (C) 2014 |
|
3 * |
|
4 * Michiel Broek <mbroek at mbse dot eu> |
|
5 * |
|
6 * This file is part of the mbsePi-apps |
|
7 * |
|
8 * This is free software; you can redistribute it and/or modify it |
|
9 * under the terms of the GNU General Public License as published by the |
|
10 * Free Software Foundation; either version 2, or (at your option) any |
|
11 * later version. |
|
12 * |
|
13 * mbsePi-apps is distributed in the hope that it will be useful, but |
|
14 * WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
16 * General Public License for more details. |
|
17 * |
|
18 * You should have received a copy of the GNU General Public License |
|
19 * along with EC-65K; see the file COPYING. If not, write to the Free |
|
20 * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
|
21 *****************************************************************************/ |
|
22 |
|
23 #include <stdio.h> |
|
24 #include <stdlib.h> |
|
25 #include <unistd.h> |
|
26 |
|
27 |
|
28 #include "main.h" |
|
29 |
|
30 |
|
31 void help(void) |
|
32 { |
|
33 fprintf(stdout, "Usage: thermomeneters [-d] [-h]\n"); |
|
34 fprintf(stdout, " -d --debug Debug on\n"); |
|
35 fprintf(stdout, " -h --help Display this help\n"); |
|
36 } |
|
37 |
|
38 |
|
39 |
|
40 void die(int onsig) |
|
41 { |
|
42 switch (onsig) { |
|
43 case SIGHUP: Log_Msg("[main] Hangup detected"); |
|
44 break; |
|
45 case SIGINT: Log_Msg("[main] Interrupt from keyboard"); |
|
46 break; |
|
47 case SIGTERM: Log_Msg("[main] Termination signal received"); |
|
48 break; |
|
49 default: Log_Msg("[main] die on signal %d", onsig); |
|
50 } |
|
51 |
|
52 exit(onsig); |
|
53 } |
|
54 |
|
55 |
|
56 |
|
57 int main(int argc, char *argv[]) |
|
58 { |
|
59 int i, c, rc; |
|
60 int bForceReset = FALSE; |
|
61 SDL_Event event; |
|
62 char *path, name[128], *Range, *p; |
|
63 FILE *fp; |
|
64 unsigned int tmp1, tmp2; |
|
65 |
|
66 while (1) { |
|
67 int option_index = 0; |
|
68 static struct option long_options[] = { |
|
69 {"debug", 0, 0, 'c'}, |
|
70 {"help", 0, 0, 'h'}, |
|
71 {0, 0, 0, 0} |
|
72 }; |
|
73 |
|
74 c = getopt_long(argc, argv, "dh", long_options, &option_index); |
|
75 if (c == -1) |
|
76 break; |
|
77 |
|
78 switch (c) { |
|
79 case 'd': |
|
80 break; |
|
81 case 'h': help(); |
|
82 return 1; |
|
83 } |
|
84 } |
|
85 |
|
86 /* |
|
87 * Catch all the signals we can, and ignore the rest. Note that SIGKILL can't be ignored |
|
88 * but that's live. This daemon should only be stopped by SIGTERM. |
|
89 * Don't catch SIGCHLD. |
|
90 */ |
|
91 for (i = 0; i < NSIG; i++) { |
|
92 if ((i != SIGCHLD) && (i != SIGKILL) && (i != SIGSTOP)) |
|
93 signal(i, (void (*))die); |
|
94 } |
|
95 |
|
96 |
|
97 return 0; |
|
98 } |
|
99 |