Minor changes (almost entirely in main.c):
* Heavily commented options * Fixed bug introduced into default_duration and -w (my fault) * Defined configuration file string defaults (no processing yet) * Added simple optimization to option processing * Reformed some comments for easier readability * Fixed bug that caused program not to drop root privs when running on port under 1024 * Converted further to use syslog instead of printf
This commit is contained in:
+92
-29
@@ -38,6 +38,7 @@
|
||||
|
||||
#define MAX_TIMER 0x10000
|
||||
#define DEFAULT_USER "nobody"
|
||||
#define CONFIG_FILE "/etc/LCDd.conf"
|
||||
|
||||
int debug_level = 3;
|
||||
char *version = VERSION;
|
||||
@@ -111,7 +112,7 @@ int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
// TODO: Use a config file!
|
||||
//char cfgfile[256] = "/etc/LCDd.cf";
|
||||
char cfgfile[256] = CONFIG_FILE;
|
||||
int i, err;
|
||||
int daemon_mode = 1;
|
||||
int disable_server_screen = 1;
|
||||
@@ -119,14 +120,10 @@ main (int argc, char **argv)
|
||||
char *str, *ing; // strings for commandline handling
|
||||
char *user = DEFAULT_USER;
|
||||
|
||||
// Ctrl-C will cause a clean exit...
|
||||
signal (SIGINT, exit_program);
|
||||
// and "kill"...
|
||||
signal (SIGTERM, exit_program);
|
||||
// and "kill -HUP" (hangup)...
|
||||
signal (SIGHUP, exit_program);
|
||||
// and just in case, "kill -KILL" (which cannot be trapped; but oh well)
|
||||
signal (SIGKILL, exit_program);
|
||||
signal (SIGINT, exit_program); // Ctrl-C will cause a clean exit...
|
||||
signal (SIGTERM, exit_program); // and "kill"...
|
||||
signal (SIGHUP, exit_program); // and "kill -HUP" (hangup)...
|
||||
signal (SIGKILL, exit_program); // and just in case, "kill -KILL" (which cannot be trapped; but oh well)
|
||||
|
||||
// If no paramaters given, give the help screen.
|
||||
if (argc == 1)
|
||||
@@ -174,6 +171,16 @@ main (int argc, char **argv)
|
||||
// Parse the command line now...
|
||||
// TODO: Move this to a separate function?
|
||||
for (i = 1; i < argc; i++) {
|
||||
if (argv[i][0] == '-') {
|
||||
|
||||
/*
|
||||
* -d <driver> [ <driver_opts> ... ]
|
||||
* --driver <driver> [ <driver_opts> ... ]
|
||||
*
|
||||
* This option does not transfer to a getopt() version;
|
||||
* will have to change the option format...
|
||||
*/
|
||||
|
||||
if (0 == strcmp (argv[i], "-d") || 0 == strcmp (argv[i], "--driver")) {
|
||||
if (argc <= i + 1)
|
||||
HelpScreen ();
|
||||
@@ -199,12 +206,38 @@ main (int argc, char **argv)
|
||||
}
|
||||
if ((err > 0) && (0 == strcmp (str, "curses")))
|
||||
daemon_mode = 0;
|
||||
|
||||
/*
|
||||
* -h
|
||||
* --help
|
||||
*
|
||||
* Help function
|
||||
*/
|
||||
|
||||
} else if (0 == strcmp (argv[i], "-h") || 0 == strcmp (argv[i], "--help")) {
|
||||
HelpScreen ();
|
||||
}
|
||||
|
||||
/*
|
||||
* -f
|
||||
* --foreground
|
||||
*
|
||||
* Keep program in foreground; use for debugging, such
|
||||
* as with gdb
|
||||
*/
|
||||
|
||||
// Redundant, but it prevents errors...
|
||||
else if (0 == strcmp (argv[i], "-f") || 0 == strcmp (argv[i], "--foreground")) {
|
||||
daemon_mode = 0;
|
||||
|
||||
/*
|
||||
* -b [ "on" | "off" | "open" ]
|
||||
* --backlight [ "on" | "off" | "open" ]
|
||||
*
|
||||
* This should be a driver option, likely within the config file.
|
||||
* What IS "open" anyway?
|
||||
*/
|
||||
|
||||
} else if (0 == strcmp (argv[i], "-b") || 0 == strcmp (argv[i], "--backlight")) {
|
||||
if (argc <= i + 1)
|
||||
HelpScreen ();
|
||||
@@ -217,6 +250,15 @@ main (int argc, char **argv)
|
||||
backlight = BACKLIGHT_OPEN;
|
||||
else
|
||||
HelpScreen ();
|
||||
|
||||
/*
|
||||
* -t
|
||||
* --type
|
||||
*
|
||||
* Type of LCD; this *DEFINITELY* should only be
|
||||
* a driver option.
|
||||
*/
|
||||
|
||||
} else if (0 == strcmp (argv[i], "-t") || 0 == strcmp (argv[i], "--type")) {
|
||||
if (i + 1 > argc)
|
||||
HelpScreen ();
|
||||
@@ -235,6 +277,16 @@ main (int argc, char **argv)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* -i
|
||||
* --serverinfo
|
||||
*
|
||||
* Display server information during normal screen
|
||||
* updates when windows are active; server information
|
||||
* is always shown if there are no windows active.
|
||||
*/
|
||||
|
||||
} else if (0 == strcmp (argv[i], "-i") || 0 == strcmp (argv[i], "--serverinfo")) {
|
||||
if (i + 1 > argc)
|
||||
HelpScreen ();
|
||||
@@ -245,6 +297,15 @@ main (int argc, char **argv)
|
||||
if (0 == strcmp (argv[i], "on"))
|
||||
disable_server_screen = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* -w <1/8 secs>
|
||||
* --waittime <1/8 secs>
|
||||
*
|
||||
* Sets the default duration that a screen
|
||||
* is present.
|
||||
*/
|
||||
|
||||
} else if (0 == strcmp (argv[i], "-w") || 0 == strcmp (argv[i], "--waittime")) {
|
||||
if (i + 1 > argc)
|
||||
HelpScreen ();
|
||||
@@ -260,38 +321,46 @@ main (int argc, char **argv)
|
||||
};
|
||||
}
|
||||
} else {
|
||||
// otherwise... Get help!
|
||||
|
||||
/*
|
||||
* End of valid options
|
||||
*/
|
||||
|
||||
printf ("Invalid parameter: %s\n", argv[i]);
|
||||
HelpScreen ();
|
||||
}
|
||||
} else {
|
||||
printf("non-option: %s", argv[i]);
|
||||
HelpScreen ();
|
||||
}
|
||||
}
|
||||
|
||||
// switch to a different user for the real work...
|
||||
if (lcd_port >= 1024)
|
||||
if (lcd_port >= 1024) // unpriviledged port
|
||||
drop_privs(user);
|
||||
|
||||
if (sock_create_server (&bind_addr, lcd_port) <= 0) {
|
||||
printf ("Error opening socket.\n");
|
||||
syslog(LOG_ERR, "error opening socket");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (lcd_port > 1024)
|
||||
if (lcd_port < 1024) // priviledged port
|
||||
drop_privs(user);
|
||||
|
||||
// Now init a bunch of required stuff...
|
||||
|
||||
if (client_init () < 0) {
|
||||
printf ("Error initializing client list\n");
|
||||
syslog(LOG_ERR, "error initializing client list");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (screenlist_init () < 0) {
|
||||
printf ("Error initializing screen list\n");
|
||||
syslog(LOG_ERR, "error initializing screen list");
|
||||
return 1;
|
||||
}
|
||||
// Make sure the server screen shows up every once in a while..
|
||||
if (server_screen_init () < 0) {
|
||||
printf ("Error initializing server screens\n");
|
||||
syslog(LOG_ERR, "error initializing server screens");
|
||||
return 1;
|
||||
} else if (disable_server_screen) {
|
||||
server_screen->priority = 256;
|
||||
@@ -368,22 +437,16 @@ exit_program (int val)
|
||||
// Other values should not be seen, but just in case..
|
||||
}
|
||||
|
||||
// Make note in the logs...
|
||||
syslog(LOG_NOTICE, buf);
|
||||
// Say goodbye!
|
||||
goodbye_screen ();
|
||||
// Can go anywhere...
|
||||
lcd_shutdown ();
|
||||
syslog(LOG_NOTICE, buf); // send message to syslog
|
||||
goodbye_screen (); // display goodbye screen on LCD display
|
||||
lcd_shutdown (); // release driver memory and file descriptors
|
||||
|
||||
// Must come before screenlist_shutdown
|
||||
client_shutdown ();
|
||||
// Must come after client_shutdown
|
||||
screenlist_shutdown ();
|
||||
// Should come after client_shutdown
|
||||
sock_close_all ();
|
||||
client_shutdown (); // shutdown clients (must come first)
|
||||
|
||||
screenlist_shutdown (); // shutdown screens (must come after client_shutdown)
|
||||
sock_close_all (); // close all open sockets (must come after client_shutdown)
|
||||
|
||||
exit (0);
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
+2
-2
@@ -14,7 +14,7 @@
|
||||
#include "main.h"
|
||||
|
||||
int default_priority = 128 ;
|
||||
int default_duration = 64 ; // About 8 seconds
|
||||
int default_duration = DEFAULT_SCREEN_DURATION ; // About 8 seconds
|
||||
|
||||
screen *
|
||||
screen_create ()
|
||||
@@ -30,7 +30,7 @@ screen_create ()
|
||||
s->id = NULL;
|
||||
s->name = NULL;
|
||||
s->priority = DEFAULT_SCREEN_PRIORITY;
|
||||
s->duration = DEFAULT_SCREEN_DURATION;
|
||||
s->duration = default_duration;
|
||||
s->heartbeat = DEFAULT_HEARTBEAT;
|
||||
s->wid = lcd.wid;
|
||||
s->hgt = lcd.hgt;
|
||||
|
||||
Reference in New Issue
Block a user