-rw-r--r-- | core/opiealarm/Makefile | 2 | ||||
-rw-r--r-- | core/opiealarm/opiealarm.c | 2 |
2 files changed, 2 insertions, 2 deletions
diff --git a/core/opiealarm/Makefile b/core/opiealarm/Makefile index e988abf..f20d451 100644 --- a/core/opiealarm/Makefile +++ b/core/opiealarm/Makefile | |||
@@ -1,26 +1,26 @@ | |||
1 | 1 | ||
2 | DESTDIR=../../bin | 2 | DESTDIR=../../bin |
3 | 3 | ||
4 | CROSS:=arm-linux- | 4 | CROSS:=arm-linux- |
5 | CC :=$(CROSS)gcc | 5 | CC :=$(CROSS)gcc |
6 | LD :=$(CROSS)gcc | 6 | LD :=$(CROSS)gcc |
7 | STRIP:=$(CROSS)strip | 7 | STRIP:=$(CROSS)strip |
8 | 8 | ||
9 | CFLAGS:=-O2 | 9 | CFLAGS:=-O2 |
10 | LDFLAGS:= | 10 | LDFLAGS:= |
11 | 11 | ||
12 | all: $(DESTDIR)/opiealarm $(DESTDIR)/opieatd | 12 | all: $(DESTDIR)/opiealarm $(DESTDIR)/opieatd |
13 | 13 | ||
14 | $(DESTDIR)/opiealarm: opiealarm.c | 14 | $(DESTDIR)/opiealarm: opiealarm.c |
15 | $(CC) $(CFLAGS) opiealarm.c -o $(DESTDIR)/opiealarm $(LDFLAGS) | 15 | $(CC) $(CFLAGS) opiealarm.c -o $(DESTDIR)/opiealarm $(LDFLAGS) |
16 | $(STRIP) -s $(DESTDIR)/opiealarm | 16 | $(STRIP) --strip-all $(DESTDIR)/opiealarm |
17 | chmod u+s $(DESTDIR)/opiealarm | 17 | chmod u+s $(DESTDIR)/opiealarm |
18 | chown root $(DESTDIR)/opiealarm 2>/dev/null || echo -e "\nopiealarm must be owned by root to work correctly.\n" | 18 | chown root $(DESTDIR)/opiealarm 2>/dev/null || echo -e "\nopiealarm must be owned by root to work correctly.\n" |
19 | 19 | ||
20 | $(DESTDIR)/opieatd: opieatd | 20 | $(DESTDIR)/opieatd: opieatd |
21 | cp opieatd $(DESTDIR)/opieatd | 21 | cp opieatd $(DESTDIR)/opieatd |
22 | chmod +x $(DESTDIR)/opieatd | 22 | chmod +x $(DESTDIR)/opieatd |
23 | 23 | ||
24 | clean: | 24 | clean: |
25 | -rm -f *~ core | 25 | -rm -f *~ core |
26 | 26 | ||
diff --git a/core/opiealarm/opiealarm.c b/core/opiealarm/opiealarm.c index 71367b3..ce0103e 100644 --- a/core/opiealarm/opiealarm.c +++ b/core/opiealarm/opiealarm.c | |||
@@ -54,307 +54,307 @@ void log_msg ( const char *msg ) | |||
54 | 54 | ||
55 | void error_msg_and_die ( int perr, const char *msg ) | 55 | void error_msg_and_die ( int perr, const char *msg ) |
56 | { | 56 | { |
57 | if ( perr ) | 57 | if ( perr ) |
58 | log_msg ( strerror ( errno )); | 58 | log_msg ( strerror ( errno )); |
59 | log_msg ( msg ); | 59 | log_msg ( msg ); |
60 | 60 | ||
61 | while ( 1 ) // pretend we are waiting on RTC, so opiealarm -r can kill us | 61 | while ( 1 ) // pretend we are waiting on RTC, so opiealarm -r can kill us |
62 | sleep ( 1 ); | 62 | sleep ( 1 ); |
63 | } | 63 | } |
64 | 64 | ||
65 | 65 | ||
66 | void sig_handler ( int sig ) | 66 | void sig_handler ( int sig ) |
67 | { | 67 | { |
68 | log_msg ( "GOT SIGNAL -> EXITING\n" ); | 68 | log_msg ( "GOT SIGNAL -> EXITING\n" ); |
69 | fclose ( log ); | 69 | fclose ( log ); |
70 | remove_pidfile ( ); | 70 | remove_pidfile ( ); |
71 | exit ( 0 ); | 71 | exit ( 0 ); |
72 | } | 72 | } |
73 | 73 | ||
74 | void usage ( void ) | 74 | void usage ( void ) |
75 | { | 75 | { |
76 | fprintf ( stderr, "Usage: opiealarm -s [-f] | -r [-a]\n\n" ); | 76 | fprintf ( stderr, "Usage: opiealarm -s [-f] | -r [-a]\n\n" ); |
77 | fprintf ( stderr, "\t-s\tSuspend mode: set RTC alarm\n" ); | 77 | fprintf ( stderr, "\t-s\tSuspend mode: set RTC alarm\n" ); |
78 | fprintf ( stderr, "\t-f \tFix RTC, if RTC and system have more than 5sec difference (suspend mode)\n" ); | 78 | fprintf ( stderr, "\t-f \tFix RTC, if RTC and system have more than 5sec difference (suspend mode)\n" ); |
79 | fprintf ( stderr, "\t-r\tResume mode: kill running opiealarm\n" ); | 79 | fprintf ( stderr, "\t-r\tResume mode: kill running opiealarm\n" ); |
80 | fprintf ( stderr, "\t-a <x>\tResuspend in <x> seconds (resume mode)\n\n" ); | 80 | fprintf ( stderr, "\t-a <x>\tResuspend in <x> seconds (resume mode)\n\n" ); |
81 | exit ( 1 ); | 81 | exit ( 1 ); |
82 | } | 82 | } |
83 | 83 | ||
84 | int fork_with_pidfile ( void ) | 84 | int fork_with_pidfile ( void ) |
85 | { | 85 | { |
86 | FILE *fp; | 86 | FILE *fp; |
87 | pid_t pid; | 87 | pid_t pid; |
88 | 88 | ||
89 | pid = fork ( ); | 89 | pid = fork ( ); |
90 | 90 | ||
91 | if ( pid > 0 ) | 91 | if ( pid > 0 ) |
92 | exit ( 0 ); | 92 | exit ( 0 ); |
93 | else if ( pid < 0 ) { | 93 | else if ( pid < 0 ) { |
94 | perror ( "forking failed" ); | 94 | perror ( "forking failed" ); |
95 | return 0; | 95 | return 0; |
96 | } | 96 | } |
97 | 97 | ||
98 | signal ( SIGTERM, sig_handler ); | 98 | signal ( SIGTERM, sig_handler ); |
99 | signal ( SIGINT, sig_handler ); | 99 | signal ( SIGINT, sig_handler ); |
100 | 100 | ||
101 | // save pid | 101 | // save pid |
102 | if (( fp = fopen ( PIDFILE, "w" ))) { | 102 | if (( fp = fopen ( PIDFILE, "w" ))) { |
103 | fprintf ( fp, "%d", getpid ( )); | 103 | fprintf ( fp, "%d", getpid ( )); |
104 | fclose ( fp ); | 104 | fclose ( fp ); |
105 | 105 | ||
106 | // detach | 106 | // detach |
107 | close ( 0 ); | 107 | close ( 0 ); |
108 | close ( 1 ); | 108 | close ( 1 ); |
109 | close ( 2 ); | 109 | close ( 2 ); |
110 | 110 | ||
111 | setpgid ( 0, 0 ); | 111 | setpgid ( 0, 0 ); |
112 | 112 | ||
113 | return 1; | 113 | return 1; |
114 | } | 114 | } |
115 | else { | 115 | else { |
116 | perror ( PIDFILE ); | 116 | perror ( PIDFILE ); |
117 | return 0; | 117 | return 0; |
118 | } | 118 | } |
119 | } | 119 | } |
120 | 120 | ||
121 | int kill_with_pidfile ( void ) | 121 | int kill_with_pidfile ( void ) |
122 | { | 122 | { |
123 | FILE *fp; | 123 | FILE *fp; |
124 | pid_t pid; | 124 | pid_t pid; |
125 | 125 | ||
126 | if (( fp = fopen ( PIDFILE, "r" ))) { | 126 | if (( fp = fopen ( PIDFILE, "r" ))) { |
127 | if ( fscanf ( fp, "%d", &pid ) == 1 ) | 127 | if ( fscanf ( fp, "%d", &pid ) == 1 ) |
128 | return ( kill ( pid, SIGTERM ) == 0 ) ? 1 : 0; | 128 | return ( kill ( pid, SIGTERM ) == 0 ) ? 1 : 0; |
129 | fclose ( fp ); | 129 | fclose ( fp ); |
130 | } | 130 | } |
131 | return 0; | 131 | return 0; |
132 | } | 132 | } |
133 | 133 | ||
134 | void remove_pidfile ( void ) | 134 | void remove_pidfile ( void ) |
135 | { | 135 | { |
136 | unlink ( PIDFILE ); | 136 | unlink ( PIDFILE ); |
137 | 137 | ||
138 | signal ( SIGTERM, SIG_DFL ); | 138 | signal ( SIGTERM, SIG_DFL ); |
139 | signal ( SIGINT, SIG_DFL ); | 139 | signal ( SIGINT, SIG_DFL ); |
140 | } | 140 | } |
141 | 141 | ||
142 | 142 | ||
143 | int main ( int argc, char **argv ) | 143 | int main ( int argc, char **argv ) |
144 | { | 144 | { |
145 | int mode = 0; | 145 | int mode = 0; |
146 | int ac_resusp = 0; | 146 | int ac_resusp = 0; |
147 | int fix_rtc = 0; | 147 | int fix_rtc = 0; |
148 | int opt; | 148 | int opt; |
149 | 149 | ||
150 | while (( opt = getopt ( argc, argv, "a:frs" )) != EOF ) { | 150 | while (( opt = getopt ( argc, argv, "a:frs" )) != EOF ) { |
151 | switch ( opt ) { | 151 | switch ( opt ) { |
152 | case 's': | 152 | case 's': |
153 | mode = 's'; | 153 | mode = 's'; |
154 | break; | 154 | break; |
155 | case 'r': | 155 | case 'r': |
156 | mode = 'r'; | 156 | mode = 'r'; |
157 | break; | 157 | break; |
158 | case 'a': | 158 | case 'a': |
159 | ac_resusp = atoi ( optarg ); | 159 | ac_resusp = atoi ( optarg ); |
160 | if ( ac_resusp < 30 ) { | 160 | if ( ac_resusp < 30 ) { |
161 | ac_resusp = 120; | 161 | ac_resusp = 120; |
162 | 162 | ||
163 | fprintf ( stderr, "Warning: resuspend timeout must be >= 30 sec. -- now set to 120 sec\n" ); | 163 | fprintf ( stderr, "Warning: resuspend timeout must be >= 30 sec. -- now set to 120 sec\n" ); |
164 | } | 164 | } |
165 | break; | 165 | break; |
166 | case 'f': | 166 | case 'f': |
167 | fix_rtc = 1; | 167 | fix_rtc = 1; |
168 | break; | 168 | break; |
169 | default: | 169 | default: |
170 | usage ( ); | 170 | usage ( ); |
171 | } | 171 | } |
172 | } | 172 | } |
173 | 173 | ||
174 | if ( geteuid ( ) != 0 ) { | 174 | if ( geteuid ( ) != 0 ) { |
175 | fprintf ( stderr, "You need root priviledges to run opiealarm." ); | 175 | fprintf ( stderr, "You need root priviledges to run opiealarm." ); |
176 | return 2; | 176 | return 2; |
177 | } | 177 | } |
178 | 178 | ||
179 | if ( !mode ) | 179 | if ( !mode ) |
180 | usage ( ); | 180 | usage ( ); |
181 | 181 | ||
182 | // kill running opiealarm | 182 | // kill running opiealarm |
183 | opiealarm_was_running = kill_with_pidfile ( ); | 183 | opiealarm_was_running = kill_with_pidfile ( ); |
184 | remove_pidfile ( ); | 184 | remove_pidfile ( ); |
185 | 185 | ||
186 | switch ( mode ) { | 186 | switch ( mode ) { |
187 | case 'r': return resume ( ac_resusp ); | 187 | case 'r': return resume ( ac_resusp ); |
188 | case 's': | 188 | case 's': |
189 | default : return suspend ( fix_rtc ); | 189 | default : return suspend ( fix_rtc ); |
190 | } | 190 | } |
191 | return 0; | 191 | return 0; |
192 | } | 192 | } |
193 | 193 | ||
194 | 194 | ||
195 | int suspend ( int fix_rtc ) | 195 | int suspend ( int fix_rtc ) |
196 | { | 196 | { |
197 | FILE *fp; | 197 | FILE *fp; |
198 | char buf [64]; | 198 | char buf [64]; |
199 | time_t alrt, syst, rtct; | 199 | time_t alrt, syst, rtct; |
200 | struct tm alr, sys, rtc; | 200 | struct tm alr, sys, rtc; |
201 | int fd; | 201 | int fd; |
202 | int rtc_sys_diff; | 202 | int rtc_sys_diff; |
203 | 203 | ||
204 | 204 | ||
205 | if ( !fork_with_pidfile ( )) | 205 | if ( !fork_with_pidfile ( )) |
206 | return 3; | 206 | return 3; |
207 | 207 | ||
208 | log = fopen ( "/tmp/opiealarm.log", "w" ); | 208 | log = fopen ( "/tmp/opiealarm.log", "w" ); |
209 | log_msg ( "STARTING\n" ); | 209 | log_msg ( "STARTING\n" ); |
210 | 210 | ||
211 | 211 | ||
212 | 212 | ||
213 | if (!( fp = fopen ( "/etc/resumeat", "r" ))) | 213 | if (!( fp = fopen ( "/etc/resumeat", "r" ))) |
214 | error_msg_and_die ( 1, "/etc/resumeat" ); | 214 | error_msg_and_die ( 1, "/etc/resumeat" ); |
215 | 215 | ||
216 | if ( !fgets ( buf, sizeof( buf ) - 1, fp )) | 216 | if ( !fgets ( buf, sizeof( buf ) - 1, fp )) |
217 | error_msg_and_die ( 1, "/etc/resumeat" ); | 217 | error_msg_and_die ( 1, "/etc/resumeat" ); |
218 | 218 | ||
219 | fclose ( fp ); | 219 | fclose ( fp ); |
220 | 220 | ||
221 | alrt = atoi ( buf ); | 221 | alrt = atoi ( buf ); |
222 | 222 | ||
223 | if ( alrt == 0 ) | 223 | if ( alrt == 0 ) |
224 | error_msg_and_die ( 0, "/etc/resumeat contains an invalid time description" ); | 224 | error_msg_and_die ( 0, "/etc/resumeat contains an invalid time description" ); |
225 | 225 | ||
226 | /* subtract 5 sec from event time... */ | 226 | /* subtract 5 sec from event time... */ |
227 | alrt -= 5; | 227 | alrt -= 5; |
228 | 228 | ||
229 | if ( log ) | 229 | if ( log ) |
230 | fprintf ( log, "Setting RTC alarm to %d\n", alrt ); | 230 | fprintf ( log, "Setting RTC alarm to %d\n", alrt ); |
231 | 231 | ||
232 | tzset ( ); | 232 | tzset ( ); |
233 | 233 | ||
234 | alr = *gmtime ( &alrt ); | 234 | alr = *gmtime ( &alrt ); |
235 | 235 | ||
236 | // get system time | 236 | // get system time |
237 | time ( &syst ); | 237 | time ( &syst ); |
238 | sys = *localtime ( &syst ); | 238 | sys = *localtime ( &syst ); |
239 | 239 | ||
240 | // Write alarm time to RTC | 240 | // Write alarm time to RTC |
241 | if (( fd = open ( "/dev/misc/rtc", O_RDWR )) < 0 ) | 241 | if (( fd = open ( "/dev/misc/rtc", O_RDWR )) < 0 ) |
242 | error_msg_and_die ( 1, "/dev/misc/rtc" ); | 242 | error_msg_and_die ( 1, "/dev/misc/rtc" ); |
243 | 243 | ||
244 | // get RTC time | 244 | // get RTC time |
245 | memset ( &rtc, 0, sizeof ( struct tm )); | 245 | memset ( &rtc, 0, sizeof ( struct tm )); |
246 | if ( ioctl ( fd, RTC_ALM_SET, &rtc ) < 0 ) | 246 | if ( ioctl ( fd, RTC_RD_TIME, &rtc ) < 0 ) |
247 | error_msg_and_die ( 1, "ioctl RTC_RD_TIME" ); | 247 | error_msg_and_die ( 1, "ioctl RTC_RD_TIME" ); |
248 | rtct = mktime ( &rtc ); | 248 | rtct = mktime ( &rtc ); |
249 | 249 | ||
250 | fprintf ( log, "System time: %02d.%02d.%04d %02d:%02d:%02d DST: %d (TZ: %s, offset: %d)\n", sys. tm_mday, sys. tm_mon + 1, sys. tm_year + 1900, sys. tm_hour, sys. tm_min, sys. tm_sec, sys. tm_isdst, sys. tm_zone, sys. tm_gmtoff ); | 250 | fprintf ( log, "System time: %02d.%02d.%04d %02d:%02d:%02d DST: %d (TZ: %s, offset: %d)\n", sys. tm_mday, sys. tm_mon + 1, sys. tm_year + 1900, sys. tm_hour, sys. tm_min, sys. tm_sec, sys. tm_isdst, sys. tm_zone, sys. tm_gmtoff ); |
251 | fprintf ( log, "RTC time: %02d.%02d.%04d %02d:%02d:%02d DST: %d (TZ: %s, offset: %d)\n", rtc. tm_mday, rtc. tm_mon + 1, rtc. tm_year + 1900, rtc. tm_hour, rtc. tm_min, rtc. tm_sec, rtc. tm_isdst, rtc. tm_zone, rtc. tm_gmtoff ); | 251 | fprintf ( log, "RTC time: %02d.%02d.%04d %02d:%02d:%02d DST: %d (TZ: %s, offset: %d)\n", rtc. tm_mday, rtc. tm_mon + 1, rtc. tm_year + 1900, rtc. tm_hour, rtc. tm_min, rtc. tm_sec, rtc. tm_isdst, rtc. tm_zone, rtc. tm_gmtoff ); |
252 | fprintf ( log, "Wakeup time: %02d.%02d.%04d %02d:%02d:%02d DST: %d (TZ: %s, offset: %d)\n", alr. tm_mday, alr. tm_mon + 1, alr. tm_year + 1900, alr. tm_hour, alr. tm_min, alr. tm_sec, alr. tm_isdst, alr. tm_zone, alr. tm_gmtoff ); | 252 | fprintf ( log, "Wakeup time: %02d.%02d.%04d %02d:%02d:%02d DST: %d (TZ: %s, offset: %d)\n", alr. tm_mday, alr. tm_mon + 1, alr. tm_year + 1900, alr. tm_hour, alr. tm_min, alr. tm_sec, alr. tm_isdst, alr. tm_zone, alr. tm_gmtoff ); |
253 | 253 | ||
254 | fprintf ( log, "System/RTC diff: %d seconds\n", ( syst - rtct ) - sys. tm_gmtoff ); | 254 | fprintf ( log, "System/RTC diff: %d seconds\n", ( syst - rtct ) - sys. tm_gmtoff ); |
255 | 255 | ||
256 | 256 | ||
257 | rtc_sys_diff = ( syst - rtct ) - sys. tm_gmtoff; | 257 | rtc_sys_diff = ( syst - rtct ) - sys. tm_gmtoff; |
258 | 258 | ||
259 | if ( fix_rtc && (( rtc_sys_diff < -4 ) || ( rtc_sys_diff > 4 ))) { | 259 | if ( fix_rtc && (( rtc_sys_diff < -4 ) || ( rtc_sys_diff > 4 ))) { |
260 | struct tm set; | 260 | struct tm set; |
261 | 261 | ||
262 | set = *gmtime ( &syst ); | 262 | set = *gmtime ( &syst ); |
263 | 263 | ||
264 | fprintf ( log, "Correcting RTC: %d seconds\n", rtc_sys_diff ); | 264 | fprintf ( log, "Correcting RTC: %d seconds\n", rtc_sys_diff ); |
265 | 265 | ||
266 | if ( ioctl ( fd, RTC_SET_TIME, &set ) < 0 ) | 266 | if ( ioctl ( fd, RTC_SET_TIME, &set ) < 0 ) |
267 | error_msg_and_die ( 1, "ioctl RTC_SET_TIME" ); | 267 | error_msg_and_die ( 1, "ioctl RTC_SET_TIME" ); |
268 | } | 268 | } |
269 | 269 | ||
270 | // set alarm time | 270 | // set alarm time |
271 | if ( ioctl ( fd, RTC_ALM_SET, &alr ) < 0 ) | 271 | if ( ioctl ( fd, RTC_ALM_SET, &alr ) < 0 ) |
272 | error_msg_and_die ( 1, "ioctl RTC_ALM_SET" ); | 272 | error_msg_and_die ( 1, "ioctl RTC_ALM_SET" ); |
273 | // enable alarm irq | 273 | // enable alarm irq |
274 | if ( ioctl ( fd, RTC_AIE_ON, 0 ) < 0 ) | 274 | if ( ioctl ( fd, RTC_AIE_ON, 0 ) < 0 ) |
275 | error_msg_and_die ( 1, "ioctl RTC_AIE_ON" ); | 275 | error_msg_and_die ( 1, "ioctl RTC_AIE_ON" ); |
276 | 276 | ||
277 | log_msg ( "SLEEPING\n" ); | 277 | log_msg ( "SLEEPING\n" ); |
278 | 278 | ||
279 | // wait for alarm irq | 279 | // wait for alarm irq |
280 | if ( read ( fd, buf, sizeof( unsigned long )) < 0 ) | 280 | if ( read ( fd, buf, sizeof( unsigned long )) < 0 ) |
281 | error_msg_and_die ( 1, "read rtc alarm" ); | 281 | error_msg_and_die ( 1, "read rtc alarm" ); |
282 | 282 | ||
283 | log_msg ( "WAKEUP\n" ); | 283 | log_msg ( "WAKEUP\n" ); |
284 | 284 | ||
285 | // disable alarm irq | 285 | // disable alarm irq |
286 | if ( ioctl ( fd, RTC_AIE_OFF, 0 ) < 0 ) | 286 | if ( ioctl ( fd, RTC_AIE_OFF, 0 ) < 0 ) |
287 | error_msg_and_die ( 1, "ioctl RTC_AIE_OFF" ); | 287 | error_msg_and_die ( 1, "ioctl RTC_AIE_OFF" ); |
288 | 288 | ||
289 | close ( fd ); | 289 | close ( fd ); |
290 | 290 | ||
291 | log_msg ( "EXITING\n" ); | 291 | log_msg ( "EXITING\n" ); |
292 | 292 | ||
293 | fclose ( log ); | 293 | fclose ( log ); |
294 | remove_pidfile ( ); | 294 | remove_pidfile ( ); |
295 | 295 | ||
296 | return 0; | 296 | return 0; |
297 | } | 297 | } |
298 | 298 | ||
299 | 299 | ||
300 | int onac ( void ) | 300 | int onac ( void ) |
301 | { | 301 | { |
302 | FILE *fp; | 302 | FILE *fp; |
303 | int on = 0; | 303 | int on = 0; |
304 | 304 | ||
305 | if (( fp = fopen ( APMFILE, "r" ))) { | 305 | if (( fp = fopen ( APMFILE, "r" ))) { |
306 | int ac = 0; | 306 | int ac = 0; |
307 | 307 | ||
308 | if ( fscanf ( fp, "%*[^ ] %*d.%*d 0x%*x 0x%x 0x%*x 0x%*x %*d%% %*i %*c", &ac ) == 1 ) | 308 | if ( fscanf ( fp, "%*[^ ] %*d.%*d 0x%*x 0x%x 0x%*x 0x%*x %*d%% %*i %*c", &ac ) == 1 ) |
309 | on = ( ac == 0x01 ) ? 1 : 0; | 309 | on = ( ac == 0x01 ) ? 1 : 0; |
310 | 310 | ||
311 | fclose ( fp ); | 311 | fclose ( fp ); |
312 | } | 312 | } |
313 | return on; | 313 | return on; |
314 | } | 314 | } |
315 | 315 | ||
316 | int resume ( int resuspend ) | 316 | int resume ( int resuspend ) |
317 | { | 317 | { |
318 | FILE *fp; | 318 | FILE *fp; |
319 | 319 | ||
320 | // re-suspend when on AC (optional) when woken up via RTC | 320 | // re-suspend when on AC (optional) when woken up via RTC |
321 | 321 | ||
322 | if ( !opiealarm_was_running ) { // opiealarm -s got it's RTC signal -> wake up by RTC | 322 | if ( !opiealarm_was_running ) { // opiealarm -s got it's RTC signal -> wake up by RTC |
323 | if ( resuspend && onac ( )) { | 323 | if ( resuspend && onac ( )) { |
324 | time_t start, now; | 324 | time_t start, now; |
325 | char *argv [4]; | 325 | char *argv [4]; |
326 | 326 | ||
327 | if ( !fork_with_pidfile ( )) | 327 | if ( !fork_with_pidfile ( )) |
328 | return 4; | 328 | return 4; |
329 | 329 | ||
330 | // sleep <resuspend> sec (not less!) | 330 | // sleep <resuspend> sec (not less!) |
331 | time ( &start ); | 331 | time ( &start ); |
332 | do { | 332 | do { |
333 | sleep ( 1 ); | 333 | sleep ( 1 ); |
334 | time ( &now ); | 334 | time ( &now ); |
335 | } while (( now - start ) < resuspend ); | 335 | } while (( now - start ) < resuspend ); |
336 | 336 | ||
337 | if ( onac ( )) { // still on ac | 337 | if ( onac ( )) { // still on ac |
338 | // system() without fork | 338 | // system() without fork |
339 | argv[0] = "qcop"; | 339 | argv[0] = "qcop"; |
340 | argv[1] = "QPE/Desktop"; | 340 | argv[1] = "QPE/Desktop"; |
341 | argv[2] = "suspend()"; | 341 | argv[2] = "suspend()"; |
342 | argv[3] = 0; | 342 | argv[3] = 0; |
343 | 343 | ||
344 | // hard coded for now ...but needed | 344 | // hard coded for now ...but needed |
345 | setenv ( "LOGNAME", "root", 1 ); | 345 | setenv ( "LOGNAME", "root", 1 ); |
346 | setenv ( "HOME", "/root", 1 ); | 346 | setenv ( "HOME", "/root", 1 ); |
347 | setenv ( "LD_LIBRARY_PATH", "/opt/QtPalmtop/lib", 1 ); | 347 | setenv ( "LD_LIBRARY_PATH", "/opt/QtPalmtop/lib", 1 ); |
348 | setenv ( "QTDIR", "/opt/QtPalmtop", 1 ); | 348 | setenv ( "QTDIR", "/opt/QtPalmtop", 1 ); |
349 | 349 | ||
350 | remove_pidfile ( ); | 350 | remove_pidfile ( ); |
351 | 351 | ||
352 | execv ( "/opt/QtPalmtop/bin/qcop", argv ); | 352 | execv ( "/opt/QtPalmtop/bin/qcop", argv ); |
353 | 353 | ||
354 | perror ( "exec for qcop failed" ); | 354 | perror ( "exec for qcop failed" ); |
355 | return 5; | 355 | return 5; |
356 | } | 356 | } |
357 | } | 357 | } |
358 | } | 358 | } |
359 | return 0; | 359 | return 0; |
360 | } | 360 | } |