From 3dab6bd8e9bbcce570fa3cb1ce39933caaabbf15 Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Mon, 18 Nov 2013 09:10:09 -0700 Subject: [PATCH] Allow sudo to compile without variadic macro support in cpp. Debugging support will be limited (no file info from warnings.) From Daniel Richard G.; Bug #621 --- common/sudo_debug.c | 12 ++++++++++++ config.h.in | 3 +++ configure | 16 ++++++++++++---- configure.ac | 7 +++++-- include/fatal.h | 17 +++++------------ include/sudo_debug.h | 5 ++++- 6 files changed, 41 insertions(+), 19 deletions(-) diff --git a/common/sudo_debug.c b/common/sudo_debug.c index 7e51ff279..33a081a13 100644 --- a/common/sudo_debug.c +++ b/common/sudo_debug.c @@ -458,6 +458,18 @@ sudo_debug_vprintf2(const char *func, const char *file, int lineno, int level, errno = saved_errno; } +#ifdef NO_VARIADIC_MACROS +void +sudo_debug_printf_nvm(int pri, const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + sudo_debug_vprintf2(NULL, NULL, 0, pri, fmt, ap); + va_end(ap); +} +#endif /* NO_VARIADIC_MACROS */ + void sudo_debug_printf2(const char *func, const char *file, int lineno, int level, const char *fmt, ...) diff --git a/config.h.in b/config.h.in index 98c355cf9..9d42f063e 100644 --- a/config.h.in +++ b/config.h.in @@ -906,6 +906,9 @@ /* Define to 1 if you want a single ticket file instead of per-tty files. */ #undef NO_TTY_TICKETS +/* Define if your C preprocessor does not support variadic macros. */ +#undef NO_VARIADIC_MACROS + /* Define to the address where bug reports for this package should be sent. */ #undef PACKAGE_BUGREPORT diff --git a/configure b/configure index f979b74e8..7f0ecd9d3 100755 --- a/configure +++ b/configure @@ -14872,7 +14872,8 @@ $as_echo "#define volatile /**/" >>confdefs.h fi -# Check for variadic macro support in cpp +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for variadic macro support in cpp" >&5 +$as_echo_n "checking for variadic macro support in cpp... " >&6; } cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ @@ -14892,9 +14893,16 @@ sudo_fprintf(stderr, "a %s", "test"); } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : - + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } else - as_fn_error $? "Your C compiler doesn't support variadic macros, try building with gcc instead" "$LINENO" 5 + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + +$as_echo "#define NO_VARIADIC_MACROS 1" >>confdefs.h + + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Your C compiler doesn't support variadic macros, debugging support will be limited" >&5 +$as_echo "$as_me: WARNING: Your C compiler doesn't support variadic macros, debugging support will be limited" >&2;} fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext @@ -16132,7 +16140,7 @@ _ACEOF fi ac_fn_c_check_type "$LINENO" "struct timespec" "ac_cv_type_struct_timespec" "#include -#if TIME_WITH_SYS_TIME +#ifdef TIME_WITH_SYS_TIME # include #endif #include diff --git a/configure.ac b/configure.ac index 08232ec9d..682e25fbe 100644 --- a/configure.ac +++ b/configure.ac @@ -2066,7 +2066,7 @@ dnl AC_PROG_GCC_TRADITIONAL AC_C_CONST AC_C_VOLATILE -# Check for variadic macro support in cpp +AC_MSG_CHECKING([for variadic macro support in cpp]) AC_COMPILE_IFELSE([AC_LANG_PROGRAM([ AC_INCLUDES_DEFAULT #if defined(__GNUC__) && __GNUC__ == 2 @@ -2074,7 +2074,10 @@ AC_INCLUDES_DEFAULT #else # define sudo_fprintf(fp, ...) fprintf((fp), __VA_ARGS__) #endif -], [sudo_fprintf(stderr, "a %s", "test");])], [], [AC_MSG_ERROR([Your C compiler doesn't support variadic macros, try building with gcc instead])]) +], [sudo_fprintf(stderr, "a %s", "test");])], [AC_MSG_RESULT([yes])], +[AC_MSG_RESULT([no]) + AC_DEFINE([NO_VARIADIC_MACROS], [1], [Define if your C preprocessor does not support variadic macros.]) + AC_MSG_WARN([Your C compiler doesn't support variadic macros, debugging support will be limited])]) dnl dnl Program checks diff --git a/include/fatal.h b/include/fatal.h index 18bf64014..9963b0f78 100644 --- a/include/fatal.h +++ b/include/fatal.h @@ -24,18 +24,11 @@ * We wrap fatal/fatalx and warning/warningx so that the same output can * go to the debug file, if there is one. */ -#if defined(SUDO_ERROR_WRAP) && SUDO_ERROR_WRAP == 0 -# if defined(__GNUC__) && __GNUC__ == 2 -# define fatal(fmt...) fatal_nodebug(fmt) -# define fatalx(fmt...) fatalx_nodebug(fmt) -# define warning(fmt...) warning_nodebug(fmt) -# define warningx(fmt...) warningx_nodebug(fmt) -# else -# define fatal(...) fatal_nodebug(__VA_ARGS__) -# define fatalx(...) fatalx_nodebug(__VA_ARGS__) -# define warning(...) warning_nodebug(__VA_ARGS__) -# define warningx(...) warningx_nodebug(__VA_ARGS__) -# endif /* __GNUC__ == 2 */ +#if (defined(SUDO_ERROR_WRAP) && SUDO_ERROR_WRAP == 0) || defined(NO_VARIADIC_MACROS) +# define fatal fatal_nodebug +# define fatalx fatalx_nodebug +# define warning warning_nodebug +# define warningx warningx_nodebug # define vfatal(fmt, ap) fatal_nodebug((fmt), (ap)) # define vfatalx(fmt, ap) fatalx_nodebug((fmt), (ap)) # define vwarning(fmt, ap) warning_nodebug((fmt), (ap)) diff --git a/include/sudo_debug.h b/include/sudo_debug.h index 4803df0bf..9a17211c8 100644 --- a/include/sudo_debug.h +++ b/include/sudo_debug.h @@ -187,7 +187,9 @@ * Variadic macros are a C99 feature but GNU cpp has supported * a (different) version of them for a long time. */ -#if defined(__GNUC__) && __GNUC__ == 2 +#if defined(NO_VARIADIC_MACROS) +# define sudo_debug_printf sudo_debug_printf_nvm +#elif defined(__GNUC__) && __GNUC__ == 2 # define sudo_debug_printf(pri, fmt...) \ sudo_debug_printf2(__func__, __FILE__, __LINE__, (pri)|sudo_debug_subsys, \ fmt) @@ -218,6 +220,7 @@ void sudo_debug_exit_str_masked(const char *func, const char *file, int line, in void sudo_debug_exit_ptr(const char *func, const char *file, int line, int subsys, const void *rval); int sudo_debug_fd_set(int fd); int sudo_debug_init(const char *debugfile, const char *settings); +void sudo_debug_printf_nvm(int pri, const char *fmt, ...) __printf0like(2, 3); void sudo_debug_printf2(const char *func, const char *file, int line, int level, const char *fmt, ...) __printf0like(5, 6); void sudo_debug_vprintf2(const char *func, const char *file, int line, int level, const char *fmt, va_list ap) __printf0like(5, 0); void sudo_debug_write(const char *str, int len, int errno_val); -- 2.40.0