Skip to content
Snippets Groups Projects
Commit 1c9d7cab authored by Tristan Matthews's avatar Tristan Matthews
Browse files

* #9736: restored command line options to daemon

Also added -v/--version flag
parent 0d661418
Branches
Tags
No related merge requests found
...@@ -50,7 +50,8 @@ AC_FUNC_ALLOCA ...@@ -50,7 +50,8 @@ AC_FUNC_ALLOCA
AC_HEADER_STDC AC_HEADER_STDC
AC_CHECK_HEADERS([arpa/inet.h fcntl.h libintl.h limits.h malloc.h memory.h \ AC_CHECK_HEADERS([arpa/inet.h fcntl.h libintl.h limits.h malloc.h memory.h \
netdb.h netinet/in.h stdlib.h string.h strings.h \ netdb.h netinet/in.h stdlib.h string.h strings.h \
sys/ioctl.h sys/socket.h sys/time.h unistd.h utime.h ostream]) sys/ioctl.h sys/socket.h sys/time.h unistd.h utime.h \
ostream getopt.h])
dnl Check for typedefs, structures, and compiler characteristics dnl Check for typedefs, structures, and compiler characteristics
AC_HEADER_STAT AC_HEADER_STAT
......
...@@ -86,7 +86,7 @@ void DBusManager::exec() ...@@ -86,7 +86,7 @@ void DBusManager::exec()
ERROR("%s: %s, exiting\n", err.name(), err.what()); ERROR("%s: %s, exiting\n", err.name(), err.what());
::exit(EXIT_FAILURE); ::exit(EXIT_FAILURE);
} catch (const std::exception &err) { } catch (const std::exception &err) {
ERROR("%s: %s, exiting\n", err.what()); ERROR("%s: exiting\n", err.what());
::exit(EXIT_FAILURE); ::exit(EXIT_FAILURE);
} }
} }
...@@ -100,7 +100,7 @@ DBusManager::exit() ...@@ -100,7 +100,7 @@ DBusManager::exit()
ERROR("%s: %s, exiting\n", err.name(), err.what()); ERROR("%s: %s, exiting\n", err.name(), err.what());
::exit(EXIT_FAILURE); ::exit(EXIT_FAILURE);
} catch (const std::exception &err) { } catch (const std::exception &err) {
ERROR("%s: %s, exiting\n", err.what()); ERROR("%s: exiting\n", err.what());
::exit(EXIT_FAILURE); ::exit(EXIT_FAILURE);
} }
} }
...@@ -35,50 +35,98 @@ ...@@ -35,50 +35,98 @@
#endif #endif
#include <iostream> #include <iostream>
#include <memory> // for auto_ptr #include <getopt.h>
#include <string>
// #include <commoncpp/common.h>
#include "fileutils.h" #include "fileutils.h"
#include "dbus/dbusmanager.h" #include "dbus/dbusmanager.h"
#include "manager.h" #include "manager.h"
/*
ost::CommandOptionNoArg console(
"console", "c", "Log in console (instead of syslog)"
);
ost::CommandOptionNoArg debug( namespace {
"debug", "d", "Debug mode (more verbose)" void print_title()
); {
std::cout << "SFLphone Daemon " << VERSION <<
", by Savoir-Faire Linux 2004-2012" << std::endl <<
"http://www.sflphone.org/" << std::endl;
}
ost::CommandOptionNoArg help( void print_usage()
"help", "h", "Print help"
);
*/
int main(int /*argc*/, char **argv)
{ {
fileutils::set_program_dir(argv[0]); std::cout << std::endl <<
// makeCommandOptionParse allocates the object with operator new, so "-c, --console \t- Log in console (instead of syslog)" << std::endl <<
// auto_ptr is fine in this context. "-d, --debug \t- Debug mode (more verbose)" << std::endl <<
// TODO: This should eventually be replaced with std::unique_ptr for C++0x "-h, --help \t- Print help" << std::endl;
// std::auto_ptr<ost::CommandOptionParse> args(ost::makeCommandOptionParse(argc, argv, "")); }
printf("SFLphone Daemon " VERSION ", by Savoir-Faire Linux 2004-2012\n" \ // Parse command line arguments, setting debug options or printing a help
"http://www.sflphone.org/\n"); // message accordingly.
/* // returns true if we should quit (i.e. help was printed), false otherwise
if (help.numSet) { bool parse_args(int argc, char *argv[])
std::cerr << args->printUsage(); {
return 0; int consoleFlag = false;
} else if (args->argsHaveError()) { int debugFlag = false;
std::cerr << args->printErrors(); int helpFlag = false;
std::cerr << args->printUsage(); int versionFlag = false;
return 1; static const struct option long_options[] = {
/* These options set a flag. */
{"debug", no_argument, NULL, 'd'},
{"console", no_argument, NULL, 'c'},
{"help", no_argument, NULL, 'h'},
{"version", no_argument, NULL, 'v'},
{0, 0, 0, 0} /* Sentinel */
};
while (true) {
/* getopt_long stores the option index here. */
int option_index = 0;
int c = getopt_long(argc, argv, "dchv", long_options, &option_index);
/* Detect the end of the options. */
if (c == -1)
break;
switch (c) {
case 'd':
debugFlag = true;
break;
case 'c':
consoleFlag = true;
break;
case 'h':
case '?':
helpFlag = true;
break;
case 'v':
versionFlag = true;
break;
default:
break;
} }
*/ }
// Logger::setConsoleLog(console.numSet);
// Logger::setDebugMode(debug.numSet); bool quit = false;
Logger::setConsoleLog(1); if (helpFlag) {
Logger::setDebugMode(1); print_usage();
quit = true;
} else if (versionFlag) {
// We've always print the title/version, so we can just exit
quit = true;
} else {
Logger::setConsoleLog(consoleFlag);
Logger::setDebugMode(debugFlag);
}
return quit;
}
}
int main(int argc, char *argv [])
{
fileutils::set_program_dir(argv[0]);
print_title();
if (parse_args(argc, argv))
return 0;
if (!fileutils::create_pidfile()) if (!fileutils::create_pidfile())
return 1; return 1;
...@@ -89,7 +137,8 @@ int main(int /*argc*/, char **argv) ...@@ -89,7 +137,8 @@ int main(int /*argc*/, char **argv)
std::cerr << e.what() << std::endl; std::cerr << e.what() << std::endl;
return 1; return 1;
} catch (...) { } catch (...) {
std::cerr << "An exception occured when initializing the system." << std::endl; std::cerr << "An exception occured when initializing " PACKAGE <<
std::endl;
return 1; return 1;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment