/* * Copyright (c) 2022 Daniel Kroczynski * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include #include #include #include #include #include "blind.h" #include "config.h" #include "log.h" static void usage(void); struct blind *bl; static void usage(void) { extern char *__progname; fprintf(stderr, "usage: %s [-dhnv] [-f file]\n", __progname); exit(1); } int main(int argc, char *argv[]) { int ch; int verbose = 0; int no_action = 0; int daemonize = 1; const char *config = BL_CONF; while ((ch = getopt(argc, argv, "dhnvf:")) != -1) { switch (ch) { case 'd': daemonize = 0; break; case 'h': fprintf(stderr, BL_TEXT " " BL_VERS "\n"); usage(); break; case 'n': no_action = 1; daemonize = 0; break; case 'f': config = optarg; break; case 'v': verbose = BL_OPT_VERBOSE; break; default: usage(); } } argc -= optind; argv += optind; if (argc || *argv) usage(); log_init(daemonize, LOG_DAEMON); log_info("%s %s", BL_TEXT, BL_VERS); if ((bl = config_init()) == NULL) log_fatal("initialization failed"); if (verbose) { bl->bl_opt |= verbose; log_set(verbose); log_debug("verbose mode on"); } if (strlcpy(bl->bl_conf, config, PATH_MAX) >= PATH_MAX) log_fatal("file name exceeds PATH_MAX"); if (config_load(bl)) log_fatal("%s", bl->bl_conf); if (no_action) { // check config log_info("configuration ok"); free(bl); exit(0); } log_debug("conf=%s", bl->bl_conf); log_debug("sock=%s", bl->bl_sock); log_debug(" ttl=%d", bl->bl_ttl); log_debug(" opt=%d", bl->bl_opt); // to be continued or not free(bl); exit(0); }