summaryrefslogtreecommitdiff
path: root/src/test/test-unit-name.c
Commit message (Collapse)AuthorAgeFilesLines
* basic: add RuntimeScope enumLennart Poettering2023-03-101-1/+1
| | | | | | | | | | | | In various tools and services we have a per-system and per-user concept. So far we sometimes used a boolean indicating whether we are in system mode, or a reversed boolean indicating whether we are in user mode, or the LookupScope enum used by the lookup path logic. Let's address that, in introduce a common enum for this, we can use all across the board. This is mostly just search/replace, no actual code changes.
* test-unit-name: fix fd leakYu Watanabe2023-01-201-1/+3
| | | | Fixes an issue reported at https://github.com/systemd/systemd/issues/22576#issuecomment-1396774385.
* test-unit-name: simplify machine-id checkNick Rosbrook2022-12-141-1/+3
|
* basic: rename util.h to logarithm.hZbigniew Jędrzejewski-Szmek2022-11-081-1/+0
| | | | | util.h is now about logarithms only, so we can rename it. Many files included util.h for no apparent reason… Those includes are dropped.
* test-unit-name: do not fail if machine-id is missingLuca Boccassi2022-10-251-8/+14
| | | | When building in a chroot there might not be any machine-id
* Merge pull request #22759 from msekletar/issue-18077-long-sysfs-paths-hashingLennart Poettering2022-04-131-3/+23
|\ | | | | Create "hashed" unit names from long paths
| * core: shorten long unit names that are based on paths and append path hash ↵Michal Sekletar2022-04-081-3/+23
| | | | | | | | | | | | at the end Fixes #18077
* | tree-wide: host_name → hostnameZbigniew Jędrzejewski-Szmek2022-04-111-2/+2
| | | | | | | | | | We use "hostname" exclusively in docs, and also in a big majority of the code. Let's use the same spelling in remaining places.
* | test-unit-name: add missing tests for specifiers, fix existing testsZbigniew Jędrzejewski-Szmek2022-04-111-42/+117
|/ | | | | | | | | | | | | | | | | | | | It turns out that in fa3cd7394c227ad38c5c09b2bc2d035e7fb14a76 back in 2013 I got the test reversed: assert_se(strncmp()) should be assert_se(strncmp==0). So the tests that were using "*" were not entirely useful ;) The function was refactored a bunch of times since then, and it seems nobody noticed. So let's replace this fragile construct by a simple fnmatch, which also has the advantage that the glob can be inserted in arbitrary places. Following up for d0aba07f1ac8d6df2ccfa033fe1e195b1b9e5272: we should have at least basic tests for all interfaces, even the deprecated ones, so that we catch obvious errors. This sorts the specifiers the same way that they are declared in the unit-printf.c, and adds tests for all the specifiers. We even were setting 'shell', but not using it in a test. Also, we shouldn't initialize variables in tests. This catches the error fixed in previous commit.
* Rename UnitFileScope to LookupScopeZbigniew Jędrzejewski-Szmek2022-03-291-1/+1
| | | | | | | | | As suggested in https://github.com/systemd/systemd/pull/22649/commits/8b3ad3983f5440eef812b34e5ed862ca59fdf7f7#r837345892 The define is generalized and moved to path-lookup.h, where it seems to fit better. This allows a recursive include to be removed and in general makes things simpler.
* test: allow to set NULL to intro or outroYu Watanabe2022-02-021-1/+1
| | | | Addresses https://github.com/systemd/systemd/pull/22338#discussion_r796741033.
* tests: rework test macros to not take code as parametersLennart Poettering2022-02-021-10/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | C macros are nasty. We use them, but we try to be conservative with them. In particular passing literal, complex code blocks as argument is icky, because of "," handling of C, and also because it's quite a challange for most code highlighters and similar. Hence, let's avoid that. Using macros for genreating functions is OK but if so, the parameters should be simple words, not full code blocks. hence, rework DEFINE_CUSTOM_TEST_MAIN() to take a function name instead of code block as argument. As side-effect this also fixes a bunch of cases where we might end up returning a negative value from main(). Some uses of DEFINE_CUSTOM_TEST_MAIN() inserted local variables into the main() functions, these are replaced by static variables, and their destructors by the static destructor logic. This doesn't fix any bugs or so, it's just supposed to make the code easier to work with and improve it easthetically. Or in other words: let's use macros where it really makes sense, but let's not go overboard with it. (And yes, FOREACH_DIRENT() is another one of those macros that take code, and I dislike that too and regret I ever added that.)
* test: Convert to TEST/TEST_RET macrosJan Janssen2021-11-281-98/+32
| | | | | Note that test-cgroup-mask, test-cgroup-unit-default and test-unit-name will now report being skipped instead of reporting success if not run under systemd.
* core: Try to prevent infinite recursive template instantiationDaan De Meyer2021-10-281-0/+17
| | | | | | | | | | | | | | | | | To prevent situations like in #17602 from happening, let's drop direct recursive template dependencies. These will almost certainly lead to infinite recursion so let's drop them immediately to avoid instantiating potentially thousands of irrelevant units. Example of a template that would lead to infinite recursion which is caught by this check: notify@.service: ``` [Unit] Wants=notify@%n.service ```
* tree-wide: make specifier expansion --root= awareLennart Poettering2021-06-241-2/+2
| | | | | | | | | | | | | | | | | | | | | | This fixes repart's, systemctl's, sysusers' and tmpfiles' specifier expansion to honour the root dir specified with --root=. This is relevant for specifiers such as %m, %o, … which are directly sourced from files on disk. This doesn't try to be overly smart: specifiers referring to runtime concepts (i.e. boot ID, architecture, hostname) rather than files on the medium are left as is. There's certainly a point to be made that they should fail in case --root= is specified, but I am not entirely convinced about that, and it's certainly something we can look into later if there's reason to. I wondered for a while how to hook this up best, but given that quite a large number of specifiers resolve to data from files on disks, and most of our tools needs this, I ultimately decided to make the root dir a first class parameter to specifier_printf(). Replaces: #16187 Fixes: #16183
* unit-name: generate a clear error code when converting an overly long fs ↵Lennart Poettering2021-06-011-2/+2
| | | | path to a unit name
* tree-wide: always drop unnecessary dot in pathYu Watanabe2021-05-281-1/+1
|
* Make unit_name_to_instance() return UnitNameFlagsZbigniew Jędrzejewski-Szmek2021-05-051-1/+1
| | | | | | | | | The function returns non-negative UnitNameFlags on success, and negative errno on error. In the past we kept the return type as int because of those negative return values. But nowadays _UNIT_NAME_INVALID == -EINVAL. And if we tried to actually return something that doesn't fit in the return type, the compiler would throw an error. By changing to the "real" return type, we allow the debugger to use symbolic representation for the variables.
* license: LGPL-2.1+ -> LGPL-2.1-or-laterYu Watanabe2020-11-091-1/+1
|
* unit-name: fix a potential memory leakFrantisek Sumsal2020-07-061-0/+2
| | | | | | | Also, add a test which verifies the issue is indeed gone. Fixes: CID#1429014 Followup to: ab19db01ae1826efb3cbdf6dcb6a14412f8844d4
* basic/unit-name: make sure UnitNameFlags is signedZbigniew Jędrzejewski-Szmek2019-12-191-0/+4
| | | | | Without that, a check like unit_name_to_instance(...) < 0 would not have the expected effect.
* Merge pull request #13994 from keszybz/bpf-refactorLennart Poettering2019-11-131-3/+2
|\ | | | | Refactor the bpf devices code and fix some bugs
| * tests: modify enter_cgroup_subroot() to return the new pathZbigniew Jędrzejewski-Szmek2019-11-111-1/+1
| |
| * tests: get rid of test-helper.[ch] completelyZbigniew Jędrzejewski-Szmek2019-11-111-1/+0
| | | | | | | | | | I don't think there's any particular reason to keep those functions in a separate file.
| * tests: make manager_skip_test() not a macro and move to tests.hZbigniew Jędrzejewski-Szmek2019-11-111-1/+1
| | | | | | | | There is nothing magic in it.
* | test-unit-name: check that unexpanded specifiers not valid unit name makeZbigniew Jędrzejewski-Szmek2019-11-121-0/+6
| |
* | test-unit-name: add usual headers and add more verbose outputZbigniew Jędrzejewski-Szmek2019-11-121-40/+84
|/ | | | | This makes it easier to see what unit_name_is_valid() returns at a glance. The output is not whitespace clean, but I think it's good enough for a test.
* core: change top-level drop-in from -.service.d to service.dAnita Zhang2019-11-071-19/+0
| | | | | | | | | | Discussed in #13743, the -.service semantic conflicts with the existing root mount and slice names, making this feature not uniformly extensible to all types. Change the name to be <type>.d instead. Updating to this format also extends the top-level dropin to unit types.
* tree-wide: drop pwd.h and grp.h when user-util.h is includedYu Watanabe2019-11-041-1/+0
|
* tree-wide: drop string.h when string-util.h or friends are includedYu Watanabe2019-11-041-1/+0
|
* core: disallow using '-.service' as a service nameAnita Zhang2019-10-071-0/+19
| | | | | -.service.d will become a special top level drop in so don't let it be a usable service name (otherwise the interaction gets complicated).
* docs: describe valid unit names in systemd.unit(5)Zbigniew Jędrzejewski-Szmek2019-08-301-0/+3
|
* basic/unit-name: allow unit_name_to_instance() to be used to classify unitsZbigniew Jędrzejewski-Szmek2019-07-191-4/+6
| | | | | | | | | | This could already be done by calling unit_name_is_*(), but if we don't know if the argument is a valid unit name, it is more convenient to have a single function which returns the type or possibly an error if the unit name is not valid. The values in the enum are sorted "by length". Not really important, but it seems more natural to me.
* headers: remove unneeded includes from util.hZbigniew Jędrzejewski-Szmek2019-03-271-0/+1
| | | | | This means we need to include many more headers in various files that simply included util.h before, but it seems cleaner to do it this way.
* Define macro for systemd-fsck-root.serviceZbigniew Jędrzejewski-Szmek2019-01-031-1/+1
| | | | There is one for systemd-fsck@.service, so for consistency...
* shared: add %g, %G specifiers for group / gid (#10368)Davide Cavalca2018-10-131-1/+7
|
* tests: add a helper function to skip with errnoZbigniew Jędrzejewski-Szmek2018-09-141-4/+2
|
* tests: use a helper function to parse environment and open loggingZbigniew Jędrzejewski-Szmek2018-09-141-2/+1
| | | | | The advantages are that we save a few lines, and that we can override logging using environment variables in more test executables.
* tests: add helper to unify skipping a test and exitingZbigniew Jędrzejewski-Szmek2018-09-141-4/+2
|
* tree-wide: drop copyright headers from frequent contributorsZbigniew Jędrzejewski-Szmek2018-06-201-3/+0
| | | | | | | | Fixes #9320. for p in Shapovalov Chevalier Rozhkov Sievers Mack Herrmann Schmidt Rudenberg Sahani Landden Andersen Watanabe; do git grep -e 'Copyright.*'$p -l|xargs perl -i -0pe 's|/([*][*])?[*]\s+([*#]\s+)?Copyright[^\n]*'$p'[^\n]*\s*[*]([*][*])?/\n*|\n|gms; s|\s+([*#]\s+)?Copyright[^\n]*'$p'[^\n]*\n*|\n|gms' done
* Drop my copyright headersZbigniew Jędrzejewski-Szmek2018-06-141-1/+0
| | | | | | | perl -i -0pe 's/\s*Copyright © .... Zbigniew Jędrzejewski.*?\n/\n/gms' man/*xml git grep -e 'Copyright.*Jędrzejewski' -l | xargs perl -i -0pe 's/(#\n)?# +Copyright © [0-9, -]+ Zbigniew Jędrzejewski.*?\n//gms' git grep -e 'Copyright.*Jędrzejewski' -l | xargs perl -i -0pe 's/\s*\/\*\*\*\s+Copyright © [0-9, -]+ Zbigniew Jędrzejewski[^\n]*?\s*\*\*\*\/\s*/\n\n/gms' git grep -e 'Copyright.*Jędrzejewski' -l | xargs perl -i -0pe 's/\s+Copyright © [0-9, -]+ Zbigniew Jędrzejewski[^\n]*//gms'
* tree-wide: beautify remaining copyright statementsLennart Poettering2018-06-141-2/+2
| | | | | | Let's unify an beautify our remaining copyright statements, with a unicode ©. This means our copyright statements are now always formatted the same way. Yay.
* tree-wide: remove Lennart's copyright linesLennart Poettering2018-06-141-1/+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.
* core: undo the dependency inversion between unit.h and all unit typesFelipe Sateler2018-05-151-0/+1
|
* test: add tests for unit_name_from_dbus_path()Yu Watanabe2018-05-131-0/+295
|
* path-util: introduce empty_to_root() and use it many placesYu Watanabe2018-05-111-2/+2
|
* Add %j/%J unit specifiersZbigniew Jędrzejewski-Szmek2018-04-241-19/+39
| | | | | | | | | Those are quite similar to %i/%I, but refer to the last dash-separated component of the name prefix. The new functionality of dash-dropins could largely supersede the template functionality, so it would be tempting to overload %i/%I. But that would not be backwards compatible. So let's add the two new letters instead.
* tests: add some tests for unit_name_is_valid() and related functionsZbigniew Jędrzejewski-Szmek2018-04-241-12/+43
| | | | | I was surprised to see that foo@bar@bar.service is a valid unit name. Apparently it is according to current code and docs.
* tree-wide: drop spurious newlines (#8764)Lennart Poettering2018-04-191-1/+0
| | | | | | | | Double newlines (i.e. one empty lines) are great to structure code. But let's avoid triple newlines (i.e. two empty lines), quadruple newlines, quintuple newlines, …, that's just spurious whitespace. It's an easy way to drop 121 lines of code, and keeps the coding style of our sources a bit tigther.