#define SNDBUF_SIZE (8*1024*1024)
+#define ALLOCA_CODE_FUNC(f, func) \
+ do { \
+ size_t _fl; \
+ const char *_func = (func); \
+ char **_f = &(f); \
+ _fl = strlen(_func) + 1; \
+ *_f = alloca(_fl + 10); \
+ memcpy(*_f, "CODE_FUNC=", 10); \
+ memcpy(*_f + 10, _func, _fl); \
+ } while(false)
+
/* We open a single fd, and we'll share it with the current process,
* all its threads, and all its subprocesses. This means we need to
* initialize it atomically, and need to operate on it atomically
char buffer[8 + LINE_MAX], p[11];
struct iovec iov[5];
char *f;
- size_t fl;
if (priority < 0 || priority > 7)
return -EINVAL;
/* func is initialized from __func__ which is not a macro, but
* a static const char[], hence cannot easily be prefixed with
* CODE_FUNC=, hence let's do it manually here. */
- fl = strlen(func) + 1;
- f = alloca(fl + 10);
- memcpy(f, "CODE_FUNC=", 10);
- memcpy(f + 10, func, fl);
+ ALLOCA_CODE_FUNC(f, func);
zero(iov);
IOVEC_SET_STRING(iov[0], buffer);
va_list ap;
struct iovec *iov = NULL;
char *f;
- size_t fl;
va_start(ap, format);
i = fill_iovec_sprintf(format, ap, 3, &iov);
goto finish;
}
- fl = strlen(func) + 1;
- f = alloca(fl + 10);
- memcpy(f, "CODE_FUNC=", 10);
- memcpy(f + 10, func, fl);
+ ALLOCA_CODE_FUNC(f, func);
IOVEC_SET_STRING(iov[0], file);
IOVEC_SET_STRING(iov[1], line);
struct iovec *niov;
char *f;
- size_t fl;
if (_unlikely_(!iov))
return -EINVAL;
niov = alloca(sizeof(struct iovec) * (n + 3));
memcpy(niov, iov, sizeof(struct iovec) * n);
- fl = strlen(func) + 1;
- f = alloca(fl + 10);
- memcpy(f, "CODE_FUNC=", 10);
- memcpy(f + 10, func, fl);
+ ALLOCA_CODE_FUNC(f, func);
IOVEC_SET_STRING(niov[n++], file);
IOVEC_SET_STRING(niov[n++], line);
const char *message) {
struct iovec iov[6];
- size_t fl;
char *f;
- fl = strlen(func) + 1;
- f = alloca(fl + 10);
- memcpy(f, "CODE_FUNC=", 10);
- memcpy(f + 10, func, fl);
+ ALLOCA_CODE_FUNC(f, func);
IOVEC_SET_STRING(iov[0], file);
IOVEC_SET_STRING(iov[1], line);