1
0
mirror of https://github.com/systemd/systemd synced 2026-03-14 09:04:47 +01:00

Compare commits

..

No commits in common. "84e492cdbad460f331c5b762876cb3043fbf6a3e" and "fd7d8bf105f122e5a6aa7b5dfff60e8a0b0f5b4e" have entirely different histories.

24 changed files with 731 additions and 986 deletions

View File

@ -13,7 +13,6 @@ ARGS=(
"--optimization=3 -Db_lto=true" "--optimization=3 -Db_lto=true"
"--optimization=3 -Db_lto=false" "--optimization=3 -Db_lto=false"
"--optimization=3 -Ddns-over-tls=openssl" "--optimization=3 -Ddns-over-tls=openssl"
"--optimization=3 -Dfexecve=true -Dstandalone-binaries=true -Dstatic-libsystemd=true -Dstatic-libudev=true"
"-Db_ndebug=true" "-Db_ndebug=true"
) )
PACKAGES=( PACKAGES=(

View File

@ -59,14 +59,14 @@ The "portable service" concept ultimately will not provide a fully isolated
environment to the payload, like containers mostly intend to. Instead they are environment to the payload, like containers mostly intend to. Instead they are
from the beginning more alike regular system services, can be controlled with from the beginning more alike regular system services, can be controlled with
the same tools, are exposed the same way in all infrastructure and so on. Their the same tools, are exposed the same way in all infrastructure and so on. Their
main difference is that they use a different root directory than the rest of the main difference is that the use a different root directory than the rest of the
system. Hence, the intention is not to run code in a different, isolated world system. Hence, the intention is not to run code in a different, isolated world
from the host — like most containers would do it — but to run it in the same from the host — like most containers would do it —, but to run it in the same
world, but with stricter access controls on what the service can see and do. world, but with stricter access controls on what the service can see and do.
As one point of differentiation: as programs run as "portable services" are As one point of differentiation: as programs run as "portable services" are
pretty much regular system services, they won't run as PID 1 (like Docker would pretty much regular system services, they won't run as PID 1 (like Docker would
do it), but as normal processes. A corollary of that is that they aren't supposed do it), but as normal process. A corollary of that is that they aren't supposed
to manage anything in their own environment (such as the network) as the to manage anything in their own environment (such as the network) as the
execution environment is mostly shared with the rest of the system. execution environment is mostly shared with the rest of the system.
@ -77,12 +77,12 @@ focus includes system extensions otherwise sometimes called "super-privileged
containers". containers".
Note that portable services are only available for system services, not for Note that portable services are only available for system services, not for
user services (i.e. the functionality cannot be used for the stuff user services. i.e. the functionality cannot be used for the stuff
bubblewrap/flatpak is focusing on). bubblewrap/flatpak is focusing on.
## Mode of Operation ## Mode of Operation
If you have a portable service image, maybe in a raw disk image called If you have portable service image, maybe in a raw disk image called
`foobar_0.7.23.raw`, then attaching the services to the host is as easy as: `foobar_0.7.23.raw`, then attaching the services to the host is as easy as:
``` ```
@ -135,7 +135,7 @@ This command does the following:
And that's already it. And that's already it.
Note that the images need to stay around (and in the same location) as long as the Note that the images need to stay around (and the same location) as long as the
portable service is attached. If an image is moved, the `RootImage=` line portable service is attached. If an image is moved, the `RootImage=` line
written to the unit drop-in would point to an non-existing place, and break the written to the unit drop-in would point to an non-existing place, and break the
logic. logic.
@ -144,7 +144,7 @@ The `portablectl detach` command executes the reverse operation: it looks for
the drop-ins and the unit files associated with the image, and removes them the drop-ins and the unit files associated with the image, and removes them
again. again.
Note that `portablectl attach` won't enable or start any of the units it copies Note that `portable attach` won't enable or start any of the units it copies
out. This still has to take place in a second, separate step. (That said We out. This still has to take place in a second, separate step. (That said We
might add options to do this automatically later on.). might add options to do this automatically later on.).
@ -223,7 +223,7 @@ read-only, immutable images (e.g. squashfs images) all files and directories to
over-mount must exist already. over-mount must exist already.
Note that as no new image format or metadata is defined, it's very Note that as no new image format or metadata is defined, it's very
straightforward to define images than can be made use of in a number of straight-forward to define images than can be made use of it a number of
different ways. For example, by using `mkosi -b` you can trivially build a different ways. For example, by using `mkosi -b` you can trivially build a
single, unified image that: single, unified image that:

View File

@ -505,7 +505,8 @@ sensor:modalias:acpi:BMA250E*:dmi:bvnLENOVO:*:pvrLenovoMIIX3-1030:*
sensor:modalias:acpi:SMO8500*:dmi:bvnLENOVO:*:pvrLenovoMIIX3-830:* sensor:modalias:acpi:SMO8500*:dmi:bvnLENOVO:*:pvrLenovoMIIX3-830:*
ACCEL_MOUNT_MATRIX=-1, 0, 0; 0, 1, 0; 0, 0, 1 ACCEL_MOUNT_MATRIX=-1, 0, 0; 0, 1, 0; 0, 0, 1
# IdeaPad D330-10IGM (both 81H3 and 81MD product numbers) # IdeaPad D330 and D330-10IGM
sensor:modalias:acpi:BOSC0200*:dmi:*:svnLENOVO:pn81H3:*
sensor:modalias:acpi:BOSC0200*:dmi:*:svnLENOVO:*:cvrLenovoideapadD330-10IGM:* sensor:modalias:acpi:BOSC0200*:dmi:*:svnLENOVO:*:cvrLenovoideapadD330-10IGM:*
ACCEL_MOUNT_MATRIX=0, 1, 0; -1, 0, 0; 0, 0, 1 ACCEL_MOUNT_MATRIX=0, 1, 0; -1, 0, 0; 0, 0, 1

File diff suppressed because it is too large Load Diff

View File

@ -301,7 +301,7 @@ def print_summary(fname, groups):
error('{}: no matches or props'.format(fname)) error('{}: no matches or props'.format(fname))
if __name__ == '__main__': if __name__ == '__main__':
args = sys.argv[1:] or sorted(glob.glob(os.path.dirname(sys.argv[0]) + '/[678][0-9]-*.hwdb')) args = sys.argv[1:] or sorted(glob.glob(os.path.dirname(sys.argv[0]) + '/[67][0-9]-*.hwdb'))
for fname in args: for fname in args:
groups = parse(fname) groups = parse(fname)

View File

@ -237,19 +237,6 @@
cannot be written. Currently only applies to random seed operations.</para></listitem> cannot be written. Currently only applies to random seed operations.</para></listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term><option>--make-machine-id-directory=yes|no|auto</option></term>
<listitem><para>Control creation and deletion of <literal>$ESP/$MACHINE_ID</literal> during
<option>install</option> and <option>remove</option>, respectively.
<literal>auto</literal> is equivalent to to <literal>yes</literal> if <literal>/etc/machine-id</literal>
resides on a filesystem other than tmpfs and <literal>no</literal> otherwise.
Defaults to <literal>auto</literal>.</para>
<para>Overriding this may be desired to hide the machine ID from the (unencrypted) ESP,
configure a <citerefentry><refentrytitle>kernel-install</refentrytitle><manvolnum>8</manvolnum></citerefentry> script, or,
conversely, commit a machine-id that only appears transient.</para></listitem>
</varlistentry>
<xi:include href="standard-options.xml" xpointer="no-pager"/> <xi:include href="standard-options.xml" xpointer="no-pager"/>
<xi:include href="standard-options.xml" xpointer="help"/> <xi:include href="standard-options.xml" xpointer="help"/>
<xi:include href="standard-options.xml" xpointer="version"/> <xi:include href="standard-options.xml" xpointer="version"/>

View File

@ -722,7 +722,7 @@ if time_epoch == -1
if time_epoch == '' and git.found() and run_command('test', '-e', '.git').returncode() == 0 if time_epoch == '' and git.found() and run_command('test', '-e', '.git').returncode() == 0
# If we're in a git repository, use the creation time of the latest git tag. # If we're in a git repository, use the creation time of the latest git tag.
latest_tag = run_command('git', 'describe', '--abbrev=0', '--tags').stdout().strip() latest_tag = run_command('git', 'describe', '--abbrev=0', '--tags').stdout().strip()
time_epoch = run_command('git', 'log', '--no-show-signature', '-1', '--format=%at', latest_tag).stdout() time_epoch = run_command('git', 'log', '-1', '--format=%at', latest_tag).stdout()
endif endif
if time_epoch == '' if time_epoch == ''
NEWS = files('NEWS') NEWS = files('NEWS')

View File

@ -49,6 +49,11 @@ SUBSYSTEM=="sound", GROUP="audio", \
SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", MODE="0664" SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", MODE="0664"
SUBSYSTEM=="firewire", ATTR{units}=="*0x00a02d:0x00010*", GROUP="video"
SUBSYSTEM=="firewire", ATTR{units}=="*0x00b09d:0x00010*", GROUP="video"
SUBSYSTEM=="firewire", ATTR{units}=="*0x00a02d:0x010001*", GROUP="video"
SUBSYSTEM=="firewire", ATTR{units}=="*0x00a02d:0x014001*", GROUP="video"
SUBSYSTEM=="firewire", TEST=="units", TEST=="model", \ SUBSYSTEM=="firewire", TEST=="units", TEST=="model", \
IMPORT{builtin}="hwdb 'ieee1394:node:ven$attr{vendor}mo$attr{model}units$attr{units}'" IMPORT{builtin}="hwdb 'ieee1394:node:ven$attr{vendor}mo$attr{model}units$attr{units}'"

View File

@ -1431,9 +1431,10 @@ int log_syntax_invalid_utf8_internal(
if (rvalue) if (rvalue)
p = utf8_escape_invalid(rvalue); p = utf8_escape_invalid(rvalue);
return log_syntax_internal(unit, level, config_file, config_line, log_syntax_internal(unit, level, config_file, config_line, 0, file, line, func,
SYNTHETIC_ERRNO(EINVAL), file, line, func, "String is not UTF-8 clean, ignoring assignment: %s", strna(p));
"String is not UTF-8 clean, ignoring assignment: %s", strna(p));
return -EINVAL;
} }
void log_set_upgrade_syslog_to_journal(bool b) { void log_set_upgrade_syslog_to_journal(bool b) {

View File

@ -1278,8 +1278,8 @@ int get_timezones(char ***ret) {
f = fopen("/usr/share/zoneinfo/zone1970.tab", "re"); f = fopen("/usr/share/zoneinfo/zone1970.tab", "re");
if (f) { if (f) {
for (;;) { for (;;) {
_cleanup_free_ char *line = NULL, *w = NULL; _cleanup_free_ char *line = NULL;
char *p; char *p, *w;
size_t k; size_t k;
r = read_line(f, LONG_LINE_MAX, &line); r = read_line(f, LONG_LINE_MAX, &line);
@ -1310,10 +1310,12 @@ int get_timezones(char ***ret) {
if (!w) if (!w)
return -ENOMEM; return -ENOMEM;
if (!GREEDY_REALLOC(zones, n_allocated, n_zones + 2)) if (!GREEDY_REALLOC(zones, n_allocated, n_zones + 2)) {
free(w);
return -ENOMEM; return -ENOMEM;
}
zones[n_zones++] = TAKE_PTR(w); zones[n_zones++] = w;
zones[n_zones] = NULL; zones[n_zones] = NULL;
} }

View File

@ -72,7 +72,7 @@ int unit_validate_alias_symlink_and_warn(const char *filename, const char *targe
const char *src, *dst; const char *src, *dst;
_cleanup_free_ char *src_instance = NULL, *dst_instance = NULL; _cleanup_free_ char *src_instance = NULL, *dst_instance = NULL;
UnitType src_unit_type, dst_unit_type; UnitType src_unit_type, dst_unit_type;
UnitNameFlags src_name_type, dst_name_type; int src_name_type, dst_name_type;
/* Check if the *alias* symlink is valid. This applies to symlinks like /* Check if the *alias* symlink is valid. This applies to symlinks like
* /etc/systemd/system/dbus.service dbus-broker.service, but not to .wants or .requires symlinks * /etc/systemd/system/dbus.service dbus-broker.service, but not to .wants or .requires symlinks

View File

@ -139,7 +139,7 @@ int unit_name_to_prefix(const char *n, char **ret) {
return 0; return 0;
} }
UnitNameFlags unit_name_to_instance(const char *n, char **ret) { int unit_name_to_instance(const char *n, char **ret) {
const char *p, *d; const char *p, *d;
assert(n); assert(n);

View File

@ -22,8 +22,8 @@ bool unit_instance_is_valid(const char *i) _pure_;
bool unit_suffix_is_valid(const char *s) _pure_; bool unit_suffix_is_valid(const char *s) _pure_;
int unit_name_to_prefix(const char *n, char **ret); int unit_name_to_prefix(const char *n, char **ret);
UnitNameFlags unit_name_to_instance(const char *n, char **ret); int unit_name_to_instance(const char *n, char **ret);
static inline UnitNameFlags unit_name_classify(const char *n) { static inline int unit_name_classify(const char *n) {
return unit_name_to_instance(n, NULL); return unit_name_to_instance(n, NULL);
} }
int unit_name_to_prefix_and_instance(const char *n, char **ret); int unit_name_to_prefix_and_instance(const char *n, char **ret);

View File

@ -29,7 +29,6 @@
#include "main-func.h" #include "main-func.h"
#include "mkdir.h" #include "mkdir.h"
#include "pager.h" #include "pager.h"
#include "parse-argument.h"
#include "parse-util.h" #include "parse-util.h"
#include "pretty-print.h" #include "pretty-print.h"
#include "random-util.h" #include "random-util.h"
@ -53,7 +52,6 @@ static bool arg_print_dollar_boot_path = false;
static bool arg_touch_variables = true; static bool arg_touch_variables = true;
static PagerFlags arg_pager_flags = 0; static PagerFlags arg_pager_flags = 0;
static bool arg_graceful = false; static bool arg_graceful = false;
static int arg_make_machine_id_directory = -1;
STATIC_DESTRUCTOR_REGISTER(arg_esp_path, freep); STATIC_DESTRUCTOR_REGISTER(arg_esp_path, freep);
STATIC_DESTRUCTOR_REGISTER(arg_xbootldr_path, freep); STATIC_DESTRUCTOR_REGISTER(arg_xbootldr_path, freep);
@ -114,19 +112,6 @@ static int acquire_xbootldr(bool unprivileged_mode, sd_id128_t *ret_uuid) {
return 1; return 1;
} }
static void settle_make_machine_id_directory(void) {
int r;
if (arg_make_machine_id_directory >= 0)
return;
r = path_is_temporary_fs("/etc/machine-id");
if (r < 0)
log_debug_errno(r, "Couldn't determine whether /etc/machine-id is on a temporary file system, assuming so.");
arg_make_machine_id_directory = r == 0;
}
/* search for "#### LoaderInfo: systemd-boot 218 ####" string inside the binary */ /* search for "#### LoaderInfo: systemd-boot 218 ####" string inside the binary */
static int get_file_version(int fd, char **v) { static int get_file_version(int fd, char **v) {
struct stat st; struct stat st;
@ -903,24 +888,6 @@ static int remove_subdirs(const char *root, const char *const *subdirs) {
return r < 0 ? r : q; return r < 0 ? r : q;
} }
static int remove_machine_id_directory(const char *root) {
sd_id128_t machine_id;
char buf[SD_ID128_STRING_MAX];
int r;
assert(root);
assert(arg_make_machine_id_directory >= 0);
if (!arg_make_machine_id_directory)
return 0;
r = sd_id128_get_machine(&machine_id);
if (r < 0)
return log_error_errno(r, "Failed to get machine id: %m");
return rmdir_one(root, sd_id128_to_string(machine_id, buf));
}
static int remove_binaries(const char *esp_path) { static int remove_binaries(const char *esp_path) {
const char *p; const char *p;
int r, q; int r, q;
@ -1007,13 +974,9 @@ static int install_loader_config(const char *esp_path) {
_cleanup_(unlink_and_freep) char *t = NULL; _cleanup_(unlink_and_freep) char *t = NULL;
_cleanup_fclose_ FILE *f = NULL; _cleanup_fclose_ FILE *f = NULL;
_cleanup_close_ int fd = -1; _cleanup_close_ int fd = -1;
sd_id128_t machine_id;
char machine_string[SD_ID128_STRING_MAX];
const char *p; const char *p;
int r; int r;
assert(arg_make_machine_id_directory >= 0);
p = prefix_roota(esp_path, "/loader/loader.conf"); p = prefix_roota(esp_path, "/loader/loader.conf");
if (access(p, F_OK) >= 0) /* Silently skip creation if the file already exists (early check) */ if (access(p, F_OK) >= 0) /* Silently skip creation if the file already exists (early check) */
return 0; return 0;
@ -1028,13 +991,6 @@ static int install_loader_config(const char *esp_path) {
fprintf(f, "#timeout 3\n" fprintf(f, "#timeout 3\n"
"#console-mode keep\n"); "#console-mode keep\n");
if (arg_make_machine_id_directory) {
r = sd_id128_get_machine(&machine_id);
if (r < 0)
return log_error_errno(r, "Failed to get machine id: %m");
fprintf(f, "default %s-*\n", sd_id128_to_string(machine_id, machine_string));
}
r = fflush_sync_and_check(f); r = fflush_sync_and_check(f);
if (r < 0) if (r < 0)
@ -1050,24 +1006,6 @@ static int install_loader_config(const char *esp_path) {
return 1; return 1;
} }
static int install_machine_id_directory(const char *root) {
sd_id128_t machine_id;
char buf[SD_ID128_STRING_MAX];
int r;
assert(root);
assert(arg_make_machine_id_directory >= 0);
if (!arg_make_machine_id_directory)
return 0;
r = sd_id128_get_machine(&machine_id);
if (r < 0)
return log_error_errno(r, "Failed to get machine id: %m");
return mkdir_one(root, sd_id128_to_string(machine_id, buf));
}
static int help(int argc, char *argv[], void *userdata) { static int help(int argc, char *argv[], void *userdata) {
_cleanup_free_ char *link = NULL; _cleanup_free_ char *link = NULL;
int r; int r;
@ -1105,8 +1043,6 @@ static int help(int argc, char *argv[], void *userdata) {
" --no-pager Do not pipe output into a pager\n" " --no-pager Do not pipe output into a pager\n"
" --graceful Don't fail when the ESP cannot be found or EFI\n" " --graceful Don't fail when the ESP cannot be found or EFI\n"
" variables cannot be written\n" " variables cannot be written\n"
" --make-machine-id-directory=yes|no|auto\n"
" Create $BOOT/$MACHINE_ID\n"
"\nSee the %2$s for details.\n", "\nSee the %2$s for details.\n",
program_invocation_short_name, program_invocation_short_name,
link, link,
@ -1126,27 +1062,24 @@ static int parse_argv(int argc, char *argv[]) {
ARG_NO_VARIABLES, ARG_NO_VARIABLES,
ARG_NO_PAGER, ARG_NO_PAGER,
ARG_GRACEFUL, ARG_GRACEFUL,
ARG_MAKE_MACHINE_ID_DIRECTORY,
}; };
static const struct option options[] = { static const struct option options[] = {
{ "help", no_argument, NULL, 'h' }, { "help", no_argument, NULL, 'h' },
{ "version", no_argument, NULL, ARG_VERSION }, { "version", no_argument, NULL, ARG_VERSION },
{ "esp-path", required_argument, NULL, ARG_ESP_PATH }, { "esp-path", required_argument, NULL, ARG_ESP_PATH },
{ "path", required_argument, NULL, ARG_ESP_PATH }, /* Compatibility alias */ { "path", required_argument, NULL, ARG_ESP_PATH }, /* Compatibility alias */
{ "boot-path", required_argument, NULL, ARG_BOOT_PATH }, { "boot-path", required_argument, NULL, ARG_BOOT_PATH },
{ "print-esp-path", no_argument, NULL, 'p' }, { "print-esp-path", no_argument, NULL, 'p' },
{ "print-path", no_argument, NULL, 'p' }, /* Compatibility alias */ { "print-path", no_argument, NULL, 'p' }, /* Compatibility alias */
{ "print-boot-path", no_argument, NULL, 'x' }, { "print-boot-path", no_argument, NULL, 'x' },
{ "no-variables", no_argument, NULL, ARG_NO_VARIABLES }, { "no-variables", no_argument, NULL, ARG_NO_VARIABLES },
{ "no-pager", no_argument, NULL, ARG_NO_PAGER }, { "no-pager", no_argument, NULL, ARG_NO_PAGER },
{ "graceful", no_argument, NULL, ARG_GRACEFUL }, { "graceful", no_argument, NULL, ARG_GRACEFUL },
{ "make-machine-id-directory", required_argument, NULL, ARG_MAKE_MACHINE_ID_DIRECTORY },
{} {}
}; };
int c, r; int c, r;
bool b;
assert(argc >= 0); assert(argc >= 0);
assert(argv); assert(argv);
@ -1199,17 +1132,6 @@ static int parse_argv(int argc, char *argv[]) {
arg_graceful = true; arg_graceful = true;
break; break;
case ARG_MAKE_MACHINE_ID_DIRECTORY:
if (streq(optarg, "auto"))
arg_make_machine_id_directory = -1; /* default */
else {
r = parse_boolean_argument("--make-machine-id-directory=", optarg, &b);
if (r < 0)
return r;
arg_make_machine_id_directory = b;
}
break;
case '?': case '?':
return -EINVAL; return -EINVAL;
@ -1608,8 +1530,6 @@ static int verb_install(int argc, char *argv[], void *userdata) {
if (r < 0) if (r < 0)
return r; return r;
settle_make_machine_id_directory();
install = streq(argv[0], "install"); install = streq(argv[0], "install");
RUN_WITH_UMASK(0002) { RUN_WITH_UMASK(0002) {
@ -1635,10 +1555,6 @@ static int verb_install(int argc, char *argv[], void *userdata) {
if (r < 0) if (r < 0)
return r; return r;
r = install_machine_id_directory(arg_dollar_boot_path());
if (r < 0)
return r;
r = install_random_seed(arg_esp_path); r = install_random_seed(arg_esp_path);
if (r < 0) if (r < 0)
return r; return r;
@ -1668,8 +1584,6 @@ static int verb_remove(int argc, char *argv[], void *userdata) {
if (r < 0) if (r < 0)
return r; return r;
settle_make_machine_id_directory();
r = remove_binaries(arg_esp_path); r = remove_binaries(arg_esp_path);
q = remove_file(arg_esp_path, "/loader/loader.conf"); q = remove_file(arg_esp_path, "/loader/loader.conf");
@ -1688,19 +1602,11 @@ static int verb_remove(int argc, char *argv[], void *userdata) {
if (q < 0 && r >= 0) if (q < 0 && r >= 0)
r = q; r = q;
q = remove_machine_id_directory(arg_esp_path);
if (q < 0 && r >= 0)
r = 1;
if (arg_xbootldr_path) { if (arg_xbootldr_path) {
/* Remove the latter two also in the XBOOTLDR partition if it exists */ /* Remove the latter two also in the XBOOTLDR partition if it exists */
q = remove_subdirs(arg_xbootldr_path, dollar_boot_subdirs); q = remove_subdirs(arg_xbootldr_path, dollar_boot_subdirs);
if (q < 0 && r >= 0) if (q < 0 && r >= 0)
r = q; r = q;
q = remove_machine_id_directory(arg_xbootldr_path);
if (q < 0 && r >= 0)
r = q;
} }
(void) sync_everything(); (void) sync_everything();

View File

@ -2213,14 +2213,14 @@ int config_parse_service_sockets(
_cleanup_free_ char *word = NULL, *k = NULL; _cleanup_free_ char *word = NULL, *k = NULL;
r = extract_first_word(&p, &word, NULL, 0); r = extract_first_word(&p, &word, NULL, 0);
if (r == 0)
return 0;
if (r == -ENOMEM) if (r == -ENOMEM)
return log_oom(); return log_oom();
if (r < 0) { if (r < 0) {
log_syntax(unit, LOG_WARNING, filename, line, r, "Trailing garbage in sockets, ignoring: %s", rvalue); log_syntax(unit, LOG_WARNING, filename, line, r, "Trailing garbage in sockets, ignoring: %s", rvalue);
return 0; return 0;
} }
if (r == 0)
return 0;
r = unit_name_printf(UNIT(s), word, &k); r = unit_name_printf(UNIT(s), word, &k);
if (r < 0) { if (r < 0) {
@ -2488,14 +2488,14 @@ int config_parse_user_group_strv_compat(
_cleanup_free_ char *word = NULL, *k = NULL; _cleanup_free_ char *word = NULL, *k = NULL;
r = extract_first_word(&p, &word, NULL, 0); r = extract_first_word(&p, &word, NULL, 0);
if (r == 0)
return 0;
if (r == -ENOMEM) if (r == -ENOMEM)
return log_oom(); return log_oom();
if (r < 0) { if (r < 0) {
log_syntax(unit, LOG_ERR, filename, line, r, "Invalid syntax: %s", rvalue); log_syntax(unit, LOG_ERR, filename, line, r, "Invalid syntax: %s", rvalue);
return -ENOEXEC; return -ENOEXEC;
} }
if (r == 0)
return 0;
r = unit_full_printf(u, word, &k); r = unit_full_printf(u, word, &k);
if (r < 0) { if (r < 0) {
@ -2654,6 +2654,8 @@ int config_parse_environ(
_cleanup_free_ char *word = NULL, *resolved = NULL; _cleanup_free_ char *word = NULL, *resolved = NULL;
r = extract_first_word(&p, &word, NULL, EXTRACT_CUNESCAPE|EXTRACT_UNQUOTE); r = extract_first_word(&p, &word, NULL, EXTRACT_CUNESCAPE|EXTRACT_UNQUOTE);
if (r == 0)
return 0;
if (r == -ENOMEM) if (r == -ENOMEM)
return log_oom(); return log_oom();
if (r < 0) { if (r < 0) {
@ -2661,8 +2663,6 @@ int config_parse_environ(
"Invalid syntax, ignoring: %s", rvalue); "Invalid syntax, ignoring: %s", rvalue);
return 0; return 0;
} }
if (r == 0)
return 0;
if (u) { if (u) {
r = unit_full_printf(u, word, &resolved); r = unit_full_printf(u, word, &resolved);
@ -2719,6 +2719,8 @@ int config_parse_pass_environ(
_cleanup_free_ char *word = NULL, *k = NULL; _cleanup_free_ char *word = NULL, *k = NULL;
r = extract_first_word(&p, &word, NULL, EXTRACT_UNQUOTE); r = extract_first_word(&p, &word, NULL, EXTRACT_UNQUOTE);
if (r == 0)
break;
if (r == -ENOMEM) if (r == -ENOMEM)
return log_oom(); return log_oom();
if (r < 0) { if (r < 0) {
@ -2726,8 +2728,6 @@ int config_parse_pass_environ(
"Trailing garbage in %s, ignoring: %s", lvalue, rvalue); "Trailing garbage in %s, ignoring: %s", lvalue, rvalue);
break; break;
} }
if (r == 0)
break;
if (u) { if (u) {
r = unit_full_printf(u, word, &k); r = unit_full_printf(u, word, &k);
@ -2794,6 +2794,8 @@ int config_parse_unset_environ(
_cleanup_free_ char *word = NULL, *k = NULL; _cleanup_free_ char *word = NULL, *k = NULL;
r = extract_first_word(&p, &word, NULL, EXTRACT_CUNESCAPE|EXTRACT_UNQUOTE); r = extract_first_word(&p, &word, NULL, EXTRACT_CUNESCAPE|EXTRACT_UNQUOTE);
if (r == 0)
break;
if (r == -ENOMEM) if (r == -ENOMEM)
return log_oom(); return log_oom();
if (r < 0) { if (r < 0) {
@ -2801,8 +2803,6 @@ int config_parse_unset_environ(
"Trailing garbage in %s, ignoring: %s", lvalue, rvalue); "Trailing garbage in %s, ignoring: %s", lvalue, rvalue);
break; break;
} }
if (r == 0)
break;
if (u) { if (u) {
r = unit_full_printf(u, word, &k); r = unit_full_printf(u, word, &k);
@ -2868,14 +2868,14 @@ int config_parse_log_extra_fields(
const char *eq; const char *eq;
r = extract_first_word(&p, &word, NULL, EXTRACT_CUNESCAPE|EXTRACT_UNQUOTE); r = extract_first_word(&p, &word, NULL, EXTRACT_CUNESCAPE|EXTRACT_UNQUOTE);
if (r == 0)
return 0;
if (r == -ENOMEM) if (r == -ENOMEM)
return log_oom(); return log_oom();
if (r < 0) { if (r < 0) {
log_syntax(unit, LOG_WARNING, filename, line, r, "Invalid syntax, ignoring: %s", rvalue); log_syntax(unit, LOG_WARNING, filename, line, r, "Invalid syntax, ignoring: %s", rvalue);
return 0; return 0;
} }
if (r == 0)
return 0;
r = unit_full_printf(u, word, &k); r = unit_full_printf(u, word, &k);
if (r < 0) { if (r < 0) {
@ -3080,6 +3080,8 @@ int config_parse_unit_requires_mounts_for(
_cleanup_free_ char *word = NULL, *resolved = NULL; _cleanup_free_ char *word = NULL, *resolved = NULL;
r = extract_first_word(&p, &word, NULL, EXTRACT_UNQUOTE); r = extract_first_word(&p, &word, NULL, EXTRACT_UNQUOTE);
if (r == 0)
return 0;
if (r == -ENOMEM) if (r == -ENOMEM)
return log_oom(); return log_oom();
if (r < 0) { if (r < 0) {
@ -3087,8 +3089,6 @@ int config_parse_unit_requires_mounts_for(
"Invalid syntax, ignoring: %s", rvalue); "Invalid syntax, ignoring: %s", rvalue);
return 0; return 0;
} }
if (r == 0)
return 0;
r = unit_full_printf(u, word, &resolved); r = unit_full_printf(u, word, &resolved);
if (r < 0) { if (r < 0) {
@ -3218,6 +3218,8 @@ int config_parse_syscall_filter(
int num; int num;
r = extract_first_word(&p, &word, NULL, 0); r = extract_first_word(&p, &word, NULL, 0);
if (r == 0)
return 0;
if (r == -ENOMEM) if (r == -ENOMEM)
return log_oom(); return log_oom();
if (r < 0) { if (r < 0) {
@ -3225,8 +3227,6 @@ int config_parse_syscall_filter(
"Invalid syntax, ignoring: %s", rvalue); "Invalid syntax, ignoring: %s", rvalue);
return 0; return 0;
} }
if (r == 0)
return 0;
r = parse_syscall_and_errno(word, &name, &num); r = parse_syscall_and_errno(word, &name, &num);
if (r < 0) { if (r < 0) {
@ -3304,14 +3304,14 @@ int config_parse_syscall_log(
_cleanup_free_ char *word = NULL; _cleanup_free_ char *word = NULL;
r = extract_first_word(&p, &word, NULL, 0); r = extract_first_word(&p, &word, NULL, 0);
if (r == 0)
return 0;
if (r == -ENOMEM) if (r == -ENOMEM)
return log_oom(); return log_oom();
if (r < 0) { if (r < 0) {
log_syntax(unit, LOG_WARNING, filename, line, r, "Invalid syntax, ignoring: %s", rvalue); log_syntax(unit, LOG_WARNING, filename, line, r, "Invalid syntax, ignoring: %s", rvalue);
return 0; return 0;
} }
if (r == 0)
return 0;
r = seccomp_parse_syscall_filter( r = seccomp_parse_syscall_filter(
word, -1, c->syscall_log, word, -1, c->syscall_log,
@ -3349,6 +3349,8 @@ int config_parse_syscall_archs(
uint32_t a; uint32_t a;
r = extract_first_word(&p, &word, NULL, EXTRACT_UNQUOTE); r = extract_first_word(&p, &word, NULL, EXTRACT_UNQUOTE);
if (r == 0)
return 0;
if (r == -ENOMEM) if (r == -ENOMEM)
return log_oom(); return log_oom();
if (r < 0) { if (r < 0) {
@ -3356,8 +3358,6 @@ int config_parse_syscall_archs(
"Invalid syntax, ignoring: %s", rvalue); "Invalid syntax, ignoring: %s", rvalue);
return 0; return 0;
} }
if (r == 0)
return 0;
r = seccomp_arch_from_string(word, &a); r = seccomp_arch_from_string(word, &a);
if (r < 0) { if (r < 0) {
@ -3463,6 +3463,8 @@ int config_parse_address_families(
int af; int af;
r = extract_first_word(&p, &word, NULL, EXTRACT_UNQUOTE); r = extract_first_word(&p, &word, NULL, EXTRACT_UNQUOTE);
if (r == 0)
return 0;
if (r == -ENOMEM) if (r == -ENOMEM)
return log_oom(); return log_oom();
if (r < 0) { if (r < 0) {
@ -3470,8 +3472,6 @@ int config_parse_address_families(
"Invalid syntax, ignoring: %s", rvalue); "Invalid syntax, ignoring: %s", rvalue);
return 0; return 0;
} }
if (r == 0)
return 0;
af = af_from_name(word); af = af_from_name(word);
if (af < 0) { if (af < 0) {
@ -3821,14 +3821,14 @@ int config_parse_delegate(
CGroupController cc; CGroupController cc;
r = extract_first_word(&p, &word, NULL, EXTRACT_UNQUOTE); r = extract_first_word(&p, &word, NULL, EXTRACT_UNQUOTE);
if (r == 0)
break;
if (r == -ENOMEM) if (r == -ENOMEM)
return log_oom(); return log_oom();
if (r < 0) { if (r < 0) {
log_syntax(unit, LOG_WARNING, filename, line, r, "Invalid syntax, ignoring: %s", rvalue); log_syntax(unit, LOG_WARNING, filename, line, r, "Invalid syntax, ignoring: %s", rvalue);
return 0; return 0;
} }
if (r == 0)
break;
cc = cgroup_controller_from_string(word); cc = cgroup_controller_from_string(word);
if (cc < 0) { if (cc < 0) {
@ -3954,8 +3954,13 @@ int config_parse_device_allow(
r = extract_first_word(&p, &path, NULL, EXTRACT_UNQUOTE); r = extract_first_word(&p, &path, NULL, EXTRACT_UNQUOTE);
if (r == -ENOMEM) if (r == -ENOMEM)
return log_oom(); return log_oom();
if (r <= 0) { if (r < 0) {
log_syntax(unit, LOG_WARNING, filename, line, r, log_syntax(unit, LOG_WARNING, filename, line, r,
"Invalid syntax, ignoring: %s", rvalue);
return 0;
}
if (r == 0) {
log_syntax(unit, LOG_WARNING, filename, line, 0,
"Failed to extract device path and rights from '%s', ignoring.", rvalue); "Failed to extract device path and rights from '%s', ignoring.", rvalue);
return 0; return 0;
} }
@ -4020,8 +4025,13 @@ int config_parse_io_device_weight(
r = extract_first_word(&p, &path, NULL, EXTRACT_UNQUOTE); r = extract_first_word(&p, &path, NULL, EXTRACT_UNQUOTE);
if (r == -ENOMEM) if (r == -ENOMEM)
return log_oom(); return log_oom();
if (r <= 0 || isempty(p)) { if (r < 0) {
log_syntax(unit, LOG_WARNING, filename, line, r, log_syntax(unit, LOG_WARNING, filename, line, r,
"Invalid syntax, ignoring: %s", rvalue);
return 0;
}
if (r == 0 || isempty(p)) {
log_syntax(unit, LOG_WARNING, filename, line, 0,
"Failed to extract device path and weight from '%s', ignoring.", rvalue); "Failed to extract device path and weight from '%s', ignoring.", rvalue);
return 0; return 0;
} }
@ -4089,8 +4099,13 @@ int config_parse_io_device_latency(
r = extract_first_word(&p, &path, NULL, EXTRACT_UNQUOTE); r = extract_first_word(&p, &path, NULL, EXTRACT_UNQUOTE);
if (r == -ENOMEM) if (r == -ENOMEM)
return log_oom(); return log_oom();
if (r <= 0 || isempty(p)) { if (r < 0) {
log_syntax(unit, LOG_WARNING, filename, line, r, log_syntax(unit, LOG_WARNING, filename, line, r,
"Invalid syntax, ignoring: %s", rvalue);
return 0;
}
if (r == 0 || isempty(p)) {
log_syntax(unit, LOG_WARNING, filename, line, 0,
"Failed to extract device path and latency from '%s', ignoring.", rvalue); "Failed to extract device path and latency from '%s', ignoring.", rvalue);
return 0; return 0;
} }
@ -4159,8 +4174,13 @@ int config_parse_io_limit(
r = extract_first_word(&p, &path, NULL, EXTRACT_UNQUOTE); r = extract_first_word(&p, &path, NULL, EXTRACT_UNQUOTE);
if (r == -ENOMEM) if (r == -ENOMEM)
return log_oom(); return log_oom();
if (r <= 0 || isempty(p)) { if (r < 0) {
log_syntax(unit, LOG_WARNING, filename, line, r, log_syntax(unit, LOG_WARNING, filename, line, r,
"Invalid syntax, ignoring: %s", rvalue);
return 0;
}
if (r == 0 || isempty(p)) {
log_syntax(unit, LOG_WARNING, filename, line, 0,
"Failed to extract device node and bandwidth from '%s', ignoring.", rvalue); "Failed to extract device node and bandwidth from '%s', ignoring.", rvalue);
return 0; return 0;
} }
@ -4245,8 +4265,13 @@ int config_parse_blockio_device_weight(
r = extract_first_word(&p, &path, NULL, EXTRACT_UNQUOTE); r = extract_first_word(&p, &path, NULL, EXTRACT_UNQUOTE);
if (r == -ENOMEM) if (r == -ENOMEM)
return log_oom(); return log_oom();
if (r <= 0 || isempty(p)) { if (r < 0) {
log_syntax(unit, LOG_WARNING, filename, line, r, log_syntax(unit, LOG_WARNING, filename, line, r,
"Invalid syntax, ignoring: %s", rvalue);
return 0;
}
if (r == 0 || isempty(p)) {
log_syntax(unit, LOG_WARNING, filename, line, 0,
"Failed to extract device node and weight from '%s', ignoring.", rvalue); "Failed to extract device node and weight from '%s', ignoring.", rvalue);
return 0; return 0;
} }
@ -4318,8 +4343,13 @@ int config_parse_blockio_bandwidth(
r = extract_first_word(&p, &path, NULL, EXTRACT_UNQUOTE); r = extract_first_word(&p, &path, NULL, EXTRACT_UNQUOTE);
if (r == -ENOMEM) if (r == -ENOMEM)
return log_oom(); return log_oom();
if (r <= 0 || isempty(p)) { if (r < 0) {
log_syntax(unit, LOG_WARNING, filename, line, r, log_syntax(unit, LOG_WARNING, filename, line, r,
"Invalid syntax, ignoring: %s", rvalue);
return 0;
}
if (r == 0 || isempty(p)) {
log_syntax(unit, LOG_WARNING, filename, line, 0,
"Failed to extract device node and bandwidth from '%s', ignoring.", rvalue); "Failed to extract device node and bandwidth from '%s', ignoring.", rvalue);
return 0; return 0;
} }
@ -4721,14 +4751,14 @@ int config_parse_namespace_path_strv(
bool ignore_enoent = false, shall_prefix = false; bool ignore_enoent = false, shall_prefix = false;
r = extract_first_word(&p, &word, NULL, EXTRACT_UNQUOTE); r = extract_first_word(&p, &word, NULL, EXTRACT_UNQUOTE);
if (r == 0)
break;
if (r == -ENOMEM) if (r == -ENOMEM)
return log_oom(); return log_oom();
if (r < 0) { if (r < 0) {
log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to extract first word, ignoring: %s", rvalue); log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to extract first word, ignoring: %s", rvalue);
return 0; return 0;
} }
if (r == 0)
break;
w = word; w = word;
if (startswith(w, "-")) { if (startswith(w, "-")) {
@ -4798,14 +4828,14 @@ int config_parse_temporary_filesystems(
const char *w; const char *w;
r = extract_first_word(&p, &word, NULL, EXTRACT_UNQUOTE); r = extract_first_word(&p, &word, NULL, EXTRACT_UNQUOTE);
if (r == 0)
return 0;
if (r == -ENOMEM) if (r == -ENOMEM)
return log_oom(); return log_oom();
if (r < 0) { if (r < 0) {
log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to extract first word, ignoring: %s", rvalue); log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to extract first word, ignoring: %s", rvalue);
return 0; return 0;
} }
if (r == 0)
return 0;
w = word; w = word;
r = extract_first_word(&w, &path, ":", EXTRACT_DONT_COALESCE_SEPARATORS); r = extract_first_word(&w, &path, ":", EXTRACT_DONT_COALESCE_SEPARATORS);
@ -4872,14 +4902,14 @@ int config_parse_bind_paths(
bool rbind = true, ignore_enoent = false; bool rbind = true, ignore_enoent = false;
r = extract_first_word(&p, &source, ":" WHITESPACE, EXTRACT_UNQUOTE|EXTRACT_DONT_COALESCE_SEPARATORS); r = extract_first_word(&p, &source, ":" WHITESPACE, EXTRACT_UNQUOTE|EXTRACT_DONT_COALESCE_SEPARATORS);
if (r == 0)
break;
if (r == -ENOMEM) if (r == -ENOMEM)
return log_oom(); return log_oom();
if (r < 0) { if (r < 0) {
log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse %s, ignoring: %s", lvalue, rvalue); log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse %s, ignoring: %s", lvalue, rvalue);
return 0; return 0;
} }
if (r == 0)
break;
r = unit_full_printf(u, source, &sresolved); r = unit_full_printf(u, source, &sresolved);
if (r < 0) { if (r < 0) {
@ -5600,7 +5630,7 @@ int config_parse_bpf_foreign_program(
r = extract_first_word(&rvalue, &word, ":", 0); r = extract_first_word(&rvalue, &word, ":", 0);
if (r == -ENOMEM) if (r == -ENOMEM)
return log_oom(); return log_oom();
if (r <= 0 || isempty(rvalue)) { if (r < 0) {
log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse foreign BPF program, ignoring: %s", rvalue); log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse foreign BPF program, ignoring: %s", rvalue);
return 0; return 0;
} }
@ -5640,11 +5670,11 @@ int config_parse_cgroup_socket_bind(
void *data, void *data,
void *userdata) { void *userdata) {
_cleanup_free_ CGroupSocketBindItem *item = NULL; _cleanup_free_ CGroupSocketBindItem *item = NULL;
const char *user_port; const char *address_family = NULL, *user_port;
uint16_t nr_ports = 0, port_min = 0; uint16_t nr_ports = 0, port_min = 0;
CGroupSocketBindItem **head = data; CGroupSocketBindItem **head = data;
_cleanup_free_ char *word = NULL; _cleanup_free_ char *word = NULL;
int af, r; int af = AF_UNSPEC, r;
if (isempty(rvalue)) { if (isempty(rvalue)) {
cgroup_context_remove_socket_bind(head); cgroup_context_remove_socket_bind(head);
@ -5654,40 +5684,29 @@ int config_parse_cgroup_socket_bind(
r = extract_first_word(&rvalue, &word, ":", 0); r = extract_first_word(&rvalue, &word, ":", 0);
if (r == -ENOMEM) if (r == -ENOMEM)
return log_oom(); return log_oom();
if (r <= 0) {
log_syntax(unit, LOG_WARNING, filename, line, r,
"Unable to parse %s= assignment, ignoring: %s", lvalue, rvalue);
return 0;
}
if (rvalue) { if (rvalue)
if (streq(word, "IPv4")) address_family = word;
if (address_family) {
if (streq(address_family, "IPv4"))
af = AF_INET; af = AF_INET;
else if (streq(word, "IPv6")) else if (streq(address_family, "IPv6"))
af = AF_INET6; af = AF_INET6;
else { else
log_syntax(unit, LOG_WARNING, filename, line, 0, return log_warning_errno(SYNTHETIC_ERRNO(EINVAL),
"Only IPv4 and IPv6 protocols are supported, ignoring."); "Only IPv4 or IPv6 protocols are supported, ignoring");
return 0;
}
user_port = rvalue;
} else {
af = AF_UNSPEC;
user_port = word;
} }
user_port = rvalue ?: word;
if (!streq(user_port, "any")) { if (!streq(user_port, "any")) {
uint16_t port_max; uint16_t port_max;
r = parse_ip_port_range(user_port, &port_min, &port_max); r = parse_ip_port_range(user_port, &port_min, &port_max);
if (r == -ENOMEM) if (r == -ENOMEM)
return log_oom(); return log_oom();
if (r < 0) { if (r < 0)
log_syntax(unit, LOG_WARNING, filename, line, r, return log_warning_errno(r, "Invalid port or port range, ignoring: %m");
"Invalid port or port range, ignoring: %m");
return 0;
}
nr_ports = 1 + port_max - port_min; nr_ports = 1 + port_max - port_min;
} }

View File

@ -10,11 +10,6 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
if (size == 0) if (size == 0)
return 0; return 0;
/* We don't want to fill the logs with assert warnings.
* Disable most logging if not running standalone */
if (!getenv("SYSTEMD_LOG_LEVEL"))
log_set_max_level(LOG_CRIT);
dummy_server_init(&s, data, size); dummy_server_init(&s, data, size);
dev_kmsg_record(&s, s.buffer, size); dev_kmsg_record(&s, s.buffer, size);
server_done(&s); server_done(&s);

View File

@ -245,69 +245,72 @@ _public_ int sd_device_new_from_devnum(sd_device **ret, char type, dev_t devnum)
} }
_public_ int sd_device_new_from_subsystem_sysname(sd_device **ret, const char *subsystem, const char *sysname) { _public_ int sd_device_new_from_subsystem_sysname(sd_device **ret, const char *subsystem, const char *sysname) {
char syspath[PATH_MAX], *name; char *name, *syspath;
size_t len = 0;
assert_return(ret, -EINVAL); assert_return(ret, -EINVAL);
assert_return(subsystem, -EINVAL); assert_return(subsystem, -EINVAL);
assert_return(sysname, -EINVAL); assert_return(sysname, -EINVAL);
assert_return(strlen(sysname) < PATH_MAX - strlen("/sys/bus/"), -ENAMETOOLONG);
if (streq(subsystem, "subsystem")) { if (streq(subsystem, "subsystem")) {
if (snprintf_ok(syspath, sizeof syspath, "/sys/subsystem/%s", sysname) && syspath = strjoina("/sys/subsystem/", sysname);
access(syspath, F_OK) >= 0) if (access(syspath, F_OK) >= 0)
return sd_device_new_from_syspath(ret, syspath); return sd_device_new_from_syspath(ret, syspath);
if (snprintf_ok(syspath, sizeof syspath, "/sys/bus/%s", sysname) && syspath = strjoina("/sys/bus/", sysname);
access(syspath, F_OK) >= 0) if (access(syspath, F_OK) >= 0)
return sd_device_new_from_syspath(ret, syspath); return sd_device_new_from_syspath(ret, syspath);
if (snprintf_ok(syspath, sizeof syspath, "/sys/class/%s", sysname) && syspath = strjoina("/sys/class/", sysname);
access(syspath, F_OK) >= 0) if (access(syspath, F_OK) >= 0)
return sd_device_new_from_syspath(ret, syspath); return sd_device_new_from_syspath(ret, syspath);
} else if (streq(subsystem, "module")) { } else if (streq(subsystem, "module")) {
if (snprintf_ok(syspath, sizeof syspath, "/sys/module/%s", sysname) && syspath = strjoina("/sys/module/", sysname);
access(syspath, F_OK) >= 0) if (access(syspath, F_OK) >= 0)
return sd_device_new_from_syspath(ret, syspath); return sd_device_new_from_syspath(ret, syspath);
} else if (streq(subsystem, "drivers")) { } else if (streq(subsystem, "drivers")) {
const char *subsys, *sep; char subsys[PATH_MAX];
char *driver;
sep = strchr(sysname, ':'); strscpy(subsys, sizeof(subsys), sysname);
if (sep && sep[1] != '\0') { /* Require ":" and something non-empty after that. */ driver = strchr(subsys, ':');
subsys = memdupa_suffix0(sysname, sep - sysname); if (driver) {
driver[0] = '\0';
driver++;
if (snprintf_ok(syspath, sizeof syspath, "/sys/subsystem/%s/drivers/%s", subsys, sep + 1) && syspath = strjoina("/sys/subsystem/", subsys, "/drivers/", driver);
access(syspath, F_OK) >= 0) if (access(syspath, F_OK) >= 0)
return sd_device_new_from_syspath(ret, syspath); return sd_device_new_from_syspath(ret, syspath);
if (snprintf_ok(syspath, sizeof syspath, "/sys/bus/%s/drivers/%s", subsys, sep + 1) && syspath = strjoina("/sys/bus/", subsys, "/drivers/", driver);
access(syspath, F_OK) >= 0) if (access(syspath, F_OK) >= 0)
return sd_device_new_from_syspath(ret, syspath); return sd_device_new_from_syspath(ret, syspath);
} }
} }
/* translate sysname back to sysfs filename */ /* translate sysname back to sysfs filename */
name = strdupa(sysname); name = strdupa(sysname);
while (name[len] != '\0') {
if (name[len] == '/')
name[len] = '!';
for (size_t i = 0; name[i]; i++) len++;
if (name[i] == '/') }
name[i] = '!';
if (snprintf_ok(syspath, sizeof syspath, "/sys/subsystem/%s/devices/%s", subsystem, name) && syspath = strjoina("/sys/subsystem/", subsystem, "/devices/", name);
access(syspath, F_OK) >= 0) if (access(syspath, F_OK) >= 0)
return sd_device_new_from_syspath(ret, syspath); return sd_device_new_from_syspath(ret, syspath);
if (snprintf_ok(syspath, sizeof syspath, "/sys/bus/%s/devices/%s", subsystem, name) && syspath = strjoina("/sys/bus/", subsystem, "/devices/", name);
access(syspath, F_OK) >= 0) if (access(syspath, F_OK) >= 0)
return sd_device_new_from_syspath(ret, syspath); return sd_device_new_from_syspath(ret, syspath);
if (snprintf_ok(syspath, sizeof syspath, "/sys/class/%s/%s", subsystem, name) && syspath = strjoina("/sys/class/", subsystem, "/", name);
access(syspath, F_OK) >= 0) if (access(syspath, F_OK) >= 0)
return sd_device_new_from_syspath(ret, syspath); return sd_device_new_from_syspath(ret, syspath);
if (snprintf_ok(syspath, sizeof syspath, "/sys/firmware/%s/%s", subsystem, sysname) && syspath = strjoina("/sys/firmware/", subsystem, "/", sysname);
access(syspath, F_OK) >= 0) if (access(syspath, F_OK) >= 0)
return sd_device_new_from_syspath(ret, syspath); return sd_device_new_from_syspath(ret, syspath);
return -ENODEV; return -ENODEV;
@ -649,15 +652,17 @@ _public_ int sd_device_new_from_device_id(sd_device **ret, const char *id) {
} }
case '+': { case '+': {
const char *subsys, *sep; char subsys[NAME_MAX+1]; /* NAME_MAX does not include the trailing NUL. */
const char *sysname;
sep = strchr(id + 1, ':'); sysname = strchr(id + 1, ':');
if (!sep || sep - id - 1 > NAME_MAX) if (!sysname)
return -EINVAL; return -EINVAL;
subsys = memdupa_suffix0(id + 1, sep - id - 1); (void) strnscpy(subsys, sizeof(subsys), id + 1, sysname - id - 1);
sysname++;
return sd_device_new_from_subsystem_sysname(ret, subsys, sep + 1); return sd_device_new_from_subsystem_sysname(ret, subsys, sysname);
} }
default: default:

View File

@ -30,11 +30,20 @@ SUBSYSTEM=="scsi_generic", SUBSYSTEMS=="scsi", ATTRS{type}=="4|5", TAG+="uaccess
SUBSYSTEM=="sound", TAG+="uaccess", \ SUBSYSTEM=="sound", TAG+="uaccess", \
OPTIONS+="static_node=snd/timer", OPTIONS+="static_node=snd/seq" OPTIONS+="static_node=snd/timer", OPTIONS+="static_node=snd/seq"
# ffado is an userspace driver for firewire sound cards
SUBSYSTEM=="firewire", ENV{ID_FFADO}=="1", TAG+="uaccess"
# Webcams, frame grabber, TV cards # Webcams, frame grabber, TV cards
SUBSYSTEM=="video4linux", TAG+="uaccess" SUBSYSTEM=="video4linux", TAG+="uaccess"
SUBSYSTEM=="dvb", TAG+="uaccess" SUBSYSTEM=="dvb", TAG+="uaccess"
# industrial cameras, some webcams, camcorders, set-top boxes, TV sets, audio devices, and more # IIDC devices: industrial cameras and some webcams
SUBSYSTEM=="firewire", ATTR{units}=="*0x00a02d:0x00010*", TAG+="uaccess"
SUBSYSTEM=="firewire", ATTR{units}=="*0x00b09d:0x00010*", TAG+="uaccess"
# AV/C devices: camcorders, set-top boxes, TV sets, audio devices, and more
SUBSYSTEM=="firewire", ATTR{units}=="*0x00a02d:0x010001*", TAG+="uaccess"
SUBSYSTEM=="firewire", ATTR{units}=="*0x00a02d:0x014001*", TAG+="uaccess"
SUBSYSTEM=="firewire", TEST=="units", ENV{IEEE1394_UNIT_FUNCTION_MIDI}=="1", TAG+="uaccess" SUBSYSTEM=="firewire", TEST=="units", ENV{IEEE1394_UNIT_FUNCTION_MIDI}=="1", TAG+="uaccess"
SUBSYSTEM=="firewire", TEST=="units", ENV{IEEE1394_UNIT_FUNCTION_AUDIO}=="1", TAG+="uaccess" SUBSYSTEM=="firewire", TEST=="units", ENV{IEEE1394_UNIT_FUNCTION_AUDIO}=="1", TAG+="uaccess"
SUBSYSTEM=="firewire", TEST=="units", ENV{IEEE1394_UNIT_FUNCTION_VIDEO}=="1", TAG+="uaccess" SUBSYSTEM=="firewire", TEST=="units", ENV{IEEE1394_UNIT_FUNCTION_VIDEO}=="1", TAG+="uaccess"

View File

@ -1754,12 +1754,12 @@ int unit_file_verify_alias(const UnitFileInstallInfo *i, const char *dst, char *
"Invalid path \"%s\" in alias.", dir); "Invalid path \"%s\" in alias.", dir);
*p = '\0'; /* dir should now be a unit name */ *p = '\0'; /* dir should now be a unit name */
UnitNameFlags type = unit_name_classify(dir); r = unit_name_classify(dir);
if (type < 0) if (r < 0)
return log_warning_errno(SYNTHETIC_ERRNO(EXDEV), return log_warning_errno(SYNTHETIC_ERRNO(EXDEV),
"Invalid unit name component \"%s\" in alias.", dir); "Invalid unit name component \"%s\" in alias.", dir);
const bool instance_propagation = type == UNIT_NAME_TEMPLATE; const bool instance_propagation = r == UNIT_NAME_TEMPLATE;
/* That's the name we want to use for verification. */ /* That's the name we want to use for verification. */
r = unit_symlink_name_compatible(path_alias, i->name, instance_propagation); r = unit_symlink_name_compatible(path_alias, i->name, instance_propagation);
@ -1776,11 +1776,11 @@ int unit_file_verify_alias(const UnitFileInstallInfo *i, const char *dst, char *
if (unit_name_is_valid(dst, UNIT_NAME_TEMPLATE)) { if (unit_name_is_valid(dst, UNIT_NAME_TEMPLATE)) {
_cleanup_free_ char *inst = NULL; _cleanup_free_ char *inst = NULL;
UnitNameFlags type = unit_name_to_instance(i->name, &inst); r = unit_name_to_instance(i->name, &inst);
if (type < 0) if (r < 0)
return log_error_errno(type, "Failed to extract instance name from %s: %m", i->name); return log_error_errno(r, "Failed to extract instance name from %s: %m", i->name);
if (type == UNIT_NAME_INSTANCE) { if (r == UNIT_NAME_INSTANCE) {
r = unit_name_replace_instance(dst, inst, &dst_updated); r = unit_name_replace_instance(dst, inst, &dst_updated);
if (r < 0) if (r < 0)
return log_error_errno(r, "Failed to build unit name from %s+%s: %m", return log_error_errno(r, "Failed to build unit name from %s+%s: %m",

View File

@ -68,6 +68,7 @@ static void test_random_u64_range_one(unsigned mod) {
x = random_u64_range(mod); x = random_u64_range(mod);
log_trace("%05u: %"PRIu64, i, x);
count[x]++; count[x]++;
max = MAX(max, count[x]); max = MAX(max, count[x]);
} }

View File

@ -471,8 +471,8 @@ static void test_build_parent_slice(void) {
} }
static void test_unit_name_to_instance(void) { static void test_unit_name_to_instance(void) {
UnitNameFlags r;
char *instance; char *instance;
int r;
log_info("/* %s */", __func__); log_info("/* %s */", __func__);

File diff suppressed because one or more lines are too long