1
0
mirror of https://github.com/systemd/systemd synced 2025-10-06 20:24:45 +02:00

Compare commits

..

No commits in common. "677ba9d062850cc37c31316ecba241a7d6c48af5" and "1d8a16f1f4827ac8f4a8a46795f311d78536dc44" have entirely different histories.

19 changed files with 238 additions and 235 deletions

View File

@ -147,54 +147,55 @@
<refsect1>
<title>Description</title>
<para>The <structname>sd_bus_error</structname> structure carries information about a D-Bus error
condition, or lack thereof. The functions described below may be used to set and query fields in this
structure.
<itemizedlist>
<listitem><para>The <structfield>name</structfield> field contains a short identifier of an error. It
should follow the rules for error names described in the D-Bus specification, subsection <ulink
url="http://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-names">Valid
Names</ulink>. A number of common, standardized error names are described in
<citerefentry><refentrytitle>sd-bus-errors</refentrytitle><manvolnum>3</manvolnum></citerefentry>, but
additional domain-specific errors may be defined by applications.</para></listitem>
<para>The <structname>sd_bus_error</structname> structure carries
information about a D-Bus error condition. The functions described
below may be used to set and query fields in this structure. The
<structfield>name</structfield> field contains a short identifier
of an error. It should follow the rules for error names described
in the D-Bus specification, subsection <ulink
url="http://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-names">Valid
Names</ulink>. A number of common, standardized error names are
described in
<citerefentry><refentrytitle>sd-bus-errors</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
but additional domain-specific errors may be defined by
applications. The <structfield>message</structfield> field usually
contains a human-readable string describing the details, but might
be <constant>NULL</constant>. An unset <structname>sd_bus_error</structname> structure
should have both fields initialized to <constant>NULL</constant>. Set an error
structure to <constant>SD_BUS_ERROR_NULL</constant> in order to
reset both fields to <constant>NULL</constant>. When no longer necessary, resources
held by the <structname>sd_bus_error</structname> structure should
be destroyed with <function>sd_bus_error_free()</function>.</para>
<listitem><para>The <structfield>message</structfield> field usually contains a human-readable string
describing the details, but might be <constant>NULL</constant>.</para></listitem>
</itemizedlist>
An unset <structname>sd_bus_error</structname> structure should have both fields initialized to
<constant>NULL</constant>, and signifies lack of an error, i.e. success. Assign
<constant>SD_BUS_ERROR_NULL</constant> to the structure in order to initialize both fields to
<constant>NULL</constant>. When no longer necessary, resources held by the
<structname>sd_bus_error</structname> structure should be destroyed with
<function>sd_bus_error_free()</function>.</para>
<para><function>sd_bus_error_set()</function> sets an error structure to the specified name and message
strings. The strings will be copied into internal, newly allocated memory. It is essential to free the
contents again when they are not required anymore (see above). Do not use this call on error structures
that have already been set. If you intend to reuse an error structure, free the old data stored in it
with <function>sd_bus_error_free()</function> first.</para>
<para><function>sd_bus_error_set()</function> will return an <varname>errno</varname>-like value (see
<citerefentry
<para><function>sd_bus_error_set()</function> sets an error
structure to the specified name and message strings. The strings
will be copied into internal, newly allocated memory. It is
essential to free the error structure again when it is not
required anymore (see above). The function will return an
<varname>errno</varname>-like negative value (see <citerefentry
project='man-pages'><refentrytitle>errno</refentrytitle><manvolnum>3</manvolnum></citerefentry>)
determined from the specified error name <parameter>name</parameter>. If <parameter>name</parameter> is
<constant>NULL</constant>, it is assumed that no error occurred, and <constant>0</constant> is returned.
If <parameter>name</parameter> is nonnull, a negative value is always returned. If
<parameter>e</parameter> is <constant>NULL</constant>, no error structure is initialized, but
<parameter>name</parameter> is still converted into an <varname>errno</varname>-style value.</para>
<para>Various well-known D-Bus errors are converted to well-known <varname>errno</varname> counterparts,
and the other ones to <constant>-EIO</constant>. See
<citerefentry><refentrytitle>sd-bus-errors</refentrytitle><manvolnum>3</manvolnum></citerefentry> for a
list of well-known error names. Additional error mappings may be defined with
<citerefentry><refentrytitle>sd_bus_error_add_map</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
</para>
<para><function>sd_bus_error_set()</function> is designed to be conveniently used in a
<function>return</function> statement. If <parameter>message</parameter> is <constant>NULL</constant>, no
message is set. This call can fail if no memory may be allocated for the name and message strings, in
which case an <constant>SD_BUS_ERROR_NO_MEMORY</constant> error will be set instead and
<constant>-ENOMEM</constant> returned. </para>
determined from the specified error name. Various well-known
D-Bus errors are converted to well-known <varname>errno</varname>
counterparts, and the other ones to <constant>-EIO</constant>. See
<citerefentry><refentrytitle>sd-bus-errors</refentrytitle><manvolnum>3</manvolnum></citerefentry>
for a list of well-known error names. Additional error mappings
may be defined with
<citerefentry><refentrytitle>sd_bus_error_add_map</refentrytitle><manvolnum>3</manvolnum></citerefentry>. If
<parameter>e</parameter> is <constant>NULL</constant>, no error structure is initialized,
but the error is still converted into an
<varname>errno</varname>-style error. If
<parameter>name</parameter> is <constant>NULL</constant>, it is
assumed that no error occurred, and 0 is returned. This means that
this function may be conveniently used in a
<function>return</function> statement. If
<parameter>message</parameter> is <constant>NULL</constant>, no message is set. This
call can fail if no memory may be allocated for the name and
message strings, in which case an
<constant>SD_BUS_ERROR_NO_MEMORY</constant> error might be set
instead and -ENOMEM be returned. Do not use this call on error
structures that are already initialized. If you intend to reuse an
error structure, free the old data stored in it with
<function>sd_bus_error_free()</function> first.</para>
<para><function>sd_bus_error_setf()</function> is similar to
<function>sd_bus_error_set()</function>, but takes a <citerefentry
@ -203,25 +204,33 @@
<structfield>message</structfield> field.</para>
<para><function>sd_bus_error_set_const()</function> is similar to
<function>sd_bus_error_set()</function>, but the string parameters are not copied internally, and must
hence remain constant and valid for the lifetime of <parameter>e</parameter>. Use this call to avoid
memory allocations when setting error structures. Since this call does not allocate memory, it will not
fail with an out-of-memory condition as <function>sd_bus_error_set()</function> may, as described
above. Alternatively, the <constant>SD_BUS_ERROR_MAKE_CONST()</constant> macro may be used to generate a
literal, constant bus error structure on-the-fly.</para>
<function>sd_bus_error_set()</function>, but the string parameters
are not copied internally, and must hence remain constant and
valid for the lifetime of <parameter>e</parameter>. Use this call
to avoid memory allocations when setting error structures. Since
this call does not allocate memory, it will not fail with an
out-of-memory condition as
<function>sd_bus_error_set()</function> can, as described
above. Alternatively, the
<constant>SD_BUS_ERROR_MAKE_CONST()</constant> macro may be used
to generate a literal, constant bus error structure
on-the-fly.</para>
<para><function>sd_bus_error_set_errno()</function> will immediately return <constant>0</constant> if the
specified error parameter <parameter>error</parameter> is <constant>0</constant>. Otherwise, it will set
<structfield>name</structfield> from an <varname>errno</varname>-like value that is converted to a D-Bus
<para><function>sd_bus_error_set_errno()</function> will set
<structfield>name</structfield> from an
<varname>errno</varname>-like value that is converted to a D-Bus
error. <citerefentry
project='die-net'><refentrytitle>strerror_r</refentrytitle><manvolnum>3</manvolnum></citerefentry> will
be used to set <structfield>message</structfield>. Well-known D-Bus error names will be used for
<structfield>name</structfield> if applicable, otherwise a name in the <literal>System.Error.</literal>
namespace will be generated. The sign of the specified error number is ignored and the absolute value is
used implicitly. If the specified error <parameter>error</parameter> is non-zero, the call always returns
a negative value, for convenient usage in <function>return</function> statements. This call might fail
due to lack of memory, in which case an <constant>SD_BUS_ERROR_NO_MEMORY</constant> error is set instead,
and <constant>-ENOMEM</constant> is returned.</para>
project='die-net'><refentrytitle>strerror_r</refentrytitle><manvolnum>3</manvolnum></citerefentry>
will be used to set <structfield>message</structfield>. Well-known
D-Bus error names will be used for <structfield>name</structfield>
if applicable, otherwise a name in the
<literal>System.Error.</literal> namespace will be generated. The
sign of the specified error number is ignored. The absolute value
is used implicitly. The call always returns a negative value, for
convenient usage in <function>return</function> statements. This
call might fail due to lack of memory, in which case an
<constant>SD_BUS_ERROR_NO_MEMORY</constant> error is set instead,
and -ENOMEM is returned.</para>
<para><function>sd_bus_error_set_errnof()</function> is similar to
<function>sd_bus_error_set_errno()</function>, but in addition to
@ -237,26 +246,28 @@
project='man-pages'><refentrytitle>va_arg</refentrytitle><manvolnum>3</manvolnum></citerefentry>
parameter list.</para>
<para><function>sd_bus_error_get_errno()</function> converts the <structfield>name</structfield> field of
an error structure to an <varname>errno</varname>-like (positive) value using the same rules as
<function>sd_bus_error_set()</function>. If <parameter>e</parameter> is <constant>NULL</constant>,
<constant>0</constant> will be returned.</para>
<para><function>sd_bus_error_get_errno()</function> converts the
<structfield>name</structfield> field of an error structure to an
<varname>errno</varname>-like (positive) value using the same
rules as <function>sd_bus_error_set()</function>. If
<parameter>e</parameter> is <constant>NULL</constant>, 0 will be
returned.</para>
<para><function>sd_bus_error_copy()</function> will initialize <parameter>dst</parameter> using the
values in <parameter>e</parameter>, if <parameter>e</parameter> has been set with an error value before.
Otherwise, it will return immediately. If the strings in <parameter>e</parameter> were set using
<function>sd_bus_error_set_const()</function>, they will be shared. Otherwise, they will be
copied. Returns a converted <varname>errno</varname>-like, negative error code or <constant>0</constant>.
Before this call, <parameter>dst</parameter> must be unset, i.e. either freshly initialized with
<constant>NULL</constant> or reset using <function>sd_bus_error_free()</function>.</para>
<para><function>sd_bus_error_copy()</function> will initialize
<parameter>dst</parameter> using the values in
<parameter>e</parameter>. If the strings in
<parameter>e</parameter> were set using
<function>sd_bus_error_set_const()</function>, they will be shared.
Otherwise, they will be copied. Returns a converted
<varname>errno</varname>-like, negative error code.</para>
<para><function>sd_bus_error_move()</function> is similar to <function>sd_bus_error_copy()</function>,
but will move any error information from <parameter>e</parameter> into <parameter>dst</parameter>,
resetting the former. This function cannot fail, as no new memory is allocated. Note that if
<parameter>e</parameter> is not set, <parameter>dst</parameter> is initializated to
<constant>SD_BUS_ERROR_NULL</constant>. Moreover, if <parameter>dst</parameter> is
<constant>NULL</constant> no operation is executed on it and resources held by <parameter>e</parameter>
are freed and reset. Returns a converted <varname>errno</varname>-like, non-positive error value.</para>
<para><function>sd_bus_error_move()</function> is similar to <function>sd_bus_error_copy()</function>, but will
move any error information from <parameter>e</parameter> into <parameter>dst</parameter>, resetting the
former. This function cannot fail, as no new memory is allocated. Note that if <parameter>e</parameter> is not set
(or <constant>NULL</constant>) <parameter>dst</parameter> is initializated to
<constant>SD_BUS_ERROR_NULL</constant>. Moreover, if <parameter>dst</parameter> is <constant>NULL</constant> no
operation is executed on it and resources held by <parameter>e</parameter> are freed and reset. Returns a
converted <varname>errno</varname>-like, negative error code.</para>
<para><function>sd_bus_error_is_set()</function> will return a
non-zero value if <parameter>e</parameter> is
@ -289,23 +300,25 @@
<refsect1>
<title>Return Value</title>
<para>The functions <function>sd_bus_error_set()</function>, <function>sd_bus_error_setf()</function>,
and <function>sd_bus_error_set_const()</function> always return <constant>0</constant> when the specified
error value is <constant>NULL</constant>, and a negative errno-like value corresponding to the
<parameter>name</parameter> parameter otherwise. The functions
<function>sd_bus_error_set_errno()</function>, <function>sd_bus_error_set_errnof()</function> and
<function>sd_bus_error_set_errnofv()</function>, return <constant>0</constant> when the specified error
value is <constant>0</constant>, and a a negative errno-like value corresponding to the
<parameter>error</parameter> parameter otherwise. If an error occurs internally, one of the negative
error values listed below will be returned.</para>
<para>The functions <function>sd_bus_error_set()</function>,
<function>sd_bus_error_setf()</function>, and
<function>sd_bus_error_set_const()</function>, when successful,
return the negative errno value corresponding to the
<parameter>name</parameter> parameter. The functions
<function>sd_bus_error_set_errno()</function>,
<function>sd_bus_error_set_errnof()</function> and
<function>sd_bus_error_set_errnofv()</function>, when successful,
return the negative value of the <parameter>error</parameter>
parameter. If an error occurs, one of the negative error values
listed below will be returned.</para>
<para><function>sd_bus_error_get_errno()</function> returns
<constant>false</constant> when <parameter>e</parameter> is
<constant>NULL</constant>, and a positive errno value mapped from
<parameter>e-&gt;name</parameter> otherwise.</para>
<para><function>sd_bus_error_copy()</function> and <function>sd_bus_error_move()</function> return a
negative error value converted from the source error, and zero if the error has not been set.</para>
<para><function>sd_bus_error_copy()</function> and <function>sd_bus_error_move()</function> return 0 or a positive
integer on success, and a negative error value converted from the error name otherwise.</para>
<para><function>sd_bus_error_is_set()</function> returns a
non-zero value when <parameter>e</parameter> and the

View File

@ -660,7 +660,7 @@ int cg_remove_xattr(const char *controller, const char *path, const char *name)
int cg_pid_get_path(const char *controller, pid_t pid, char **ret_path) {
_cleanup_fclose_ FILE *f = NULL;
const char *fs, *controller_str = NULL; /* silence gcc warning about unitialized variable */
const char *fs, *controller_str;
int unified, r;
assert(pid >= 0);
@ -720,7 +720,6 @@ int cg_pid_get_path(const char *controller, pid_t pid, char **ret_path) {
continue;
*e = 0;
assert(controller_str);
r = string_contains_word(l, ",", controller_str);
if (r < 0)
return r;

View File

@ -515,10 +515,10 @@ char *replace_env_n(const char *format, size_t n, char **env, unsigned flags) {
ALTERNATE_VALUE,
} state = WORD;
const char *e, *word = format, *test_value = NULL; /* test_value is initialized to appease gcc */
const char *e, *word = format, *test_value;
char *k;
_cleanup_free_ char *r = NULL;
size_t i, len = 0; /* len is initialized to appease gcc */
size_t i, len;
int nest = 0;
assert(format);
@ -581,12 +581,13 @@ char *replace_env_n(const char *format, size_t n, char **env, unsigned flags) {
word = e+1;
state = WORD;
} else if (*e == ':') {
if (flags & REPLACE_ENV_ALLOW_EXTENDED) {
len = e - word - 2;
state = TEST;
} else
if (!(flags & REPLACE_ENV_ALLOW_EXTENDED))
/* Treat this as unsupported syntax, i.e. do no replacement */
state = WORD;
else {
len = e-word-2;
state = TEST;
}
}
break;

View File

@ -121,7 +121,7 @@ int write_string_stream_ts(
const struct timespec *ts) {
bool needs_nl;
int r, fd = -1;
int r, fd;
assert(f);
assert(line);
@ -140,8 +140,8 @@ int write_string_stream_ts(
needs_nl = !(flags & WRITE_STRING_FILE_AVOID_NEWLINE) && !endswith(line, "\n");
if (needs_nl && (flags & WRITE_STRING_FILE_DISABLE_BUFFER)) {
/* If STDIO buffering was disabled, then let's append the newline character to the string
* itself, so that the write goes out in one go, instead of two */
/* If STDIO buffering was disabled, then let's append the newline character to the string itself, so
* that the write goes out in one go, instead of two */
line = strjoina(line, "\n");
needs_nl = false;
@ -164,7 +164,6 @@ int write_string_stream_ts(
if (ts) {
const struct timespec twice[2] = {*ts, *ts};
assert(fd >= 0);
if (futimens(fd, twice) < 0)
return -errno;
}

View File

@ -14,7 +14,6 @@
#include <sys/types.h>
#include <sys/un.h>
#include "errno-util.h"
#include "macro.h"
#include "missing_network.h"
#include "missing_socket.h"
@ -265,7 +264,7 @@ static inline int getsockopt_int(int fd, int level, int optname, int *ret) {
socklen_t sl = sizeof(v);
if (getsockopt(fd, level, optname, &v, &sl) < 0)
return negative_errno();
return -errno;
if (sl != sizeof(v))
return -EIO;

View File

@ -1367,7 +1367,7 @@ static int status_welcome(void) {
static int write_container_id(void) {
const char *c;
int r = 0; /* silence gcc warning about r being unitialized below */
int r;
c = getenv("container");
if (isempty(c))

View File

@ -1008,7 +1008,7 @@ static int attach_luks_or_plain_or_bitlk_by_tpm2(
_cleanup_(sd_event_unrefp) sd_event *event = NULL;
_cleanup_free_ char *friendly = NULL;
int keyslot = arg_key_slot, r;
size_t decrypted_key_size = 0; /* Silence gcc warning about unitialized variable */
size_t decrypted_key_size;
assert(cd);
assert(name);
@ -1058,12 +1058,15 @@ static int attach_luks_or_plain_or_bitlk_by_tpm2(
&policy_hash, &policy_hash_size,
&keyslot,
&token);
if (r == -ENXIO)
if (r == -ENXIO) {
/* No further TPM2 tokens found in the LUKS2 header.*/
return log_debug_errno(SYNTHETIC_ERRNO(EAGAIN),
found_some
? "No TPM2 metadata matching the current system state found in LUKS2 header, falling back to traditional unlocking."
: "No TPM2 metadata enrolled in LUKS2 header, falling back to traditional unlocking.");
if (found_some)
return log_debug_errno(SYNTHETIC_ERRNO(EAGAIN),
"No TPM2 metadata matching the current system state found in LUKS2 header, falling back to traditional unlocking.");
else
return log_debug_errno(SYNTHETIC_ERRNO(EAGAIN),
"No TPM2 metadata enrolled in LUKS2 header, falling back to traditional unlocking.");
}
if (r < 0)
return r;
@ -1088,7 +1091,6 @@ static int attach_luks_or_plain_or_bitlk_by_tpm2(
if (r != -EAGAIN) /* EAGAIN means: no tpm2 chip found */
return r;
}
assert(decrypted_key);
if (!monitor) {
/* We didn't find the TPM2 device. In this case, watch for it via udev. Let's create

View File

@ -86,10 +86,8 @@ static int bus_error_name_to_errno(const char *name) {
if (m->code == BUS_ERROR_MAP_END_MARKER)
break;
if (streq(m->name, name)) {
assert(m->code > 0);
if (streq(m->name, name))
return m->code;
}
}
m = ALIGN_TO_PTR(__start_SYSTEMD_BUS_ERROR_MAP, sizeof(void*));
@ -105,10 +103,8 @@ static int bus_error_name_to_errno(const char *name) {
continue;
}
if (streq(m->name, name)) {
assert(m->code > 0);
if (streq(m->name, name))
return m->code;
}
m++;
}
@ -236,7 +232,6 @@ finish:
}
int bus_error_setfv(sd_bus_error *e, const char *name, const char *format, va_list ap) {
int r;
if (!name)
return 0;
@ -258,28 +253,23 @@ int bus_error_setfv(sd_bus_error *e, const char *name, const char *format, va_li
e->_need_free = 1;
}
r = bus_error_name_to_errno(name);
assert(r > 0);
return -r;
return -bus_error_name_to_errno(name);
}
_public_ int sd_bus_error_setf(sd_bus_error *e, const char *name, const char *format, ...) {
int r;
if (format) {
int r;
va_list ap;
va_start(ap, format);
r = bus_error_setfv(e, name, format, ap);
assert(!name || r < 0);
va_end(ap);
return r;
}
r = sd_bus_error_set(e, name, NULL);
assert(!name || r < 0);
return r;
return sd_bus_error_set(e, name, NULL);
}
_public_ int sd_bus_error_copy(sd_bus_error *dest, const sd_bus_error *e) {
@ -465,7 +455,7 @@ _public_ int sd_bus_error_set_errno(sd_bus_error *e, int error) {
if (!e)
return -error;
if (error == 0)
return 0;
return -error;
assert_return(!bus_error_is_dirty(e), -EINVAL);

View File

@ -3171,7 +3171,7 @@ static int process_child(sd_event *e, int64_t threshold, int64_t *ret_min_priori
zero(s->child.siginfo);
if (waitid(P_PID, s->child.pid, &s->child.siginfo,
WNOHANG | (s->child.options & WEXITED ? WNOWAIT : 0) | s->child.options) < 0)
return negative_errno();
return -errno;
if (s->child.siginfo.si_pid != 0) {
bool zombie = IN_SET(s->child.siginfo.si_code, CLD_EXITED, CLD_KILLED, CLD_DUMPED);

View File

@ -265,12 +265,9 @@ _public_ struct udev_device *udev_monitor_receive_device(struct udev_monitor *ud
* Returns: 0 on success, otherwise a negative error value.
*/
_public_ int udev_monitor_filter_add_match_subsystem_devtype(struct udev_monitor *udev_monitor, const char *subsystem, const char *devtype) {
int r;
assert_return(udev_monitor, -EINVAL);
r = sd_device_monitor_filter_add_match_subsystem_devtype(udev_monitor->monitor, subsystem, devtype);
return r < 0 ? r : 0;
return sd_device_monitor_filter_add_match_subsystem_devtype(udev_monitor->monitor, subsystem, devtype);
}
/**
@ -286,12 +283,9 @@ _public_ int udev_monitor_filter_add_match_subsystem_devtype(struct udev_monitor
* Returns: 0 on success, otherwise a negative error value.
*/
_public_ int udev_monitor_filter_add_match_tag(struct udev_monitor *udev_monitor, const char *tag) {
int r;
assert_return(udev_monitor, -EINVAL);
r = sd_device_monitor_filter_add_match_tag(udev_monitor->monitor, tag);
return r < 0 ? r : 0;
return sd_device_monitor_filter_add_match_tag(udev_monitor->monitor, tag);
}
/**

View File

@ -207,10 +207,14 @@ enum nss_status _nss_resolve_gethostbyname4_r(
int *errnop, int *h_errnop,
int32_t *ttlp) {
_cleanup_(varlink_unrefp) Varlink *link = NULL;
_cleanup_(json_variant_unrefp) JsonVariant *cparams = NULL;
_cleanup_(resolve_hostname_reply_destroy) ResolveHostnameReply p = {};
JsonVariant *rparams, *entry;
_cleanup_(json_variant_unrefp) JsonVariant *cparams = NULL;
struct gaih_addrtuple *r_tuple = NULL, *r_tuple_first = NULL;
_cleanup_(varlink_unrefp) Varlink *link = NULL;
const char *canonical = NULL, *error_id = NULL;
JsonVariant *entry, *rparams;
size_t l, ms, idx, c = 0;
char *r_name;
int r;
PROTECT_ERRNO;
@ -237,7 +241,6 @@ enum nss_status _nss_resolve_gethostbyname4_r(
* DNSSEC errors and suchlike. (We don't use UNAVAIL in this case so that the nsswitch.conf
* configuration can distinguish such executed but negative replies from complete failure to
* talk to resolved). */
const char *error_id;
r = varlink_call(link, "io.systemd.Resolve.ResolveHostname", cparams, &rparams, &error_id, NULL);
if (r < 0)
goto fail;
@ -253,7 +256,6 @@ enum nss_status _nss_resolve_gethostbyname4_r(
if (json_variant_is_blank_object(p.addresses))
goto not_found;
size_t n_addresses = 0;
JSON_VARIANT_ARRAY_FOREACH(entry, p.addresses) {
AddressParameters q = {};
@ -269,13 +271,13 @@ enum nss_status _nss_resolve_gethostbyname4_r(
goto fail;
}
n_addresses++;
c++;
}
const char *canonical = p.name ?: name;
size_t l = strlen(canonical);
size_t idx, ms = ALIGN(l+1) + ALIGN(sizeof(struct gaih_addrtuple)) * n_addresses;
canonical = p.name ?: name;
l = strlen(canonical);
ms = ALIGN(l+1) + ALIGN(sizeof(struct gaih_addrtuple)) * c;
if (buflen < ms) {
UNPROTECT_ERRNO;
*errnop = ERANGE;
@ -284,13 +286,12 @@ enum nss_status _nss_resolve_gethostbyname4_r(
}
/* First, append name */
char *r_name = buffer;
memcpy(r_name, canonical, l + 1);
idx = ALIGN(l + 1);
r_name = buffer;
memcpy(r_name, canonical, l+1);
idx = ALIGN(l+1);
/* Second, append addresses */
struct gaih_addrtuple *r_tuple = NULL,
*r_tuple_first = (struct gaih_addrtuple*) (buffer + idx);
r_tuple_first = (struct gaih_addrtuple*) (buffer + idx);
JSON_VARIANT_ARRAY_FOREACH(entry, p.addresses) {
AddressParameters q = {};
@ -312,7 +313,7 @@ enum nss_status _nss_resolve_gethostbyname4_r(
idx += ALIGN(sizeof(struct gaih_addrtuple));
}
assert(r_tuple); /* We had at least one address, so r_tuple must be set */
assert(r_tuple);
r_tuple->next = NULL; /* Override last next pointer */
assert(idx == ms);
@ -352,10 +353,13 @@ enum nss_status _nss_resolve_gethostbyname3_r(
int32_t *ttlp,
char **canonp) {
_cleanup_(varlink_unrefp) Varlink *link = NULL;
_cleanup_(json_variant_unrefp) JsonVariant *cparams = NULL;
_cleanup_(resolve_hostname_reply_destroy) ResolveHostnameReply p = {};
JsonVariant *rparams, *entry;
_cleanup_(json_variant_unrefp) JsonVariant *cparams = NULL;
char *r_name, *r_aliases, *r_addr, *r_addr_list;
_cleanup_(varlink_unrefp) Varlink *link = NULL;
const char *canonical, *error_id = NULL;
size_t l, idx, ms, alen, i = 0, c = 0;
JsonVariant *entry, *rparams;
int r;
PROTECT_ERRNO;
@ -385,7 +389,6 @@ enum nss_status _nss_resolve_gethostbyname3_r(
if (r < 0)
goto fail;
const char *error_id;
r = varlink_call(link, "io.systemd.Resolve.ResolveHostname", cparams, &rparams, &error_id, NULL);
if (r < 0)
goto fail;
@ -401,7 +404,6 @@ enum nss_status _nss_resolve_gethostbyname3_r(
if (json_variant_is_blank_object(p.addresses))
goto not_found;
size_t n_addresses = 0;
JSON_VARIANT_ARRAY_FOREACH(entry, p.addresses) {
AddressParameters q = {};
@ -417,15 +419,15 @@ enum nss_status _nss_resolve_gethostbyname3_r(
goto fail;
}
n_addresses++;
c++;
}
const char *canonical = p.name ?: name;
canonical = p.name ?: name;
size_t alen = FAMILY_ADDRESS_SIZE(af);
size_t l = strlen(canonical);
alen = FAMILY_ADDRESS_SIZE(af);
l = strlen(canonical);
size_t idx, ms = ALIGN(l + 1) + n_addresses * ALIGN(alen) + (n_addresses + 2) * sizeof(char*);
ms = ALIGN(l+1) + c*ALIGN(alen) + (c+2) * sizeof(char*);
if (buflen < ms) {
UNPROTECT_ERRNO;
@ -435,19 +437,18 @@ enum nss_status _nss_resolve_gethostbyname3_r(
}
/* First, append name */
char *r_name = buffer;
r_name = buffer;
memcpy(r_name, canonical, l+1);
idx = ALIGN(l+1);
/* Second, create empty aliases array */
char *r_aliases = buffer + idx;
r_aliases = buffer + idx;
((char**) r_aliases)[0] = NULL;
idx += sizeof(char*);
/* Third, append addresses */
char *r_addr = buffer + idx;
r_addr = buffer + idx;
size_t i = 0;
JSON_VARIANT_ARRAY_FOREACH(entry, p.addresses) {
AddressParameters q = {};
@ -467,16 +468,16 @@ enum nss_status _nss_resolve_gethostbyname3_r(
i++;
}
assert(i == n_addresses);
idx += n_addresses * ALIGN(alen);
assert(i == c);
idx += c * ALIGN(alen);
/* Fourth, append address pointer array */
char *r_addr_list = buffer + idx;
for (i = 0; i < n_addresses; i++)
r_addr_list = buffer + idx;
for (i = 0; i < c; i++)
((char**) r_addr_list)[i] = r_addr + i*ALIGN(alen);
((char**) r_addr_list)[i] = NULL;
idx += (n_addresses + 1) * sizeof(char*);
idx += (c+1) * sizeof(char*);
assert(idx == ms);
@ -539,8 +540,8 @@ static void name_parameters_destroy(NameParameters *p) {
}
static const JsonDispatch name_parameters_dispatch_table[] = {
{ "ifindex", JSON_VARIANT_INTEGER, json_dispatch_ifindex, offsetof(NameParameters, ifindex), 0 },
{ "name", JSON_VARIANT_STRING, json_dispatch_string, offsetof(NameParameters, name), JSON_MANDATORY },
{ "ifindex", JSON_VARIANT_INTEGER, json_dispatch_ifindex, offsetof(NameParameters, ifindex), 0 },
{ "name", JSON_VARIANT_UNSIGNED, json_dispatch_string, offsetof(NameParameters, name), JSON_MANDATORY },
{}
};
@ -552,10 +553,14 @@ enum nss_status _nss_resolve_gethostbyaddr2_r(
int *errnop, int *h_errnop,
int32_t *ttlp) {
_cleanup_(varlink_unrefp) Varlink *link = NULL;
_cleanup_(json_variant_unrefp) JsonVariant *cparams = NULL;
_cleanup_(resolve_address_reply_destroy) ResolveAddressReply p = {};
JsonVariant *rparams, *entry;
_cleanup_(json_variant_unrefp) JsonVariant *cparams = NULL;
char *r_name, *r_aliases, *r_addr, *r_addr_list;
_cleanup_(varlink_unrefp) Varlink *link = NULL;
JsonVariant *entry, *rparams;
const char *n, *error_id;
unsigned c = 0, i = 0;
size_t ms = 0, idx;
int r;
PROTECT_ERRNO;
@ -589,7 +594,6 @@ enum nss_status _nss_resolve_gethostbyaddr2_r(
if (r < 0)
goto fail;
const char* error_id;
r = varlink_call(link, "io.systemd.Resolve.ResolveAddress", cparams, &rparams, &error_id, NULL);
if (r < 0)
goto fail;
@ -605,8 +609,6 @@ enum nss_status _nss_resolve_gethostbyaddr2_r(
if (json_variant_is_blank_object(p.names))
goto not_found;
size_t ms = 0, idx;
JSON_VARIANT_ARRAY_FOREACH(entry, p.names) {
_cleanup_(name_parameters_destroy) NameParameters q = {};
@ -617,10 +619,9 @@ enum nss_status _nss_resolve_gethostbyaddr2_r(
ms += ALIGN(strlen(q.name) + 1);
}
size_t n_names = json_variant_elements(p.names);
ms += ALIGN(len) + /* the address */
2 * sizeof(char*) + /* pointer to the address, plus trailing NULL */
n_names * sizeof(char*); /* pointers to aliases, plus trailing NULL */
ms += ALIGN(len) + /* the address */
2 * sizeof(char*) + /* pointers to the address, plus trailing NULL */
json_variant_elements(p.names) * sizeof(char*); /* pointers to aliases, plus trailing NULL */
if (buflen < ms) {
UNPROTECT_ERRNO;
@ -630,43 +631,44 @@ enum nss_status _nss_resolve_gethostbyaddr2_r(
}
/* First, place address */
char *r_addr = buffer;
r_addr = buffer;
memcpy(r_addr, addr, len);
idx = ALIGN(len);
/* Second, place address list */
char *r_addr_list = buffer + idx;
r_addr_list = buffer + idx;
((char**) r_addr_list)[0] = r_addr;
((char**) r_addr_list)[1] = NULL;
idx += sizeof(char*) * 2;
/* Third, reserve space for the aliases array, plus trailing NULL */
char *r_aliases = buffer + idx;
idx += sizeof(char*) * n_names;
/* Third, reserve space for the aliases array */
r_aliases = buffer + idx;
idx += sizeof(char*) * c;
/* Fourth, place aliases */
char *r_name = buffer + idx;
size_t i = 0;
i = 0;
r_name = buffer + idx;
JSON_VARIANT_ARRAY_FOREACH(entry, p.names) {
_cleanup_(name_parameters_destroy) NameParameters q = {};
size_t l;
char *z;
r = json_dispatch(entry, name_parameters_dispatch_table, NULL, json_dispatch_flags, &q);
if (r < 0)
goto fail;
size_t l = strlen(q.name);
char *z = buffer + idx;
memcpy(z, q.name, l + 1);
l = strlen(q.name);
z = buffer + idx;
memcpy(z, n, l+1);
if (i > 0)
((char**) r_aliases)[i - 1] = z;
((char**) r_aliases)[i-1] = z;
i++;
idx += ALIGN(l + 1);
idx += ALIGN(l+1);
}
((char**) r_aliases)[n_names - 1] = NULL;
((char**) r_aliases)[c-1] = NULL;
assert(idx == ms);
result->h_name = r_name;

View File

@ -1205,7 +1205,7 @@ static int nsec3_hash_to_gcrypt_md(uint8_t algorithm) {
int dnssec_nsec3_hash(DnsResourceRecord *nsec3, const char *name, void *ret) {
uint8_t wire_format[DNS_WIRE_FORMAT_HOSTNAME_MAX];
_cleanup_(gcry_md_closep) gcry_md_hd_t md = NULL;
gcry_md_hd_t md = NULL;
gcry_error_t err;
size_t hash_size;
int algorithm;
@ -1249,8 +1249,10 @@ int dnssec_nsec3_hash(DnsResourceRecord *nsec3, const char *name, void *ret) {
gcry_md_write(md, nsec3->nsec3.salt, nsec3->nsec3.salt_size);
result = gcry_md_read(md, 0);
if (!result)
return -EIO;
if (!result) {
r = -EIO;
goto finish;
}
for (k = 0; k < nsec3->nsec3.iterations; k++) {
uint8_t tmp[hash_size];
@ -1261,12 +1263,18 @@ int dnssec_nsec3_hash(DnsResourceRecord *nsec3, const char *name, void *ret) {
gcry_md_write(md, nsec3->nsec3.salt, nsec3->nsec3.salt_size);
result = gcry_md_read(md, 0);
if (!result)
return -EIO;
if (!result) {
r = -EIO;
goto finish;
}
}
memcpy(ret, result, hash_size);
return (int) hash_size;
r = (int) hash_size;
finish:
gcry_md_close(md);
return r;
}
static int nsec3_is_good(DnsResourceRecord *rr, DnsResourceRecord *nsec3) {

View File

@ -183,7 +183,7 @@ static DnsTransactionState dns_query_candidate_state(DnsQueryCandidate *c) {
if (c->error_code != 0)
return DNS_TRANSACTION_ERRNO;
SET_FOREACH(t, c->transactions)
SET_FOREACH(t, c->transactions) {
switch (t->state) {
@ -213,6 +213,7 @@ static DnsTransactionState dns_query_candidate_state(DnsQueryCandidate *c) {
break;
}
}
return state;
}

View File

@ -98,11 +98,8 @@ static int bus_message_read_dns_one(
if (r < 0)
return r;
if (!dns_server_address_valid(family, &a)) {
r = sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid DNS server address");
assert(r < 0);
return r;
}
if (!dns_server_address_valid(family, &a))
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid DNS server address");
if (extended) {
r = sd_bus_message_read(message, "q", &port);

View File

@ -300,8 +300,7 @@ int config_parse(
(void) stat_warn_permissions(filename, &st);
mtime = timespec_load(&st.st_mtim);
} else
mtime = 0;
}
for (;;) {
_cleanup_free_ char *buf = NULL;

View File

@ -280,7 +280,7 @@ static int guess_type(const char **name, char ***prefixes, bool *is_collection,
int conf_files_cat(const char *root, const char *name) {
_cleanup_strv_free_ char **dirs = NULL, **files = NULL;
_cleanup_free_ char *path = NULL;
char **prefix, **prefixes = NULL; /* explicit initialization to appease gcc */
char **prefixes, **prefix;
bool is_collection;
const char *extension;
char **t;
@ -289,8 +289,6 @@ int conf_files_cat(const char *root, const char *name) {
r = guess_type(&name, &prefixes, &is_collection, &extension);
if (r < 0)
return r;
assert(prefixes);
assert(extension);
STRV_FOREACH(prefix, prefixes) {
assert(endswith(*prefix, "/"));

View File

@ -448,16 +448,13 @@ static int varlink_write(Varlink *v) {
assert(v->fd >= 0);
/* We generally prefer recv()/send() (mostly because of MSG_NOSIGNAL) but also want to be compatible
* with non-socket IO, hence fall back automatically.
*
* Use a local variable to help gcc figure out that we set 'n' in all cases. */
bool prefer_write = v->prefer_read_write;
if (!prefer_write) {
* with non-socket IO, hence fall back automatically */
if (!v->prefer_read_write) {
n = send(v->fd, v->output_buffer + v->output_buffer_index, v->output_buffer_size, MSG_DONTWAIT|MSG_NOSIGNAL);
if (n < 0 && errno == ENOTSOCK)
prefer_write = v->prefer_read_write = true;
v->prefer_read_write = true;
}
if (prefer_write)
if (v->prefer_read_write)
n = write(v->fd, v->output_buffer + v->output_buffer_index, v->output_buffer_size);
if (n < 0) {
if (errno == EAGAIN)
@ -534,13 +531,12 @@ static int varlink_read(Varlink *v) {
rs = v->input_buffer_allocated - (v->input_buffer_index + v->input_buffer_size);
bool prefer_read = v->prefer_read_write;
if (!prefer_read) {
if (!v->prefer_read_write) {
n = recv(v->fd, v->input_buffer + v->input_buffer_index + v->input_buffer_size, rs, MSG_DONTWAIT);
if (n < 0 && errno == ENOTSOCK)
prefer_read = v->prefer_read_write = true;
v->prefer_read_write = true;
}
if (prefer_read)
if (v->prefer_read_write)
n = read(v->fd, v->input_buffer + v->input_buffer_index + v->input_buffer_size, rs);
if (n < 0) {
if (errno == EAGAIN)

View File

@ -307,9 +307,7 @@ int start_unit(int argc, char *argv[], void *userdata) {
method = verb_to_method(argv[0]);
job_type = verb_to_job_type(argv[0]);
mode = arg_job_mode;
} else
method = job_type = mode = NULL;
}
one_name = NULL;
}
} else {

View File

@ -103,15 +103,22 @@ static int setup_tests(bool *run_ambient) {
nobody = getpwnam(NOBODY_USER_NAME);
if (!nobody)
return log_warning_errno(SYNTHETIC_ERRNO(ENOENT), "Couldn't find 'nobody' user: %m");
return log_error_errno(SYNTHETIC_ERRNO(ENOENT), "Could not find nobody user: %m");
test_uid = nobody->pw_uid;
test_gid = nobody->pw_gid;
*run_ambient = false;
r = prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_CLEAR_ALL, 0, 0, 0);
/* There's support for PR_CAP_AMBIENT if the prctl() call succeeded or error code was something else
* than EINVAL. The EINVAL check should be good enough to rule out false positives. */
*run_ambient = r >= 0 || errno != EINVAL;
/* There's support for PR_CAP_AMBIENT if the prctl() call
* succeeded or error code was something else than EINVAL. The
* EINVAL check should be good enough to rule out false
* positives. */
if (r >= 0 || errno != EINVAL)
*run_ambient = true;
return 0;
}
@ -242,7 +249,7 @@ static void test_ensure_cap_64bit(void) {
}
int main(int argc, char *argv[]) {
bool run_ambient = false; /* unnecessary initialization to silence gcc warning */
bool run_ambient;
test_setup_logging(LOG_INFO);