summaryrefslogtreecommitdiffstats
path: root/src/daemon
diff options
context:
space:
mode:
authorDenys Vlasenko <dvlasenk@redhat.com>2011-01-20 20:33:34 +0100
committerDenys Vlasenko <dvlasenk@redhat.com>2011-01-20 20:33:34 +0100
commite3d48ee0458f1d0078da65bad99804d2ba58aaf0 (patch)
tree5495c0a50ba3357025a3deb7b5c72c3af9cfc9fe /src/daemon
parentd7d62ea5ee19f5cad52dcfb2f2a49d8d36fa1228 (diff)
downloadabrt-e3d48ee0458f1d0078da65bad99804d2ba58aaf0.tar.gz
abrt-e3d48ee0458f1d0078da65bad99804d2ba58aaf0.tar.xz
abrt-e3d48ee0458f1d0078da65bad99804d2ba58aaf0.zip
make option handling more regular across all tools
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
Diffstat (limited to 'src/daemon')
-rw-r--r--src/daemon/Daemon.cpp50
-rw-r--r--src/daemon/abrt-action-save-package-data.c42
-rw-r--r--src/daemon/abrt-handle-crashdump.c13
-rw-r--r--src/daemon/abrt-server.c36
4 files changed, 73 insertions, 68 deletions
diff --git a/src/daemon/Daemon.cpp b/src/daemon/Daemon.cpp
index 8d972a9a..7c063d9d 100644
--- a/src/daemon/Daemon.cpp
+++ b/src/daemon/Daemon.cpp
@@ -34,6 +34,8 @@
#include "Daemon.h"
#include "parse_options.h"
+#define PROGNAME "abrtd"
+
using namespace std;
@@ -463,10 +465,10 @@ static void run_main_loop(GMainLoop* loop)
fds = (GPollFD *)xrealloc(fds, fds_size * sizeof(fds[0]));
}
- if (s_timeout)
+ if (s_timeout != 0)
alarm(s_timeout);
g_poll(fds, nfds, timeout);
- if (s_timeout)
+ if (s_timeout != 0)
alarm(0);
some_ready = g_main_context_check(context, max_priority, fds, nfds);
@@ -486,7 +488,7 @@ static void start_syslog_logging()
* Otherwise fprintf(stderr) dumps messages into random fds, etc. */
xdup2(STDIN_FILENO, STDOUT_FILENO);
xdup2(STDIN_FILENO, STDERR_FILENO);
- openlog("abrtd", 0, LOG_DAEMON);
+ openlog(PROGNAME, 0, LOG_DAEMON);
logmode = LOGMODE_SYSLOG;
putenv((char*)"ABRT_SYSLOG=1");
}
@@ -523,23 +525,6 @@ static void sanitize_dump_dir_rights()
ensure_writable_dir(VAR_RUN"/abrt", 0755, "root");
}
-static char *timeout_opt;
-static const char* abrtd_usage = _("abrtd [options]");
-enum {
- OPT_v = 1 << 0,
- OPT_d = 1 << 1,
- OPT_s = 1 << 2,
- OPT_t = 1 << 3,
-};
-/* Keep enum above and order of options below in sync! */
-static struct options abrtd_options[] = {
- OPT__VERBOSE(&g_verbose),
- OPT_BOOL( 'd' , 0, NULL, _("Do not daemonize")),
- OPT_BOOL( 's' , 0, NULL, _("Log to syslog even with -d")),
- OPT_INTEGER( 't' , 0, &timeout_opt, _("Exit after SEC seconds of inactivity")),
- OPT_END()
-};
-
int main(int argc, char** argv)
{
int parent_pid = getpid();
@@ -558,9 +543,24 @@ int main(int argc, char** argv)
if (env_verbose)
g_verbose = atoi(env_verbose);
- unsigned opts = parse_opts(argc, argv, abrtd_options, abrtd_usage);
-
- msg_prefix = "abrtd"; /* for log(), error_msg() and such */
+ const char *program_usage_string = _(
+ PROGNAME" [options]"
+ );
+ enum {
+ OPT_v = 1 << 0,
+ OPT_d = 1 << 1,
+ OPT_s = 1 << 2,
+ OPT_t = 1 << 3,
+ };
+ /* Keep enum above and order of options below in sync! */
+ struct options program_options[] = {
+ OPT__VERBOSE(&g_verbose),
+ OPT_BOOL( 'd', NULL, NULL , _("Do not daemonize")),
+ OPT_BOOL( 's', NULL, NULL , _("Log to syslog even with -d")),
+ OPT_INTEGER('t', NULL, &s_timeout, _("Exit after SEC seconds of inactivity")),
+ OPT_END()
+ };
+ unsigned opts = parse_opts(argc, argv, program_options, program_usage_string);
unsetenv("ABRT_SYSLOG");
putenv(xasprintf("ABRT_VERBOSE=%u", g_verbose));
@@ -571,7 +571,7 @@ int main(int argc, char** argv)
const char *env_path = getenv("PATH");
if (!env_path || !env_path[0])
putenv((char*)"PATH=/usr/sbin:/usr/bin:/sbin:/bin");
-
+ msg_prefix = PROGNAME; /* for log(), error_msg() and such */
if (opts & OPT_s)
start_syslog_logging();
@@ -581,7 +581,7 @@ int main(int argc, char** argv)
signal(SIGTERM, handle_signal);
signal(SIGINT, handle_signal);
signal(SIGCHLD, handle_signal);
- if (s_timeout)
+ if (s_timeout != 0)
signal(SIGALRM, handle_signal);
/* Daemonize unless -d */
diff --git a/src/daemon/abrt-action-save-package-data.c b/src/daemon/abrt-action-save-package-data.c
index d912dec4..8ddd1d8c 100644
--- a/src/daemon/abrt-action-save-package-data.c
+++ b/src/daemon/abrt-action-save-package-data.c
@@ -267,36 +267,36 @@ static int SavePackageDescriptionToDebugDump(const char *dump_dir_name)
return error;
}
-static const char *dump_dir_name = ".";
-static const char abrt_action_save_package_data_usage[] =
- PROGNAME" [options] -d DIR\n"
- "\n"
- "Query package database and save package name, component, and description";
-enum {
- OPT_v = 1 << 0,
- OPT_d = 1 << 1,
- OPT_s = 1 << 2,
-};
-/* Keep enum above and order of options below in sync! */
-static struct options abrt_action_save_package_data_options[] = {
- OPT__VERBOSE(&g_verbose),
- OPT_STRING('d', NULL, &dump_dir_name, "DIR", "Crash dump directory"),
- OPT_BOOL( 's', NULL, NULL, "Log to syslog"),
- OPT_END()
-};
-
int main(int argc, char **argv)
{
char *env_verbose = getenv("ABRT_VERBOSE");
if (env_verbose)
g_verbose = atoi(env_verbose);
- unsigned opts = parse_opts(argc, argv, abrt_action_save_package_data_options,
- abrt_action_save_package_data_usage);
+ const char *dump_dir_name = ".";
+
+ /* Can't keep these strings/structs static: _() doesn't support that */
+ const char *program_usage_string = _(
+ PROGNAME" [options] -d DIR\n"
+ "\n"
+ "Query package database and save package name, component, and description"
+ );
+ enum {
+ OPT_v = 1 << 0,
+ OPT_d = 1 << 1,
+ OPT_s = 1 << 2,
+ };
+ /* Keep enum above and order of options below in sync! */
+ struct options program_options[] = {
+ OPT__VERBOSE(&g_verbose),
+ OPT_STRING('d', NULL, &dump_dir_name, "DIR", _("Crash dump directory")),
+ OPT_BOOL( 's', NULL, NULL , _("Log to syslog")),
+ OPT_END()
+ };
+ unsigned opts = parse_opts(argc, argv, program_options, program_usage_string);
putenv(xasprintf("ABRT_VERBOSE=%u", g_verbose));
msg_prefix = PROGNAME;
-
if (opts & OPT_s)
{
openlog(msg_prefix, 0, LOG_DAEMON);
diff --git a/src/daemon/abrt-handle-crashdump.c b/src/daemon/abrt-handle-crashdump.c
index 2286de60..c778c792 100644
--- a/src/daemon/abrt-handle-crashdump.c
+++ b/src/daemon/abrt-handle-crashdump.c
@@ -38,11 +38,13 @@ int main(int argc, char **argv)
if (env_verbose)
g_verbose = atoi(env_verbose);
- const char *program_usage = _(
+ /* Can't keep these strings/structs static: _() doesn't support that */
+ const char *program_usage_string = _(
PROGNAME" [-vs]" /*" [-c CONFFILE]"*/ " -d DIR -e EVENT\n"
" or: "PROGNAME" [-vs]" /*" [-c CONFFILE]"*/ " [-d DIR] -l[PFX]\n"
"\n"
- "Handle crash dump according to rules in abrt_event.conf");
+ "Handle crash dump according to rules in abrt_event.conf"
+ );
enum {
OPT_v = 1 << 0,
OPT_s = 1 << 1,
@@ -61,11 +63,12 @@ int main(int argc, char **argv)
// OPT_STRING( 'c', NULL, &conf_filename, "CONFFILE", _("Configuration file" )),
OPT_END()
};
-
- unsigned opts = parse_opts(argc, argv, program_options, program_usage);
+ unsigned opts = parse_opts(argc, argv, program_options, program_usage_string);
if (!(opts & (OPT_e|OPT_l)))
- show_usage_and_die(program_usage, program_options);
+ show_usage_and_die(program_usage_string, program_options);
+
putenv(xasprintf("ABRT_VERBOSE=%u", g_verbose));
+ msg_prefix = PROGNAME;
if (opts & OPT_s)
{
openlog(msg_prefix, 0, LOG_DAEMON);
diff --git a/src/daemon/abrt-server.c b/src/daemon/abrt-server.c
index 47457aaf..3415e95c 100644
--- a/src/daemon/abrt-server.c
+++ b/src/daemon/abrt-server.c
@@ -21,6 +21,7 @@
#include "hooklib.h"
#include "parse_options.h"
+#define PROGNAME "abrt-server"
/* Maximal length of backtrace. */
#define MAX_BACKTRACE_SIZE (1024*1024)
@@ -275,31 +276,32 @@ static void process_message(const char *message)
static void dummy_handler(int sig_unused) {}
-static const char abrt_server_usage[] = "abrt-server [options]";
-enum {
- OPT_v = 1 << 0,
- OPT_u = 1 << 1,
- OPT_s = 1 << 2,
-};
-/* Keep enum above and order of options below in sync! */
-static struct options abrt_server_options[] = {
- OPT__VERBOSE(&g_verbose),
- OPT_INTEGER( 'u' , 0, &client_uid, "Use UID as client uid"),
- OPT_BOOL( 's' , 0, NULL, "Log to syslog"),
- OPT_END()
-};
-
int main(int argc, char **argv)
{
char *env_verbose = getenv("ABRT_VERBOSE");
if (env_verbose)
g_verbose = atoi(env_verbose);
- unsigned opts = parse_opts(argc, argv, abrt_server_options,
- abrt_server_usage);
+ /* Can't keep these strings/structs static: _() doesn't support that */
+ const char *program_usage_string = _(
+ PROGNAME" [options]"
+ );
+ enum {
+ OPT_v = 1 << 0,
+ OPT_u = 1 << 1,
+ OPT_s = 1 << 2,
+ };
+ /* Keep enum above and order of options below in sync! */
+ struct options program_options[] = {
+ OPT__VERBOSE(&g_verbose),
+ OPT_INTEGER('u', NULL, &client_uid, _("Use UID as client uid")),
+ OPT_BOOL( 's', NULL, NULL , _("Log to syslog")),
+ OPT_END()
+ };
+ unsigned opts = parse_opts(argc, argv, program_options, program_usage_string);
putenv(xasprintf("ABRT_VERBOSE=%u", g_verbose));
- msg_prefix = xasprintf("abrt-server[%u]", getpid());
+ msg_prefix = xasprintf(PROGNAME"[%u]", getpid());
if (opts & OPT_s)
{
openlog(msg_prefix, 0, LOG_DAEMON);