[Git][NTPsec/ntpsec][master] 3 commits: assert: clean up tabs and formatting in ntp_assert.h
Gary E. Miller
gitlab at mg.gitlab.com
Sat Jun 3 00:26:21 UTC 2017
Gary E. Miller pushed to branch master at NTPsec / ntpsec
Commits:
d64182e9 by Gary E. Miller at 2017-06-02T17:01:55-07:00
assert: clean up tabs and formatting in ntp_assert.h
- - - - -
1f6050b6 by Gary E. Miller at 2017-06-02T17:16:03-07:00
backtrace: make backtrace_log() public.
So it can be used in catchTrap().
- - - - -
272e915f by Gary E. Miller at 2017-06-02T17:20:56-07:00
backtrace: remove duplicate backtrace_log() code.
- - - - -
3 changed files:
- include/ntp_assert.h
- libntp/assert.c
- ntpd/ntp_sandbox.c
Changes:
=====================================
include/ntp_assert.h
=====================================
--- a/include/ntp_assert.h
+++ b/include/ntp_assert.h
@@ -9,17 +9,17 @@
* example:
*
* int foo(char *a) {
- * int result;
- * int value;
+ * int result;
+ * int value;
*
- * REQUIRE(a != NULL);
- * ...
- * bar(&value);
- * INSIST(value > 2);
- * ...
+ * REQUIRE(a != NULL);
+ * ...
+ * bar(&value);
+ * INSIST(value > 2);
+ * ...
*
- * ENSURE(result != 12);
- * return result;
+ * ENSURE(result != 12);
+ * return result;
* }
*
* open question: when would we use INVARIANT()?
@@ -40,41 +40,47 @@
#define INVARIANT(x) assert(x)
#define ENSURE(x) assert(x)
-# else /* not FlexeLint */
+# else /* not FlexeLint */
/*% isc assertion type */
typedef enum {
- assertiontype_require,
- assertiontype_ensure,
- assertiontype_insist,
- assertiontype_invariant
+ assertiontype_require,
+ assertiontype_ensure,
+ assertiontype_insist,
+ assertiontype_invariant
} assertiontype_t;
/* our assertion catcher */
-extern void assertion_failed(const char *, int,
- assertiontype_t,
- const char *)
- __attribute__ ((__noreturn__));
+extern void assertion_failed(const char *, int, assertiontype_t, const char *)
+ __attribute__ ((__noreturn__));
#define REQUIRE(cond) \
- ((void) ((cond) || (assertion_failed(__FILE__, __LINE__, \
- assertiontype_require, \
- #cond), 0)))
+ ((void) ((cond) || (assertion_failed(__FILE__, __LINE__, \
+ assertiontype_require, #cond), 0)))
#define ENSURE(cond) \
- ((void) ((cond) || (assertion_failed(__FILE__, __LINE__, \
- assertiontype_ensure, \
- #cond), 0)))
+ ((void) ((cond) || (assertion_failed(__FILE__, __LINE__, \
+ assertiontype_ensure, #cond), 0)))
#define INSIST(cond) \
- ((void) ((cond) || (assertion_failed(__FILE__, __LINE__, \
- assertiontype_insist, \
- #cond), 0)))
+ ((void) ((cond) || (assertion_failed(__FILE__, __LINE__, \
+ assertiontype_insist, #cond), 0)))
+
#define INVARIANT(cond) \
- ((void) ((cond) || (assertion_failed(__FILE__, __LINE__, \
- assertiontype_invariant, \
- #cond), 0)))
+ ((void) ((cond) || (assertion_failed(__FILE__, __LINE__, \
+ assertiontype_invariant, #cond), 0)))
# endif /* not FlexeLint */
-#endif /* GUARD_NTP_ASSERT_H */
+#if defined(USEBACKTRACE) && \
+ (defined(HAVE_BACKTRACE_SYMBOLS_FD) || defined (HAVE__UNWIND_BACKTRACE))
+ /* doing backtrace */
+
+extern void backtrace_log(void);
+
+#else
+ /* not doing backtrace */
+# define BACKTRACE_DISABLED 1
+#endif /* ! USEBACKTRACE */
+
+#endif /* GUARD_NTP_ASSERT_H */
=====================================
libntp/assert.c
=====================================
--- a/libntp/assert.c
+++ b/libntp/assert.c
@@ -42,8 +42,6 @@
# ifdef HAVE_BACKTRACE_SYMBOLS_FD
#include <execinfo.h>
-void backtrace_log(void);
-
void
backtrace_log(void) {
int j, nptrs;
@@ -107,16 +105,9 @@ backtrace_log(void) {
return (ISC_R_SUCCESS);
}
-# else
-# define BACKTRACE_DISABLED 1
-# endif
-#else /* ! USEBACKTRACE */
-# define BACKTRACE_DISABLED 1
-#endif /* USEBACKTRACE */
+#endif /* HAVE__UNWIND_BACKTRACE */
-static const char *
-assertion_typetotext(assertiontype_t type)
- __attribute__((const));
+#endif /* USEBACKTRACE */
/*% Type to Text */
static const char *
=====================================
ntpd/ntp_sandbox.c
=====================================
--- a/ntpd/ntp_sandbox.c
+++ b/ntpd/ntp_sandbox.c
@@ -12,6 +12,7 @@
#include <signal.h>
#include "config.h"
+#include "ntp_assert.h"
#ifdef ENABLE_DROPROOT
# include <ctype.h>
@@ -34,9 +35,6 @@ static priv_set_t *highprivs = NULL;
#ifdef HAVE_SECCOMP_H
# include <seccomp.h>
-# ifdef HAVE_BACKTRACE_SYMBOLS_FD
-# include <execinfo.h>
-# endif
static void catchTrap(int sig, siginfo_t *, void *);
#endif
@@ -451,26 +449,9 @@ static void catchTrap(int sig, siginfo_t *si, void *u)
msyslog(LOG_ERR, "ERROR: SIGSYS/seccomp bad syscall %d/%#x\n",
si->si_syscall, si->si_arch);
}
-#ifdef HAVE_BACKTRACE_SYMBOLS_FD
- {
-#define BT_BUF_SIZE 100
-
- int j, nptrs;
- void *buffer[BT_BUF_SIZE];
- char **strings;
-
- nptrs = backtrace(buffer, BT_BUF_SIZE);
- strings = backtrace_symbols(buffer, nptrs);
- msyslog(LOG_ERR, "Stack trace:\n");
- if (strings) {
- /* skip trace of this shim function */
- for (j = 1; j < nptrs; j++)
- msyslog(LOG_ERR, " %s\n", strings[j]);
-
- free(strings);
- }
- }
-#endif /* HAVE_BACKTRACE_SYMBOLS_FD */
+#ifndef BACKTRACE_DISABLED
+ backtrace_log();
+#endif
exit(1);
}
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/ba14955871f71ef16a620e442e1b0fa0b4c61d7b...272e915fd73083345b1682be3e57961867f50006
---
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/ba14955871f71ef16a620e442e1b0fa0b4c61d7b...272e915fd73083345b1682be3e57961867f50006
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20170603/af3c8fc4/attachment.html>
More information about the vc
mailing list