mirror of
https://git.jami.net/savoirfairelinux/jami-daemon.git
synced 2025-08-12 22:09:25 +08:00
* #9736: restored command line options to daemon
Also added -v/--version flag
This commit is contained in:
@ -50,7 +50,8 @@ AC_FUNC_ALLOCA
|
||||
AC_HEADER_STDC
|
||||
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 \
|
||||
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
|
||||
AC_HEADER_STAT
|
||||
|
@ -86,7 +86,7 @@ void DBusManager::exec()
|
||||
ERROR("%s: %s, exiting\n", err.name(), err.what());
|
||||
::exit(EXIT_FAILURE);
|
||||
} catch (const std::exception &err) {
|
||||
ERROR("%s: %s, exiting\n", err.what());
|
||||
ERROR("%s: exiting\n", err.what());
|
||||
::exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
@ -100,7 +100,7 @@ DBusManager::exit()
|
||||
ERROR("%s: %s, exiting\n", err.name(), err.what());
|
||||
::exit(EXIT_FAILURE);
|
||||
} catch (const std::exception &err) {
|
||||
ERROR("%s: %s, exiting\n", err.what());
|
||||
ERROR("%s: exiting\n", err.what());
|
||||
::exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
@ -35,50 +35,98 @@
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
#include <memory> // for auto_ptr
|
||||
#include <string>
|
||||
// #include <commoncpp/common.h>
|
||||
#include <getopt.h>
|
||||
#include "fileutils.h"
|
||||
|
||||
#include "dbus/dbusmanager.h"
|
||||
#include "manager.h"
|
||||
/*
|
||||
ost::CommandOptionNoArg console(
|
||||
"console", "c", "Log in console (instead of syslog)"
|
||||
);
|
||||
|
||||
ost::CommandOptionNoArg debug(
|
||||
"debug", "d", "Debug mode (more verbose)"
|
||||
);
|
||||
namespace {
|
||||
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(
|
||||
"help", "h", "Print help"
|
||||
);
|
||||
*/
|
||||
int main(int /*argc*/, char **argv)
|
||||
void print_usage()
|
||||
{
|
||||
std::cout << std::endl <<
|
||||
"-c, --console \t- Log in console (instead of syslog)" << std::endl <<
|
||||
"-d, --debug \t- Debug mode (more verbose)" << std::endl <<
|
||||
"-h, --help \t- Print help" << std::endl;
|
||||
}
|
||||
|
||||
// Parse command line arguments, setting debug options or printing a help
|
||||
// message accordingly.
|
||||
// returns true if we should quit (i.e. help was printed), false otherwise
|
||||
bool parse_args(int argc, char *argv[])
|
||||
{
|
||||
int consoleFlag = false;
|
||||
int debugFlag = false;
|
||||
int helpFlag = false;
|
||||
int versionFlag = false;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
bool quit = false;
|
||||
if (helpFlag) {
|
||||
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]);
|
||||
// makeCommandOptionParse allocates the object with operator new, so
|
||||
// auto_ptr is fine in this context.
|
||||
// TODO: This should eventually be replaced with std::unique_ptr for C++0x
|
||||
// std::auto_ptr<ost::CommandOptionParse> args(ost::makeCommandOptionParse(argc, argv, ""));
|
||||
|
||||
printf("SFLphone Daemon " VERSION ", by Savoir-Faire Linux 2004-2012\n" \
|
||||
"http://www.sflphone.org/\n");
|
||||
/*
|
||||
if (help.numSet) {
|
||||
std::cerr << args->printUsage();
|
||||
print_title();
|
||||
if (parse_args(argc, argv))
|
||||
return 0;
|
||||
} else if (args->argsHaveError()) {
|
||||
std::cerr << args->printErrors();
|
||||
std::cerr << args->printUsage();
|
||||
return 1;
|
||||
}
|
||||
*/
|
||||
// Logger::setConsoleLog(console.numSet);
|
||||
// Logger::setDebugMode(debug.numSet);
|
||||
Logger::setConsoleLog(1);
|
||||
Logger::setDebugMode(1);
|
||||
|
||||
if (!fileutils::create_pidfile())
|
||||
return 1;
|
||||
@ -89,7 +137,8 @@ int main(int /*argc*/, char **argv)
|
||||
std::cerr << e.what() << std::endl;
|
||||
return 1;
|
||||
} catch (...) {
|
||||
std::cerr << "An exception occured when initializing the system." << std::endl;
|
||||
std::cerr << "An exception occured when initializing " PACKAGE <<
|
||||
std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user