Commit Graph

55 Commits

Author SHA1 Message Date
Lennart Poettering cb3108669d tree-wide: more IOVEC_MAKE() conversions 2018-11-28 13:08:19 +09:00
Yu Watanabe b3ae7237c6 sd-resolve: introduce sd_resolve_query_{get,set}_floating() 2018-11-05 13:19:02 +09:00
Yu Watanabe a8319dea1d sd-resolve: introduce sd_resolve_query_{get,set}_destroy_callback() 2018-11-05 13:19:02 +09:00
Yu Watanabe 8301aa0bf1 tree-wide: use DEFINE_TRIVIAL_REF_UNREF_FUNC() macro or friends where applicable 2018-08-27 14:01:46 +09:00
Yu Watanabe b127bc99d1 sd-resolve: workaround for structured initialization to nested structs
When a nested struct is initialized by structured initializer, then
padding space is not cleared by zero. So, before setting values,
this makes explicitly set zero including padding.

This fixes the following false positive warning by valgrind:
```
==492== Syscall param sendmsg(msg.msg_iov[0]) points to uninitialised byte(s)
==492==    at 0x56D0CF7: sendmsg (in /usr/lib64/libpthread-2.27.so)
==492==    by 0x4FDD3C5: sd_resolve_getaddrinfo (sd-resolve.c:975)
==492==    by 0x110B9E: manager_connect (timesyncd-manager.c:879)
==492==    by 0x10B729: main (timesyncd.c:165)
==492==  Address 0x1fff0008f1 is on thread 1's stack
==492==  in frame #1, created by sd_resolve_getaddrinfo (sd-resolve.c:928)
==492==
```
2018-07-29 16:05:23 +09:00
Yu Watanabe 2a12960bcd sd-resolve: use structured initialization at more places 2018-07-29 16:01:37 +09:00
Yu Watanabe 8f5dd8c094 tree-wide: drop empty comments 2018-06-29 11:00:30 +09:00
Lennart Poettering 0c69794138 tree-wide: remove Lennart's copyright lines
These lines are generally out-of-date, incomplete and unnecessary. With
SPDX and git repository much more accurate and fine grained information
about licensing and authorship is available, hence let's drop the
per-file copyright notice. Of course, removing copyright lines of others
is problematic, hence this commit only removes my own lines and leaves
all others untouched. It might be nicer if sooner or later those could
go away too, making git the only and accurate source of authorship
information.
2018-06-14 10:20:20 +02:00
Lennart Poettering 818bf54632 tree-wide: drop 'This file is part of systemd' blurb
This part of the copyright blurb stems from the GPL use recommendations:

https://www.gnu.org/licenses/gpl-howto.en.html

The concept appears to originate in times where version control was per
file, instead of per tree, and was a way to glue the files together.
Ultimately, we nowadays don't live in that world anymore, and this
information is entirely useless anyway, as people are very welcome to
copy these files into any projects they like, and they shouldn't have to
change bits that are part of our copyright header for that.

hence, let's just get rid of this old cruft, and shorten our codebase a
bit.
2018-06-14 10:20:20 +02:00
Lennart Poettering 4aab839c90 sd-resolve: tweak error assignment code a bit, use abs() and regular functions
Let's tweak the assignment of errors a bit, and automatically abs()
errnos, similar to how log_error_errno() and friends does it.

Macros are fine to use, but regular functions usually preferable if
there's no reason to use macros, because they avoid multiple evaluation
and suchlike. Hence, let's just use a regular funciton for assigning
errors, instead of macros.

Follow-up for #8993
2018-05-19 15:14:18 +02:00
Zbigniew Jędrzejewski-Szmek 38dad44332 sd-resolve: fix check for packet size
The protocol is that a string is serialized with the nul byte at the end, and
the terminator is included in length. We'd call strndup with offset 0, length
len1-1, and then a second time with offset len1, length len2-1, so in the end
the check was off by one. But let's require the terminating nul too, even if
we don't access it.

CID #1383035.
2018-05-15 12:31:42 +02:00
Zbigniew Jędrzejewski-Szmek 2da063370a sd-resolve: use structured initializers and _cleanup_
Also remove a break that cannot be reached and a resolve->dead check
that duplicates the loop condition.
2018-05-15 12:31:39 +02:00
Zbigniew Jędrzejewski-Szmek e8bce4fad3 sd-resolve: trivial indentation fixes 2018-05-15 12:27:02 +02:00
Zbigniew Jędrzejewski-Szmek f6ddae40ab sd-resolve: do not assert on packet size received over a socket
This is external data, even if trusted. We should not assert on it, but verify
and return proper error instead, which assert_return does. In particular,
write(2) says that a partial write could occur when interupted by a signal.
When compiled with asserts disabled, we could access memory outside of the
allocated buffer.

CID #1237671.
Follow-up for 1a96c8e1cc.
2018-05-15 12:25:44 +02:00
Zbigniew Jędrzejewski-Szmek 0b45ff5278 sd-resolve: add helper macro for setting of ret/_errno/_h_errno
Just to make things a bit shorter. This fixes an error where errno==-EIO would be set
(negative value), introduced in 1a96c8e1cc.
2018-05-14 17:22:22 +02:00
Zbigniew Jędrzejewski-Szmek 11a1589223 tree-wide: drop license boilerplate
Files which are installed as-is (any .service and other unit files, .conf
files, .policy files, etc), are left as is. My assumption is that SPDX
identifiers are not yet that well known, so it's better to retain the
extended header to avoid any doubt.

I also kept any copyright lines. We can probably remove them, but it'd nice to
obtain explicit acks from all involved authors before doing that.
2018-04-06 18:58:55 +02:00
Lennart Poettering 7fe2903c23 fd-util: move certain fds above fd #2 (#8129)
This adds some paranoia code that moves some of the fds we allocate for
longer periods of times to fds > 2 if they are allocated below this
boundary. This is a paranoid safety thing, in order to avoid that
external code might end up erroneously use our fds under the assumption
they were valid stdin/stdout/stderr. Think: some app closes
stdin/stdout/stderr and then invokes 'fprintf(stderr, …' which causes
writes on our fds.

This both adds the helper to do the moving as well as ports over a
number of users to this new logic. Since we don't want to litter all our
code with invocations of this I tried to strictly focus on fds we keep
open for long periods of times only and only in code that is frequently
loaded into foreign programs (under the assumptions that in our own
codebase we are smart enough to always keep stdin/stdout/stderr
allocated to avoid this pitfall). Specifically this means all code used
by NSS and our sd-xyz API:

1. our logging APIs
2. sd-event
3. sd-bus
4. sd-resolve
5. sd-netlink

This changed was inspired by this:

https://github.com/systemd/systemd/issues/8075#issuecomment-363689755

This shows that apparently IRL there are programs that do close
stdin/stdout/stderr, and we should accomodate for that.

Note that this won't fix any bugs, this just makes sure that buggy
programs are less likely to interfere with out own code.
2018-02-09 17:53:28 +01:00
Lennart Poettering dccca82b1a log: minimize includes in log.h
log.h really should only include the bare minimum of other headers, as
it is really pulled into pretty much everything else and already in
itself one of the most basic pieces of code we have.

Let's hence drop inclusion of:

1. sd-id128.h because it's entirely unneeded in current log.h
2. errno.h, dito.
3. sys/signalfd.h which we can replace by a simple struct forward
   declaration
4. process-util.h which was needed for getpid_cached() which we now hide
   in a funciton log_emergency_level() instead, which nicely abstracts
   the details away.
5. sys/socket.h which was needed for struct iovec, but a simple struct
   forward declaration suffices for that too.

Ultimately this actually makes our source tree larger (since users of
the functionality above must now include it themselves, log.h won't do
that for them), but I think it helps to untangle our web of includes a
tiny bit.

(Background: I'd like to isolate the generic bits of src/basic/ enough
so that we can do a git submodule import into casync for it)
2018-01-11 14:44:31 +01:00
Lennart Poettering 5e9f01e8a6 tree-wide: in all threads we fork off in library code, block all signals
This ensures that in all threads we fork off in the background in our
code we mask out all signals, so that our thread won't end up getting
signals delivered the main process should be getting.

We always set the signal mask before forking off the thread, so that the
thread has the right mask set from its earliest existance on.
2018-01-04 13:27:27 +01:00
Lennart Poettering fa7ff4cf03 tree-wide: properly name all threads we fork off 2017-12-25 11:48:21 +01:00
Lennart Poettering 4de8d3f59e
Merge pull request #7486 from keszybz/coverity-fixes
Fixes for issues spotted by coverity (and some cleanups)
2017-11-28 15:04:11 +01:00
Zbigniew Jędrzejewski-Szmek 1a96c8e1cc sd-resolve: check that name fits in the specified packet length
Coverity complained that we didn't check if the data is long enough.
2017-11-28 09:25:38 +01:00
Lennart Poettering 971fea3203 sd-resolve: propagate timeouts in sd_resolve_wait() the same way as in sd_bus_wait(): ETIMEDOUT
Thankfully this is an internal API still, so we can mkae changes like
this.
2017-11-27 17:08:34 +01:00
Zbigniew Jędrzejewski-Szmek 53e1b68390 Add SPDX license identifiers to source files under the LGPL
This follows what the kernel is doing, c.f.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=5fd54ace4721fc5ce2bb5aef6318fcf17f421460.
2017-11-19 19:08:15 +01:00
Lennart Poettering df0ff12775 tree-wide: make use of getpid_cached() wherever we can
This moves pretty much all uses of getpid() over to getpid_raw(). I
didn't specifically check whether the optimization is worth it for each
replacement, but in order to keep things simple and systematic I
switched over everything at once.
2017-07-20 20:27:24 +02:00
0xAX 3a1707fff1 sd-resolve: use close_many() (#3643) 2016-07-02 08:17:26 -07:00
Zbigniew Jędrzejewski-Szmek 9d4e7d1380 sd-resolve: ignore error in pthread_join()
CID #1338424.
2016-04-08 21:08:42 -04:00
Vito Caputo 313cefa1d9 tree-wide: make ++/-- usage consistent WRT spacing
Throughout the tree there's spurious use of spaces separating ++ and --
operators from their respective operands.  Make ++ and -- operator
consistent with the majority of existing uses; discard the spaces.
2016-02-22 20:32:04 -08:00
Lennart Poettering 32d2064523 libsystemd-network: sd-event uses 64bit priorities, expose them in the APIs as such 2016-02-20 22:42:29 +01:00
Zbigniew Jędrzejewski-Szmek 79d6297252 Use (void) to silenc coverity on proc title changes
This is a cosmetic best-effort thing anyway.
2016-02-19 07:35:35 -05:00
Lennart Poettering 91ba5ac7d0 Merge pull request #2589 from keszybz/resolve-tool-2
Better support of OPENPGPKEY, CAA, TLSA packets and tests
2016-02-13 11:15:41 +01:00
Zbigniew Jędrzejewski-Szmek 75f32f047c Add memcpy_safe
ISO/IEC 9899:1999 §7.21.1/2 says:
Where an argument declared as size_t n specifies the length of the array
for a function, n can have the value zero on a call to that
function. Unless explicitly stated otherwise in the description of a
particular function in this subclause, pointer arguments on such a call
shall still have valid values, as described in 7.1.4.

In base64_append_width memcpy was called as memcpy(x, NULL, 0).  GCC 4.9
started making use of this and assumes This worked fine under -O0, but
does something strange under -O3.

This patch fixes a bug in base64_append_width(), fixes a possible bug in
journal_file_append_entry_internal(), and makes use of the new function
to simplify the code in other places.
2016-02-11 13:07:02 -05:00
Daniel Mack b26fa1a2fb tree-wide: remove Emacs lines from all files
This should be handled fine now by .dir-locals.el, so need to carry that
stuff in every file.
2016-02-10 13:41:57 +01:00
Lennart Poettering 4afd3348c7 tree-wide: expose "p"-suffix unref calls in public APIs to make gcc cleanup easy
GLIB has recently started to officially support the gcc cleanup
attribute in its public API, hence let's do the same for our APIs.

With this patch we'll define an xyz_unrefp() call for each public
xyz_unref() call, to make it easy to use inside a
__attribute__((cleanup())) expression. Then, all code is ported over to
make use of this.

The new calls are also documented in the man pages, with examples how to
use them (well, I only added docs where the _unref() call itself already
had docs, and the examples, only cover sd_bus_unrefp() and
sd_event_unrefp()).

This also renames sd_lldp_free() to sd_lldp_unref(), since that's how we
tend to call our destructors these days.

Note that this defines no public macro that wraps gcc's attribute and
makes it easier to use. While I think it's our duty in the library to
make our stuff easy to use, I figure it's not our duty to make gcc's own
features easy to use on its own. Most likely, client code which wants to
make use of this should define its own:

       #define _cleanup_(function) __attribute__((cleanup(function)))

Or similar, to make the gcc feature easier to use.

Making this logic public has the benefit that we can remove three header
files whose only purpose was to define these functions internally.

See #2008.
2015-11-27 19:19:36 +01:00
Michal Schmidt 5263a45b5c sd-resolve: simplify pthread_join() call
POSIX says:
The pthread_join() function shall not return an error code of [EINTR].
2015-11-05 13:44:15 +01:00
Lennart Poettering b5efdb8af4 util-lib: split out allocation calls into alloc-util.[ch] 2015-10-27 13:45:53 +01:00
Lennart Poettering c004493cde util-lib: split out IO related calls to io-util.[ch] 2015-10-26 01:24:38 +01:00
Lennart Poettering 3ffd4af220 util-lib: split out fd-related operations into fd-util.[ch]
There are more than enough to deserve their own .c file, hence move them
over.
2015-10-25 13:19:18 +01:00
Lennart Poettering 07630cea1f util-lib: split our string related calls from util.[ch] into its own file string-util.[ch]
There are more than enough calls doing string manipulations to deserve
its own files, hence do something about it.

This patch also sorts the #include blocks of all files that needed to be
updated, according to the sorting suggestions from CODING_STYLE. Since
pretty much every file needs our string manipulation functions this
effectively means that most files have sorted #include blocks now.

Also touches a few unrelated include files.
2015-10-24 23:05:02 +02:00
Lennart Poettering 1fac0c31ab sd-resolve: drop res_query() API
Querying low-level DNS RRs should be done via resolved now, not via
glibc's awful res_query() API anymore. Let's not introduce an async
wrapper for it hence.
2015-08-27 20:47:13 +02:00
Zbigniew Jędrzejewski-Szmek e62d9b8192 Add (void) where we don't care about return value 2015-03-15 17:26:58 -04:00
Zbigniew Jędrzejewski-Szmek d448c7927a sd-resolve: use different element of union to make code more readable
They both point to the same location, but the reader
is not forced to look back to the beginning of the function
to see that.
2015-03-13 23:42:17 -04:00
Thomas Hindoe Paaboel Andersen 2eec67acbb remove unused includes
This patch removes includes that are not used. The removals were found with
include-what-you-use which checks if any of the symbols from a header is
in use.
2015-02-23 23:53:42 +01:00
Thomas Hindoe Paaboel Andersen 0a6f50c0af include <poll.h> instead of <sys/poll.h>
include-what-you-use automatically does this and it makes finding
unnecessary harder to spot. The only content of poll.h is a include
of sys/poll.h so should be harmless.
2015-02-12 20:47:38 +01:00
Lennart Poettering 96c76ac49c sd-resolve: scale number of threads by queries currently being processed, rather than number of queries currently referenced
This way a query that blocks for a longer time, and whose reference has
been dropped won't block subsequent lookups from finishing.
2014-08-12 19:30:18 +02:00
Lennart Poettering 85529c815b sd-resolve: fix allocation if query ids, never reuse them 2014-08-12 19:29:27 +02:00
Lennart Poettering 502fe44ea4 sd-resolve: keep floating query referenced while we access it 2014-08-12 19:28:32 +02:00
Lennart Poettering f2e2415d69 resolve: fix copy/paste error 2014-05-15 17:31:14 +02:00
Lennart Poettering 4a134c4903 sd-resolve: add "floating" resolve queries
Same story as for sd-bus and sd-event: allow passing NULL to store query
in in which case the query is freed automatically.
2014-05-15 17:13:05 +02:00
Lennart Poettering 73dec31974 sd-resolve: make sure we can destroy a query object from its own callback handler 2014-05-05 23:49:19 +02:00