__dso_public int sudo_fatal_callback_deregister(void (*func)(void));
__dso_public int sudo_fatal_callback_register(void (*func)(void));
__dso_public char *sudo_warn_gettext(const char *msgid) __format_arg(1);
+__dso_public char *sudo_warn_strerror(int errnum);
__dso_public void sudo_fatal_nodebug(const char *, ...) __printf0like(1, 2) __attribute__((__noreturn__));
__dso_public void sudo_fatalx_nodebug(const char *, ...) __printflike(1, 2) __attribute__((__noreturn__));
__dso_public void sudo_vfatal_nodebug(const char *, va_list ap) __printf0like(1, 0) __attribute__((__noreturn__));
static struct sudo_fatal_callback_list callbacks;
-static void _warning(int, const char *, va_list);
+static void _warning(int errnum, const char *fmt, va_list ap);
static void
do_cleanup(void)
va_list ap;
va_start(ap, fmt);
- _warning(1, fmt, ap);
+ _warning(errno, fmt, ap);
va_end(ap);
do_cleanup();
exit(EXIT_FAILURE);
void
sudo_vfatal_nodebug(const char *fmt, va_list ap)
{
- _warning(1, fmt, ap);
+ _warning(errno, fmt, ap);
do_cleanup();
exit(EXIT_FAILURE);
}
va_list ap;
va_start(ap, fmt);
- _warning(1, fmt, ap);
+ _warning(errno, fmt, ap);
va_end(ap);
}
void
sudo_vwarn_nodebug(const char *fmt, va_list ap)
{
- _warning(1, fmt, ap);
+ _warning(errno, fmt, ap);
}
void
}
static void
-_warning(int use_errno, const char *fmt, va_list ap)
+_warning(int errnum, const char *fmt, va_list ap)
{
- int serrno = errno;
char *str;
sudo_evasprintf(&str, fmt, ap);
- if (use_errno) {
+ if (errnum) {
if (fmt != NULL) {
sudo_printf(SUDO_CONV_ERROR_MSG,
- _("%s: %s: %s\n"), getprogname(), str, strerror(serrno));
+ _("%s: %s: %s\n"), getprogname(), str,
+ sudo_warn_strerror(errnum));
} else {
sudo_printf(SUDO_CONV_ERROR_MSG,
- _("%s: %s\n"), getprogname(), strerror(serrno));
+ _("%s: %s\n"), getprogname(),
+ sudo_warn_strerror(errnum));
}
} else {
sudo_printf(SUDO_CONV_ERROR_MSG,
_("%s: %s\n"), getprogname(), str ? str : "(null)");
}
efree(str);
- errno = serrno;
}
/*
/*
- * Copyright (c) 2012-2013 Todd C. Miller <Todd.Miller@courtesan.com>
+ * Copyright (c) 2012-2014 Todd C. Miller <Todd.Miller@courtesan.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
return msg;
}
#endif /* HAVE_LIBINTL_H */
+
+char *
+sudo_warn_strerror(int errnum)
+{
+ int warning_locale;
+ char *errmsg;
+
+ sudoers_setlocale(SUDOERS_LOCALE_USER, &warning_locale);
+ errmsg = strerror(errnum);
+ sudoers_setlocale(warning_locale, NULL);
+
+ return errmsg;
+}
/*
- * Copyright (c) 2013 Todd C. Miller <Todd.Miller@courtesan.com>
+ * Copyright (c) 2013-2014 Todd C. Miller <Todd.Miller@courtesan.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
#include <stdio.h>
#include <stdlib.h>
+#ifdef HAVE_STRING_H
+# include <string.h>
+#endif /* HAVE_STRING_H */
+#ifdef HAVE_STRINGS_H
+# include <strings.h>
+#endif /* HAVE_STRINGS_H */
#define DEFAULT_TEXT_DOMAIN "sudo"
#include "gettext.h" /* must be included before missing.h */
return gettext(msgid);
}
#endif /* HAVE_LIBINTL_H */
+
+/* No need to swap locales in the front end. */
+char *
+sudo_warn_strerror(int errnum)
+{
+ return strerror(errnum);
+}