25 #include "dlgBrew.h" |
25 #include "dlgBrew.h" |
26 |
26 |
27 #ifdef HAVE_SDL_SDL_H |
27 #ifdef HAVE_SDL_SDL_H |
28 |
28 |
29 int debug = FALSE; /* Console debugging */ |
29 int debug = FALSE; /* Console debugging */ |
|
30 static pid_t pgrp, mypid; |
30 int my_shutdown = FALSE; /* Shutdown requested */ |
31 int my_shutdown = FALSE; /* Shutdown requested */ |
31 char *Paneltype = NULL; /* Panel to emulate */ |
32 char *Paneltype = NULL; /* Panel to emulate */ |
32 int PAN_x; /* Screen X size */ |
33 int PAN_x; /* Screen X size */ |
33 int PAN_y; /* Screen Y size */ |
34 int PAN_y; /* Screen Y size */ |
34 |
35 |
36 int LCD_bcol; /* LCD background color */ |
37 int LCD_bcol; /* LCD background color */ |
37 |
38 |
38 SDL_Surface *PAN_surface = NULL; /* Main surface */ |
39 SDL_Surface *PAN_surface = NULL; /* Main surface */ |
39 |
40 |
40 |
41 |
|
42 int server(void); |
|
43 |
41 void help(void) |
44 void help(void) |
42 { |
45 { |
43 fprintf(stdout, "Usage: brewpanel [-d] [-h] [-p <paneltype>]\n"); |
46 fprintf(stdout, "Usage: brewpanel [-d] [-h] [-p <paneltype>]\n"); |
44 fprintf(stdout, " -d --debug Debug on\n"); |
47 fprintf(stdout, " -d --debug Debug on\n"); |
45 fprintf(stdout, " -h --help Display this help\n"); |
48 fprintf(stdout, " -h --help Display this help\n"); |
113 for (i = 0; i < NSIG; i++) { |
115 for (i = 0; i < NSIG; i++) { |
114 if ((i != SIGCHLD) && (i != SIGKILL) && (i != SIGSTOP)) |
116 if ((i != SIGCHLD) && (i != SIGKILL) && (i != SIGSTOP)) |
115 signal(i, (void (*))die); |
117 signal(i, (void (*))die); |
116 } |
118 } |
117 |
119 |
|
120 if (debug) { |
|
121 /* |
|
122 * Run in foreground when debugging |
|
123 */ |
|
124 rc = server(); |
|
125 } else { |
|
126 /* |
|
127 * Fork the daemon |
|
128 */ |
|
129 if ((pgrp = setpgid(0, 0)) == -1) { |
|
130 syslog(LOG_NOTICE, "setpgpid failed"); |
|
131 } |
|
132 |
|
133 frk = fork(); |
|
134 switch (frk) { |
|
135 case -1: |
|
136 syslog(LOG_NOTICE, "Daemon fork failed: %s", strerror(errno)); |
|
137 exit(1); |
|
138 case 0: /* |
|
139 * Run the daemon |
|
140 */ |
|
141 fclose(stdin); |
|
142 if (open("/dev/null", O_RDONLY) != 0) { |
|
143 syslog(LOG_NOTICE, "Reopen of stdin to /dev/null failed"); |
|
144 _exit(2); |
|
145 } |
|
146 fclose(stdout); |
|
147 if (open("/dev/null", O_WRONLY | O_APPEND | O_CREAT,0600) != 1) { |
|
148 syslog(LOG_NOTICE, "Reopen of stdout to /dev/null failed"); |
|
149 _exit(2); |
|
150 } |
|
151 fclose(stderr); |
|
152 if (open("/dev/null", O_WRONLY | O_APPEND | O_CREAT,0600) != 2) { |
|
153 syslog(LOG_NOTICE, "Reopen of stderr to /dev/null failed"); |
|
154 _exit(2); |
|
155 } |
|
156 mypid = getpid(); |
|
157 rc = server(); |
|
158 break; |
|
159 /* Not reached */ |
|
160 default: |
|
161 /* |
|
162 * Here we detach this process and let the child |
|
163 * run the deamon process. |
|
164 */ |
|
165 syslog(LOG_NOTICE, "Starting daemon with pid %d", frk); |
|
166 exit(0); |
|
167 } |
|
168 } |
|
169 |
|
170 syslog(LOG_NOTICE, "Finished, rc=%d", rc); |
|
171 return rc; |
|
172 } |
|
173 |
|
174 |
|
175 int server(void) |
|
176 { |
|
177 int max_x = 0, max_y = 0; |
|
178 SDL_Rect **modes; |
|
179 char title[81]; |
|
180 |
118 /* |
181 /* |
119 * Initialize defaults, Video and Audio |
182 * Initialize defaults, Video and Audio |
120 */ |
183 */ |
121 if ((SDL_Init(SDL_INIT_TIMER | SDL_INIT_AUDIO | SDL_INIT_VIDEO) == -1)) { |
184 if ((SDL_Init(SDL_INIT_TIMER | SDL_INIT_AUDIO | SDL_INIT_VIDEO) == -1)) { |
122 syslog(LOG_NOTICE, "[main] could not initialize SDL: %s", SDL_GetError()); |
185 syslog(LOG_NOTICE, "[main] could not initialize SDL: %s", SDL_GetError()); |