Commit Graph
3854 Commits
Author SHA1 Message Date
Yu Watanabe 14dde316c7 sd-json: use sd_json_dispatch_const_string() in sd_json_dispatch_string()
Also, do similar for json_dispatch_user_group_name().
2024-10-07 09:53:36 +02:00
Yu Watanabe f769518c9a tree-wide: drop doubled empty lines 2024-10-07 09:51:37 +02:00
Mike Yuan 0aae1a09a3 path-lookup: move xdg_user_dirs() to xdg-autostart-generator
This is the only place where xdg_user_dir() is needed and
makes sense. All other invocations have been replaced with
user_search_dirs() - see previous commits for details.
2024-10-06 19:42:39 +02:00
Mike Yuan 5ce4902249 path-lookup: refactor lookup_paths_init() search paths handling
* Rename user_dirs() -> user_unit_search_dirs() and port to
  user_search_dirs()
* Use STRV_IFNOTNULL to guard paths that could be NULL,
  assert otherwise
2024-10-06 19:42:39 +02:00
Mike Yuan 1f8eedba9d path-lookup: introduce user_search_dirs() (shall replace xdg_user_dirs())
xdg_user_dirs() doesn't seem well-organized currently.
In all other xdg_user_*() funcs we assume /etc/xdg/systemd
to be a symlink to /etc/systemd/, hence it is the odd one out.
Also, when the relevant envvar is unset, it only returns
the global search dirs.

sd_path_lookup() actually covers this nicely with SD_PATH_SEARCH_*,
where the combined search paths (from user home and system) are used.
Therefore, let's introduce a wrapper for that, and deprecate xdg_user_dirs()
(would be removed in later commits).
2024-10-06 19:42:39 +02:00
Mike Yuan 546110ded9 path-lookup: assert that LOOKUP_PATHS_{EXCLUDE,TEMPORARY}_GENERATED are not used in conjunction 2024-10-06 19:42:39 +02:00
Mike Yuan cfda202fa9 path-lookup: unify *_generator_binary_paths() 2024-10-06 19:32:55 +02:00
Mike Yuan 536f6bd467 path-lookup: modernize get_paths_from_environ()
Use retval rather than additional param to indicate
whether the normal paths shall be appended.
2024-10-06 19:32:55 +02:00
Mike Yuan b8018297a8 path-lookup: shortcut patch_root_prefix() if no root_dir 2024-10-06 19:32:54 +02:00
Mike Yuan 716fab66ab path-lookup: unify acquire_{config,control,attached}_dir()
Note that -ENXIO reported by xdg_user_config_dir() is now properly
propagated rather than ignored, as unlike XDG_RUNTIME_DIR, XDG_CONFIG_HOME
has a default value hence ENXIO is not really expected.
2024-10-06 19:32:54 +02:00
Mike Yuan bd79a88f34 path-lookup: use path_strv_contains() rather than strv_contains() 2024-10-06 19:32:54 +02:00
Mike Yuan 0e0e20bfb1 path-lookup: clean up acquire_{generator,transient}_dirs() a bit 2024-10-06 19:32:54 +02:00
Mike Yuan 8cff087d27 path-lookup: modernize runtime_directory() too 2024-10-06 19:32:53 +02:00
Mike Yuan 60cd6deb06 path-lookup: deduplicate xdg_user_*() with sd_path_lookup()
While at it, place ret param at last.
2024-10-06 19:27:12 +02:00
Mike Yuan f005e267bc path-lookup: move from basic/ to libsystemd/
So that sd_path_lookup() can be utilized to replace
duplicate functions.
2024-10-06 19:27:12 +02:00
Mike Yuan cd7d732dc5 path-lookup: move NETWORK_DIRS to network-util.h 2024-10-06 19:27:11 +02:00
Mike Yuan 3f8999a76e fs-util: rename laccess to access_nofollow
In order to distinguish it from libc function naming.
2024-10-05 01:30:43 +02:00
Mike Yuan 7c1dd9e288 various: correct laccess() error check
laccess is our own macro that uses RET_NERRNO.
2024-10-04 21:26:04 +02:00
Lennart Poettering da01f7c246 sd-varlink: mark functions that can take 'more' flag in IDL structures with an explicit flag
Let's mark functions that accept the 'more' flag explicitly for that,
and validate for this explicitly.

This is preparation for
https://github.com/varlink/varlink.github.io/issues/26, if we get that
one day. Let's make sure that from day #1 we have this info available
even if we don't generate this in the IDL for now.

Also enables the two flags for all interfaces we export that use the
logic.
2024-10-02 09:22:52 +02:00
Lennart Poettering 0376ef36a1 json: add json_dispatch_const_user_group_name()
This is the same as json_dispatch_user_group_name() but fills in the
string as "const char*" to the JSON field. Or in other words, it's what
sd_json_dispatch_const_string() is to sd_json_dispatch_string().

Note this drops the SD_JSON_STRICT flags from various dispatch tables
for these fields, and replaces this by SD_JSON_RELAX, i.e. the opposite
behaviour. As #34558 correctly suggests we should validate user names
in lookup functions using the lax rules, rather than the strict ones,
since clients not knowing the rules might ask us for arbitrary
resolution.

(SD_JSON_RELAX internally translates to valid_user_group_name() with the
VALID_USER_RELAX flag).

See: #34558
2024-10-01 08:32:00 +02:00
Mike Yuan a2c8652a2a tree-wide: use strv_extend_strv_consume() where appropriate 2024-09-21 00:53:50 +02:00
Mike Yuan 2b19bed790 sd-path: trivial cleanups for sd_path_lookup{,_strv}() 2024-09-20 00:10:25 +02:00
Mike Yuan 8664dd3c1f sd-path: modernize from_user_dir()
Deduplicate logic through sd_path_lookup() and from_home_dir().
Besides, rename to from_xdg_user_dir() to indicate
it's a XDG thing.
2024-09-20 00:10:25 +02:00
Yu Watanabe 26d35019de tree-wide: drop unnecessary 'struct' 2024-09-19 01:34:57 +09:00
Mike Yuan 4591c89a15 sd-network: introduce sd_network_link_get_netdev_file{,_dropins} 2024-09-09 23:20:42 +02:00
Mike Yuan ad501930d7 socket-util: make recvmsg_safe() handle MSG_TRUNC too
Also, unify MSG_TRUNC handling all across the codebase.
2024-09-04 18:51:44 +02:00
Mike Yuan 6f0d6ef7ce sd-varlink: check correct errno
'n' can also be assigned from recvmsg_safe(), which is our own
func returning negative errno.
2024-09-04 18:50:54 +02:00
Daan De Meyer 5064de1383 Merge pull request #34224 from yuwata/network-make-qdisc-reconfigurable
network: make qdisc reconfigurable
2024-09-04 12:07:16 +02:00
Daan De Meyer eabff5267e json-util: Add JSON_BUILD_PAIR_UNSIGNED_NOT_EQUAL() 2024-09-03 12:08:42 +02:00
Daan De Meyer 0ea8d4bc8c json-util: Add JSON_BUILD_TRISTATE() and friends 2024-09-03 12:08:42 +02:00
Daan De Meyer 6647bbeab1 json-util: Add JSON_BUILD_PAIR_BASE64_NON_EMPTY() and friends 2024-09-03 12:08:42 +02:00
Daan De Meyer a85e9670f6 json-util: Add JSON_BUILD_PAIR_BYTE_ARRAY_NON_EMPTY() 2024-09-03 12:08:42 +02:00
Daan De Meyer 7606139e61 json-util: Add JSON_BUILD_PAIR_INTEGER_NON_NEGATIVE() 2024-09-03 12:08:42 +02:00
Daan De Meyer ab8a5e1f99 json-util: Add JSON_BUILD_PAIR_INTEGER_NON_ZERO() 2024-09-03 12:08:42 +02:00
Daan De Meyer 9ba489c7f6 json-util: Add JSON_BUILD_PAIR_CALLBACK_NON_NULL()
Like JSON_BUILD_PAIR_CALLBACK(), but doesn't add anything to the variant
if the callback doesn't put anything in the return argument.
2024-09-03 12:08:41 +02:00
Daan De Meyer 5b5579066d json-util: Add JSON_BUILD_PAIR_DUAL_TIMESTAMP_NON_NULL() 2024-09-03 12:08:23 +02:00
Daan De Meyer 95e2f04144 json-util: Add JSON_BUILD_PAIR_DUAL_TIMESTAMP() 2024-09-03 12:06:42 +02:00
Daan De Meyer 0e88e150c5 json-util: Add JSON_BUILD_RATELIMIT() 2024-09-03 12:06:40 +02:00
Daan De Meyer ed207e5261 json-util: Add JSON_BUILD_STRING_ORDERED_SET() 2024-09-03 12:03:02 +02:00
Lennart Poettering 7fd18c93d8 resolved: include Varlink error on inconsistent DNS-SD services in introspection data
Let's also rename the error slightly, since what happens here is that a
a valid service RR name is CNAME'd onto an invalid one. That's an
inconsistency on the server side, which we really should report as such.

Follow-up for: b48ab08732
2024-09-03 10:42:14 +09:00
Daan De Meyer 21d9eeb5e6 networkd: Replace existing objects instead of doing nothing if they exist
Currently, if for example a traffic control object already exist, networkd
will silently do nothing, even if the settings in the network file for the
traffic control object have changed. Let's instead replace the object if it
already exists so that new settings from the network file are applied as
expected.

Fixes #31226
2024-09-02 14:12:49 +09:00
Adrian Vovk aa2e664e18 sysupdated: Register known error types
This fixes a bug introduced during review of sysupdated. Originally,
we just returned EALREADY verbatim to signify that the target is
already up-to-date. Then we switched this to a proper error
(org.freedesktop.sysupdate1.NoCandidate) during review. But that now
maps to EIO, not EALREADY. Thus, whenever there's nothing to update,
updatectl would report I/O errors to the user, even though nothing
actually went wrong.
2024-08-30 21:43:44 -04:00
Yu Watanabe 9f563bcd74 Merge pull request #34123 from yuwata/sd-device
sd-device: expose sd_device_get_device_id() and sd_device_get_driver_subsystem()
2024-08-28 11:33:09 +09:00
Yu Watanabe 5ab1250534 sd-device-monitor: introduce sd_device_monitor_get_events() and _get_timeout()
Follow-up for bab889c51e (#33032).

Currently, they unconditionally returns EPOLLIN and USEC_INFINITY, respectively.
Just for consistency with sd-bus, sd-journal, sd-varlink, and so on. All
they have _get_fd(), _get_events(), and _get_timeout().

Closes #34094.
2024-08-28 05:35:07 +09:00
Yu Watanabe d36d71cade test: use more suitable assertions 2024-08-28 05:35:07 +09:00
Yu Watanabe bbb7a0e6ed sd-varlink: make the argument type consistent with header 2024-08-28 05:35:07 +09:00
Yu Watanabe cd7c71154c sd-device: make sd_device_new_from_subsystem_sysname() stricter
As workarounded by fc0cbed2db, the pair of
subsystem and sysname is not unique. For examples,
- /sys/bus/gpio and /sys/class/gpio, both have gpiochip%N. However, these point to different devpaths.
- /sys/bus/mdio_bus and /sys/class/mdio_bus,
- /sys/bus/mei and /sys/class/mei,
- /sys/bus/typec and /sys/class/typec, and so on.

Let's refuse to provide sd_device object in such cases.
2024-08-28 05:26:08 +09:00
Yu Watanabe 1ff0164be5 sd-device: make device_get_device_id() public
We have already exposed sd_device_new_from_device_id(), but we have
never provide the way to get device ID from an existing sd_device
object.
2024-08-28 05:26:04 +09:00
Yu Watanabe 44bc6f3cab sd-device: introduce sd_device_get_driver_subsystem()
To create the sd_device object of a driver, the function
sd_device_new_from_subsystem_sysname() requires "drivers" for subsystem
and e.g. "pci:iwlwifi" for sysname. Similarly, sd_device_new_from_device_id()
also requires driver subsystem. However, we have never provided a
way to get the driver subsystem ("pci" for the previous example) from
an existing sd_device object.

Let's introduce a way to get driver subsystem.
2024-08-28 05:18:14 +09:00
Yu Watanabe 55e35a4d59 sd-device: refuse earlier when too long ifname is passed to sd_device_new_from_ifname()
Otherwise, alloca() called in strjoina() may trigger assertion.

This partially reverts 3652891c39.
The commit mistakenly dropped the check.
2024-08-28 05:18:14 +09:00