summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDenys Vlasenko <dvlasenk@redhat.com>2010-10-12 14:39:31 +0200
committerDenys Vlasenko <dvlasenk@redhat.com>2010-10-12 14:39:31 +0200
commit0bf035eaac1106c3eb6daecb277c193c9160d1af (patch)
treeccae87d00f91b9e3e68b3070f5dab3027d1891d4 /src
parent4d68ae093b68bd857165cc249deb3486f81966bf (diff)
downloadabrt-0bf035eaac1106c3eb6daecb277c193c9160d1af.tar.gz
abrt-0bf035eaac1106c3eb6daecb277c193c9160d1af.tar.xz
abrt-0bf035eaac1106c3eb6daecb277c193c9160d1af.zip
Return a bitmask of found options from parse_opts()
This patch makes it easier to analyze "bool" type options - now they are all just bits in a single return value, no need to have an integer variable for each option. The previous behavior is retained too: it is useful for "cumulative" options like -vvv. The patch also removes all OPT_GROUPs. Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
Diffstat (limited to 'src')
-rw-r--r--src/daemon/Daemon.cpp28
-rw-r--r--src/daemon/abrt-action-generate-backtrace.c31
-rw-r--r--src/daemon/abrt-action-save-package-data.cpp27
-rw-r--r--src/daemon/abrt-server.c13
4 files changed, 49 insertions, 50 deletions
diff --git a/src/daemon/Daemon.cpp b/src/daemon/Daemon.cpp
index f6073134..97cafe82 100644
--- a/src/daemon/Daemon.cpp
+++ b/src/daemon/Daemon.cpp
@@ -87,8 +87,6 @@ using namespace std;
*/
CCommLayerServer* g_pCommLayer;
-static bool daemonize = true;
-
static volatile sig_atomic_t s_sig_caught;
static int s_signal_pipe[2];
static int s_signal_pipe_write = -1;
@@ -860,16 +858,21 @@ static void sanitize_dump_dir_rights()
ensure_writable_dir(VAR_RUN"/abrt", 0755, "root");
}
-static int daemonize_opt, syslog_opt;
+enum {
+ OPT_v = 1 << 0,
+ OPT_d = 1 << 1,
+ OPT_s = 1 << 2,
+ OPT_t = 1 << 3,
+};
+
static char *timeout_opt;
static const char* abrtd_usage = _("abrtd [options]");
static struct options abrtd_options[] = {
OPT__VERBOSE(&g_verbose),
- OPT_GROUP(""),
- OPT_BOOL( 'd' , 0, &daemonize_opt, _("Do not daemonize")),
- OPT_BOOL( 's' , 0, &syslog_opt, _("Log to syslog even with -d")),
+ 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()
};
@@ -892,12 +895,9 @@ int main(int argc, char** argv)
if (env_verbose)
g_verbose = atoi(env_verbose);
- parse_opts(argc, argv, abrtd_options, abrtd_usage);
-
- if (daemonize_opt)
- daemonize = false;
+ unsigned opts = parse_opts(argc, argv, abrtd_options, abrtd_usage);
- if (syslog_opt)
+ if (opts & OPT_s)
start_syslog_logging();
putenv(xasprintf("ABRT_VERBOSE=%u", g_verbose));
@@ -914,7 +914,7 @@ int main(int argc, char** argv)
signal(SIGALRM, handle_signal);
/* Daemonize unless -d */
- if (daemonize)
+ if (!(opts & OPT_d))
{
/* forking to background */
pid_t pid = fork();
@@ -1042,13 +1042,13 @@ int main(int argc, char** argv)
/* Initialization error */
error_msg("Error while initializing daemon");
/* Inform parent that initialization failed */
- if (daemonize)
+ if (!(opts & OPT_d))
kill(parent_pid, SIGINT);
goto cleanup;
}
/* Inform parent that we initialized ok */
- if (daemonize)
+ if (!(opts & OPT_d))
{
VERB1 log("Signalling parent");
kill(parent_pid, SIGTERM);
diff --git a/src/daemon/abrt-action-generate-backtrace.c b/src/daemon/abrt-action-generate-backtrace.c
index 4be123b8..d07562d2 100644
--- a/src/daemon/abrt-action-generate-backtrace.c
+++ b/src/daemon/abrt-action-generate-backtrace.c
@@ -24,7 +24,7 @@
#define DEBUGINFO_CACHE_DIR LOCALSTATEDIR"/cache/abrt-di"
static const char *dump_dir_name = ".";
-static char *debuginfo_dirs;
+static const char *debuginfo_dirs;
static int exec_timeout_sec = 60;
@@ -240,18 +240,24 @@ static char *get_backtrace(struct dump_dir *dd)
return bt;
}
-static char *d_opt, *i_opt;
-static int s_opt;
+enum {
+ OPT_v = 1 << 0,
+ OPT_d = 1 << 1,
+ OPT_i = 1 << 2,
+ OPT_t = 1 << 3,
+ OPT_s = 1 << 4,
+};
+
+static char *i_opt;
static const char abrt_action_generage_backtrace_usage[] = "abrt-action-generate-backtrace [options] -d DIR";
static struct options abrt_action_generate_backtrace_options[] = {
OPT__VERBOSE(&g_verbose),
- OPT_GROUP(""),
- OPT_STRING( 'd' , 0, &d_opt, "dir", "Crash dump directory"),
+ OPT_STRING( 'd' , 0, &dump_dir_name, "dir", "Crash dump directory"),
OPT_STRING( 'i' , 0, &i_opt, "dir1[:dir2]...", "Additional debuginfo directories"),
OPT_INTEGER( 't' , 0, &exec_timeout_sec, "Kill gdb if it runs for more than SECONDS"),
- OPT_BOOL( 's' , 0, &s_opt, "Log to syslog even with -d"),
+ OPT_BOOL( 's' , 0, NULL, "Log to syslog even with -d"),
OPT_END()
};
@@ -261,26 +267,19 @@ int main(int argc, char **argv)
if (env_verbose)
g_verbose = atoi(env_verbose);
- parse_opts(argc, argv, abrt_action_generate_backtrace_options,
+ unsigned opts = parse_opts(argc, argv, abrt_action_generate_backtrace_options,
abrt_action_generage_backtrace_usage);
- if (!d_opt)
- parse_usage_and_die(abrt_action_generage_backtrace_usage,
- abrt_action_generate_backtrace_options);
-
- dump_dir_name = d_opt;
-
- debuginfo_dirs = xstrdup(DEBUGINFO_CACHE_DIR);
+ debuginfo_dirs = DEBUGINFO_CACHE_DIR;
if (i_opt)
{
- free(debuginfo_dirs);
debuginfo_dirs = xasprintf("%s:%s", DEBUGINFO_CACHE_DIR, i_opt);
}
putenv(xasprintf("ABRT_VERBOSE=%u", g_verbose));
msg_prefix = xasprintf("abrt-action-generate-backtrace[%u]", getpid());
- if (s_opt)
+ if (opts & OPT_s)
{
openlog(msg_prefix, 0, LOG_DAEMON);
logmode = LOGMODE_SYSLOG;
diff --git a/src/daemon/abrt-action-save-package-data.cpp b/src/daemon/abrt-action-save-package-data.cpp
index d72f46c0..1c2f6051 100644
--- a/src/daemon/abrt-action-save-package-data.cpp
+++ b/src/daemon/abrt-action-save-package-data.cpp
@@ -267,16 +267,20 @@ static int SavePackageDescriptionToDebugDump(const char *dump_dir_name)
return error;
}
-static char *d_opt;
-static int s_opt;
+enum {
+ OPT_v = 1 << 0,
+ OPT_d = 1 << 1,
+ OPT_s = 1 << 2,
+};
+
+static const char *dump_dir_name = ".";
static const char abrt_action_save_package_data_usage[] = "abrt-action-save-package-data [options] -d DIR";
static struct options abrt_action_save_package_data_options[] = {
OPT__VERBOSE(&g_verbose),
- OPT_GROUP(""),
- OPT_STRING( 'd' , 0, &d_opt, "dir", "Crash dump directory"),
- OPT_BOOL( 's' , 0, &s_opt, "Log to syslog"),
+ OPT_STRING( 'd' , 0, &dump_dir_name, "dir", "Crash dump directory"),
+ OPT_BOOL( 's' , 0, NULL, "Log to syslog"),
OPT_END()
};
@@ -286,20 +290,13 @@ int main(int argc, char **argv)
if (env_verbose)
g_verbose = atoi(env_verbose);
- const char *dump_dir_name = ".";
-
- parse_opts(argc, argv, abrt_action_save_package_data_options,
+ unsigned opts = parse_opts(argc, argv, abrt_action_save_package_data_options,
abrt_action_save_package_data_usage);
- if (!d_opt)
- parse_usage_and_die(abrt_action_save_package_data_usage,
- abrt_action_save_package_data_options);
-
- dump_dir_name = d_opt;
-
putenv(xasprintf("ABRT_VERBOSE=%u", g_verbose));
msg_prefix = xasprintf("abrt-action-save-package-data[%u]", getpid());
- if (s_opt)
+
+ if (opts & OPT_s)
{
openlog(msg_prefix, 0, LOG_DAEMON);
logmode = LOGMODE_SYSLOG;
diff --git a/src/daemon/abrt-server.c b/src/daemon/abrt-server.c
index b25d431d..4da0fc58 100644
--- a/src/daemon/abrt-server.c
+++ b/src/daemon/abrt-server.c
@@ -277,15 +277,18 @@ static void process_message(const char *message)
static void dummy_handler(int sig_unused) {}
-static int s_opt;
+enum {
+ OPT_v = 1 << 0,
+ OPT_u = 1 << 1,
+ OPT_s = 1 << 2,
+};
static const char abrt_server_usage[] = "abrt-server [options]";
static struct options abrt_server_options[] = {
OPT__VERBOSE(&g_verbose),
- OPT_GROUP(""),
OPT_INTEGER( 'u' , 0, &client_uid, "Use UID as client uid"),
- OPT_BOOL( 's' , 0, &s_opt, "Log to syslog"),
+ OPT_BOOL( 's' , 0, NULL, "Log to syslog"),
OPT_END()
};
@@ -295,12 +298,12 @@ int main(int argc, char **argv)
if (env_verbose)
g_verbose = atoi(env_verbose);
- parse_opts(argc, argv, abrt_server_options,
+ unsigned opts = parse_opts(argc, argv, abrt_server_options,
abrt_server_usage);
putenv(xasprintf("ABRT_VERBOSE=%u", g_verbose));
msg_prefix = xasprintf("abrt-server[%u]", getpid());
- if (s_opt)
+ if (opts & OPT_s)
{
openlog(msg_prefix, 0, LOG_DAEMON);
logmode = LOGMODE_SYSLOG;