summaryrefslogtreecommitdiff
path: root/src/basic/parse-util.c
Commit message (Collapse)AuthorAgeFilesLines
* missing: drop old OOM related definitionsYu Watanabe2018-12-061-0/+1
| | | | These are exposed earlier than linux-3.11. Let's just include linux/oom.h.
* parse-util: allow parse_boolean() to take a NULL argumentLennart Poettering2018-11-301-1/+2
| | | | | | | It's pretty useful to allow parse_boolean() to take a NULL argument and return an error in that case, rather than abort. i.e. making this a runtime rather than programming error allows us to shorten code elsewhere.
* parse-util: rework parse_dev() based on safe_atou() and ↵Lennart Poettering2018-11-291-6/+20
| | | | | | | | DEVICE_MAJOR_VALID()/DEVICE_MINOR_VALID() Let's be a bit more careful when parsing major/minor pairs, and filter out more corner cases. This also means using safe_atou() rather than sscanf() to avoid weird negative unsigned handling and such.
* networkd: add support to configure ip rule port range and protocol.Susant Sahani2018-11-281-0/+20
| | | | | | | | | Please see: iprule: support for ip_proto, sport and dport match options https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/commit/?id=f686f764682745daf6a93b0a6330ba42a961f858 Closes 10622
* trivial: fix spelling in code commentsThomas Haller2018-09-301-1/+1
| | | | Based-on-patch-by: Rafael Fontenelle <rafaelff@gnome.org>
* parse-util: in parse_permille() check negative earlierLennart Poettering2018-07-251-3/+4
| | | | | | | | If 'v' is negative, it's wrong to add the decimal to it, as we'd actually need to subtract it in this case. But given that we don't want to allow negative vaues anyway, simply check earlier whether what we have parsed so far was negative, and react to that before adding the decimal to it.
* tree-wide: remove Lennart's copyright linesLennart Poettering2018-06-141-3/+0
| | | | | | | | | | | These lines are generally out-of-date, incomplete and unnecessary. With SPDX and git repository much more accurate and fine grained information about licensing and authorship is available, hence let's drop the per-file copyright notice. Of course, removing copyright lines of others is problematic, hence this commit only removes my own lines and leaves all others untouched. It might be nicer if sooner or later those could go away too, making git the only and accurate source of authorship information.
* tree-wide: drop 'This file is part of systemd' blurbLennart Poettering2018-06-141-2/+0
| | | | | | | | | | | | | | | | This part of the copyright blurb stems from the GPL use recommendations: https://www.gnu.org/licenses/gpl-howto.en.html The concept appears to originate in times where version control was per file, instead of per tree, and was a way to glue the files together. Ultimately, we nowadays don't live in that world anymore, and this information is entirely useless anyway, as people are very welcome to copy these files into any projects they like, and they shouldn't have to change bits that are part of our copyright header for that. hence, let's just get rid of this old cruft, and shorten our codebase a bit.
* basic/parse-util: remove unnecessary parenthesesZbigniew Jędrzejewski-Szmek2018-06-131-1/+1
|
* parse-util: add permille parser + testsMarc Kleine-Budde2018-06-091-0/+52
|
* basic: split parsing of the OOM score adjust value into its own function in ↵Lennart Poettering2018-05-171-0/+17
| | | | | | | | | | parse-util.c And port config_parse_exec_oom_score_adjust() over to use it. While we are at it, let's also fix config_parse_exec_oom_score_adjust() to accept an empty string for turning off OOM score adjustments set earlier.
* parse-util: add explicit parsers for MTU valuesLennart Poettering2018-04-261-0/+26
| | | | | | | | | We use MTUs all over the place, let's add a unified, strict parser for it, that takes MTU ranges into account. We already have parse_ifindex() close-by, hence this appears to be a natural addition, in particular as the range checking is not entirely trivial to do, as it depends on the protocol used.
* tree-wide: drop license boilerplateZbigniew Jędrzejewski-Szmek2018-04-061-13/+0
| | | | | | | | | | Files which are installed as-is (any .service and other unit files, .conf files, .policy files, etc), are left as is. My assumption is that SPDX identifiers are not yet that well known, so it's better to retain the extended header to avoid any doubt. I also kept any copyright lines. We can probably remove them, but it'd nice to obtain explicit acks from all involved authors before doing that.
* Merge pull request #8534 from poettering/safe-atoi-fullZbigniew Jędrzejewski-Szmek2018-03-231-28/+6
|\ | | | | some improvements to safe_atou() to allow specification of arbitrary bases
| * parse-util: similar to safe_atou16_full() add safe_atou_full()Lennart Poettering2018-03-211-2/+3
| | | | | | | | | | | | What's good for uint16_t is also good for unsigned. This is preparation for: #8140
| * parse-util: introduce safe_atou16_full()Lennart Poettering2018-03-211-26/+3
| | | | | | | | | | | | | | safe_atou16_full() is like safe_atou16() but also takes a base parameter. safe_atou16() is then implemented as inline function on top of it, passing 0 as base. Similar safe_atoux16() is reworked as inline function too, with 16 as base.
* | macro: introduce TAKE_PTR() macroLennart Poettering2018-03-221-2/+1
|/ | | | | | | | | | | | | | | | This macro will read a pointer of any type, return it, and set the pointer to NULL. This is useful as an explicit concept of passing ownership of a memory area between pointers. This takes inspiration from Rust: https://doc.rust-lang.org/std/option/enum.Option.html#method.take and was suggested by Alan Jenkins (@sourcejedi). It drops ~160 lines of code from our codebase, which makes me like it. Also, I think it clarifies passing of ownership, and thus helps readability a bit (at least for the initiated who know the new macro)
* Fix format-truncation compile failure by typecasting USB IDs (#8250)Patrick Uiterwijk2018-02-221-0/+24
| | | | | | | | | | | | | | This patch adds safe_atoux16 for parsing an unsigned hexadecimal 16bit int, and uses that for parsing USB device and vendor IDs. This fixes a compile error with gcc-8 because while we know that USB IDs are 2 bytes, the compiler does not know that. ../src/udev/udev-builtin-hwdb.c:80:38: error: '%04X' directive output may be truncated writing between 4 and 8 bytes into a region of size between 2 and 6 [-Werror=format-truncation=] Signed-off-by: Adam Williamson <awilliam@redhat.com> Signed-off-by: Patrick Uiterwijk <puiterwijk@redhat.com>
* parse-util: detect overflows in parse_percent_unbounded()Lennart Poettering2018-01-161-4/+5
| | | | | We shouldn't accept percentages beyon INT32_MAX and consider them valid.
* parse-util: coding style fixLennart Poettering2018-01-161-8/+8
| | | | Let's not rely on C's downgrade-to-bool feature to check for NUL bytes
* locale-util: add freelocale() cleanup helperLennart Poettering2018-01-161-8/+4
|
* basic: introduce *_to_string_with_check() functionsYu Watanabe2018-01-021-1/+2
| | | | They are used in later commits.
* Add SPDX license identifiers to source files under the LGPLZbigniew Jędrzejewski-Szmek2017-11-191-0/+1
| | | | | This follows what the kernel is doing, c.f. https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=5fd54ace4721fc5ce2bb5aef6318fcf17f421460.
* parse-util: add parse_errno() and parse_syscall_and_errno()Yu Watanabe2017-11-111-0/+59
|
* tree-wide: use IN_SET macro (#6977)Yu Watanabe2017-10-041-1/+1
|
* parse-util: introduce pid_is_valid()Lennart Poettering2017-07-311-1/+1
| | | | | | Checking for validity of a PID is relatively easy, but let's add a helper cal for this too, in order to make things more readable and more similar to uid_is_valid(), gid_is_valid() and friends.
* parse-util: introduce parse_dev() helperFranck Bui2017-06-061-0/+15
|
* fix includesMatija Skala2017-03-151-1/+0
| | | | | | | linux/sockios.h is needed for the SIOCGSTAMPNS macro xlocale.h is included indirectly in glibc and doesn't even exist in other libcs
* core: introduce parse_ip_port (#4825)Susant Sahani2016-12-061-0/+16
| | | | | 1. Listed in TODO. 2. Tree wide replace safe_atou16 with parse_ip_port incase it's used for ports.
* util-lib: unify parsing of nice level valuesLennart Poettering2016-08-051-1/+17
| | | | | | | | This adds parse_nice() that parses a nice level and ensures it is in the right range, via a new nice_is_valid() helper. It then ports over a number of users to this. No functional changes.
* util-lib: add parse_percent_unbounded() for percentages over 100% (#3886)David Michael2016-08-041-2/+9
| | | This permits CPUQuota to accept greater values as documented.
* util-lib: introduce parse_percent() for parsing percent specificationsLennart Poettering2016-06-141-0/+19
| | | | And port a couple of users over to it.
* tree-wide: minor formatting inconsistency cleanupsVito Caputo2016-02-231-1/+1
|
* tree-wide: remove Emacs lines from all filesDaniel Mack2016-02-101-2/+0
| | | | | This should be handled fine now by .dir-locals.el, so need to carry that stuff in every file.
* tree-wide: check if errno is greater than zero (2)Zbigniew Jędrzejewski-Szmek2016-01-131-11/+11
| | | | | Compare errno with zero in a way that tells gcc that (if the condition is true) errno is positive.
* basic: re-sort includesThomas Hindoe Paaboel Andersen2015-12-011-1/+1
| | | | | My previous patch to only include what we use accidentially placed the added inlcudes in non-sorted order.
* basic: include only what we useThomas Hindoe Paaboel Andersen2015-11-301-1/+9
| | | | | This is a cleaned up result of running iwyu but without forward declarations on src/basic.
* calendarspec: sub-second support, v3Hristo Venev2015-11-171-0/+36
|
* parse-util: really refuse parsing negative values as positive ones, even on ↵Lennart Poettering2015-11-101-34/+66
| | | | | | | | | | | | x86-32 strtoull() doesn't make it particularly easy to detect passed-in negative numbers, as it silently converts them to positive ones without generating any error. Since we are not interested in negative values we should hence explicitly filter them out by looking at the string directly and returning ERANGE if we see a leading "-". Fixes: #1829
* parse-util: introduce parse_ifindex() and make use of it everywhereLennart Poettering2015-11-031-0/+13
| | | | | We have enough places where we parse an ifindex, hence introduce a proper parsing function for it, that verifies all parameters.
* parse-util: Introduce new parse_range functionFilipe Brandenburger2015-10-271-0/+39
| | | | | | | This function will be useful for CPUAffinity settings that involve ranges of CPUs. Make it generic and include test coverage to prevent regressions.
* util-lib: split string parsing related calls from util.[ch] into parse-util.[ch]Lennart Poettering2015-10-271-0/+408