Commit Graph

47 Commits

Author SHA1 Message Date
Shawn Landden 3b1c524154 add REMOTE_ADDR and REMOTE_PORT for Accept=yes 2015-03-10 09:00:27 -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
Michal Schmidt 710708a54c shared: handle unnamed sockets in socket_address_equal()
Make sure we don't inspect sun_path of unnamed sockets.
Since we cannot know if two unnamed sockets' adresses refer to the same
socket, just return false.
2015-02-20 03:35:12 +01:00
Michal Schmidt 02233928a5 shared: avoid semi-duplicating socket_address_equal()
Just call socket_address_equal() from socket_address_matches_fd()
instead of implementing similar comparing of addresses.
2015-02-20 03:35:11 +01:00
Michal Schmidt dbafedacba shared: use SocketAddress in socket_address_matches_fd()
Cleanup. No behavior change.
2015-02-20 03:35:11 +01:00
Michal Schmidt c78e47a61f core, shared: in deserializing, match same files reached via different paths
When dbus.socket is updated like this:
-ListenStream=/var/run/dbus/system_bus_socket
+ListenStream=/run/dbus/system_bus_socket
... and daemon-reload is performed, bad things happen.
During deserialization systemd does not recognize that the two paths
refer to the same named socket and replaces the socket file with a new
one. As a result, applications hang when they try talking to dbus.

Fix this by finding a match not only when the path names are equal, but
also when they point to the same inode.
In socket_address_equal() it is necessary to move the address size
comparison into the abstract sockets branch. For path name sockets the
comparison must not be done and for other families it is redundant
(their sizes are constant and checked by socket_address_verify()).

FIFOs and special files can also have multiple pathnames, so compare the
inodes for them as well. Note that previously the pathname checks used
streq_ptr(), but the paths cannot be NULL.

Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1186018
2015-02-20 03:35:04 +01:00
Michal Schmidt 4a62c710b6 treewide: another round of simplifications
Using the same scripts as in f647962d64 "treewide: yet more log_*_errno
+ return simplifications".
2014-11-28 19:57:32 +01:00
Michal Schmidt 56f64d9576 treewide: use log_*_errno whenever %m is in the format string
If the format string contains %m, clearly errno must have a meaningful
value, so we might as well use log_*_errno to have ERRNO= logged.

Using:
find . -name '*.[ch]' | xargs sed -r -i -e \
's/log_(debug|info|notice|warning|error|emergency)\((".*%m.*")/log_\1_errno(errno, \2/'

Plus some whitespace, linewrap, and indent adjustments.
2014-11-28 19:49:27 +01:00
Michal Schmidt f647962d64 treewide: yet more log_*_errno + return simplifications
Using:
find . -name '*.[ch]' | while read f; do perl -i.mmm -e \
 'local $/;
  local $_=<>;
  s/(if\s*\([^\n]+\))\s*{\n(\s*)(log_[a-z_]*_errno\(\s*([->a-zA-Z_]+)\s*,[^;]+);\s*return\s+\g4;\s+}/\1\n\2return \3;/msg;
  print;'
 $f
done

And a couple of manual whitespace fixups.
2014-11-28 18:56:16 +01:00
Michal Schmidt 279d3c9cea treewide: more log_*_errno() conversions 2014-11-28 14:45:55 +01:00
Michal Schmidt da927ba997 treewide: no need to negate errno for log_*_errno()
It corrrectly handles both positive and negative errno values.
2014-11-28 13:29:21 +01:00
Michal Schmidt 0a1beeb642 treewide: auto-convert the simple cases to log_*_errno()
As a followup to 086891e5c1 "log: add an "error" parameter to all
low-level logging calls and intrdouce log_error_errno() as log calls
that take error numbers", use sed to convert the simple cases to use
the new macros:

find . -name '*.[ch]' | xargs sed -r -i -e \
's/log_(debug|info|notice|warning|error|emergency)\("(.*)%s"(.*), strerror\(-([a-zA-Z_]+)\)\);/log_\1_errno(-\4, "\2%m"\3);/'

Multi-line log_*() invocations are not covered.
And we also should add log_unit_*_errno().
2014-11-28 12:04:41 +01:00
Zbigniew Jędrzejewski-Szmek cb6518345f socket-util: use IP address when hostname is not found
socknameinfo_pretty() would fail for addresses without reverse DNS,
but we do not want that to happen.
2014-10-23 00:26:35 -04:00
Lennart Poettering db73295acc util: never use ether_ntoa(), since it formats with %x, not %02x, which makes ethernet addresses look funny 2014-08-15 13:19:03 +02:00
Lennart Poettering 90ab504273 resolved: skip IPv6 LLMNR if IPv6 is not available 2014-08-13 15:00:12 +02:00
Lennart Poettering f01e5736f1 timesyncd: move the generic sockaddr_equal() call to socket-util.h 2014-08-12 14:54:32 +02:00
Zbigniew Jędrzejewski-Szmek b31f535c9a shared/socket-util: add function to query remote address 2014-07-15 22:31:40 -04:00
Lennart Poettering 3b653205cf shared: split out in_addr related calls from socket-util.[ch] into its private in-addr-util.[ch]
These are enough calls for a new file, and they are sufficiently
different from the sockaddr-related calls, hence let's split this out.
2014-07-10 21:15:26 +02:00
Marc-Antoine Perennou 57827c087c fix in_addr_prefix_intersect for 32bits
shifting from a non fixed number of bits >= to the size of the type
leads to weird results, handle the special case of << 32 to fix it.

This was causing a test failure from test-socket-util:
Assertion 'in_addr_prefix_intersect(f, &ua, apl, &ub, bpl) == result' failed at
/var/tmp/paludis/build/sys-apps-systemd-scm/work/systemd-scm/src/test/test-socket-util.c:147, function
test_in_addr_prefix_intersect_one(). Aborting.

Minimal reproducer:

paludisbuild@Lou /tmp $ cat test.c
static void test(unsigned m) {
        unsigned nm = 0xFFFFFFFFUL << (32-m);
        printf("%u: %x\n", m, nm);
}

int main (void) {
        test(1);
        test(0);
        return 0;
}
paludisbuild@Lou /tmp $ gcc -m32 -std=gnu99 test.c -o test32
paludisbuild@Lou /tmp $ ./test32
1: 80000000
0: ffffffff
paludisbuild@Lou /tmp $ gcc -std=gnu99 test.c -o test64
paludisbuild@Lou /tmp $ ./test64
1: 80000000
0: 0
2014-06-22 12:26:09 -04:00
Lennart Poettering 059f6c42b7 networkd: add a number of calls to manipulate in_addr_union structs 2014-06-18 18:28:29 +02:00
Lennart Poettering bd1fe7c79d socket: optionally remove sockets/FIFOs in the file system after use 2014-06-04 13:12:34 +02:00
Zbigniew Jędrzejewski-Szmek de0671ee7f Remove unnecessary casts in printfs
No functional change expected :)
2014-05-15 15:29:58 +02:00
Lennart Poettering 39883f622f make gcc shut up
If -flto is used then gcc will generate a lot more warnings than before,
among them a number of use-without-initialization warnings. Most of them
without are false positives, but let's make them go away, because it
doesn't really matter.
2014-02-19 17:53:50 +01:00
Lennart Poettering 33649f58af shared: fix getpeername_pretty() for AF_UNIX sockets 2013-12-25 01:29:55 +01:00
Lennart Poettering 79a98c609d unit: include peer identity in description of per-connection socket-activated services 2013-12-25 01:29:55 +01:00
Lennart Poettering eff0527098 util: unify SO_PEERCRED/SO_PEERSEC invocations
Introduce new call getpeercred() which internally just uses SO_PEERCRED
but checks if the returned data is actually useful due to namespace
quirks.
2013-12-24 15:53:04 +01:00
Lennart Poettering 4d49b48c60 socket: rework things to have only one sockaddr formatter 2013-11-07 00:13:58 +01:00
Lennart Poettering 8569a77629 socket-proxyd: rework to support multiple sockets and splice()-based zero-copy network IO
This also drops --ignore-env, which can't really work anymore if we
allow multiple fds. Also adds support for pretty printing of peer
identities for debug purposes, and abstract namespace UNIX sockets. Also
ensures that we never take more connections than a certain limit.
2013-11-06 23:03:12 +01:00
Lennart Poettering 175a3d25d0 active: rework make_socket_fd() to be based on socket_address_listen()
Among other things this makes sure we set SO_REUSEADDR which is
immensely useful.
2013-11-06 23:03:12 +01:00
Zbigniew Jędrzejewski-Szmek b47d419c25 Modernization
Fixes minor leak in error path in device.c.
2013-10-13 17:56:54 -04:00
Lennart Poettering a57f7e2c82 core: rework how we match mount units against each other
Previously to automatically create dependencies between mount units we
matched every mount unit agains all others resulting in O(n^2)
complexity. On setups with large amounts of mount units this might make
things slow.

This change replaces the matching code to use a hashtable that is keyed
by a path prefix, and points to a set of units that require that path to
be around. When a new mount unit is installed it is hence sufficient to
simply look up this set of units via its own file system paths to know
which units to order after itself.

This patch also changes all unit types to only create automatic mount
dependencies via the RequiresMountsFor= logic, and this is exposed to
the outside to make things more transparent.

With this change we still have some O(n) complexities in place when
handling mounts, but that's currently unavoidable due to kernel APIs,
and still substantially better than O(n^2) as before.

https://bugs.freedesktop.org/show_bug.cgi?id=69740
2013-09-26 20:20:30 +02:00
Harald Hoyer 7fd1b19bc9 move _cleanup_ attribute in front of the type
http://lists.freedesktop.org/archives/systemd-devel/2013-April/010510.html
2013-04-18 09:11:22 +02:00
Zbigniew Jędrzejewski-Szmek bcb161b023 errno is positive
Make sure we compare errno against positive error codes.
The ones in hwclock.c and install.c can have an impact, the
rest are unlikely to be hit or in code that isn't widely
used.

Also check that errno > 0, to help gcc know that we are
returning a negative error code.
2013-04-11 19:13:18 -04:00
Zbigniew Jędrzejewski-Szmek 8333c77edf Always use errno > 0 to help gcc
gcc thinks that errno might be negative, and functions could return
something positive on error (-errno). Should not matter in practice,
but makes an -O4 build much quieter.
2013-03-29 10:12:41 -04:00
Zbigniew Jędrzejewski-Szmek 2ca0435be9 systemd-activate: add a socket-activation test tool 2013-02-27 22:10:14 -05:00
Harald Hoyer a5c32cff1f honor SELinux labels, when creating and writing config files
Also split out some fileio functions to fileio.c and provide a SELinux
aware pendant in fileio-label.c

see https://bugzilla.redhat.com/show_bug.cgi?id=881577
2013-02-14 16:19:38 +01:00
Thomas Hindoe Paaboel Andersen 641906e936 use strneq instead of strncmp 2013-02-13 00:56:13 +01:00
Lennart Poettering 01e10de3c2 socket: support socket activation of containers 2012-12-22 22:17:58 +01:00
Michal Sekletar 8520cfa584 socket-util: added check of return value 2012-12-17 11:41:31 +01:00
Zbigniew Jędrzejewski-Szmek 6b6ed3e3eb shared/socket-util: kill gcc warning about uninitialized variable
The warning was invalid, but distracting.
2012-11-13 02:23:02 +01:00
Michal Schmidt f8b69d1dfc shared, core: do not always accept numbers in string lookups
The behaviour of the common name##_from_string conversion is surprising.
It accepts not only the strings from name##_table but also any number
that falls within the range of the table. The order of items in most of
our tables is an internal affair. It should not be visible to the user.

I know of a case where the surprising numeric conversion leads to a crash.

We will allow the direct numeric conversion only for the tables where the
mapping of strings to numeric values has an external meaning. This holds
for the following lookup tables:
 - netlink_family, ioprio_class, ip_tos, sched_policy - their numeric
   values are stable as they are defined by the Linux kernel interface.
 - log_level, log_facility_unshifted - the well-known syslog interface.

We allow the user to use numeric values whose string names systemd does
not know. For instance, the user may want to test a new kernel featuring
a scheduling policy that did not exist when his systemd version was
released. A slightly unpleasant effect of this is that the
name##_to_string conversion cannot return pointers to constant strings
anymore. The strings have to be allocated on demand and freed by the
caller.
2012-10-30 15:41:15 +01:00
Lennart Poettering 5198dabcce man: document behaviour of ListenStream= with only a port number in regards to IPv4/IPv6 2012-10-03 14:18:55 -04:00
Kay Sievers 9eb977db5b util: split-out path-util.[ch] 2012-05-08 02:33:10 +02:00
Lennart Poettering 5430f7f2bc relicense to LGPLv2.1 (with exceptions)
We finally got the OK from all contributors with non-trivial commits to
relicense systemd from GPL2+ to LGPL2.1+.

Some udev bits continue to be GPL2+ for now, but we are looking into
relicensing them too, to allow free copy/paste of all code within
systemd.

The bits that used to be MIT continue to be MIT.

The big benefit of the relicensing is that closed source code may now
link against libsystemd-login.so and friends.
2012-04-12 00:24:39 +02:00
Kay Sievers cc527a4734 split selinux label operations out of cgroup-util, socket-util
This prevents linking of selinux and libdl for another 15 binaries.
2012-04-11 12:49:00 +02:00
Kay Sievers 49e942b2bc rename basic.la to shared.la and put selinux deps in shared-selinx.la
Only 34 of 74 tools need libselinux linked, and libselinux is a pain
with its unconditional library constructor.
2012-04-10 22:43:05 +02:00
Kay Sievers d7832d2c6e util: move all to shared/ and split external dependencies in separate internal libraries
Before:
  $ ldd /lib/systemd/systemd-timestamp
  linux-vdso.so.1 =>  (0x00007fffb05ff000)
  libselinux.so.1 => /lib64/libselinux.so.1 (0x00007f90aac57000)
  libcap.so.2 => /lib64/libcap.so.2 (0x00007f90aaa53000)
  librt.so.1 => /lib64/librt.so.1 (0x00007f90aa84a000)
  libc.so.6 => /lib64/libc.so.6 (0x00007f90aa494000)
  /lib64/ld-linux-x86-64.so.2 (0x00007f90aae90000)
  libdl.so.2 => /lib64/libdl.so.2 (0x00007f90aa290000)
  libattr.so.1 => /lib64/libattr.so.1 (0x00007f90aa08a000)
  libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f90a9e6e000)

After:
  $ ldd systemd-timestamp
  linux-vdso.so.1 =>  (0x00007fff3cbff000)
  libselinux.so.1 => /lib64/libselinux.so.1 (0x00007f5eaa1c3000)
  librt.so.1 => /lib64/librt.so.1 (0x00007f5ea9fbb000)
  libc.so.6 => /lib64/libc.so.6 (0x00007f5ea9c04000)
  /lib64/ld-linux-x86-64.so.2 (0x00007f5eaa3fc000)
  libdl.so.2 => /lib64/libdl.so.2 (0x00007f5ea9a00000)
  libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f5ea97e4000)
2012-04-10 14:13:38 +02:00
Renamed from src/socket-util.c (Browse further)