Commit 7bc05c77 7bc05c7755523cdb1222463e5e3c9e71f6906f18 by Sergey Poznyakoff

Fix eventual dangling pointers

Don't set mu_log_tag, leave that to the caller.

* libmailutils/cli/cli.c (mu_cli_ext): Don't set mu_log_tag.
* libmailutils/stdstream/strerr.c: Use MU_LOG_TAG macro from
syslog.h
* sieve/sieve.c: Redo --no-program-name support
1 parent dd3598aa
......@@ -500,16 +500,9 @@ mu_cli_ext (int argc, char **argv,
hints.flags &= ~MU_CFHINT_PER_USER_FILE;
/* Set program name */
if (hints.flags & MU_CFHINT_PROGRAM)
{
if (!mu_log_tag)
mu_log_tag = (char*)hints.program;
}
else
if (!(hints.flags & MU_CFHINT_PROGRAM))
{
mu_set_program_name (argv[0]);
if (!mu_log_tag)
mu_log_tag = (char*)mu_program_name;
hints.program = (char*) mu_program_name;
hints.flags |= MU_CFHINT_PROGRAM;
}
......
......@@ -117,7 +117,7 @@ mu_stdstream_strerr_setup (int type)
if (mu_stdstream_strerr_create (&str, type,
mu_log_facility, LOG_ERR,
mu_log_tag, NULL) == 0)
MU_LOG_TAG (), NULL) == 0)
{
if (mu_log_print_severity)
{
......
......@@ -59,6 +59,7 @@ int dry_run;
static int sieve_print_locus = 1; /* Should the log messages include the
locus */
static int no_program_name;
static void
modify_debug_flags (mu_debug_level_t set, mu_debug_level_t clr)
......@@ -124,13 +125,6 @@ cli_email (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
mu_parseopt_error (po, _("invalid email: %s"), mu_strerror (rc));
}
static void
cli_no_program_name (struct mu_parseopt *po, struct mu_option *opt,
char const *arg)
{
mu_log_tag = NULL;
}
static struct mu_option sieve_options[] = {
{ "dry-run", 'n', NULL, MU_OPTION_DEFAULT,
N_("do not execute any actions, just print what would be done"),
......@@ -168,7 +162,7 @@ static struct mu_option sieve_options[] = {
mu_c_bool, &expression_option },
{ "no-program-name", 0, NULL, MU_OPTION_DEFAULT,
N_("do not prefix diagnostic messages with the program name"),
mu_c_string, NULL, cli_no_program_name },
mu_c_int, &no_program_name },
MU_OPTION_END
}, *options[] = { sieve_options, NULL };
......@@ -414,6 +408,20 @@ main (int argc, char *argv[])
mu_cli (argc, argv, &cli, sieve_capa, NULL, &argc, &argv);
if (dry_run)
verbose++;
if (no_program_name)
{
mu_stream_t errstr;
mu_log_tag = NULL;
rc = mu_stdstream_strerr_create (&errstr, MU_STRERR_STDERR, 0, 0,
NULL, NULL);
if (rc == 0)
{
mu_stream_destroy (&mu_strerr);
mu_strerr = errstr;
}
}
if (argc == 0)
{
......