From 9fa8ce5d62a24efa4e5b584f5a6cf921e3052be8 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Wed, 28 May 2014 16:06:57 +0200 Subject: Don't include config.h everywhere. --- src/miavd.cc | 144 +++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 136 insertions(+), 8 deletions(-) (limited to 'src/miavd.cc') diff --git a/src/miavd.cc b/src/miavd.cc index 2a9b97b..1658648 100644 --- a/src/miavd.cc +++ b/src/miavd.cc @@ -24,23 +24,151 @@ * along with MIaV; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ +#include +#include +#include + +#include + #include #include "miav_daemon.h" - #include "miav_config.h" -#include -#include +static const char version_str[] = +"Pentominos Dataserver - Miav v" VERSION "\n" +; + +static const char copyright_str[] = +"Copyright (C) 2006-2007 Bent Bisballe Nyeng - Aasimon.org.\n" +"This is free software. You may redistribute copies of it under the terms of\n" +"the GNU General Public License .\n" +"There is NO WARRANTY, to the extent permitted by law.\n" +"\n" +"Written by Bent Bisballe Nyeng (deva@aasimon.org)\n" +; + +static const char usage_str[] = +"Usage: %s [options]\n" +"Options:\n" +" -c, --config file Read configfile from 'file' (default "ETC"/miav.conf)\n" +" -f, --foreground Run in foreground mode (non-daemon mode)\n" +" -u, --user user Run as 'user' (overrides the configfile)\n" +" -g, --group group Run as 'group' (overrides the configfile)\n" +" -v, --version Print version information and exit.\n" +" -h, --help Print this message and exit.\n" +" -D, --debug ddd Enable debug messages on 'ddd'; see documentation for details\n" +" -L, --logfile file Write output to file, instead of stderr.\n" + /* +" -P, --pidfile file Write pid of the running daemon to file.\n" + */ +; int main(int argc, char *argv[]) { - MiavDaemon daemon; + const char *hugin_filter = "+all"; + const char *logfile = NULL; + int c; + std::string configfile = ETC"/miav.conf"; + char *user = NULL; + char *group = NULL; + bool foreground = false; + // std::string pidfile; + + unsigned int hugin_flags = 0; + + int option_index = 0; + while(1) { + // int this_option_optind = optind ? optind : 1; + static struct option long_options[] = { + {"foreground", no_argument, 0, 'f'}, + {"config", required_argument, 0, 'c'}, + {"user", required_argument, 0, 'u'}, + {"group", required_argument, 0, 'g'}, + {"help", no_argument, 0, 'h'}, + {"version", no_argument, 0, 'v'}, + {"debug", required_argument, 0, 'D'}, + //{"pidfile", required_argument, 0, 'P'}, + {"logfile", required_argument, 0, 'L'}, + {0, 0, 0, 0} + }; + + c = getopt_long (argc, argv, "hvfc:u:g:D:P:L:", + long_options, &option_index); + + if (c == -1) + break; + + switch(c) { + case 'L': + hugin_flags |= HUG_FLAG_OUTPUT_TO_FILE; + logfile = strdup(optarg); + break; + + case 'c': + configfile = optarg; + break; + + case 'f': + foreground = true; + break; + + case 'u': + user = strdup(optarg); + break; + + case 'g': + group = strdup(optarg); + break; + + case 'D': + hugin_flags |= HUG_FLAG_USE_FILTER; + hugin_filter = optarg; + break; + /* + case 'P': + pidfile = optarg; + break; + */ + case '?': + case 'h': + printf("%s", version_str); + printf(usage_str, argv[0]); + return 0; + + case 'v': + printf("%s", version_str); + printf("%s", copyright_str); + return 0; + + default: + break; + } + } + + if(logfile == NULL) hugin_flags |= HUG_FLAG_OUTPUT_TO_STDOUT; + + hug_status_t status = hug_init(hugin_flags, + HUG_OPTION_FILTER, hugin_filter, + HUG_OPTION_FILENAME, logfile, + HUG_OPTION_END); + if(status != HUG_STATUS_OK) { + printf("Error: %d\n", status); + return 1; + } + + MiavConfig cfg(configfile.c_str()); + config = &cfg; // Global config object + + int port = cfg.readInt("server_port"); + + MiavDaemon daemon(port); - MiavConfig cfg(ETC"/miav.conf"); + const char *cuser = cfg.readString("server_user")->c_str(); + const char *cgroup = cfg.readString("server_group")->c_str(); - string *user = cfg.readString("server_user"); - string *group = cfg.readString("server_group"); + if(user) cuser = user; + if(group) cgroup = group; - return daemon.run(user->c_str(), group->c_str(), true); + return daemon.run(cuser, cgroup, foreground); } -- cgit v1.2.3