Commit Graph

264 Commits

Author SHA1 Message Date
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
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
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
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 8fcde01280 util-lib: split stat()/statfs()/stavfs() related calls into stat-util.[ch] 2015-10-27 13:25:56 +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 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 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
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 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
Lennart Poettering ece174c543 tree-wide: drop {} from one-line if blocks
Patch via coccinelle.
2015-09-09 08:20:20 +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
Thomas Hindoe Paaboel Andersen 7d6884b65e tree-wide: fix indentation 2015-08-06 00:44:19 +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
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
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
Thomas Hindoe Paaboel Andersen 920b52e490 tree-wide: remove spurious space 2015-06-08 23:11:26 +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
Tom Gundersen 3b64e4d4f4 udev: add some asserts
Mostly for documentation purposes.
2015-06-02 18:12:47 +02:00
Kay Sievers f4cf2e5b2f udev: add SYSCTL{} support 2015-03-11 11:15:53 +01:00
Tom Gundersen b94da8cf72 libudev: add missing hunks
This should have been committed with
  udev_device_add_property - implicitly mark properties for saving to db
2015-03-09 23:36:27 +01:00
Tom Gundersen df546eb56a libudev: udev_device_add_property - implicitly mark properties for saving to db
Properties should only be saved to the db when added to the udev_device by udevd, and only if
the property does not start with a '.'. Make this implicit rather than expose the marking of
properties.
2015-03-09 22:50:44 +01:00
Lennart Poettering 2783fe064b udev: strings in C are NUL-terminated anyway, no need to add a second NUL... 2014-11-30 00:21:49 +01:00
Tom Gundersen 9f5ecdb0b1 udev: rules - ignore the lack of trailing newline
Also accept '\r' as newline character.

This dropps warnings of the type:

  invalid key/value pair in file /usr/lib/udev/rules.d/40-usb-media-players.rules
  on line 26, starting at character 25 ('')
2014-11-28 21:57:52 +01:00
Tom Gundersen 6501b52d35 udev: rules - print the first invalid character
The current code would print the character following the first invalid
character.

Given an udev rules-file without a trailing newline we would otherwise print
garbage:

  invalid key/value pair in file /usr/lib/udev/rules.d/40-usb-media-players.rules
  on line 26, starting at character 25 ('m')

This is now changed to print

  invalid key/value pair in file /usr/lib/udev/rules.d/40-usb-media-players.rules
  on line 26, starting at character 25 ('')

(still not very good as printing \0 just gives the empty string)
2014-11-28 21:54:24 +01:00
Tom Gundersen 84198c1892 udev: rules - modernise add_rule a bit 2014-11-28 21:54:24 +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 ff49bc3212 treewide: drop unnecessary trailing \n in log_*() calls 2014-11-28 14:26:31 +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
Kay Sievers adeba5008e udev: support ENV{}=="" global property matches 2014-11-13 20:35:06 +01:00
Ronny Chevalier 00b06165a1 udev: use properly the systemd logging functions 2014-11-12 21:44:38 +01:00
Kay Sievers b12b78712e udev: use the systemd logging functions in udev tools 2014-11-12 18:35:18 +01:00
Tom Gundersen 6c8aaf0c1b udev: rules - close empty file
If the file is found to be empty, we exit early without closing the file first.

Found by coverity. Fixes CID #1237759.
2014-09-17 19:55:23 +02:00
Tom Gundersen 85639427b3 udev: rules - add missing whitespace to log message 2014-09-16 12:12:57 +02:00
Tom Gundersen 23bf8dd7d5 libudev: drop util_lookup_{user,group}
Use shared versions instead. Difference is with overwriting of repeated user/group
name, and lack of logging.
2014-09-16 12:12:56 +02:00
Tom Gundersen 6711741365 udev: timeout - warn after a third of the timeout before killing 2014-09-11 23:45:01 +02:00
David Herrmann 8e3ba3772c udev: allow removing tags via TAG-="foobar"
This extends the udev parser to support OP_REMOVE (-=) and adds support
for TAG-= to remove previously set tags. We don't fail if the tag didn't
exist.

This is pretty handy if we ship default rules for seat-assignments and
users want to exclude specific devices from that. They can easily add
rules that drop any automatically added "seat" tags again.
2014-09-11 15:22:16 +02:00
Tom Gundersen ec3281d3b6 udev: fix copy-paste error in log message 2014-09-10 18:09:32 +02:00
Tom Gundersen ac9c87dbc4 Revert "libudev: use get_*_creds from shared rather than util_lookup_*"
This reverts commit a56ba6158b.

The commit was pushed in error.
2014-08-01 22:33:20 +02:00
Tom Gundersen a56ba6158b libudev: use get_*_creds from shared rather than util_lookup_* 2014-08-01 16:34:50 +02:00
Hannes Reinecke 9f20a8a376 udev: fixup commit dd5eddd28a
Commit dd5eddd28a accidentally
removed one line too many.
2014-07-30 11:40:13 +02:00
Kay Sievers 9ec6e95b04 udev: place opening { at the same line as the function declaration 2014-07-29 15:49:25 +02:00
Kay Sievers dd5eddd28a udev: unify event timeout handling 2014-07-29 15:18:27 +02:00
Zbigniew Jędrzejewski-Szmek ed88bcfb7c Be more careful when checking for empty files
If we want to avoid reading a totally empty file, it seems better
to check after we have opened the file, not before.
2014-07-16 19:00:03 -04:00
Robert Milasan 209b031e4f udev: increase the size of RESULT buffer
Under some conditions, in udev_rules_apply_to_event the fact that
result is 1024 bytes, creates problems if the output of the running
command/app is bigger then 1024 bytes.
2014-04-24 11:26:26 +02:00
Kay Sievers ca2bb1606a udev: do not export "static node" tags for non-existing devices 2014-04-02 15:47:09 +02:00
Josh Triplett f8294e4175 Use strlen even for constant strings
GCC optimizes strlen("string constant") to a constant, even with -O0.
Thus, replace patterns like sizeof("string constant")-1 with
strlen("string constant") where possible, for clarity.  In particular,
for expressions intended to add up the lengths of components going into
a string, this often makes it clearer that the expression counts the
trailing '\0' exactly once, by putting the +1 for the '\0' at the end of
the expression, rather than hidden in a sizeof in the middle of the
expression.
2014-03-16 09:52:56 -04:00
Zbigniew Jędrzejewski-Szmek 06beed6dc6 Remove unused variable and two function stubs 2014-02-17 22:35:35 -05:00
Lennart Poettering 955d98c9c1 everywhere: make use of new0() and macro() macros, and stop using perror() 2014-02-13 14:45:51 +01:00
Greg KH 29804cc1e0 use memzero(foo, length); for all memset(foo, 0, length); calls
In trying to track down a stupid linker bug, I noticed a bunch of
memset() calls that should be using memzero() to make it more "obvious"
that the options are correct (i.e. 0 is not the length, but the data to
set).  So fix up all current calls to memset(foo, 0, length) to
memzero(foo, length).
2014-01-31 11:55:01 +01:00
Kay Sievers d6f116a7b1 udev: static_node - do not exit rule after first static_node item
The nodes usually do not exist, so handle the next item instead of
skipping the entire rule.
2014-01-22 10:47:48 +01:00
Zbigniew Jędrzejewski-Szmek 2ad8416dd0 No need to canonicalize fixed paths 2014-01-08 22:15:27 -05:00
Zbigniew Jędrzejewski-Szmek e3e0314b56 systemctl: allow globbing in commands which take multiple unit names 2013-12-26 13:24:36 -05:00
Lennart Poettering 9f6445e34a log: log_error() and friends add a newline after each line anyway, so avoid including it in the log strings 2013-12-24 16:39:37 +01:00
Thomas Hindoe Paaboel Andersen f168c27313 trivial coding style clean ups
- Add space between if/for and the opening parentheses
- Place the opening brace on same line as the function (not for  udev)

From the CODING_STYLE
Try to use this:
    void foo() {
    }
instead of this:
    void foo()
    {
    }
2013-12-03 22:27:45 +01:00
Daniel Buch f5f6d0e255 tree-wide usage of %m specifier instead of strerror(errno)
Also for log_error() except where a specific error is specified

e.g. errno ? strerror(errno) : "Some user specified message"
2013-11-26 21:07:46 +10:00
Kay Sievers 5c11fbe3a7 udev: udevd - rules can be NULL when reloading 2013-11-04 15:54:33 +01:00
Kay Sievers 75716dd8ea udev: rules - move parsing error to log_error() 2013-10-30 15:49:46 +01:00
Kay Sievers 0aa5b4d1f7 udev: do not allow to change the DEVPATH of a device 2013-10-30 01:58:26 +01:00
Tom Gundersen 97f2d76d4f path_check_timestamp: only keep the most recent timestamp
There is no point in keeping one timestamp for each directory, as we only
ever care about the most recent one.
2013-10-29 16:12:11 +01:00
Tom Gundersen 8e18485284 udev: move udev_rules_check_timestamp to shared
I want to use this from a bulitin in a subsequent patch.
2013-10-26 14:34:31 +02:00
Kay Sievers c26547d612 udev: support custom Linux Security Module labels for device nodes 2013-10-08 02:23:24 +02:00
Dave Reisner 3cf0f8f7e0 udev-rules: avoid erroring on trailing whitespace
https://bugs.archlinux.org/task/36950
2013-09-16 11:46:05 -04:00
Shawn Landden 7c902b1468 udev: fix printf(3) type specifier
src/udev/udev-rules.c: In function 'add_rule':
src/udev/udev-rules.c:1078:33: warning: format '%lu' expects argument of type 'long unsigned int', but argument 8 has type 'int' [-Wformat=]
                                 log_error("invalid key/value pair in file %s on line %u,"
                                 ^
2013-08-23 12:48:14 -04:00
Zbigniew Jędrzejewski-Szmek 1291bc895b udev: when complaining about invalid characters, print them out
systemd-udevd[6260]: invalid key/value pair in file /usr/lib/udev/rules.d/60-ffado.rules on line 46,starting at character 84 ('#')
2013-08-20 21:18:43 -04:00
Dave Reisner e736cf3582 udev-rules: report rule parsing errors from get_key 2013-07-29 21:51:58 -04:00
Tom Gundersen 15a722007d udev: static_node - don't touch permissions uneccessarily
Don't set default permissions if only TAGS were specified in a rule.
2013-07-24 15:13:00 +02:00
Tom Gundersen 490f008762 udev: log error if chmod/chown of static dev nodes fails 2013-07-24 15:13:00 +02:00
Tom Gundersen 84b6ad702e udev: export tags of "dead" device nodes to /run/udev/static_node-tags/
Based on a patch by Kay Sievers.

A tag is exported at boot as a symlinks to the device node in the folder
/run/udev/static_node-tags/<tagname>/, if the device node exists.

These tags are cleaned up by udevadm info --cleanup-db, but are otherwise
never removed.
2013-07-16 20:07:57 +02:00
Jan Janssen 9c3fd04e7d libudev: Use correct type for sizeof 2013-06-24 12:41:01 +02:00
Anatol Pomozov ab06eef810 Fix spelling errors using 'codespell' tool 2013-04-15 08:40:05 -04:00
Thomas Hindoe Paaboel Andersen 641906e936 use strneq instead of strncmp 2013-02-13 00:56:13 +01:00
Kay Sievers 7850b3b837 shared: conf-files - add root parameter 2013-02-08 10:23:04 +01:00
Kay Sievers d5a89d7dc1 udev: move string copy functions to shared/ 2013-01-09 19:06:46 +01:00
Kay Sievers 1edefa4f1d udev: in addition to DEVMODE, honor DEVUID, DEVGID from the uevent 2012-12-31 04:48:44 +01:00
Kay Sievers 1298001ec5 use the same email address everywhere 2012-11-12 19:47:43 +01:00
Kay Sievers 40fe8b11be udev: use usec_t and now() 2012-11-12 01:03:14 +01:00
Kay Sievers ff944daa01 udev: get rid of SYSCONFDIR 2012-10-28 04:04:22 +01:00
Kay Sievers 915bf0f60f udev: use strbuf to store rules strings 2012-10-22 16:28:04 +02:00
Kay Sievers 07845c142b udev: support multiple entries for ENV{SYSTEMD_ALIAS} and ENV{SYSTEM_WANTS} 2012-10-09 00:16:50 +02:00
Kay Sievers 8a1733871f udev: remove SYMLINK "unique" option 2012-10-08 21:54:39 +02:00
Václav Pavlín 0820a4f0f6 udev: free rule structure on error 2012-09-23 14:24:43 +02:00
Kay Sievers 238b53a024 udev: fix typo in copyright 2012-08-08 18:24:50 +02:00
Kay Sievers 3b8c1cb01f udev: initialize rules dir timestamps when reading rules
On Wed, Aug 8, 2012 at 11:48 AM, Michael Schroeder <mls@suse.de> wrote:
> if rules are installed in the first 3 seconds after the udev start,
> the stamps will all be zero, so the [first] call to check_rules_timestamp()
> will just copy the current mtime [and not cause a rules re-load].
2012-08-08 14:45:16 +02:00
Kay Sievers 4cb72937d3 udev: get rid of TEST_PREFIX and use unshare() to fake /sys, /dev, /run 2012-07-15 22:10:46 +02:00
Kay Sievers 47ef94ac5f udev: add some O_CLOEXEC 2012-07-05 17:33:24 +02:00
Kay Sievers da5d4bf64f udev: skip timestamp check if rules are already free()d during reload 2012-05-31 01:17:59 +02:00
Kay Sievers 9eb977db5b util: split-out path-util.[ch] 2012-05-08 02:33:10 +02:00
Kay Sievers 2c21044f05 util: split-out conf-file.[ch] 2012-05-07 19:01:24 +02:00
Kay Sievers 775f8b3c74 udev: use conf_files_list() to search rules files 2012-05-07 13:21:05 +02:00
Kay Sievers 395ea97815 udev: fix the ENV{} blacklist logic 2012-05-04 02:29:36 +02:00
Kay Sievers 33502ffe2e udev: use startswith() and streq() 2012-04-16 20:54:17 +02:00
Kay Sievers 6ada823a9a udev: remove configuration options for /dev, /sys, /run directories 2012-04-16 19:20:57 +02:00
Kay Sievers 8fef0ff25c udev: replace ARRAY_SIZE() with ELEMENTSOF() 2012-04-16 19:20:57 +02:00
Kay Sievers 4590cfe455 udev: fix RUN+= logic regarding builtin vs. program 2012-04-11 22:34:25 +02:00
Kay Sievers 04a9d3a00a udev: fix gcc warnings showing up after adding $(AM_CFLAGS) 2012-04-10 17:27:46 +02:00
Kay Sievers 2d13da8821 udev: remove RUN+="socket:.." and udev_monitor_new_from_netlink() 2012-04-09 21:18:30 +02:00
Kay Sievers 83cd6b754b udev: convert 'uaccess' to a builtin 2012-04-09 19:25:41 +02:00
Kay Sievers baa30fbc2c udev: switch to systemd logging functions 2012-04-08 16:06:20 +02:00
Kay Sievers 3e2147858f move imported udev into place 2012-04-04 05:05:07 +02:00
Renamed from src/udev/src/udev-rules.c (Browse further)