4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
24 #include <sys/types.h>
26 #define SCRIPT "/etc/alix-switch"
27 #define GPIOBASE 0x6100
29 typedef void (*sighandler_t
)(int);
31 static sighandler_t
handle_signal (int sig_nr
, sighandler_t signalhandler
) {
33 struct sigaction neu_sig
, alt_sig
;
35 neu_sig
.sa_handler
= signalhandler
;
36 sigemptyset(&neu_sig
.sa_mask
);
37 neu_sig
.sa_flags
= SA_RESTART
;
38 if (sigaction (sig_nr
, &neu_sig
, &alt_sig
) < 0)
41 return alt_sig
.sa_handler
;
44 static void start_daemon (void) {
49 handle_signal(SIGHUP
, SIG_IGN
);
50 if ((pid
= fork ()) != 0)
53 if ((sid
= setsid()) < 0)
56 for (i
= sysconf(_SC_OPEN_MAX
); i
> 0; i
--)
61 int main(int argc
, char *argv
[]) {
64 unsigned long bPort
= 0;
65 struct timespec sleep
;
66 int bDaemon
= 0, bSwitch
= 0, bState
= 0;
68 for(i
= 1; i
< argc
; i
++) {
69 if (!strcasecmp(argv
[i
], "-d") || !strcasecmp(argv
[i
], "--daemon")) {
72 printf( "\nusage: %s [-d | --daemon]\n", argv
[0]);
78 fprintf( stderr
, "Could not set I/O permissions to level 3\n");
86 sleep
.tv_nsec
= 50000000;
89 bPort
= inl(GPIOBASE
+ 0xB0);
90 if ((bPort
& 0x100) == 0)
95 if (bState
&& !bSwitch
)
99 nanosleep(&sleep
, NULL
);
103 fprintf(stderr
, "Could not set I/O permissions to level 0");