diff options
author | Stef Walter <stef@memberwebs.com> | 2006-01-27 01:29:51 +0000 |
---|---|---|
committer | Stef Walter <stef@memberwebs.com> | 2006-01-27 01:29:51 +0000 |
commit | 308449c0d80f0473476edc7b6bea4f0691ab042b (patch) | |
tree | 4c69e58e965aeb99251c7a35a2e181f5cc3eb56d | |
parent | 53c0296161ef4c654b026f56685d024d8ed8261d (diff) |
Added command line options. See #58
-rw-r--r-- | configure.in | 17 | ||||
-rw-r--r-- | daemon/rrdbotd.c | 84 |
2 files changed, 79 insertions, 22 deletions
diff --git a/configure.in b/configure.in index f841f18..5f4f5bd 100644 --- a/configure.in +++ b/configure.in @@ -10,13 +10,13 @@ AM_CONFIG_HEADER([config.h]) # Debug mode AC_ARG_ENABLE(debug, - AC_HELP_STRING([--enable-debug], - [Compile binaries in debug mode])) + AC_HELP_STRING([--enable-debug], + [Compile binaries in debug mode])) if test "$enable_debug" = "yes"; then - CFLAGS="$CFLAGS -g -O0" - AC_DEFINE_UNQUOTED(_DEBUG, 1, [In debug mode]) - echo "enabling debug compile mode" + CFLAGS="$CFLAGS -g -O0" + AC_DEFINE_UNQUOTED(_DEBUG, 1, [In debug mode]) + echo "enabling debug compile mode" fi dnl Check for programs. @@ -37,6 +37,13 @@ AC_HEADER_STDC AC_CHECK_HEADERS([rrd.h], , [echo "ERROR: rrd headers not found"]) dnl TODO: AC_CHECK_HEADERS +# Have to resolve this for the path below +if test "${prefix}" = "NONE"; then + prefix=$ac_default_prefix +fi + +AC_DEFINE_UNQUOTED(CONF_PREFIX, "`eval echo ${sysconfdir}`", [Installation Prefix] ) + AC_MSG_RESULT() AC_CONFIG_FILES([Makefile diff --git a/daemon/rrdbotd.c b/daemon/rrdbotd.c index 8ee9c1c..63cafc1 100644 --- a/daemon/rrdbotd.c +++ b/daemon/rrdbotd.c @@ -48,6 +48,12 @@ #include "stringx.h" #include "rrdbotd.h" +/* The default command line options */ +#define DEFAULT_CONFIG CONF_PREFIX "/rrdbot" +#define DEFAULT_WORK "/var/db/rrdbot" +#define DEFAULT_RETRIES 3 +#define DEFAULT_TIMEOUT 5 + /* ----------------------------------------------------------------------------- * GLOBALS */ @@ -57,7 +63,7 @@ rb_state g_state; /* TODO: These should be set from the command line */ static int daemonized = 0; -static int debug_level = 7; +static int debug_level = LOG_ERR; /* ----------------------------------------------------------------------------- * CLEANUP @@ -169,7 +175,7 @@ rb_message (int level, const char* msg, ...) static void usage() { - fprintf(stderr, "usage: rrdcollectd\n"); + fprintf(stderr, "usage: rrdcollectd [-c confdir] [-w workdir] [-d level] [-p pidfile] [-r retries] [-t timeout]\n"); fprintf(stderr, " rrdcollectd -v\n"); exit(2); } @@ -179,27 +185,66 @@ usage() int main(int argc, char* argv[]) { - int daemonize; + const char* pidfile = NULL; + int daemonize = 1; char ch; + char* t; /* Initialize the state stuff */ memset(&g_state, 0, sizeof(g_state)); - /* TODO: These should come from configure, and from arguments */ - g_state.rrddir = "/data/projects/rrdui/work"; - g_state.confdir = "/data/projects/rrdui/conf"; - g_state.retries = 3; - g_state.timeout = 5; + g_state.rrddir = DEFAULT_WORK; + g_state.confdir = DEFAULT_CONFIG; + g_state.retries = DEFAULT_RETRIES; + g_state.timeout = DEFAULT_TIMEOUT; + + /* Parse the arguments nicely */ + while((ch = getopt(argc, argv, "c:d:p:r:t:w:v")) != -1) + { + switch(ch) + { + + /* Config directory */ + case 'c': + g_state.confdir = optarg; + break; + + /* Don't daemonize */ + case 'd': + daemonize = 0; + debug_level = strtol(optarg, &t, 10); + if(*t || debug_level > 4) + errx(1, "invalid debug log level: %s", optarg); + debug_level += LOG_ERR; + break; + + /* Write out a pid file */ + case 'p': + pidfile = optarg; + break; + + /* The number of SNMP retries */ + case 'r': + g_state.retries = strtol(optarg, &t, 10); + if(*t || g_state.retries < 0) + errx(1, "invalid number of retries: %s", optarg); + break; - /* Parse the arguments nicely */ - while((ch = getopt(argc, argv, "v")) != -1) - { - switch(ch) - { + /* The default timeout */ + case 't': + g_state.timeout = strtol(optarg, &t, 10); + if(*t || g_state.timeout <= 0) + errx(1, "invalid timeout (must be above zero): %s", optarg); + break; + + /* The work directory */ + case 'w': + g_state.rrddir = optarg; + break; /* Print version number */ case 'v': - printf("rrdcollectd (version %s)\n", VERSION); + printf("rrdbotd (version %s)\n", VERSION); exit(0); break; @@ -209,11 +254,14 @@ main(int argc, char* argv[]) usage(); break; } - } + } argc -= optind; argv += optind; + if(argc != 0) + usage(); + /* The mainloop server */ server_init(); @@ -221,6 +269,9 @@ main(int argc, char* argv[]) rb_config_parse(); rb_snmp_engine_init(); + if(daemonize) + warnx("TODO: daemon mode not implemented yet"); + /* Now let it go */ if(server_run() == -1) err(1, "critical failure running SNMP engine"); @@ -230,6 +281,5 @@ main(int argc, char* argv[]) rb_config_free(); server_uninit(); - return 0; + return 0; } - |