basic/log: add concept of "synthethic errnos"
Synthetic errnos are processed like normal, and may be used in %m and become the return value from log_*(), but they are not logged in the journal.
This commit is contained in:
+29
-53
@@ -484,6 +484,8 @@ static int log_do_header(
|
||||
const char *extra_field, const char *extra) {
|
||||
int r;
|
||||
|
||||
error = IS_SYNTHETIC_ERRNO(error) ? 0 : ERRNO_VALUE(error);
|
||||
|
||||
r = snprintf(header, size,
|
||||
"PRIORITY=%i\n"
|
||||
"SYSLOG_FACILITY=%i\n"
|
||||
@@ -569,15 +571,12 @@ int log_dispatch_internal(
|
||||
|
||||
assert_raw(buffer);
|
||||
|
||||
if (error < 0)
|
||||
error = -error;
|
||||
|
||||
if (log_target == LOG_TARGET_NULL)
|
||||
return -error;
|
||||
return -ERRNO_VALUE(error);
|
||||
|
||||
/* Patch in LOG_DAEMON facility if necessary */
|
||||
if ((level & LOG_FACMASK) == 0)
|
||||
level = log_facility | LOG_PRI(level);
|
||||
level |= log_facility;
|
||||
|
||||
if (open_when_needed)
|
||||
log_open();
|
||||
@@ -636,7 +635,7 @@ int log_dispatch_internal(
|
||||
if (open_when_needed)
|
||||
log_close();
|
||||
|
||||
return -error;
|
||||
return -ERRNO_VALUE(error);
|
||||
}
|
||||
|
||||
int log_dump_internal(
|
||||
@@ -652,11 +651,8 @@ int log_dump_internal(
|
||||
|
||||
/* This modifies the buffer... */
|
||||
|
||||
if (error < 0)
|
||||
error = -error;
|
||||
|
||||
if (_likely_(LOG_PRI(level) > log_max_level[realm]))
|
||||
return -error;
|
||||
return -ERRNO_VALUE(error);
|
||||
|
||||
return log_dispatch_internal(level, error, file, line, func, NULL, NULL, NULL, NULL, buffer);
|
||||
}
|
||||
@@ -674,14 +670,11 @@ int log_internalv_realm(
|
||||
char buffer[LINE_MAX];
|
||||
PROTECT_ERRNO;
|
||||
|
||||
if (error < 0)
|
||||
error = -error;
|
||||
|
||||
if (_likely_(LOG_PRI(level) > log_max_level[realm]))
|
||||
return -error;
|
||||
return -ERRNO_VALUE(error);
|
||||
|
||||
/* Make sure that %m maps to the specified error (or "Success"). */
|
||||
errno = error;
|
||||
errno = ERRNO_VALUE(error);
|
||||
|
||||
(void) vsnprintf(buffer, sizeof buffer, format, ap);
|
||||
|
||||
@@ -723,14 +716,11 @@ static int log_object_internalv(
|
||||
PROTECT_ERRNO;
|
||||
char *buffer, *b;
|
||||
|
||||
if (error < 0)
|
||||
error = -error;
|
||||
|
||||
if (_likely_(LOG_PRI(level) > log_max_level[LOG_REALM_SYSTEMD]))
|
||||
return -error;
|
||||
return -ERRNO_VALUE(error);
|
||||
|
||||
/* Make sure that %m maps to the specified error (or "Success"). */
|
||||
errno = error;
|
||||
errno = ERRNO_VALUE(error);
|
||||
|
||||
/* Prepend the object name before the message */
|
||||
if (object) {
|
||||
@@ -853,7 +843,7 @@ int log_format_iovec(
|
||||
* since vasprintf() leaves it afterwards at
|
||||
* an undefined location */
|
||||
|
||||
errno = error;
|
||||
errno = ERRNO_VALUE(error);
|
||||
|
||||
va_copy(aq, ap);
|
||||
r = vasprintf(&m, format, aq);
|
||||
@@ -892,17 +882,12 @@ int log_struct_internal(
|
||||
PROTECT_ERRNO;
|
||||
va_list ap;
|
||||
|
||||
if (error < 0)
|
||||
error = -error;
|
||||
|
||||
if (_likely_(LOG_PRI(level) > log_max_level[realm]))
|
||||
return -error;
|
||||
|
||||
if (log_target == LOG_TARGET_NULL)
|
||||
return -error;
|
||||
if (_likely_(LOG_PRI(level) > log_max_level[realm]) ||
|
||||
log_target == LOG_TARGET_NULL)
|
||||
return -ERRNO_VALUE(error);
|
||||
|
||||
if ((level & LOG_FACMASK) == 0)
|
||||
level = log_facility | LOG_PRI(level);
|
||||
level |= log_facility;
|
||||
|
||||
if (IN_SET(log_target,
|
||||
LOG_TARGET_AUTO,
|
||||
@@ -922,7 +907,8 @@ int log_struct_internal(
|
||||
};
|
||||
bool fallback = false;
|
||||
|
||||
/* If the journal is available do structured logging */
|
||||
/* If the journal is available do structured logging.
|
||||
* Do not report the errno if it is synthetic. */
|
||||
log_do_header(header, sizeof(header), level, error, file, line, func, NULL, NULL, NULL, NULL);
|
||||
iovec[n++] = IOVEC_MAKE_STRING(header);
|
||||
|
||||
@@ -943,7 +929,7 @@ int log_struct_internal(
|
||||
if (open_when_needed)
|
||||
log_close();
|
||||
|
||||
return -error;
|
||||
return -ERRNO_VALUE(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -954,7 +940,7 @@ int log_struct_internal(
|
||||
while (format) {
|
||||
va_list aq;
|
||||
|
||||
errno = error;
|
||||
errno = ERRNO_VALUE(error);
|
||||
|
||||
va_copy(aq, ap);
|
||||
(void) vsnprintf(buf, sizeof buf, format, aq);
|
||||
@@ -975,7 +961,7 @@ int log_struct_internal(
|
||||
if (open_when_needed)
|
||||
log_close();
|
||||
|
||||
return -error;
|
||||
return -ERRNO_VALUE(error);
|
||||
}
|
||||
|
||||
return log_dispatch_internal(level, error, file, line, func, NULL, NULL, NULL, NULL, buf + 8);
|
||||
@@ -995,17 +981,12 @@ int log_struct_iovec_internal(
|
||||
size_t i;
|
||||
char *m;
|
||||
|
||||
if (error < 0)
|
||||
error = -error;
|
||||
|
||||
if (_likely_(LOG_PRI(level) > log_max_level[realm]))
|
||||
return -error;
|
||||
|
||||
if (log_target == LOG_TARGET_NULL)
|
||||
return -error;
|
||||
if (_likely_(LOG_PRI(level) > log_max_level[realm]) ||
|
||||
log_target == LOG_TARGET_NULL)
|
||||
return -ERRNO_VALUE(error);
|
||||
|
||||
if ((level & LOG_FACMASK) == 0)
|
||||
level = log_facility | LOG_PRI(level);
|
||||
level |= log_facility;
|
||||
|
||||
if (IN_SET(log_target, LOG_TARGET_AUTO,
|
||||
LOG_TARGET_JOURNAL_OR_KMSG,
|
||||
@@ -1028,7 +1009,7 @@ int log_struct_iovec_internal(
|
||||
}
|
||||
|
||||
if (sendmsg(journal_fd, &mh, MSG_NOSIGNAL) >= 0)
|
||||
return -error;
|
||||
return -ERRNO_VALUE(error);
|
||||
}
|
||||
|
||||
for (i = 0; i < n_input_iovec; i++)
|
||||
@@ -1036,7 +1017,7 @@ int log_struct_iovec_internal(
|
||||
break;
|
||||
|
||||
if (_unlikely_(i >= n_input_iovec)) /* Couldn't find MESSAGE=? */
|
||||
return -error;
|
||||
return -ERRNO_VALUE(error);
|
||||
|
||||
m = strndupa(input_iovec[i].iov_base + STRLEN("MESSAGE="),
|
||||
input_iovec[i].iov_len - STRLEN("MESSAGE="));
|
||||
@@ -1239,14 +1220,9 @@ int log_syntax_internal(
|
||||
va_list ap;
|
||||
const char *unit_fmt = NULL;
|
||||
|
||||
if (error < 0)
|
||||
error = -error;
|
||||
|
||||
if (_likely_(LOG_PRI(level) > log_max_level[LOG_REALM_SYSTEMD]))
|
||||
return -error;
|
||||
|
||||
if (log_target == LOG_TARGET_NULL)
|
||||
return -error;
|
||||
if (_likely_(LOG_PRI(level) > log_max_level[LOG_REALM_SYSTEMD]) ||
|
||||
log_target == LOG_TARGET_NULL)
|
||||
return -ERRNO_VALUE(error);
|
||||
|
||||
errno = error;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user