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

Compare commits

...

23 Commits

Author SHA1 Message Date
Luca Boccassi
677ba9d062 resolved: use _cleanup_(gcry_md_closep) in one more place
Documentation says gcry_md_close will ignore a NULL input so should be safe:

https://gnupg.org/documentation/manuals/gcrypt/Working-with-hash-algorithms.html

Makes Coverity happy, follow-up for 248b1e0aa4

CID #1451555
2021-04-01 15:00:51 +01:00
Zbigniew Jędrzejewski-Szmek
0f4b6e59bd libudev: fix return of udev_monitor_filter_add_match_subsystem_devtype()
Follow-up for 7117842657c0fc5a3446b6fe158615279cf2d650.

sd_device_monitor_filter_add_match_subsystem_devtype() now returns 1 to signify
that something was done, and 0 to signify that nothing was done, but
udev_monitor_filter_add_match_subsystem_devtype() needs to return 0 as documented.

udev_monitor_filter_add_match_tag() is adjusted to match.

This makes gdm start successfully here again.
Before, it would just not boot, with nothing very obvious in the logs:
gdm[1756]: Gdm: GdmDisplay: Session never registered, failing

Replaces #19171.
2021-04-01 14:59:58 +01:00
Luca Boccassi
4cf1b41568
Merge pull request #19168 from keszybz/nss-resolve-unfoobar
Fix nss-resolve reverse alias lookups
2021-04-01 10:07:46 +01:00
Luca Boccassi
bd506dfb5e
Merge pull request #19169 from keszybz/reenable-maybe-unitialized-warning
Fix a bunch of maybe-unitialized warnings but don't enable the warning yet
2021-04-01 09:36:46 +01:00
Zbigniew Jędrzejewski-Szmek
1dbd0bdb3a basic/env-util: silence two gcc warnings 2021-03-31 18:24:54 +02:00
Zbigniew Jędrzejewski-Szmek
c26f7dd9f0 cryptsetup: silence gcc maybe-unused warning
Simplify one debug stmt while at it.
2021-03-31 18:24:54 +02:00
Zbigniew Jędrzejewski-Szmek
703e2870b1 systemctl: silence gcc maybe-unused warning 2021-03-31 18:24:53 +02:00
Zbigniew Jędrzejewski-Szmek
1c93632ead shared/pretty-print: silence gcc warning
gcc was very unhappy for some reason:

[988/1664] Compiling C object systemd-oomd.p/src_oom_oomd.c.o
In file included from ../src/basic/path-util.h:10,
                 from ../src/shared/pretty-print.c:14,
                 from ../src/oom/oomd.c:15:
../src/shared/pretty-print.c: In function ‘conf_files_cat’:
../src/basic/strv.h:123:32: warning: ‘prefixes’ may be used uninitialized [-Wmaybe-uninitialized]
  123 |         for ((s) = (l); (s) && *(s); (s)++)
      |                                ^
In file included from ../src/oom/oomd.c:15:
../src/shared/pretty-print.c:283:16: note: ‘prefixes’ was declared here
  283 |         char **prefixes, **prefix;
      |                ^~~~~~~~
../src/shared/pretty-print.c:305:12: warning: ‘is_collection’ may be used uninitialized in this function [-Wmaybe-uninitialized]
  305 |         if (!is_collection) {
      |            ^
../src/shared/pretty-print.c:301:13: warning: ‘extension’ may be used uninitialized in this function [-Wmaybe-uninitialized]
  301 |         r = conf_files_list_strv(&files, extension, root, 0, (const char* const*) dirs);
      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Maybe this is caused by the statis char** variables?
2021-03-31 18:24:53 +02:00
Zbigniew Jędrzejewski-Szmek
1a2948fece core: silence gcc warning 2021-03-31 18:24:53 +02:00
Zbigniew Jędrzejewski-Szmek
487c123a32 shared/bus-message-util: silence gcc warning
[1/429] Compiling C object src/shared/libsystemd-shared-248.a.p/bus-message-util.c.o
../src/shared/bus-message-util.c: In function ‘bus_message_read_dns_servers’:
../src/shared/bus-message-util.c:165:21: warning: ‘family’ may be used uninitialized in this function [-Wmaybe-uninitialized]
  165 |                 r = in_addr_full_new(family, &a, port, 0, server_name, dns + n);
      |                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../src/shared/bus-message-util.c:165:21: warning: ‘port’ may be used uninitialized in this function [-Wmaybe-uninitialized]
../src/shared/bus-message-util.c:165:21: warning: ‘server_name’ may be used uninitialized in this function [-Wmaybe-uninitialized]

The warning would be there despite all the asserts in bus_error_setfv() and
sd_bus_error_set(). So let's add an explicit assert.
2021-03-31 18:24:53 +02:00
Zbigniew Jędrzejewski-Szmek
9fd8d678ba shared/conf-parser: fix unitialized variable
Introduced in 4f9ff96a55187927a4164a19df580329f4c6522b.
2021-03-31 18:24:53 +02:00
Zbigniew Jędrzejewski-Szmek
0a94e77ed4 test-capability: silence gcc warning
[2/3] Compiling C object test-capability.p/src_test_test-capability.c.o
../src/test/test-capability.c: In function ‘main’:
../src/test/test-capability.c:270:12: warning: ‘run_ambient’ may be used uninitialized in this function [-Wmaybe-uninitialized]
  270 |         if (run_ambient)
      |            ^

gcc-11.0.1-0.3.fc34.x86_64
2021-03-31 18:24:53 +02:00
Zbigniew Jędrzejewski-Szmek
bc20c31bbc basic/cgroup-util: silence gcc warning about unitialized variable 2021-03-31 18:24:53 +02:00
Zbigniew Jędrzejewski-Szmek
bfd9bfccce sd-event: silence gcc's maybe-unitialized warning
[91/180] Compiling C object libsystemd.a.p/src_libsystemd_sd-event_sd-event.c.o
In file included from ../src/basic/macro.h:12,
                 from ../src/basic/alloc-util.h:9,
                 from ../src/libsystemd/sd-event/sd-event.c:11:
../src/libsystemd/sd-event/sd-event.c: In function ‘sd_event_wait’:
../src/fundamental/macro-fundamental.h:86:63: warning: ‘child_min_priority’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   86 |                 UNIQ_T(A, aq) < UNIQ_T(B, bq) ? UNIQ_T(A, aq) : UNIQ_T(B, bq); \
      |                                                               ^
../src/libsystemd/sd-event/sd-event.c:3983:45: note: ‘child_min_priority’ was declared here
 3983 |                 int64_t epoll_min_priority, child_min_priority;
      |                                             ^~~~~~~~~~~~~~~~~~

Alternative to #19159.
2021-03-31 18:24:53 +02:00
Zbigniew Jędrzejewski-Szmek
4990d4b8ff varlink: use two local flag variables to silence gcc warning
[59/655] Compiling C object src/shared/libsystemd-shared-248.a.p/varlink.c.o
../src/shared/varlink.c: In function ‘varlink_write’:
../src/shared/varlink.c:459:12: warning: ‘n’ may be used uninitialized in this function [-Wmaybe-uninitialized]
  459 |         if (n < 0) {
      |            ^
../src/shared/varlink.c: In function ‘varlink_process’:
../src/shared/varlink.c:541:12: warning: ‘n’ may be used uninitialized in this function [-Wmaybe-uninitialized]
  541 |         if (n < 0) {
      |            ^
../src/shared/varlink.c:486:17: note: ‘n’ was declared here
  486 |         ssize_t n;
      |                 ^
2021-03-31 18:24:53 +02:00
Zbigniew Jędrzejewski-Szmek
af46237ea1 man: split the description of sd_bus_error_set()
It was one giant all of text in pseudo-random order. Let's split it into
paragraphs talk about one subject each.

And unfortunately, the description of what happens when the error is not
set was not correct. In general, various functions treat 0/NULL as
not-an-error, and return 0.
2021-03-31 18:24:53 +02:00
Zbigniew Jędrzejewski-Szmek
b9c19bc384 sd-bus: add asserts showing that sd_bus_error_setf() returns negative
(when name is specified).
2021-03-31 18:24:44 +02:00
Zbigniew Jędrzejewski-Szmek
c7e964c944 sd-bus: add assert to tell the compiler that the error code is positive
I was hoping it would help with the following gcc warning:
[35/657] Compiling C object src/shared/libsystemd-shared-248.a.p/bus-message-util.c.o
../src/shared/bus-message-util.c: In function ‘bus_message_read_dns_servers’:
../src/shared/bus-message-util.c:165:21: warning: ‘family’ may be used uninitialized in this function [-Wmaybe-uninitialized]
  165 |                 r = in_addr_full_new(family, &a, port, 0, server_name, dns + n);
      |                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../src/shared/bus-message-util.c:165:21: warning: ‘port’ may be used uninitialized in this function [-Wmaybe-uninitialized]
../src/shared/bus-message-util.c:165:21: warning: ‘server_name’ may be used uninitialized in this function [-Wmaybe-uninitialized]

It actually doesn't, but the compiler has a point here: the code is specified
in sd_bus_error_map[], and it has no way of knowning that we want it to be a
positive value.

I think this should be an assert, because if this assumption fails, a
programming error has occured, something that'd want to catch.
2021-03-31 18:22:53 +02:00
Zbigniew Jędrzejewski-Szmek
55e2cfc938 basic/fileio: silence gcc's maybe-unitialized warning
[11/657] Compiling C object src/basic/libbasic.a.p/fileio.c.o
../src/basic/fileio.c: In function ‘write_string_stream_ts’:
../src/basic/fileio.c:167:21: warning: ‘fd’ may be used uninitialized in this function [-Wmaybe-uninitialized]
  167 |                 if (futimens(fd, twice) < 0)
      |                     ^~~~~~~~~~~~~~~~~~~
2021-03-31 18:22:53 +02:00
Zbigniew Jędrzejewski-Szmek
befab2c40c basic/socket-util: add hint to silence gcc's maybe-unitialized warning
[59/1551] Compiling C object src/basic/libbasic.a.p/socket-util.c.o
../src/basic/socket-util.c: In function ‘socket_get_mtu’:
../src/basic/socket-util.c:1393:16: warning: ‘mtu’ may be used uninitialized in this function [-Wmaybe-uninitialized]
 1393 |         *ret = (size_t) mtu;
      |                ^~~~~~~~~~~~
2021-03-31 18:22:53 +02:00
Zbigniew Jędrzejewski-Szmek
adf6d848df resolved: drop unnecessary {} 2021-03-31 18:22:53 +02:00
Zbigniew Jędrzejewski-Szmek
75d2f0a0c4 nss-resolve: define variables in the body
Same motivation as in the parent commit: let's define variables later, ideally
right when they are first initialized, so it's easier to figure out that they
are properly initialized.

error_id and r_tuple* were previously initialized, but I don't see why they
would need to be.

No functional change intended.
2021-03-31 17:19:03 +02:00
Zbigniew Jędrzejewski-Szmek
77fac974fe nss-resolve: fix parsing of io.systemd.Resolve.ResolveAddress reply
Since the switch to varlink in 0c73f4f075a2d23f7cabe708b589f19f4bbbec37, the
code wasn't functional. The JSON_VARIANT_UNSIGNED/JSON_VARIANT_STRING mismatch
meant that we'd reject any reply. Once past that, the code would use
unitialized 'c' and 'n' variables, so it's lucky we never got that far ;)

With -Wmaybe-unitialized, gcc would warn.

I think that declaring the huge list of local variables with very short names
at the top of the function was making it harder to understand what is going on
in the function. So let's rename the variables a bit, and initialize them upon
declaration if possible.

$ build/test-nss-hosts resolve 1.1.1.1 1.0.0.1 10.38.5.41
======== resolve ========
_nss_resolve_gethostbyaddr2_r("1.1.1.1") → status=NSS_STATUS_SUCCESS
                   errno=999/--- h_errno=0/Resolver Error 0 (no error) ttl=0
        "one.one.one.one"
        AF_INET 1.1.1.1

_nss_resolve_gethostbyaddr_r("1.1.1.1") → status=NSS_STATUS_SUCCESS
                   errno=999/--- h_errno=0/Resolver Error 0 (no error)
        "one.one.one.one"
        AF_INET 1.1.1.1

_nss_resolve_gethostbyaddr2_r("1.0.0.1") → status=NSS_STATUS_SUCCESS
                   errno=999/--- h_errno=0/Resolver Error 0 (no error) ttl=0
        "one.one.one.one"
        AF_INET 1.0.0.1

_nss_resolve_gethostbyaddr_r("1.0.0.1") → status=NSS_STATUS_SUCCESS
                   errno=999/--- h_errno=0/Resolver Error 0 (no error)
        "one.one.one.one"
        AF_INET 1.0.0.1

_nss_resolve_gethostbyaddr2_r("10.38.5.41") → status=NSS_STATUS_SUCCESS
                   errno=999/--- h_errno=0/Resolver Error 0 (no error) ttl=0
        "squid.redhat.com"
        alias "squid.corp.redhat.com"
        alias "squid2.corp.redhat.com"
        alias "squid3.corp.redhat.com"
        alias "squid4.corp.redhat.com"
        alias "squid5.corp.redhat.com"
        AF_INET 10.38.5.41

_nss_resolve_gethostbyaddr_r("10.38.5.41") → status=NSS_STATUS_SUCCESS
                   errno=999/--- h_errno=0/Resolver Error 0 (no error)
        "squid.redhat.com"
        alias "squid.corp.redhat.com"
        alias "squid2.corp.redhat.com"
        alias "squid3.corp.redhat.com"
        alias "squid4.corp.redhat.com"
        alias "squid5.corp.redhat.com"
        AF_INET 10.38.5.41

(I have 10.38.5.41 squid.redhat.com squid.corp.redhat.com squid2.corp.redhat.com squid3.corp.redhat.com squid4.corp.redhat.com squid5.corp.redhat.com
in /etc/hosts for testing.)
2021-03-31 16:28:14 +02:00
19 changed files with 235 additions and 238 deletions

View File

@ -147,55 +147,54 @@
<refsect1>
<title>Description</title>
<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
<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. 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>
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><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
<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
project='man-pages'><refentrytitle>errno</refentrytitle><manvolnum>3</manvolnum></citerefentry>)
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>
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>
<para><function>sd_bus_error_setf()</function> is similar to
<function>sd_bus_error_set()</function>, but takes a <citerefentry
@ -204,33 +203,25 @@
<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> 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>
<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>
<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
<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
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. 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>
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>
<para><function>sd_bus_error_set_errnof()</function> is similar to
<function>sd_bus_error_set_errno()</function>, but in addition to
@ -246,28 +237,26 @@
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>, 0 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>,
<constant>0</constant> will be returned.</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_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_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_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_is_set()</function> will return a
non-zero value if <parameter>e</parameter> is
@ -300,25 +289,23 @@
<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>, 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>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><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 0 or a positive
integer on success, and a negative error value converted from the error name 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_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;
const char *fs, *controller_str = NULL; /* silence gcc warning about unitialized variable */
int unified, r;
assert(pid >= 0);
@ -720,6 +720,7 @@ 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;
const char *e, *word = format, *test_value = NULL; /* test_value is initialized to appease gcc */
char *k;
_cleanup_free_ char *r = NULL;
size_t i, len;
size_t i, len = 0; /* len is initialized to appease gcc */
int nest = 0;
assert(format);
@ -581,13 +581,12 @@ 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))
if (flags & REPLACE_ENV_ALLOW_EXTENDED) {
len = e - word - 2;
state = TEST;
} else
/* 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;
int r, fd = -1;
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,6 +164,7 @@ 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,6 +14,7 @@
#include <sys/types.h>
#include <sys/un.h>
#include "errno-util.h"
#include "macro.h"
#include "missing_network.h"
#include "missing_socket.h"
@ -264,7 +265,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 -errno;
return negative_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;
int r = 0; /* silence gcc warning about r being unitialized below */
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;
size_t decrypted_key_size = 0; /* Silence gcc warning about unitialized variable */
assert(cd);
assert(name);
@ -1058,15 +1058,12 @@ 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.*/
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.");
}
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 (r < 0)
return r;
@ -1091,6 +1088,7 @@ 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,9 +86,11 @@ static int bus_error_name_to_errno(const char *name) {
if (m->code == BUS_ERROR_MAP_END_MARKER)
break;
if (streq(m->name, name))
if (streq(m->name, name)) {
assert(m->code > 0);
return m->code;
}
}
m = ALIGN_TO_PTR(__start_SYSTEMD_BUS_ERROR_MAP, sizeof(void*));
while (m < __stop_SYSTEMD_BUS_ERROR_MAP) {
@ -103,8 +105,10 @@ static int bus_error_name_to_errno(const char *name) {
continue;
}
if (streq(m->name, name))
if (streq(m->name, name)) {
assert(m->code > 0);
return m->code;
}
m++;
}
@ -232,6 +236,7 @@ finish:
}
int bus_error_setfv(sd_bus_error *e, const char *name, const char *format, va_list ap) {
int r;
if (!name)
return 0;
@ -253,23 +258,28 @@ int bus_error_setfv(sd_bus_error *e, const char *name, const char *format, va_li
e->_need_free = 1;
}
return -bus_error_name_to_errno(name);
r = bus_error_name_to_errno(name);
assert(r > 0);
return -r;
}
_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;
}
return sd_bus_error_set(e, name, NULL);
r = sd_bus_error_set(e, name, NULL);
assert(!name || r < 0);
return r;
}
_public_ int sd_bus_error_copy(sd_bus_error *dest, const sd_bus_error *e) {
@ -455,7 +465,7 @@ _public_ int sd_bus_error_set_errno(sd_bus_error *e, int error) {
if (!e)
return -error;
if (error == 0)
return -error;
return 0;
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 -errno;
return negative_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,9 +265,12 @@ _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);
return sd_device_monitor_filter_add_match_subsystem_devtype(udev_monitor->monitor, subsystem, devtype);
r = sd_device_monitor_filter_add_match_subsystem_devtype(udev_monitor->monitor, subsystem, devtype);
return r < 0 ? r : 0;
}
/**
@ -283,9 +286,12 @@ _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);
return sd_device_monitor_filter_add_match_tag(udev_monitor->monitor, tag);
r = sd_device_monitor_filter_add_match_tag(udev_monitor->monitor, tag);
return r < 0 ? r : 0;
}
/**

View File

@ -207,14 +207,10 @@ enum nss_status _nss_resolve_gethostbyname4_r(
int *errnop, int *h_errnop,
int32_t *ttlp) {
_cleanup_(resolve_hostname_reply_destroy) ResolveHostnameReply p = {};
_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;
_cleanup_(json_variant_unrefp) JsonVariant *cparams = NULL;
_cleanup_(resolve_hostname_reply_destroy) ResolveHostnameReply p = {};
JsonVariant *rparams, *entry;
int r;
PROTECT_ERRNO;
@ -241,6 +237,7 @@ 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;
@ -256,6 +253,7 @@ 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 = {};
@ -271,13 +269,13 @@ enum nss_status _nss_resolve_gethostbyname4_r(
goto fail;
}
c++;
n_addresses++;
}
canonical = p.name ?: name;
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;
l = strlen(canonical);
ms = ALIGN(l+1) + ALIGN(sizeof(struct gaih_addrtuple)) * c;
if (buflen < ms) {
UNPROTECT_ERRNO;
*errnop = ERANGE;
@ -286,12 +284,13 @@ enum nss_status _nss_resolve_gethostbyname4_r(
}
/* First, append name */
r_name = buffer;
memcpy(r_name, canonical, l+1);
idx = ALIGN(l+1);
char *r_name = buffer;
memcpy(r_name, canonical, l + 1);
idx = ALIGN(l + 1);
/* Second, append addresses */
r_tuple_first = (struct gaih_addrtuple*) (buffer + idx);
struct gaih_addrtuple *r_tuple = NULL,
*r_tuple_first = (struct gaih_addrtuple*) (buffer + idx);
JSON_VARIANT_ARRAY_FOREACH(entry, p.addresses) {
AddressParameters q = {};
@ -313,7 +312,7 @@ enum nss_status _nss_resolve_gethostbyname4_r(
idx += ALIGN(sizeof(struct gaih_addrtuple));
}
assert(r_tuple);
assert(r_tuple); /* We had at least one address, so r_tuple must be set */
r_tuple->next = NULL; /* Override last next pointer */
assert(idx == ms);
@ -353,13 +352,10 @@ enum nss_status _nss_resolve_gethostbyname3_r(
int32_t *ttlp,
char **canonp) {
_cleanup_(resolve_hostname_reply_destroy) ResolveHostnameReply p = {};
_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;
_cleanup_(json_variant_unrefp) JsonVariant *cparams = NULL;
_cleanup_(resolve_hostname_reply_destroy) ResolveHostnameReply p = {};
JsonVariant *rparams, *entry;
int r;
PROTECT_ERRNO;
@ -389,6 +385,7 @@ 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;
@ -404,6 +401,7 @@ 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 = {};
@ -419,15 +417,15 @@ enum nss_status _nss_resolve_gethostbyname3_r(
goto fail;
}
c++;
n_addresses++;
}
canonical = p.name ?: name;
const char *canonical = p.name ?: name;
alen = FAMILY_ADDRESS_SIZE(af);
l = strlen(canonical);
size_t alen = FAMILY_ADDRESS_SIZE(af);
size_t l = strlen(canonical);
ms = ALIGN(l+1) + c*ALIGN(alen) + (c+2) * sizeof(char*);
size_t idx, ms = ALIGN(l + 1) + n_addresses * ALIGN(alen) + (n_addresses + 2) * sizeof(char*);
if (buflen < ms) {
UNPROTECT_ERRNO;
@ -437,18 +435,19 @@ enum nss_status _nss_resolve_gethostbyname3_r(
}
/* First, append name */
r_name = buffer;
char *r_name = buffer;
memcpy(r_name, canonical, l+1);
idx = ALIGN(l+1);
/* Second, create empty aliases array */
r_aliases = buffer + idx;
char *r_aliases = buffer + idx;
((char**) r_aliases)[0] = NULL;
idx += sizeof(char*);
/* Third, append addresses */
r_addr = buffer + idx;
char *r_addr = buffer + idx;
size_t i = 0;
JSON_VARIANT_ARRAY_FOREACH(entry, p.addresses) {
AddressParameters q = {};
@ -468,16 +467,16 @@ enum nss_status _nss_resolve_gethostbyname3_r(
i++;
}
assert(i == c);
idx += c * ALIGN(alen);
assert(i == n_addresses);
idx += n_addresses * ALIGN(alen);
/* Fourth, append address pointer array */
r_addr_list = buffer + idx;
for (i = 0; i < c; i++)
char *r_addr_list = buffer + idx;
for (i = 0; i < n_addresses; i++)
((char**) r_addr_list)[i] = r_addr + i*ALIGN(alen);
((char**) r_addr_list)[i] = NULL;
idx += (c+1) * sizeof(char*);
idx += (n_addresses + 1) * sizeof(char*);
assert(idx == ms);
@ -541,7 +540,7 @@ 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_UNSIGNED, json_dispatch_string, offsetof(NameParameters, name), JSON_MANDATORY },
{ "name", JSON_VARIANT_STRING, json_dispatch_string, offsetof(NameParameters, name), JSON_MANDATORY },
{}
};
@ -553,14 +552,10 @@ enum nss_status _nss_resolve_gethostbyaddr2_r(
int *errnop, int *h_errnop,
int32_t *ttlp) {
_cleanup_(resolve_address_reply_destroy) ResolveAddressReply p = {};
_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;
_cleanup_(json_variant_unrefp) JsonVariant *cparams = NULL;
_cleanup_(resolve_address_reply_destroy) ResolveAddressReply p = {};
JsonVariant *rparams, *entry;
int r;
PROTECT_ERRNO;
@ -594,6 +589,7 @@ 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;
@ -609,6 +605,8 @@ 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 = {};
@ -619,9 +617,10 @@ 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*) + /* pointers to the address, plus trailing NULL */
json_variant_elements(p.names) * sizeof(char*); /* pointers to aliases, plus trailing NULL */
2 * sizeof(char*) + /* pointer to the address, plus trailing NULL */
n_names * sizeof(char*); /* pointers to aliases, plus trailing NULL */
if (buflen < ms) {
UNPROTECT_ERRNO;
@ -631,44 +630,43 @@ enum nss_status _nss_resolve_gethostbyaddr2_r(
}
/* First, place address */
r_addr = buffer;
char *r_addr = buffer;
memcpy(r_addr, addr, len);
idx = ALIGN(len);
/* Second, place address list */
r_addr_list = buffer + idx;
char *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 */
r_aliases = buffer + idx;
idx += sizeof(char*) * c;
/* Third, reserve space for the aliases array, plus trailing NULL */
char *r_aliases = buffer + idx;
idx += sizeof(char*) * n_names;
/* Fourth, place aliases */
i = 0;
r_name = buffer + idx;
char *r_name = buffer + idx;
size_t i = 0;
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;
l = strlen(q.name);
z = buffer + idx;
memcpy(z, n, l+1);
size_t l = strlen(q.name);
char *z = buffer + idx;
memcpy(z, q.name, 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];
gcry_md_hd_t md = NULL;
_cleanup_(gcry_md_closep) gcry_md_hd_t md = NULL;
gcry_error_t err;
size_t hash_size;
int algorithm;
@ -1249,10 +1249,8 @@ 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) {
r = -EIO;
goto finish;
}
if (!result)
return -EIO;
for (k = 0; k < nsec3->nsec3.iterations; k++) {
uint8_t tmp[hash_size];
@ -1263,18 +1261,12 @@ 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) {
r = -EIO;
goto finish;
}
if (!result)
return -EIO;
}
memcpy(ret, result, hash_size);
r = (int) hash_size;
finish:
gcry_md_close(md);
return r;
return (int) hash_size;
}
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,7 +213,6 @@ static DnsTransactionState dns_query_candidate_state(DnsQueryCandidate *c) {
break;
}
}
return state;
}

View File

@ -98,8 +98,11 @@ static int bus_message_read_dns_one(
if (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 (!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 (extended) {
r = sd_bus_message_read(message, "q", &port);

View File

@ -300,7 +300,8 @@ 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 **prefixes, **prefix;
char **prefix, **prefixes = NULL; /* explicit initialization to appease gcc */
bool is_collection;
const char *extension;
char **t;
@ -289,6 +289,8 @@ 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,13 +448,16 @@ 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 */
if (!v->prefer_read_write) {
* 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) {
n = send(v->fd, v->output_buffer + v->output_buffer_index, v->output_buffer_size, MSG_DONTWAIT|MSG_NOSIGNAL);
if (n < 0 && errno == ENOTSOCK)
v->prefer_read_write = true;
prefer_write = v->prefer_read_write = true;
}
if (v->prefer_read_write)
if (prefer_write)
n = write(v->fd, v->output_buffer + v->output_buffer_index, v->output_buffer_size);
if (n < 0) {
if (errno == EAGAIN)
@ -531,12 +534,13 @@ static int varlink_read(Varlink *v) {
rs = v->input_buffer_allocated - (v->input_buffer_index + v->input_buffer_size);
if (!v->prefer_read_write) {
bool prefer_read = v->prefer_read_write;
if (!prefer_read) {
n = recv(v->fd, v->input_buffer + v->input_buffer_index + v->input_buffer_size, rs, MSG_DONTWAIT);
if (n < 0 && errno == ENOTSOCK)
v->prefer_read_write = true;
prefer_read = v->prefer_read_write = true;
}
if (v->prefer_read_write)
if (prefer_read)
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,7 +307,9 @@ 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,22 +103,15 @@ static int setup_tests(bool *run_ambient) {
nobody = getpwnam(NOBODY_USER_NAME);
if (!nobody)
return log_error_errno(SYNTHETIC_ERRNO(ENOENT), "Could not find nobody user: %m");
return log_warning_errno(SYNTHETIC_ERRNO(ENOENT), "Couldn't 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. */
if (r >= 0 || errno != EINVAL)
*run_ambient = true;
/* 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;
return 0;
}
@ -249,7 +242,7 @@ static void test_ensure_cap_64bit(void) {
}
int main(int argc, char *argv[]) {
bool run_ambient;
bool run_ambient = false; /* unnecessary initialization to silence gcc warning */
test_setup_logging(LOG_INFO);