Commit graph

1037 commits

Author SHA1 Message Date
Zbigniew Jędrzejewski-Szmek 948aaa7c52 tree-wide: standardize on $(PACKAGE_VERSION) for the version string
We defined both $(VERSION) and $(PACKAGE_VERSION) with the same contents.
$(PACKAGE_VERSION) is slightly more descriptive, so settle on that, and
drop the other define.
2017-04-04 20:36:09 -04:00
Franck Bui 765a00b98d udev: net_id - support predictable ifnames on vio buses (#5675)
For IBM PowerVM Virtual I/O network devices, we can build predictable names
based on the slot number passed as part of the OF "reg" property.  Valid slot
numbers range between 2-32767, so we only need the bottom half of the unit
address passed.

For example:

  /proc/device-tree/vdevice/l-lan@30000002
  /proc/device-tree/vdevice/vnic@30000005

would initially map to something like:

  /sys/devices/vio/30000002/net/eth0
  /sys/devices/vio/30000005/net/eth1

and would then translate to env2 and env5

This patch ignores the bus number, as there should only ever be one bus, and
then remove leading zeros.
2017-03-31 16:32:09 +02:00
Viktor Mihajlovski fb92fbb1b1 udev: Use parent bus id for virtio disk builtin path-id (#5500)
The builtin path id for virtio block devices has been changed
to use the bus id without a prefix "virtio-pci" to be
compatible with all virtio transport types.

In order to not break existing setups, the by-path symlinks for
virtio block devices on the PCI bus are reintroduced by udev rules.
The virtio-pci symlinks are considered to be deprecated and
should be replaced by the native PCI symlinks.

Example output for a virtio disk in PCI slot 7:
 $ ls  /dev/disk/by-path
 pci-0000:00:07.0
 pci-0000:00:07.0-part1
 virtio-pci-0000:00:07.0
 virtio-pci-0000:00:07.0-part1

See also
[1] https://lists.freedesktop.org/archives/systemd-devel/2017-February/038326.html
[2] https://lists.freedesktop.org/archives/systemd-devel/2017-March/038397.html

This reverts f073b1b but keeps the same symlinks for compatibility.
2017-03-01 15:30:17 -05:00
Zbigniew Jędrzejewski-Szmek dd7e1d6298 udev-builtin-blkid: use -errno not -1 as error code
The code that calls this function doesn't care, but it looks bad.
2017-02-21 16:42:51 -05:00
Zbigniew Jędrzejewski-Szmek b382db9f3b tree-wide: simplify handling of blkid errors 2017-02-21 16:41:33 -05:00
Zbigniew Jędrzejewski-Szmek 3877500c5b udev-builtin-net_id: fix warning about discarded "const" attribute (#5385) 2017-02-19 11:00:42 +03:00
Zbigniew Jędrzejewski-Szmek 52d1f5e569 Merge pull request #5373 from poettering/coredump-timestamp-fixes
various coredump fixes
2017-02-17 15:23:52 -05:00
Viktor Mihajlovski ecc11cf70c udev: fix id_net_name_path for virtio-ccw interfaces (#5357)
The CCW id_net_name_path detection didn't account for virtio
interfaces on the CCW bus. As a result the default interface
names for virtio-ccw interfaces would use the old eth<x>
format instead of enc<busid>.

Since virtio-pci interface naming follows the naming rules
of the parent bus, the names_ccw() logic was changed to apply
the CCW interface naming rules to virtio interfaces as well,
e.g. enc2000 for an interface with a CCW bus id 0.0.2000.
As virtio interfaces are apt to get the otherwise unusual
CCW bus id 0.0.0000, the last '0' is now preserved in this
case.

The virtio subsystem skipping loop has been moved from
names_pci() into a function skip_virtio() that can be reused
for all bus types with virtio network devices.

Since virtio-ccw interfaces use single CCW addresses the ccwgroup
requirement was relaxed and the C definitions were changed
accordingly.
2017-02-17 16:18:01 +01:00
Lennart Poettering 76341acc38 udevd: use signal_to_string() instead of strsignal() at one place
strsignal() sucks, as it tries to generate human readable strings from
something that isn't really human readable by concept. Let's use
signal_to_string() instead, making this more grokkable. Difference is:
SIGINT gets translated → "SIGINT" rather than → "Interrupted".
2017-02-17 11:18:22 +01:00
Dan Streetman be45268352 udev-event: use in-place whitespace replacement
Instead of using a temp buffer to replace whitespace in variable
substitutions, just allow util_replace_whitespace to replace in-place.
Add a comment to util_replace_whitespace indicating it is used to replace
in-place, to prevent accidental future breakage.
2017-01-27 07:58:00 -05:00
Dan Streetman 0d53705b65 udev-event: refactor udev_event_apply_format
Move the large case statement into its own function
2017-01-27 07:58:00 -05:00
Zbigniew Jędrzejewski-Szmek 42d768790c udev: fix variable assignment
gcc doesn't like &, even though &sbuf and buf are the same things afaiu.

Follow-up for e20a917105.
2017-01-15 11:52:53 -05:00
Zbigniew Jędrzejewski-Szmek 6b3d378331 Merge pull request #4879 from poettering/systemd 2017-01-14 21:29:27 -05:00
Zbigniew Jędrzejewski-Szmek 5aac0be024 Merge pull request #4837 from ddstreet/master
Replace spaces in expanded fields in SYMLINK properties by default.
2017-01-11 16:40:04 -05:00
Mike Gilbert c9f7b4d356 build-sys: add check for gperf lookup function signature (#5055)
gperf-3.1 generates lookup functions that take a size_t length
parameter instead of unsigned int. Test for this at configure time.

Fixes: https://github.com/systemd/systemd/issues/5039
2017-01-10 08:39:05 +01:00
Peter Hutterer 64083a6078 udev: add ID_INPUT_SWITCH for devices with switch capability (#5057) 2017-01-10 08:36:46 +01:00
Dan Streetman 0a10235ed4 udev-rules: perform whitespace replacement for symlink subst values
If the string_escape option is either unset or 'replace' (i.e. if it is
not 'none'), then enable whitespace replacement in SYMLINK variable
substitution values, as added in the last patch.

This will keep any whitespace that is directly contained in a SYMLINK
value, but will replace any whitespace that is added to the SYMLINK
value as a result of variable substitution (except $result/%c).

This fixes bug 4833.
2017-01-03 17:24:52 -05:00
Dan Streetman e20a917105 udev-event: add replace_whitespace param to udev_event_apply_format
If replace_whitespace is true, each substitution value has all its
whitespace removed/replaced by util_replace_whitespace (except the
SUBST_RESULT substitution - $result{} or %c{} - which handles spaces
itself as field separators).  All existing callers are updated to
pass false, so no functional change is made by this patch.

This is needed so the SYMLINK assignment can replace any spaces
introduced through variable substitution, becuase the SYMLINK value is
a space-separated list of symlinks to create.  Any variables that
contain spaces will thus unexpectedly change the symlink value from
a single symlink to multiple incorrectly-named symlinks.

This is used in the next patch, which enables the whitespace
replacement for SYMLINK variable substitution.
2017-01-03 17:12:00 -05:00
Lennart Poettering 1d84ad9445 util-lib: various improvements to kernel command line parsing
This improves kernel command line parsing in a number of ways:

a) An kernel option "foo_bar=xyz" is now considered equivalent to
   "foo-bar-xyz", i.e. when comparing kernel command line option names "-" and
   "_" are now considered equivalent (this only applies to the option names
   though, not the option values!). Most of our kernel options used "-" as word
   separator in kernel command line options so far, but some used "_". With
   this change, which was a source of confusion for users (well, at least of
   one user: myself, I just couldn't remember that it's systemd.debug-shell,
   not systemd.debug_shell). Considering both as equivalent is inspired how
   modern kernel module loading normalizes all kernel module names to use
   underscores now too.

b) All options previously using a dash for separating words in kernel command
   line options now use an underscore instead, in all documentation and in
   code. Since a) has been implemented this should not create any compatibility
   problems, but normalizes our documentation and our code.

c) All kernel command line options which take booleans (or are boolean-like)
   have been reworked so that "foobar" (without argument) is now equivalent to
   "foobar=1" (but not "foobar=0"), thus normalizing the handling of our
   boolean arguments. Specifically this means systemd.debug-shell and
   systemd_debug_shell=1 are now entirely equivalent.

d) All kernel command line options which take an argument, and where no
   argument is specified will now result in a log message. e.g. passing just
   "systemd.unit" will no result in a complain that it needs an argument. This
   is implemented in the proc_cmdline_missing_value() function.

e) There's now a call proc_cmdline_get_bool() similar to proc_cmdline_get_key()
   that parses booleans (following the logic explained in c).

f) The proc_cmdline_parse() call's boolean argument has been replaced by a new
   flags argument that takes a common set of bits with proc_cmdline_get_key().

g) All kernel command line APIs now begin with the same "proc_cmdline_" prefix.

h) There are now tests for much of this. Yay!
2016-12-21 19:09:08 +01:00
Reverend Homer 8fb3f00997 tree-wide: replace all readdir cycles with FOREACH_DIRENT{,_ALL} (#4853) 2016-12-09 10:04:30 +01:00
Thomas Hindoe Paaboel Andersen 11754a3486 udev: remove duplicate flag
One SA_RESTART is enough. Fall out from
e28c7cd066
2016-12-06 00:09:43 +01:00
Tobias Stoeckmann cd05bb8baf Spot inconsistent quoting (just one single quote) (#4732)
It is possible to specify only one quote in udev rules, which is not
detected as an invalid quoting (" instead of "" for empty string).

Technically this doesn't lead to a bug, because the string ends in two
terminating nul characters at this position, but a user should still be
reminded that his configuration is invalid.
2016-12-01 18:46:36 -05:00
Lennart Poettering e28c7cd066 tree-wide: set SA_RESTART for signal handlers we install
We already set it in most cases, but make sure to set it in all others too, and
document that that's a good idea.
2016-12-01 12:41:17 +01:00
Daniel Wagner a92cf7840f udevd: check correct return value of fcntl() (#4758)
This looks like a copy&paste error from the code block above.
2016-11-28 18:24:26 +01:00
Maks Naumov 45d34fa7fb link: fix offload features initialization (#4639) 2016-11-14 11:33:43 +01:00
Susant Sahani a39f92d391 Link: port to new ethtool ETHTOOL_xLINKSETTINGS
Link: port to new ethtool ETHTOOL_xLINKSETTINGS
This patch defines a new ETHTOOL_GLINKSETTINGS/SLINKSETTINGS API,
handled by the new get_link_ksettings/set_link_ksettings .

This is a WIP version based on this [kernel
patch](https://patchwork.kernel.org/patch/8411401/).

commit 0527f1c

3f1ac7a700ommit
35afb33
2016-11-10 15:12:56 +05:30
Zbigniew Jędrzejewski-Szmek f97b34a629 Rename formats-util.h to format-util.h
We don't have plural in the name of any other -util files and this
inconsistency trips me up every time I try to type this file name
from memory. "formats-util" is even hard to pronounce.
2016-11-07 10:15:08 -05:00
Lennart Poettering 493fd52f1a Merge pull request #4510 from keszybz/tree-wide-cleanups
Tree wide cleanups
2016-11-03 13:59:20 -06:00
Zbigniew Jędrzejewski-Szmek e02c613560 udev/udev-watch: calculate the real buffer sizes needed 2016-11-02 22:36:43 -04:00
Zbigniew Jędrzejewski-Szmek e68eedbbdc Revert some uses of xsprintf
This reverts some changes introduced in d054f0a4d4.
xsprintf should be used in cases where we calculated the right buffer
size by hand (using DECIMAL_STRING_MAX and such), and never in cases where
we are printing externally specified strings of arbitrary length.

Fixes #4534.
2016-11-02 22:36:29 -04:00
Jiří Pírko 4887b656c2 udev: net_id: add support for phys_port_name attribute (#4506)
Switch drivers uses phys_port_name attribute to pass front panel port
name to user. Use it to generate netdev names.

Signed-off-by: Jiri Pirko <jiri@mellanox.com>
2016-11-01 20:46:01 -06:00
Michal Sekletar 4f985bd802 udev: allow substitutions for SECLABEL key (#4505) 2016-10-28 12:09:14 +02:00
Zbigniew Jędrzejewski-Szmek 605405c6cc tree-wide: drop NULL sentinel from strjoin
This makes strjoin and strjoina more similar and avoids the useless final
argument.

spatch -I . -I ./src -I ./src/basic -I ./src/basic -I ./src/shared -I ./src/shared -I ./src/network -I ./src/locale -I ./src/login -I ./src/journal -I ./src/journal -I ./src/timedate -I ./src/timesync -I ./src/nspawn -I ./src/resolve -I ./src/resolve -I ./src/systemd -I ./src/core -I ./src/core -I ./src/libudev -I ./src/udev -I ./src/udev/net -I ./src/udev -I ./src/libsystemd/sd-bus -I ./src/libsystemd/sd-event -I ./src/libsystemd/sd-login -I ./src/libsystemd/sd-netlink -I ./src/libsystemd/sd-network -I ./src/libsystemd/sd-hwdb -I ./src/libsystemd/sd-device -I ./src/libsystemd/sd-id128 -I ./src/libsystemd-network --sp-file coccinelle/strjoin.cocci --in-place $(git ls-files src/*.c)

git grep -e '\bstrjoin\b.*NULL' -l|xargs sed -i -r 's/strjoin\((.*), NULL\)/strjoin(\1)/'

This might have missed a few cases (spatch has a really hard time dealing
with _cleanup_ macros), but that's no big issue, they can always be fixed
later.
2016-10-23 11:43:27 -04:00
Zbigniew Jędrzejewski-Szmek d7f69e16f1 tree-wide: make parse_proc_cmdline() strip "rd." prefix automatically
This stripping is contolled by a new boolean parameter. When the parameter
is true, it means that the caller does not care about the distinction between
initrd and real root, and wants to act on both rd-dot-prefixed and unprefixed
parameters in the initramfs, and only on the unprefixed parameters in real
root. If the parameter is false, behaviour is the same as before.

Changes by caller:
log.c (systemd.log_*):      changed to accept rd-dot-prefix params
pid1:                       no change, custom logic
cryptsetup-generator:       no change, still accepts rd-dot-prefix params
debug-generator:            no change, does not accept rd-dot-prefix params
fsck:                       changed to accept rd-dot-prefix params
fstab-generator:            no change, custom logic
gpt-auto-generator:         no change, custom logic
hibernate-resume-generator: no change, does not accept rd-dot-prefix params
journald:                   changed to accept rd-dot-prefix params
modules-load:               no change, still accepts rd-dot-prefix params
quote-check:                no change, does not accept rd-dot-prefix params
udevd:                      no change, still accepts rd-dot-prefix params

I added support for "rd." params in the three cases where I think it's
useful: logging, fsck options, journald forwarding options.
2016-10-22 16:08:55 -04:00
Zbigniew Jędrzejewski-Szmek 92e724670f udev: change kernel commandline option parsing
- do not crash if an option without value is specified on the kernel command
  line, e.g. "udev.log-priority" :P
- simplify the code a bit
- warn about unknown "udev.*" options — this should make it easier to spot
  typos and reduce user confusion
2016-10-22 14:42:12 -04:00
Zbigniew Jędrzejewski-Szmek 96287a4916 tree-wide: allow state to be passed through to parse_proc_cmdline_item
No functional change.
2016-10-22 14:24:52 -04:00
Zbigniew Jędrzejewski-Szmek 6b430fdb7c tree-wide: use mfree more 2016-10-16 23:35:39 -04:00
Stefan Schweter 1f1a5e8b40 udevadm: use parse_sec instead of atoi for timeout option (#4331)
log_error method is used instead of fprintf
2016-10-11 09:08:04 +02:00
0xAX c76cf844d6 tree-wide: pass return value of make_null_stdio() to warning instead of errno (#4328)
as @poettering suggested in the #4320
2016-10-10 19:51:33 +02:00
0xAX 9fc932bff1 tree-wide: print warning in a failure case of make_null_stdio() (#4320)
The make_null_stdio() may fail. Let's check its result and print
warning message instead of keeping silence.
2016-10-09 22:55:24 -04:00
Lennart Poettering 429b435026 sd-device/networkd: unify code to get a socket for issuing netdev ioctls on
As suggested here:

https://github.com/systemd/systemd/pull/4296#issuecomment-251911349

Let's try AF_INET first as socket, but let's fall back to AF_NETLINK, so that
we can use a protocol-independent socket here if possible. This has the benefit
that our code will still work even if AF_INET/AF_INET6 is made unavailable (for
exmple via seccomp), at least on current kernels.
2016-10-06 19:04:01 +02:00
Keith Busch b4c6f71b82 udev/path_id: introduce support for NVMe devices (#4169)
This appends the nvme name and namespace identifier attribute the the
PCI path for by-path links. Symlinks like the following are now present:

lrwxrwxrwx. 1 root root 13 Sep 16 12:12 pci-0000:01:00.0-nvme-1 -> ../../nvme0n1
lrwxrwxrwx. 1 root root 15 Sep 16 12:12 pci-0000:01:00.0-nvme-1-part1 -> ../../nvme0n1p1

Cc: Michal Sekletar <sekletar.m@gmail.com>
Signed-off-by: Keith Busch <keith.busch@intel.com>
2016-09-26 21:01:07 +02:00
Zbigniew Jędrzejewski-Szmek 303a2ebcb6 udev: use get_proc_cmdline_key instead of FOREACH_WORD_QUOTED 2016-09-13 20:10:54 -04:00
Susant Sahani a9dee27f0d fix #4080
ethtool_sset_info  adding some extra space to it.

also fix valgrind warning
```
Unloaded link configuration context.
==31690==
==31690== HEAP SUMMARY:
==31690==     in use at exit: 8,192 bytes in 2 blocks
==31690==   total heap usage: 431 allocs, 429 frees, 321,164 bytes allocated
==31690==
==31690== 4,096 bytes in 1 blocks are still reachable in loss record 1 of 2
==31690==    at 0x4C2BBAD: malloc (vg_replace_malloc.c:299)
==31690==    by 0x166B32: mempool_alloc_tile (mempool.c:62)
==31690==    by 0x166BBC: mempool_alloc0_tile (mempool.c:81)
==31690==    by 0x15B8FC: hashmap_base_new (hashmap.c:732)
==31690==    by 0x15B9F7: internal_hashmap_new (hashmap.c:766)
==31690==    by 0x151291: conf_files_list_strv_internal (conf-files.c:103)
==31690==    by 0x1514BA: conf_files_list_strv (conf-files.c:135)
==31690==    by 0x13A1CF: link_config_load (link-config.c:227)
==31690==    by 0x135B68: builtin_net_setup_link_init
(udev-builtin-net_setup_link.c:77)
==31690==    by 0x1306B3: udev_builtin_init (udev-builtin.c:57)
==31690==    by 0x11E984: adm_builtin (udevadm-test-builtin.c:72)
==31690==    by 0x117B4D: run_command (udevadm.c:75)
```
Fixes #4080
2016-09-02 16:06:58 +05:30
Susant Sahani f7ea90fbba link : add support to configure LRO and GRO Offload features
The patch supports to configure

GenericReceiveOffload
LargeReceiveOffload
2016-08-31 12:47:02 +05:30
Susant Sahani 50725d10e3 link : add support to configure Offload features (#4017)
This patch supports these features to be on or off

Generic Segmentation Offload
TCP Segmentation Offload
UDP Segmentation Offload

fixes #432
2016-08-30 16:52:04 +02:00
Michal Sekletar 1ef72b55ba udev: inform systemd how many workers we can potentially spawn (#4036) 2016-08-25 08:18:42 +02:00
Lennart Poettering 1d98fef17d core: when forcibly killing/aborting left-over unit processes log about it
Let's lot at LOG_NOTICE about any processes that we are going to
SIGKILL/SIGABRT because clean termination of them didn't work.

This turns the various boolean flag parameters to cg_kill(), cg_migrate() and
related calls into a single binary flags parameter, simply because the function
now gained even more parameters and the parameter listed shouldn't get too
long.

Logging for killing processes is done either when the kill signal is SIGABRT or
SIGKILL, or on explicit request if KILL_TERMINATE_AND_LOG instead of LOG_TERMINATE
is passed. This isn't used yet in this patch, but is made use of in a later
patch.
2016-07-20 14:35:15 +02:00
Stef Walter 8d00539d99 udev: Line buffer 'udev monitor' output (#3733)
Callers of the 'udev monitor' tool expect to see output when
an event occurs. The stdio buffering defeats that. This patch
switches it to line buffering.
2016-07-15 12:24:34 +02:00
Andreas Pokorny d3a37494e6 Fix tablet detection, by replicating decision tree of non-multi-touch axes (#3724)
Signed-off-by: Andreas Pokorny <andreas.pokorny@canonical.com>
2016-07-14 22:42:10 +02:00
Torstein Husebø 61233823aa treewide: fix typos and remove accidental repetition of words 2016-07-11 16:18:43 +02:00
Michal Sekletar 905c37e60e udevadm: explicitly relabel /etc/udev/hwdb.bin after rename (#3686)
This is basically the same change as ea68351.
2016-07-08 17:43:05 +02:00
Zbigniew Jędrzejewski-Szmek 19a29798bc udevadm: trivial simplification 2016-06-14 17:12:23 -04:00
Lennart Poettering a3071999b8 udev-builtin-blkid: fix GPT_FLAG_NO_AUTO check for ESP (#3450)
The flags check was accidentally placed in the ESP if block, but should be in
the root if block.

This corrects: 0238d4c660

Fixes: #3440

Also see: #3441
2016-06-09 10:51:20 +02:00
Franck Bui e95764ec91 udevd: try close ctrl connection blocking socket only once when spawning a new worker (#3387) 2016-05-30 16:35:34 +02:00
Zbigniew Jędrzejewski-Szmek 755700bbd4 Udevadm trivial cleanups (#3331)
* udevadm-info: use _cleanup_

* udevadm-info: propagate return value from export_devices()

* sd-device: add comment and remove unnecessary braces
2016-05-24 12:07:42 +02:00
Lennart Poettering fc2fffe770 tree-wide: introduce new SOCKADDR_UN_LEN() macro, and use it everywhere
The macro determines the right length of a AF_UNIX "struct sockaddr_un" to pass to
connect() or bind(). It automatically figures out if the socket refers to an
abstract namespace socket, or a socket in the file system, and properly handles
the full length of the path field.

This macro is not only safer, but also simpler to use, than the usual
offsetof() + strlen() logic.
2016-05-05 22:24:36 +02:00
Lubomir Rintel fa394301e2 udev: fix build with DEBUG=1
Alternatively, this could perhaps be removed since it was broken for a
long time and noone seemed to care.

But it was helpful for me today.
2016-05-03 22:35:27 +02:00
Zbigniew Jędrzejewski-Szmek ccddd104fc tree-wide: use mdash instead of a two minuses 2016-04-21 23:00:13 -04:00
Zbigniew Jędrzejewski-Szmek b3b90a25f3 udevadm: assert return value
This mirrors what we do in now().
CID #1351755.
2016-04-08 21:08:21 -04:00
Zbigniew Jędrzejewski-Szmek 045e00cf16 udevd: use (void) to silence coverity
CID #1351429.
2016-04-08 21:08:18 -04:00
Mike Frysinger 27d13af71c include sys/sysmacros.h in more places
Since glibc is moving away from implicitly including sys/sysmacros.h
all the time via sys/types.h, include the header directly in more
places.  This seems to cover most makedev/major/minor usage.
2016-03-14 23:29:10 -04:00
Zbigniew Jędrzejewski-Szmek c3dacc8bbf selinux: always try to load the full selinux db
https://github.com/systemd/systemd/pull/2508#issuecomment-190901170
Maybe fixes https://bugzilla.redhat.com/show_bug.cgi?id=1308771.
2016-03-01 20:39:30 -05:00
Vito Caputo 9ed794a32d tree-wide: minor formatting inconsistency cleanups 2016-02-23 14:20:34 -08:00
Lennart Poettering 4d080d7798 Merge pull request #2701 from keszybz/udev-rules
udev-rules cleanup fix
2016-02-22 23:25:36 +01:00
Zbigniew Jędrzejewski-Szmek 916a8d4341 udev-rules: fix querying of attributes
faccessat returns 0 on success.

A cosmetic fix is also included: the slash was doubled unnecessarily.
2016-02-22 13:21:32 -05:00
Tom Gundersen 7c7c0cbe64 Merge pull request #2685 from poettering/lldp-fixes2
lldp fixes, second iteration
2016-02-22 17:38:34 +01:00
Zbigniew Jędrzejewski-Szmek fdd21be6f5 udev-rules: use _cleanup_ for fclose 2016-02-21 11:05:13 -05:00
Zbigniew Jędrzejewski-Szmek 19a8e656a9 udev-rules: make error messages about rules more uniform
Also downgrade non-fatal warnings to log_warning.

Previously rule_add_key() would check the output array and log a cryptic
error and return -1. Most of the time the return value was ignored. This
does not seems right, because the buffer can overflow with enough rules.
It would also check if we have enough space for the *next* rule, even if
there might be not next rule, i.e. off-by-one.

Replace this with a check that we have enough space for a next rule before
we start parsing.

Normally using macros to alter flow is not allowed, but in this case I
think it is worth it, because it allows lots of boilerplate code to be
removed and hides repeated boring parameters, making function logic much
easier to follow.
2016-02-21 11:05:11 -05:00
Zbigniew Jędrzejewski-Szmek f4850a1d95 udev-rules: rewrite function to avoid clobbering arguments
If the attribute wasn't found, the last filename looked at was returned in
the input/output argument. This just seems bad style.

The return value was ignored, so change function to return void.
2016-02-21 11:05:08 -05:00
Zbigniew Jędrzejewski-Szmek 99f16bb8d9 udev-rules: modernize syntax a bit 2016-02-21 11:05:06 -05:00
Zbigniew Jędrzejewski-Szmek 4fd6af76c4 udev-rules: log_oom() on memory error and abort processing of event
CID #1313566.

Also, change the return value to void, because it is ignored anyway.
2016-02-21 11:05:02 -05:00
Lennart Poettering 0ef6f45425 tree-wide: place #pragma once at the same place everywhere
Usually, we place the #pragma once before the copyright blurb in header files,
but in a few cases we didn't. Move those around, so that we do the same thing
everywhere.
2016-02-20 22:42:29 +01:00
Hendrik Brueckner 5181ab917d udev/path_id: correct segmentation fault due to missing NULL check
Running "udevadm test-builtin path_id /sys/devices/platform/" results
in a segmentation fault.

The problem is that udev_device_get_subsystem(dev) might return NULL
in a streq() call.  Solve this problem by using streq_ptr() instead.
2016-02-19 15:21:18 +01:00
Nathan McSween e306723ec4 Remove/add (un)needed includes 2016-02-18 23:34:30 +00:00
Lennart Poettering 6d2353394f udev: fix cg_unified() return code checking
Fixes fall-out from 8b3aa503c1.

Fixes: #2635
2016-02-16 15:30:04 +01: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
Michal Sekletar f073b1b3c0 path_id: reintroduce by-path links for virtio block devices
Enumeration of virtio buses is global and hence
non-deterministic. However, we are guaranteed there is never going to be
more than one virtio bus per parent PCI device. While populating
ID_PATH we simply skip virtio part of the syspath and we extend the path
using the sysname of the parent PCI device.

With this patch udev creates following by-path links for virtio-blk
device /dev/vda which contains two partitions.

ls -l /dev/disk/by-path/
total 0
lrwxrwxrwx 1 root root  9 Feb  9 10:47 virtio-pci-0000:00:05.0 -> ../../vda
lrwxrwxrwx 1 root root 10 Feb  9 10:47 virtio-pci-0000:00:05.0-part1 -> ../../vda1
lrwxrwxrwx 1 root root 10 Feb  9 10:47 virtio-pci-0000:00:05.0-part2 -> ../../vda2

See:
http://lists.linuxfoundation.org/pipermail/virtualization/2015-August/030328.html

Fixes #2501
2016-02-09 12:25:42 +01:00
Dimitri John Ledkov 0037a669ac udev: net_id - for ccw bus, shorten the identifier and stip leading zeros
The commmon case default qeth link is enccw0.0.0600 is rather long.

Thus strip leading zeros (which doesn't make the bus_id unstable),
similar to the PCI domain case.

Also 'ccw' is redundant on S/390, as there aren't really other buses
available which could have qeth driver interfaces. Not sure why this
code is even compiled on non-s390[x] platforms. But to distinguish from
e.g. MAC stable names shorten the suffix to just 'c'.

Thus enccw0.0.0600 becomes enc600.
2016-01-29 17:54:30 +01:00
Lennart Poettering 6c1e69f945 udev: filter out non-sensically high onboard indexes reported by the kernel
Let's not accept onboard interface indexes, that are so high that they are obviously non-sensical.

Fixes: #2407
2016-01-25 17:50:33 +01:00
Zbigniew Jędrzejewski-Szmek efa1606eec udevd: do not clean up fds in main
fds will also be closed during manager cleanup in run, leading
to an error when we try to close them again. It is now possible
to "leak" the fds on error, but it's an unlikely event and we
will exit immediately anyway.

Fixes #2418.
2016-01-23 11:45:22 -05:00
Zbigniew Jędrzejewski-Szmek e5d7bce12d udevd: initialize fds to -1 and close them before exiting
Little change in practice, because the program will exit soon
afterwards, but the standard style of closing all fds is now followed.
Also gets rid of gcc warning about fd_ctrl and fd_uevent being
unitialized.
2016-01-18 15:21:28 -05:00
Zbigniew Jędrzejewski-Szmek f5e5c28f42 tree-wide: check if errno is greater then zero
gcc is confused by the common idiom of
  return errno ? -errno : -ESOMETHING
and thinks a positive value may be returned. Replace this condition
with errno > 0 to help gcc and avoid many spurious warnings. I filed
a gcc rfe a long time ago, but it hard to say if it will ever be
implemented [1].

Both conventions were used in the codebase, this change makes things
more consistent. This is a follow up to bcb161b023.

[1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61846
2016-01-13 15:09:55 -05:00
Daniel Mack d054f0a4d4 tree-wide: use xsprintf() where applicable
Also add a coccinelle receipt to help with such transitions.
2016-01-12 15:36:32 +01:00
Andreas Pokorny 1a3439ef68 udev: Fix touch screen detection
Use BTN_TOUCH or INPUT_PROP_DIRECT to detect touch screens.

Signed-off-by: Andreas Pokorny <andreas.pokorny@canonical.com>
2016-01-01 13:35:36 +01:00
Daniel Mack 0896271419 Merge pull request #2110 from keszybz/udev-indentation
Udev indentation
2015-12-09 14:18:37 +01:00
Zbigniew Jędrzejewski-Szmek 461577eeb3 udev/scsi_id: fix some strange indentation 2015-12-07 00:45:08 -05:00
Zbigniew Jędrzejewski-Szmek 3f65d73149 udev: add emacs header line
Otherwise emacs wants to use 2-space indentation and other
attrocities.
2015-12-07 00:45:08 -05:00
Zbigniew Jędrzejewski-Szmek 9eba69df1c udev: fix NULL deref when executing rules
We quite obviously check whether event->dev_db is nonnull, and
right after that call a function which asserts the same. Move
the call under the same if.

https://bugzilla.redhat.com/show_bug.cgi?id=1283971
2015-12-07 00:44:14 -05: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
Daniel Mack a57246551a Merge pull request #1926 from phomes/include-order-libudev
tree-wide: group include of libudev.h with sd-*
2015-11-17 09:36:25 +01:00
Thomas Hindoe Paaboel Andersen b4bbcaa9c4 tree-wide: group include of libudev.h with sd-* 2015-11-17 07:06:08 +01:00
Lennart Poettering 4a0b58c4a3 tree-wide: use right cast macros for UIDs, GIDs and PIDs 2015-11-17 00:52:10 +01:00
Thomas Hindoe Paaboel Andersen cf0fbc49e6 tree-wide: sort includes
Sort the includes accoding to the new coding style.
2015-11-16 22:09:36 +01:00
Martin Pitt dbe81cbd2a siphash24: change result argument to uint64_t
Change the "out" parameter from uint8_t[8] to uint64_t. On architectures which
enforce pointer alignment this fixes crashes when we previously cast an
unaligned array to uint64_t*, and on others this should at least improve
performance as the compiler now aligns these properly.

This also simplifies the code in most cases by getting rid of typecasts. The
only place which we can't change is struct duid's en.id, as that is _packed_
and public API, so we can't enforce alignment of the "id" field and have to
use memcpy instead.
2015-11-16 15:20:29 +01:00
Liu Yuan Yuan e7eb5a8d88 udev/path_id: improve and enhance bus detection for Linux on z Systems
Improve and enhance the path_id udev builtin to correctly handle bus'
available on Linux on z Systems (s390).

Previously, the CCW bus and, in particular, any FCP devices on it, have
been treated separately.  This commit integrates the CCW bus into the
device chain loop.  FCP devices and their associated SCSI disks are now
handled through the common SCSI handling functions in path_id.

This implies also a change in the naming of the symbolic links created
by udev.  So any backports of this commit to existing Linux distribution
must be done with care.  If a backport is required, a udev rule must be
created to also create the "old-style" symbolic links.

Apart from the CCW bus, this commit adds bus support for the:

- ccwgroup bus which manages network devices, and
- ap bus which manages cryptographic adapters
- iucv bus which manages IUCV devices on z/VM
2015-11-13 11:50:42 +01:00
Daniel Mack b0bc8dbd73 Merge pull request #1820 from michich/errno-v2
[v2] treewide: treatment of errno and other cleanups
2015-11-09 21:56:49 +01:00
Michal Schmidt e1427b138f treewide: apply errno.cocci
with small manual cleanups for style.
2015-11-09 20:01:06 +01:00
Jan Engelhardt a8eaaee72a doc: correct orthography, word forms and missing/extraneous words 2015-11-06 13:45:21 +01:00
Michal Schmidt 709f6e46a3 treewide: use the negative error codes returned by our functions
Our functions return negative error codes.
Do not rely on errno being set after calling our own functions.
2015-11-05 13:44:06 +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 7d50b32a12 util-lib: split out globbing related calls into glob-util.[ch] 2015-10-27 13:25:58 +01:00
Lennart Poettering 15a5e95075 util-lib: split out printf() helpers to stdio-util.h 2015-10-27 13:25:57 +01:00
Lennart Poettering 8f328d36c9 socket-util: move CMSG_FOREACH() from macro.h to socket-util.h 2015-10-27 13:25:57 +01:00
Lennart Poettering ee104e11e3 user-util: move UID/GID related macros from macro.h to user-util.h 2015-10-27 13:25:57 +01:00
Lennart Poettering 4e731273ed util-lib: move /proc/cmdline parsing code to proc-cmdline.[ch] 2015-10-27 13:25:57 +01:00
Lennart Poettering 8b43440b7e util-lib: move string table stuff into its own string-table.[ch] 2015-10-27 13:25:56 +01:00
Lennart Poettering 8fcde01280 util-lib: split stat()/statfs()/stavfs() related calls into stat-util.[ch] 2015-10-27 13:25:56 +01:00
Lennart Poettering f4f15635ec util-lib: move a number of fs operations into fs-util.[ch] 2015-10-27 13:25:56 +01:00
Lennart Poettering 0d39fa9c69 util-lib: move more file I/O related calls into fileio.[ch] 2015-10-27 13:25:55 +01:00
Lennart Poettering 6bedfcbb29 util-lib: split string parsing related calls from util.[ch] into parse-util.[ch] 2015-10-27 13:25:55 +01:00
Lennart Poettering b1d4f8e154 util-lib: split out user/group/uid/gid calls into user-util.[ch] 2015-10-26 01:24:38 +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 00229fe48f util: move logind_running() to login-util.[ch] 2015-10-24 23:30:40 +02: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 4f5dd3943b util: split out escaping code into escape.[ch]
This really deserves its own file, given how much code this is now.
2015-10-24 23:04:42 +02:00
Martin Pitt 1d3f8fa747 keymap: Drop keyboard-keys-to-name.h
We don't use that anywhere any more. With the introduction of alias names it
also is not a proper mapping any more as several keys (e. g. KEY_COFFEE and
KEY_SCREENLOCK) have the same numerical mapping.
2015-10-14 07:15:58 +02:00
Jacob Keller 66d3752e81 document ability to disable MACAddressPolicy
While it is currently possible to either not set MACAddressPolicy or set
it to a value different from "persistent" or "random", it is not obvious
that a user can do so. Add a policy, "none", which simply retains kernel
MAC addresses (same as not filling in the policy at all) and document it
so that users are aware of this setting.

Signed-off-by: Jacob Keller <jacob.keller@gmail.com>
2015-10-05 15:55:25 -07:00
Kay Sievers 5a6d44ed77 Merge pull request #1428 from franciozzy/tagenhance
Enhance matching of TAG keys
2015-10-01 19:10:06 +02:00
Michal Schmidt 46b57b6eec udev: fix format string after conversion to log_*_errno()
Use %m where previously %s was used together with strerrno().

Fixes: e53fc357a9 "tree-wide: remove a number of invocations of
       strerror() and replace by %m"
2015-10-01 11:28:40 +02:00
Felipe Franciosi 4302857b31 Support OP_NOMATCH for TAG key
The TAG key can be used in rules for event matching. At the moment, it
does not support inequality tests. This patch enhances the key test to
validate the rule if it does not contain a given TAG (by TAG!="value").

Signed-off-by: Felipe Franciosi <felipe@paradoxo.org>
2015-09-30 22:07:16 +01:00
Lennart Poettering e53fc357a9 tree-wide: remove a number of invocations of strerror() and replace by %m
Let's clean up our tree a bit, and reduce invocations of the
thread-unsafe strerror() by replacing it with printf()'s %m specifier.
2015-09-30 22:26:16 +02:00
Lennart Poettering 618234a525 basic: split out cpu set specific APIs into cpu-set-util.[ch] 2015-09-30 22:26:16 +02:00
Kay Sievers a6affd88ba udev: ata_id - ATA_ID_SATA_CAPABILITY == 76 2015-09-22 18:00:52 +02:00
Tom Lyon cf22cddcfd Fixup WWN bytes for big-endian systems 2015-09-21 14:36:32 -07:00
Lennart Poettering 57255510c9 tree-wide: replace while(1) by for(;;) everywhere
Another Coccinelle script.
2015-09-09 14:59:53 +02:00
Lennart Poettering 1f6b411372 tree-wide: update empty-if coccinelle script to cover empty-while and more
Let's also clean up single-line while and for blocks.
2015-09-09 14:59:51 +02:00
Daniel Mack 0fa7d1f5be Merge pull request #1207 from poettering/coccinelle-fixes
Coccinelle fixes
2015-09-09 09:57:29 +02:00
Lennart Poettering ece174c543 tree-wide: drop {} from one-line if blocks
Patch via coccinelle.
2015-09-09 08:20:20 +02:00
Lennart Poettering 76ef789d26 tree-wide: make use of log_error_errno() return value
Turns this:

        r = -errno;
        log_error_errno(errno, "foo");

into this:

        r = log_error_errno(errno, "foo");

and this:

        r = log_error_errno(errno, "foo");
        return r;

into this:

        return log_error_errno(errno, "foo");
2015-09-09 08:20:20 +02:00
Lennart Poettering 7f6e12b033 tree-wide: drop redundant if checks before safe_close()
Replace this:

        if (fd >= 0)
                safe_close(fd);

by this:

        safe_close(fd);
2015-09-09 08:20:19 +02:00
Lennart Poettering 66e405837b tree-wide: make more code use safe_close()
Replace this:

        close(fd);
        fd = -1;

write this:

        fd = safe_close(fd);
2015-09-09 08:20:19 +02:00
Lennart Poettering a1e58e8ee1 tree-wide: use coccinelle to patch a lot of code to use mfree()
This replaces this:

        free(p);
        p = NULL;

by this:

        p = mfree(p);

Change generated using coccinelle. Semantic patch is added to the
sources.
2015-09-09 08:19:27 +02:00
David Milburn ba86822db7 udev: build by-path identifiers for ATA devices.
/dev/disk/by-path

total 0
lrwxrwxrwx. 1 root root  9 Sep  4 10:02 pci-0000:00:1f.2-ata-2 -> ../../sr0
lrwxrwxrwx. 1 root root  9 Sep  4 10:02 pci-0000:00:1f.2-ata-3 -> ../../sdd
lrwxrwxrwx. 1 root root 10 Sep  4 10:02 pci-0000:00:1f.2-ata-3-part1 -> ../../sdd1
lrwxrwxrwx. 1 root root 10 Sep  4 10:02 pci-0000:00:1f.2-ata-3-part2 -> ../../sdd2
lrwxrwxrwx. 1 root root 10 Sep  4 10:02 pci-0000:00:1f.2-ata-3-part3 -> ../../sdd3
lrwxrwxrwx. 1 root root  9 Sep  4 10:02 pci-0000:03:00.0-ata-4 -> ../../sda
lrwxrwxrwx. 1 root root 10 Sep  4 10:02 pci-0000:03:00.0-ata-4-part1 -> ../../sda1
lrwxrwxrwx. 1 root root 10 Sep  4 10:02 pci-0000:03:00.0-ata-4-part2 -> ../../sda2
lrwxrwxrwx. 1 root root  9 Sep  4 10:02 pci-0000:08:00.0-ata-1 -> ../../sdc
lrwxrwxrwx. 1 root root 10 Sep  4 10:02 pci-0000:08:00.0-ata-1-part1 -> ../../sdc1
lrwxrwxrwx. 1 root root 10 Sep  4 10:02 pci-0000:08:00.0-ata-1-part2 -> ../../sdc2
2015-09-08 16:41:49 -05:00
David Herrmann 4211d5bd13 sd-login: fix sd_seat_get_active() to return ENODATA
This seems to be an oversight from:
    707b66c663

We have to return ENODATA instead of ENOENT if a requested entry is
non-present. Also fix the call-site in udev to check for these errors.
2015-09-08 14:03:22 +02:00
David Herrmann e859aa9e99 udev: ignore ENOEXEC from cgroup lookup
The recent cgroup-rework changed the error code for un-mounted cgroupfs to
ENOEXEC. Make sure udev ignores it just like ENOENT and does not spill
warnings on the screen.
2015-09-03 15:19:15 +02:00
Tom Gundersen 54683f0f9b udev: net_id - support predictable ifnames on virtio buses
Virtio buses are undeterministically enumerated, so we cannot use them as a basis
for deterministic naming (see bf81e792f3). However, we are guaranteed that there
is only ever one virtio bus for every parent device, so we can simply skip over
the virtio buses when naming the devices.
2015-09-02 14:24:17 +02:00
Kay Sievers 25568304d2 udev: control - add FIXME comment to remove work-around 2015-08-27 12:57:17 +02:00
Markus Elfring dc4ebc0787 Bug #944: Deletion of unnecessary checks before calls of the function "free"
The function "free" is documented in the way that no action shall occur for
a passed null pointer. It is therefore not needed that a function caller
repeats a corresponding check.
http://stackoverflow.com/questions/18775608/free-a-null-pointer-anyway-or-check-first

This issue was fixed by using the software Coccinelle 1.0.1.
2015-08-17 09:30:49 +02:00
Tom Gundersen 02d0f8a8a5 Merge pull request #939 from karelzak/smatch
treewide: trivial issues detected by smatch
2015-08-12 15:19:23 +02:00
Kay Sievers 0238d4c660 gpt-auto-generator: apply partition-type flags only to specific partition-types
The partition-type flags are defined independently for every partition-type. Apply
them only to the types where they are defined, and not to the ESP, which does not
appear to share the same set of flags.

  https://github.com/systemd/systemd/issues/920
2015-08-11 13:07:25 +02:00
Karel Zak 93b1da8525 udev: variable dereferenced before check 'cmsg' 2015-08-06 13:46:49 +02:00
Daniel Mack 7c43bfecfa Merge pull request #883 from phomes/bool_vs_error_codes
tree-wide: do not return error codes as bool
2015-08-06 01:12:45 +02:00
Thomas Hindoe Paaboel Andersen 756775814c tree-wide: do not return error codes as bool 2015-08-06 00:49:45 +02:00
Thomas Hindoe Paaboel Andersen 7d6884b65e tree-wide: fix indentation 2015-08-06 00:44:19 +02:00
Kay Sievers 8dbf626535 udev: uaccess - do not log error when device node disappears
https://github.com/systemd/systemd/issues/875
2015-08-05 20:33:48 +02:00
WaLyong Cho 5ab58c2091 smack-util: revise smack-util apis and add read smack attr apis
- Add smack xattr lookup table
- Unify all of mac_smack_apply_xxx{_fd}() to mac_smack_apply() and
  mac_smack_apply_fd().
- Add smack xattr read apis similar with apply apis as
  mac_smack_read{_fd}().
2015-08-04 21:11:19 +09:00
Lennart Poettering 38a03f06a7 sd-event: make sure sd_event_now() cannot fail
Previously, if the event loop never ran before sd_event_now() would
fail. With this change it will instead fall back to invoking now(). This
way, the function cannot fail anymore, except for programming error when
invoking it with wrong parameters.

This takes into account the fact that many callers did not handle the
error condition correctly, and if the callers did, then they kept simply
invoking now() as fall back on their own. Hence let's shorten the code
using this call, and make things more robust, and let's just fall back
to now() internally.

Whether now() is used or the cache timestamp may still be detected via
the return value of sd_event_now(). If > 0 is returned, then the fall
back to now() was used, if == 0 is returned, then the cached value was
returned.

This patch also simplifies many of the invocations of sd_event_now():
the manual fall back to now() can be removed. Also, in cases where the
call is invoked withing void functions we can now protect the invocation
via assert_se(), acknowledging the fact that the call cannot fail
anymore except for programming errors with the parameters.

This change is inspired by #841.
2015-08-03 17:34:49 +02:00
David Herrmann 97b11eedff tree-wide: introduce mfree()
Pretty trivial helper which wraps free() but returns NULL, so we can
simplify this:
        free(foobar);
        foobar = NULL;
to this:
        foobar = mfree(foobar);
2015-07-31 19:56:38 +02:00
Daniel Mack 2fc09a9cdd tree-wide: use free_and_strdup()
Use free_and_strdup() where appropriate and replace equivalent,
open-coded versions.
2015-07-30 13:09:01 +02:00
Daniel Mack 4e18de3d27 udev: Fix udev_builtin_run_once()
Honour the boolean return value type.
This was an oversight in f89d10ae4.
2015-07-28 14:38:31 +02:00
Daniel Mack f89d10ae45 udev: check more builtins[] pointers before dereferencing
Fix some more locations where pointers from builtins[] are dereferenced
before checking. Related to 8cacf69b1.
2015-07-28 13:58:40 +02:00
Daniel Mack 87b46c575a Merge pull request #756 from ldzhong/fix
udev: avoid coredump when initializing udev builtins
2015-07-28 13:32:09 +02:00
Lidong Zhong 8cacf69b1b udev: avoid coredump when initializing udev builtins
If one of the macros(HAVE_BLKID/HAVE_KMOD/HAVE_ACL) is not
defined, there will be a coredump
2015-07-28 19:07:05 +08:00
Thomas Hindoe Paaboel Andersen 7bea001ea4 ata_id: remove unused union member
The last use of octa was removed in 01f61d331b
2015-07-25 00:14:13 +02:00
Daniel Mack 45d9a30414 tree-wide: do not use _cleanup_free_ on const pointers
free() cannot be used with const pointers. However, our _cleanup_free_
handler features cast logic that hides that qualifier, so we don't get a
warning.
2015-07-24 13:52:30 +02:00
Daniel Mack 7121b2152a Merge pull request #702 from ldzhong/fix
udev: fix parameter process
2015-07-24 11:59:30 +02:00
Lidong Zhong e14b6f211c udev: fix parameter process 2015-07-24 16:39:55 +08:00
Zbigniew Jędrzejewski-Szmek 01f61d331b ata_id: unreverse WWN identifier
An endianness conversion was lost in 6024a6e302.
Restore it. Now ata_id and scsi_id output match.

https://bugzilla.redhat.com/show_bug.cgi?id=1227503
2015-07-22 00:24:15 -04:00
Michal Schmidt 3567afa5b4 udev: unify reporting of invalid cmdline keys
This way it does not need distinct string literals and it also preserves
the "rd." prefix.
2015-07-21 20:07:34 +02:00
Michal Schmidt e00f5bddde udev: fix crash with invalid udev.log-priority
Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1245293
2015-07-21 20:07:34 +02:00
Daniel Mack ad118bda15 tree-wide: fix write_string_file() user that should not create files
The latest consolidation cleanup of write_string_file() revealed some users
of that helper which should have used write_string_file_no_create() in the
past but didn't. Basically, all existing users that write to files in /sys
and /proc should not expect to write to a file which is not yet existant.
2015-07-06 19:27:20 -04:00
Daniel Mack 4c1fc3e404 fileio: consolidate write_string_file*()
Merge write_string_file(), write_string_file_no_create() and
write_string_file_atomic() into write_string_file() and provide a flags mask
that allows combinations of atomic writing, newline appending and automatic
file creation. Change all users accordingly.
2015-07-06 19:19:25 -04:00
Daniel Mack b6b3475533 Merge pull request #463 from dvdhrm/udev-run
udev: destroy manager before cleaning environment
2015-07-01 13:42:16 -04:00
David Herrmann 077fc5e260 udev: destroy manager before cleaning environment
Due to our _cleanup_ usage for the udev manager, it will be destroyed
after the "exit:" label has finished. Therefore, it is the last
destruction done in main(). This has two side-effects:
  - mac_selinux is destroyed before the udev manager is, possible causing
    use-after-free if the manager-cleanup accesses selinux data
  - log_close() is called *before* the manager is destroyed, possibly
    re-opening the log if you use --debug (and thus not re-applying the
    --debug option)

Avoid this by moving the manager-handling into a new function called
run(). This function will be left before we enter the "exit:" label in
main(), hence, the manager object will be destroyed early.
2015-07-01 19:30:24 +02:00
Kay Sievers 78d3e041a5 udevd: force --debug mode to stderr
https://github.com/systemd/systemd/issues/462
2015-07-01 19:20:59 +02:00
Kay Sievers 64ea3f926d Merge pull request #411 from teg/udev-simplify-exec-envp
udev: event - simplify udev_event_spawn() logic
2015-06-30 22:32:45 +02:00
Kay Sievers f2b8052fb6 udev: remove WAIT_FOR key
This facility was never a proper solution, but only papered over
real bugs in the kernel. There are no known sysfs "timing bugs"
since a long time.
2015-06-30 19:57:40 +02:00
Tom Gundersen bbf3520673 udev: event - simplify udev_event_spawn() logic
Push the extraction of the envp + argv as close as possible to their use, to avoid code
duplication. As a sideeffect fix logging when delaing execution.
2015-06-29 19:51:04 +02:00
Bastien Nocera 0051ebf7e5 udev: Remove accelerometer helper
It's moved to the iio-sensor-proxy D-Bus service.
2015-06-27 21:48:52 +02:00
Jan Engelhardt ec62e85873 ata_id: unbotch format specifier
Commit v218-247-g11c6f69 broke the output of the utility. "%1$" PRIu64
"x" expands to "%1$lux", essentially "%lux", which shows the problem.
u and x cannot be combined, u wins as the type character, and x gets
emitted verbatim to stdout.

References: https://bugzilla.redhat.com/show_bug.cgi?id=1227503
2015-06-24 02:02:05 +02:00
Tom Gundersen 56b13bcc99 udevadm: trigger - check return values
Fixes CID#1296243.
2015-06-23 17:20:12 +02:00
Tom Gundersen b6aab8ef9c udev: worker - check return value of udev_monitor_enable_receiving()
Fixes CID#1297430.
2015-06-23 17:20:12 +02:00
Tom Gundersen f6e0a35376 udev: event - check return code of dup2()
This fixes CID#1304688.
2015-06-23 17:20:12 +02:00
Tom Gundersen e448a1c3a3 udev: bulitin-hwdb - fix memory leak
This fixes CID#1292782.
2015-06-23 17:20:12 +02:00
Tom Gundersen 11b9fb15be udevd: suppress warning if we don't find cgroup
This is expected on non-systemd systems, so just log it at debug level.

This fixes issue #309.
2015-06-22 16:55:49 +02:00
Thomas Hindoe Paaboel Andersen 118786182b udved: remove dead code
Leftover from 6af5e6a4c9
2015-06-17 20:33:25 +02:00
Tom Gundersen 40e749b59b udevd: daemon - connect /dev/null to std{in,out,err} in debug mode
This is essentially a revert of 5c67cf2 and fixes issue #190.
2015-06-17 18:07:20 +02:00
David Herrmann ab7854df73 udev: don't close FDs before dropping them from epoll
Make sure we never close fds before we drop their related event-source.
This will cause horrible disruptions if the fd-num is re-used by someone
else. Under normal conditions, this should not cause any problems as the
close() will drop the fd from the epoll-set automatically. However, this
changes if you have any child processes with a copy of that fd.

This fixes issue #163.

Background:
        If you create an epoll-set via epoll_create() (lets call it 'EFD')
        you can add file-descriptors to it to watch for events. Whenever
        you call EPOLL_CTL_ADD on a file-descriptor you want to watch, the
        kernel looks up the attached "struct file" pointer, that this FD
        refers to. This combination of the FD-number and the "struct file"
        pointer is used as key to link it into the epoll-set (EFD).

        This means, if you duplicate your file-descriptor, you can watch
        this file-descriptor, too (because the duplicate will have a
        different FD-number, hence, the combination of FD-number and
        "struct file" is different as before).

        If you want to stop watching an FD, you use EPOLL_CTL_DEL and pass
        the FD to the kernel. The kernel again looks up your
        file-descriptor in your FD-table to find the linked "struct file".
        This FD-number and "struct file" combination is then dropped from
        the epoll-set (EFD).

        Last, but not least: If you close a file-descriptor that is linked
        to an epoll-set, the kernel does *NOTHING* regarding the
        epoll-set. This is a vital observation! Because this means, your
        epoll_wait() calls will still return the metadata you used to
        watch/subscribe your file-descriptor to events.
        There is one exception to this rule: If the file-descriptor that
        you just close()ed was the last FD that referred to the underlying
        "struct file", then _all_ epoll-set watches/subscriptions are
        destroyed. Hence, if you never dup()ed your FD, then a simple
        close() will also unsubscribe it from any epoll-set.

        With this in mind, lets look at fork():
                Assume you have an epoll-set (EFD) and a bunch of FDs
                subscribed to events on that EFD. If you now call fork(),
                the new process gets a copy of your file-descriptor table.
                This means, the whole table is copied and the "struct
                file" reference of each FD is increased by 1. It is
                important to notice that the FD-numbers in the child are
                exactly the same as in the parent (eg., FD #5 in the child
                refers to the same "struct file" as FD #5 in the parent).

                This means, if the child calls EPOLL_CTL_DEL on an FD, the
                kernel will look up the linked "struct file" and drop the
                FD-number and "struct file" combination from the epoll-set
                (EFD). However, this will effectively drop the
                subscription that was installed by the parent.

                To sum up: even though the child gets a duplicate of the
                EFD and all FDs, the subscriptions in the EFD are *NOT*
                duplicated!

Now, with this in mind, lets look at what udevd does:
        Udevd has a bunch of file-descriptors that it watches in its
        sd-event main-loop. Whenever a uevent is received, the event is
        dispatched on its workers. If no suitable worker is present, a new
        worker is fork()ed to handle the event. Inside of this worker, we
        try to free all resources we inherited. However, the fork() call
        is done from a call-stack that is never rewinded. Therefore, this
        call stack might own references that it drops once it is left.
        Those references we cannot deduce from the fork()'ed process;
        effectively causing us to leak objects in the worker (eg., the
        call to sd_event_dispatch() that dispatched our uevent owns a
        reference to the sd_event object it used; and drops it again once
        the function is left).

        (Another example is udev_monitor_ref() for each 'worker' that is
         also inherited by all children; thus keeping the udev-monitor and
         the uevent-fd alive in all children (which is the real cause for
         bug #163))

        (The extreme variant is sd_event_source_unref(), which explicitly
         keeps event-sources alive, if they're currently dispatched,
         knowing that the dispatcher will free the event once done. But
         if the dispatcher is in the parent, the child will never ever
         free that object, thus leaking it)

        This is usually not an issue. However, if such an object has a
        file-descriptor embedded, this FD is left open and never closed in
        the child.

In manager_exit(), if we now destroy an object (i.e., close its embedded
file-descriptor) before we destroy its related sd_event_source, then
sd-event will not be able to drop the FD from the epoll-set (EFD). This
is, because the FD is no longer valid at the time we call EPOLL_CTL_DEL.
Hence, the kernel cannot figure out the linked "struct file" and thus
cannot remove the FD-number plus "struct file" combination; effectively
leaving the subscription in the epoll-set.
Since we leak the uevent-fd in the children, they retain a copy of the FD
pointing to the same "struct file". Thus, the EFD-subscription are not
automatically removed by close() (as described above). Therefore, the main
daemon will still get its metadata back on epoll_watch() whenever an event
occurs (even though it already freed the metadata). This then causes the
free-after-use bug described in #163.

This patch fixes the order in which we destruct objects and related
sd-event-sources. Some open questions remain:

 * Why does source_io_unregister() not warn on EPOLL_CTL_DEL failures?
   This really needs to be turned into an assert_return().

 * udevd really should not leak file-descriptors into its children. Fixing
   this would *not* have prevented this bug, though (since the child-setup
   is still async).
   It's non-trivial to fix this, though. The stack-context of the caller
   cannot be rewinded, so we cannot figure out temporary refs. Maybe it's
   time to exec() the udev-workers?

 * Why does the kernel not copy FD-subscriptions across fork()?
   Or at least drop subscriptions if you close() your FD (it uses the
   FD-number as key, so it better subscribe to it)?
   Or it better used
         FD+"struct file_table*"+"struct file*"
   as key to not allow the childen to share the subscription table..
   *sigh*
   Seems like we have to live with that API forever.
2015-06-17 00:31:57 +02:00
Lennart Poettering 72c0a2c255 everywhere: port everything to sigprocmask_many() and friends
This ports a lot of manual code over to sigprocmask_many() and friends.

Also, we now consistly check for sigprocmask() failures with
assert_se(), since the call cannot realistically fail unless there's a
programming error.

Also encloses a few sd_event_add_signal() calls with (void) when we
ignore the return values for it knowingly.
2015-06-15 20:13:23 +02:00
Kay Sievers 15daf6a834 Merge pull request #144 from teg/udev-spawn-log-less-2
udevd: event - don't log about failures of spawn processes when this …
2015-06-14 20:19:54 +02:00
Tom Gundersen 1c4baffc18 sd-netlink: rename from sd-rtnl 2015-06-13 19:52:54 +02:00
Lennart Poettering 2a1288ff89 util: introduce CMSG_FOREACH() macro and make use of it everywhere
It's only marginally shorter then the usual for() loop, but certainly
more readable.
2015-06-10 19:29:47 +02:00
Tom Gundersen 53318514cc udevd: event - don't log about failures of spawn processes when this is expected
PROGRAM and IMPORT{program} uses the exit code of the spawn process to decide if a rule matches or not,
a failing process is hence normal operation and not something we should warn about.

We still warn about other types of failing processes.
2015-06-10 17:55:53 +02:00
Lennart Poettering efbea94798 Revert "hwdb: actually search /run/udev/hwdb.d" 2015-06-09 11:26:06 +02:00
Peter Hutterer 03dfe7b749 hwdb: actually search /run/udev/hwdb.d
The documentation claims hwdb entries may be placed in the volatile
/run/udev/hwdb.d directory but nothing actually looked at it.
2015-06-09 11:52:10 +10:00
Thomas Hindoe Paaboel Andersen 920b52e490 tree-wide: remove spurious space 2015-06-08 23:11:26 +02:00
Tom Gundersen 11b1dd8cec udevd: merge manager_new() and manager_listen() again
Now that listen_fds() have been split out, we can safely move the allocation
of the manager object after doing the forking (the fork is done to notify legcay
init-systems that the fds are ready).

Subsequently, we can merge manager_listen() back into managre_new().

This entails a minor behaviour change: the application of permissions to
static device nodes now happens after the fork (but still before notifying
systemd about being ready).
2015-06-03 02:10:58 +02:00
Tom Gundersen 7500cd5e96 udevd: make sd_notify independent of forknig/notify mode
This will simply silently fail on non-systemd systems, so there is no reason
to make it conditional.

Also make it clear that we notify systemd about being ready as the last step
before starting the event loop, whereas the forking might need to happen
earlier.
2015-06-03 02:03:17 +02:00
Tom Gundersen b7f74dd48f udevd: manager - split listen_fds() out of manager_new()
This will allow us in a follow-up commit to listen to fds before forking and
still allocate the manager only after the fork.
2015-06-03 02:03:15 +02:00
Tom Gundersen f59118ec79 udevd: unify fd handling in forking/notify modes
Hide the differenec in listen_fds, by simply opening the fds
here in case they are not passed in.
2015-06-03 02:01:46 +02:00
Tom Gundersen c26d1879c7 udevd: make cgroup logic independent of socket passing
This should have no behavioural change, but it is odd to tie the cgroup cleaning to
whether or not we are passed sockets.

The point really is if we are guaranteed to be in a dedicated cgroup, so instead
check for our parent being PID1 (we already implicitly only do this on systemd
systems).
2015-06-03 01:53:26 +02:00
Tom Gundersen bf6871639e udevd: only bind ctrl and netlink sockets when we open them
If they are passed from PID1 this is not necessary.
2015-06-03 01:41:35 +02:00
Tom Gundersen fcff1e7241 udevd: rename systemd_fds to listen_fds 2015-06-03 01:41:35 +02:00
Tom Gundersen 8314de1d81 udevd: simplify signal mask handling
We used to block all signals, and restore the original signal mask before exec'ing
external processes.

Now we just block the signals we care about and unconditionally unblock all signals
before exec'ing.
2015-06-03 01:41:34 +02:00
Andreas Pokorny 495968cf4e udev: input_id - use ABS_MT_SLOT{-1} to exclude non touch screen devices
Peek at the ABS_MT_SLOT-1 axis. Expect that touch screens only
have axes inside the MT range.
2015-06-03 08:31:02 +10:00
Andreas Pokorny fa5a113d11 udev: input_id - use direct property and mt axis for touch screen detection
A lot of touch screens use INPUT_PROP_DIRECT to indicate that touch input
maps directly to the underlying screen, while the BTN_TOUCH bit might not be
set.
2015-06-03 08:31:02 +10:00
Andreas Pokorny 15264e5aee udev: input_id - refactor device detection
This change switches to bools and separates bit flag evaluation from
decision making and application of udev properties, while hopefully
keeping the same semantics. Apart from using BTN_LEFT instead of BTN_MOUSE
for mouse detection.
2015-06-03 08:31:02 +10:00
Tom Gundersen 28541a3d7c udev-builtin: path_id - don't pass NULL to udev_device_get_parent()
Being explicit about this makes the code easier to follow IMHO.
2015-06-02 18:12:47 +02:00