1
0
mirror of https://github.com/systemd/systemd synced 2026-04-03 21:54:58 +02:00

Compare commits

..

No commits in common. "d874a13efc51fe49c8870542fa1c9a64ca7e5e93" and "d7654742eeb808c9a82fcf4ef3591d5cd582190f" have entirely different histories.

70 changed files with 292 additions and 435 deletions

View File

@ -153,34 +153,25 @@ SPDX-License-Identifier: LGPL-2.1-or-later
## Using C Constructs
- Allocate local variables where it makes sense: at the top of the block, or at
the point where they can be initialized. Avoid huge variable declaration
lists at the top of the function.
As an exception, `r` is typically used for a local state variable, but should
almost always be declared as the last variable at the top of the function.
the point where they can be initialized. `r` is typically used for a local
state variable, but should almost always be declared at the top of the
function.
```c
{
uint64_t a;
uint64_t a, b;
int r;
r = frobnicate(&a);
a = frobnicate();
b = a + 5;
r = do_something();
if (r < 0)
uint64_t b = a + 1, c;
r = foobarify(a, b, &c);
if (r < 0)
const char *pretty = prettify(a, b, c);
}
```
- Do not mix multiple variable definitions with function invocations or
complicated expressions:
- Do not mix function invocations with variable definitions in one line.
```c
{
@ -234,7 +225,7 @@ SPDX-License-Identifier: LGPL-2.1-or-later
- To determine the length of a constant string `"foo"`, don't bother with
`sizeof("foo")-1`, please use `strlen()` instead (both gcc and clang optimize
the call away for fixed strings). The only exception is when declaring an
array. In that case use `STRLEN()`, which evaluates to a static constant and
array. In that case use STRLEN, which evaluates to a static constant and
doesn't force the compiler to create a VLA.
- Please use C's downgrade-to-bool feature only for expressions that are

View File

@ -1051,7 +1051,7 @@ static int analyze_critical_chain(int argc, char *argv[], void *userdata) {
}
unit_times_hashmap = h;
pager_open(arg_pager_flags);
(void) pager_open(arg_pager_flags);
puts("The time when unit became active or started is printed after the \"@\" character.\n"
"The time the unit took to start is printed after the \"+\" character.\n");
@ -1121,7 +1121,7 @@ static int analyze_blame(int argc, char *argv[], void *userdata) {
return table_log_add_error(r);
}
pager_open(arg_pager_flags);
(void) pager_open(arg_pager_flags);
return table_print(table, NULL);
}
@ -1349,7 +1349,7 @@ static int dump(int argc, char *argv[], void *userdata) {
if (r < 0)
return bus_log_connect_error(r, arg_transport);
pager_open(arg_pager_flags);
(void) pager_open(arg_pager_flags);
if (!sd_bus_can_send(bus, SD_BUS_TYPE_UNIX_FD))
return dump_fallback(bus);
@ -1376,7 +1376,7 @@ static int cat_config(int argc, char *argv[], void *userdata) {
char **arg, **list;
int r;
pager_open(arg_pager_flags);
(void) pager_open(arg_pager_flags);
list = strv_skip(argv, 1);
STRV_FOREACH(arg, list) {
@ -1523,7 +1523,7 @@ static int dump_exit_status(int argc, char *argv[], void *userdata) {
return table_log_add_error(r);
}
pager_open(arg_pager_flags);
(void) pager_open(arg_pager_flags);
return table_print(table, NULL);
}
@ -1568,7 +1568,7 @@ static int dump_capabilities(int argc, char *argv[], void *userdata) {
(void) table_set_sort(table, (size_t) 1);
}
pager_open(arg_pager_flags);
(void) pager_open(arg_pager_flags);
return table_print(table, NULL);
}
@ -1652,7 +1652,7 @@ static void dump_syscall_filter(const SyscallFilterSet *set) {
static int dump_syscall_filters(int argc, char *argv[], void *userdata) {
bool first = true;
pager_open(arg_pager_flags);
(void) pager_open(arg_pager_flags);
if (strv_isempty(strv_skip(argv, 1))) {
_cleanup_set_free_ Set *kernel = NULL, *known = NULL;
@ -1824,7 +1824,7 @@ static int dump_filesystems(int argc, char *argv[], void *userdata) {
return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), "Not compiled with libbpf support, sorry.");
#endif
pager_open(arg_pager_flags);
(void) pager_open(arg_pager_flags);
if (strv_isempty(strv_skip(argv, 1))) {
_cleanup_set_free_ Set *kernel = NULL, *known = NULL;
@ -2270,7 +2270,7 @@ static int do_security(int argc, char *argv[], void *userdata) {
if (r < 0)
return bus_log_connect_error(r, arg_transport);
pager_open(arg_pager_flags);
(void) pager_open(arg_pager_flags);
if (arg_security_policy) {
r = json_parse_file(/*f=*/ NULL, arg_security_policy, /*flags=*/ 0, &policy, &line, &column);
@ -2309,7 +2309,7 @@ static int help(int argc, char *argv[], void *userdata) {
_cleanup_free_ char *link = NULL, *dot_link = NULL;
int r;
pager_open(arg_pager_flags);
(void) pager_open(arg_pager_flags);
r = terminal_urlify_man("systemd-analyze", "1", &link);
if (r < 0)

View File

@ -328,6 +328,13 @@ static inline int __coverity_check_and_return__(int condition) {
ans; \
})
#define UPDATE_FLAG(orig, flag, b) \
((b) ? ((orig) | (flag)) : ((orig) & ~(flag)))
#define SET_FLAG(v, flag, b) \
(v) = UPDATE_FLAG(v, flag, b)
#define FLAGS_SET(v, flags) \
((~(v) & (flags)) == 0)
#define SWAP_TWO(x, y) do { \
typeof(x) _t = (x); \
(x) = (y); \

View File

@ -413,7 +413,6 @@ bool fstype_is_ro(const char *fstype) {
return STR_IN_SET(fstype,
"DM_verity_hash",
"iso9660",
"erofs",
"squashfs");
}

View File

@ -217,7 +217,7 @@ static int run(int argc, char *argv[]) {
return log_error_errno(r, "Failed to enumerate binfmt.d files: %m");
if (arg_cat_config) {
pager_open(arg_pager_flags);
(void) pager_open(arg_pager_flags);
return cat_files(NULL, files, 0);
}

View File

@ -1286,7 +1286,7 @@ static int verb_status(int argc, char *argv[], void *userdata) {
r = 0; /* If we couldn't determine the path, then don't consider that a problem from here on, just show what we
* can show */
pager_open(arg_pager_flags);
(void) pager_open(arg_pager_flags);
if (is_efi_boot()) {
static const struct {
@ -1444,7 +1444,7 @@ static int verb_list(int argc, char *argv[], void *userdata) {
if (config.n_entries == 0)
log_info("No boot loader entries found.");
else {
pager_open(arg_pager_flags);
(void) pager_open(arg_pager_flags);
printf("Boot Loader Entries:\n");

View File

@ -551,7 +551,7 @@ static EFI_STATUS reboot_into_firmware(void) {
UINT64 osind = 0;
EFI_STATUS err;
if (!FLAGS_SET(get_os_indications_supported(), EFI_OS_INDICATIONS_BOOT_TO_FW_UI))
if (!(get_os_indications_supported() & EFI_OS_INDICATIONS_BOOT_TO_FW_UI))
return log_error_status_stall(EFI_UNSUPPORTED, L"Reboot to firmware interface not supported.");
(void) efivar_get_uint64_le(EFI_GLOBAL_GUID, L"OsIndications", &osind);
@ -924,7 +924,7 @@ static BOOLEAN menu_run(
case KEYPRESS(0, SCAN_F10, 0): /* HP and Lenovo. */
case KEYPRESS(0, SCAN_DELETE, 0): /* Same as F2. */
case KEYPRESS(0, SCAN_ESC, 0): /* HP. */
if (FLAGS_SET(get_os_indications_supported(), EFI_OS_INDICATIONS_BOOT_TO_FW_UI)) {
if (get_os_indications_supported() & EFI_OS_INDICATIONS_BOOT_TO_FW_UI) {
firmware_setup = TRUE;
/* Let's make sure the user really wants to do this. */
status = PoolPrint(L"Press Enter to reboot into firmware interface.");
@ -1590,7 +1590,7 @@ static void config_load_entries(
if (f->FileName[0] == '.')
continue;
if (FLAGS_SET(f->Attribute, EFI_FILE_DIRECTORY))
if (f->Attribute & EFI_FILE_DIRECTORY)
continue;
if (!endswith_no_case(f->FileName, L".conf"))
@ -2026,23 +2026,16 @@ static void config_entry_add_linux(
return;
for (;;) {
enum {
SECTION_CMDLINE,
SECTION_OSREL,
_SECTION_MAX,
};
static const CHAR8* const sections[_SECTION_MAX + 1] = {
[SECTION_CMDLINE] = (const CHAR8 *) ".cmdline",
[SECTION_OSREL] = (const CHAR8 *) ".osrel",
NULL,
};
_cleanup_freepool_ CHAR16 *os_name_pretty = NULL, *os_name = NULL, *os_id = NULL,
*os_version = NULL, *os_version_id = NULL, *os_build_id = NULL, *os_image_version = NULL;
_cleanup_freepool_ CHAR8 *content = NULL;
UINTN offs[_SECTION_MAX] = {};
UINTN szs[_SECTION_MAX] = {};
const CHAR8 *sections[] = {
(CHAR8 *)".osrel",
(CHAR8 *)".cmdline",
NULL
};
UINTN offs[ELEMENTSOF(sections)-1] = {};
UINTN szs[ELEMENTSOF(sections)-1] = {};
CHAR8 *line;
UINTN pos = 0;
CHAR8 *key, *value;
@ -2053,7 +2046,7 @@ static void config_entry_add_linux(
if (f->FileName[0] == '.')
continue;
if (FLAGS_SET(f->Attribute, EFI_FILE_DIRECTORY))
if (f->Attribute & EFI_FILE_DIRECTORY)
continue;
if (!endswith_no_case(f->FileName, L".efi"))
continue;
@ -2061,11 +2054,11 @@ static void config_entry_add_linux(
continue;
/* look for .osrel and .cmdline sections in the .efi binary */
err = pe_file_locate_sections(linux_dir, f->FileName, (const CHAR8**) sections, offs, szs);
if (EFI_ERROR(err) || szs[SECTION_OSREL] == 0)
err = pe_file_locate_sections(linux_dir, f->FileName, sections, offs, szs);
if (EFI_ERROR(err))
continue;
err = file_read(linux_dir, f->FileName, offs[SECTION_OSREL], szs[SECTION_OSREL], &content, NULL);
err = file_read(linux_dir, f->FileName, offs[0], szs[0], &content, NULL);
if (EFI_ERROR(err))
continue;
@ -2129,24 +2122,21 @@ static void config_entry_add_linux(
path,
os_image_version ?: (os_version ?: (os_version_id ? : os_build_id)));
config_entry_parse_tries(entry, L"\\EFI\\Linux", f->FileName, L".efi");
if (szs[SECTION_CMDLINE] == 0)
continue;
FreePool(content);
content = NULL;
/* read the embedded cmdline file */
err = file_read(linux_dir, f->FileName, offs[SECTION_CMDLINE], szs[SECTION_CMDLINE], &content, NULL);
err = file_read(linux_dir, f->FileName, offs[1], szs[1], &content, NULL);
if (!EFI_ERROR(err)) {
/* chomp the newline */
if (content[szs[SECTION_CMDLINE] - 1] == '\n')
content[szs[SECTION_CMDLINE] - 1] = '\0';
if (content[szs[1]-1] == '\n')
content[szs[1]-1] = '\0';
entry->options = stra_to_str(content);
}
config_entry_parse_tries(entry, L"\\EFI\\Linux", f->FileName, L".efi");
}
}
}
@ -2362,7 +2352,7 @@ static void config_load_all_entries(
config_entry_add_loader_auto(config, loaded_image->DeviceHandle, root_dir, loaded_image_path,
L"auto-efi-default", '\0', L"EFI Default Loader", NULL);
if (config->auto_firmware && FLAGS_SET(get_os_indications_supported(), EFI_OS_INDICATIONS_BOOT_TO_FW_UI))
if (config->auto_firmware && (get_os_indications_supported() & EFI_OS_INDICATIONS_BOOT_TO_FW_UI))
config_entry_add_call(config,
L"auto-reboot-to-firmware-setup",
L"Reboot Into Firmware Interface",

View File

@ -375,7 +375,7 @@ EFI_STATUS pack_cpio(
if (dirent->FileName[0] == '.')
continue;
if (FLAGS_SET(dirent->Attribute, EFI_FILE_DIRECTORY))
if (dirent->Attribute & EFI_FILE_DIRECTORY)
continue;
if (match_suffix && !endswith_no_case(dirent->FileName, match_suffix))
continue;

View File

@ -103,7 +103,7 @@ EFI_STATUS load_drivers(
if (dirent->FileName[0] == '.')
continue;
if (FLAGS_SET(dirent->Attribute, EFI_FILE_DIRECTORY))
if (dirent->Attribute & EFI_FILE_DIRECTORY)
continue;
if (!endswith_no_case(dirent->FileName, EFI_MACHINE_TYPE_NAME L".efi"))
continue;

View File

@ -45,12 +45,6 @@ stub_sources = '''
cpio.c
'''.split()
if efi_arch in ['x86', 'x86_64']
stub_sources += 'linux_x86.c'
else
stub_sources += 'linux.c'
endif
if conf.get('ENABLE_EFI') == 1 and get_option('gnu-efi') != 'false'
efi_cc = get_option('efi-cc')
if efi_cc.length() == 0
@ -203,10 +197,11 @@ if have_gnu_efi
compile_args = cc.get_supported_arguments(
basic_disabled_warnings +
possible_common_cc_flags + [
'-ffreestanding',
'-fno-stack-protector',
'-fno-strict-aliasing',
'-fpic',
'-fwide-exec-charset=UCS2',
'-fshort-wchar',
'-Wall',
'-Wextra',
'-Wsign-compare',
@ -214,8 +209,6 @@ if have_gnu_efi
) + [
'-nostdlib',
'-std=gnu99',
'-ffreestanding',
'-fshort-wchar',
'-isystem', efi_incdir,
'-isystem', efi_incdir / gnu_efi_path_arch,
'-I', fundamental_path,
@ -224,52 +217,46 @@ if have_gnu_efi
'-include', efi_config_h,
'-include', version_h,
]
if ['ia32', 'x86_64'].contains(efi_arch)
stub_sources += 'linux_x86.c'
else
stub_sources += 'linux.c'
endif
if efi_arch == 'x86_64'
compile_args += ['-mno-red-zone',
'-mno-sse',
'-mno-mmx']
elif efi_arch == 'x86'
elif efi_arch == 'ia32'
compile_args += ['-mno-sse',
'-mno-mmx']
elif efi_arch == 'arm'
compile_args += cc.get_supported_arguments([
'-mgeneral-regs-only',
'-mfpu=none'
])
if cc.has_argument('-mgeneral-regs-only')
compile_args += ['-mgeneral-regs-only']
endif
# We are putting the efi_cc command line together ourselves, so make sure to pull any
# relevant compiler flags from meson/CFLAGS as povided by the user or distro.
if get_option('werror')
if cc.has_argument('-mfpu=none')
compile_args += ['-mfpu=none']
endif
endif
if get_option('werror') == true
compile_args += ['-Werror']
endif
if get_option('debug')
compile_args += ['-ggdb', '-DEFI_DEBUG']
endif
if get_option('optimization') != '0'
compile_args += ['-O' + get_option('optimization')]
if get_option('buildtype') == 'debug'
compile_args += ['-ggdb', '-O0', '-DEFI_DEBUG']
elif get_option('buildtype') == 'debugoptimized'
compile_args += ['-ggdb', '-Og', '-DEFI_DEBUG']
else
compile_args += ['-O2']
endif
if get_option('b_ndebug') == 'true' or (
get_option('b_ndebug') == 'if-release' and ['plain', 'release'].contains(get_option('buildtype')))
compile_args += ['-DNDEBUG']
endif
foreach arg : get_option('c_args')
if arg in ['-Werror', '-g', '-ggdb', '-O1', '-O2', '-O3', '-Og', '-Os', '-DNDEBUG']
message('Using "@0@" from c_args for EFI compiler'.format(arg))
compile_args += arg
endif
endforeach
efi_ldflags = ['-T', efi_lds,
'-shared',
'-Bsymbolic',
'-nostdlib',
'--no-undefined',
'--warn-common',
'--fatal-warnings',
'-znocombreloc',
'--build-id=sha1',
'-L', efi_libdir,
@ -304,6 +291,7 @@ if have_gnu_efi
systemd_boot_efi_name = 'systemd-boot@0@.efi'.format(EFI_MACHINE_TYPE_NAME)
stub_elf_name = 'linux@0@.elf.stub'.format(EFI_MACHINE_TYPE_NAME)
stub_efi_name = 'linux@0@.efi.stub'.format(EFI_MACHINE_TYPE_NAME)
no_undefined_symbols = find_program('no-undefined-symbols.sh')
efi_stubs = []
foreach tuple : [['systemd_boot.so', systemd_boot_efi_name, systemd_boot_objects, false],
@ -337,6 +325,12 @@ if have_gnu_efi
install_dir : bootlibdir)
efi_stubs += [[so, stub]]
if want_tests != 'false'
test('no-undefined-symbols-' + tuple[0],
no_undefined_symbols,
args : so)
endif
endforeach
############################################################

View File

@ -0,0 +1,9 @@
#!/bin/bash
# SPDX-License-Identifier: LGPL-2.1-or-later
set -eu
set -o pipefail
if nm -D -u "${1:?}" | grep ' U '; then
echo "Undefined symbols detected!"
exit 1
fi

View File

@ -122,8 +122,7 @@ static inline BOOLEAN verify_pe(const struct PeFileHeader *pe) {
return CompareMem(pe->Magic, PE_FILE_MAGIC, STRLEN(PE_FILE_MAGIC)) == 0 &&
pe->FileHeader.Machine == TARGET_MACHINE_TYPE &&
pe->FileHeader.NumberOfSections > 0 &&
pe->FileHeader.NumberOfSections <= MAX_SECTIONS &&
IN_SET(pe->OptionalHeader.Magic, OPTHDR32_MAGIC, OPTHDR64_MAGIC);
pe->FileHeader.NumberOfSections <= MAX_SECTIONS;
}
static inline UINTN section_table_offset(const struct DosFileHeader *dos, const struct PeFileHeader *pe) {
@ -183,8 +182,15 @@ EFI_STATUS pe_alignment_info(
return EFI_LOAD_ERROR;
*ret_entry_point_address = pe->OptionalHeader.AddressOfEntryPoint;
if (pe->OptionalHeader.Magic == OPTHDR32_MAGIC) {
*ret_size_of_image = pe->OptionalHeader.SizeOfImage;
*ret_section_alignment = pe->OptionalHeader.SectionAlignment;
} else if (pe->OptionalHeader.Magic == OPTHDR64_MAGIC) {
*ret_size_of_image = pe->OptionalHeader.SizeOfImage;
*ret_section_alignment = pe->OptionalHeader.SectionAlignment;
} else
return EFI_UNSUPPORTED;
return EFI_SUCCESS;
}

View File

@ -154,7 +154,7 @@ EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *sys_table) {
_SECTION_MAX,
};
static const CHAR8* const sections[_SECTION_MAX + 1] = {
const CHAR8* const sections[] = {
[SECTION_CMDLINE] = (const CHAR8*) ".cmdline",
[SECTION_LINUX] = (const CHAR8*) ".linux",
[SECTION_INITRD] = (const CHAR8*) ".initrd",
@ -172,7 +172,6 @@ EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *sys_table) {
UINTN addrs[_SECTION_MAX] = {};
UINTN szs[_SECTION_MAX] = {};
CHAR8 *cmdline = NULL;
_cleanup_freepool_ CHAR8 *cmdline_owned = NULL;
EFI_STATUS err;
InitializeLib(image, sys_table);
@ -188,11 +187,8 @@ EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *sys_table) {
return log_error_status_stall(err, L"Error getting a LoadedImageProtocol handle: %r", err);
err = pe_memory_locate_sections(loaded_image->ImageBase, (const CHAR8**) sections, addrs, szs);
if (EFI_ERROR(err) || szs[SECTION_LINUX] == 0) {
if (!EFI_ERROR(err))
err = EFI_NOT_FOUND;
if (EFI_ERROR(err))
return log_error_status_stall(err, L"Unable to locate embedded .linux section: %r", err);
}
/* Show splash screen as early as possible */
graphics_splash((const UINT8*) loaded_image->ImageBase + addrs[SECTION_SPLASH], szs[SECTION_SPLASH], NULL);
@ -205,13 +201,18 @@ EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *sys_table) {
/* if we are not in secure boot mode, or none was provided, accept a custom command line and replace the built-in one */
if ((!secure_boot_enabled() || cmdline_len == 0) && loaded_image->LoadOptionsSize > 0 &&
*(CHAR16 *) loaded_image->LoadOptions > 0x1F) {
CHAR16 *options;
CHAR8 *line;
options = (CHAR16 *)loaded_image->LoadOptions;
cmdline_len = (loaded_image->LoadOptionsSize / sizeof(CHAR16)) * sizeof(CHAR8);
cmdline = cmdline_owned = AllocatePool(cmdline_len);
if (!cmdline)
line = AllocatePool(cmdline_len);
if (!line)
return log_oom();
for (UINTN i = 0; i < cmdline_len; i++)
cmdline[i] = ((CHAR16 *) loaded_image->LoadOptions)[i];
line[i] = options[i];
cmdline = line;
/* Let's measure the passed kernel command line into the TPM. Note that this possibly
* duplicates what we already did in the boot menu, if that was already used. However, since

View File

@ -493,21 +493,14 @@ void log_error_stall(const CHAR16 *fmt, ...) {
assert(fmt);
INT32 attr = ST->ConOut->Mode->Attribute;
ST->ConOut->SetAttribute(ST->ConOut, EFI_LIGHTRED|EFI_BACKGROUND_BLACK);
if (ST->ConOut->Mode->CursorColumn > 0)
Print(L"\n");
va_start(args, fmt);
VPrint(fmt, args);
va_end(args);
Print(L"\n");
ST->ConOut->SetAttribute(ST->ConOut, attr);
/* Give the user a chance to see the message. */
BS->Stall(3 * 1000 * 1000);
}
@ -741,7 +734,7 @@ EFI_STATUS open_directory(
err = get_file_info_harder(dir, &file_info, NULL);
if (EFI_ERROR(err))
return err;
if (!FLAGS_SET(file_info->Attribute, EFI_FILE_DIRECTORY))
if (!(file_info->Attribute & EFI_FILE_DIRECTORY))
return EFI_LOAD_ERROR;
*ret = TAKE_PTR(dir);

View File

@ -486,7 +486,7 @@ static int tree_one(sd_bus *bus, const char *service) {
return log_oom();
}
pager_open(arg_pager_flags);
(void) pager_open(arg_pager_flags);
l = set_get_strv(done);
if (!l)
@ -526,7 +526,7 @@ static int tree(int argc, char **argv, void *userdata) {
if (r < 0)
return log_error_errno(r, "Failed to get name list: %m");
pager_open(arg_pager_flags);
(void) pager_open(arg_pager_flags);
STRV_FOREACH(i, names) {
int q;
@ -556,7 +556,7 @@ static int tree(int argc, char **argv, void *userdata) {
printf("\n");
if (argv[2]) {
pager_open(arg_pager_flags);
(void) pager_open(arg_pager_flags);
printf("Service %s%s%s:\n", ansi_highlight(), *i, ansi_normal());
}
@ -979,7 +979,7 @@ static int introspect(int argc, char **argv, void *userdata) {
if (arg_xml_interface) {
/* Just dump the received XML and finish */
pager_open(arg_pager_flags);
(void) pager_open(arg_pager_flags);
puts(xml);
return 0;
}
@ -1098,7 +1098,7 @@ static int introspect(int argc, char **argv, void *userdata) {
typesafe_qsort(sorted, k, member_compare_funcp);
pager_open(arg_pager_flags);
(void) pager_open(arg_pager_flags);
if (arg_legend)
printf("%-*s %-*s %-*s %-*s %s\n",
@ -1358,7 +1358,7 @@ static int status(int argc, char **argv, void *userdata) {
if (r < 0)
return r;
pager_open(arg_pager_flags);
(void) pager_open(arg_pager_flags);
if (!isempty(argv[1])) {
r = parse_pid(argv[1], &pid);
@ -2038,7 +2038,7 @@ static int call(int argc, char **argv, void *userdata) {
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
if (arg_json_format_flags & (JSON_FORMAT_PRETTY|JSON_FORMAT_PRETTY_AUTO))
pager_open(arg_pager_flags);
(void) pager_open(arg_pager_flags);
r = json_transform_message(reply, &v);
if (r < 0)
@ -2047,7 +2047,7 @@ static int call(int argc, char **argv, void *userdata) {
json_variant_dump(v, arg_json_format_flags, NULL, NULL);
} else if (arg_verbose) {
pager_open(arg_pager_flags);
(void) pager_open(arg_pager_flags);
r = sd_bus_message_dump(reply, stdout, 0);
if (r < 0)
@ -2147,7 +2147,7 @@ static int get_property(int argc, char **argv, void *userdata) {
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
if (arg_json_format_flags & (JSON_FORMAT_PRETTY|JSON_FORMAT_PRETTY_AUTO))
pager_open(arg_pager_flags);
(void) pager_open(arg_pager_flags);
r = json_transform_variant(reply, contents, &v);
if (r < 0)
@ -2156,7 +2156,7 @@ static int get_property(int argc, char **argv, void *userdata) {
json_variant_dump(v, arg_json_format_flags, NULL, NULL);
} else if (arg_verbose) {
pager_open(arg_pager_flags);
(void) pager_open(arg_pager_flags);
r = sd_bus_message_dump(reply, stdout, SD_BUS_MESSAGE_DUMP_SUBTREE_ONLY);
if (r < 0)
@ -2233,7 +2233,7 @@ static int help(void) {
if (r < 0)
return log_oom();
pager_open(arg_pager_flags);
(void) pager_open(arg_pager_flags);
printf("%s [OPTIONS...] COMMAND ...\n\n"
"%sIntrospect the D-Bus IPC bus.%s\n"

View File

@ -191,8 +191,8 @@ static int run(int argc, char *argv[]) {
if (r <= 0)
return r;
pager_open(arg_pager_flags);
if (arg_full < 0 && pager_have())
r = pager_open(arg_pager_flags);
if (r > 0 && arg_full < 0)
arg_full = true;
if (arg_full > 0)

View File

@ -2902,7 +2902,7 @@ int main(int argc, char *argv[]) {
goto finish;
if (IN_SET(arg_action, ACTION_TEST, ACTION_HELP, ACTION_DUMP_CONFIGURATION_ITEMS, ACTION_DUMP_BUS_PROPERTIES, ACTION_BUS_INTROSPECT))
pager_open(arg_pager_flags);
(void) pager_open(arg_pager_flags);
if (arg_action != ACTION_RUN)
skip_setup = true;

View File

@ -3457,38 +3457,27 @@ static void manager_notify_finished(Manager *m) {
}
static void user_manager_send_ready(Manager *m) {
int r;
assert(m);
/* We send READY=1 on reaching basic.target only when running in --user mode. */
if (!MANAGER_IS_USER(m) || m->ready_sent)
return;
r = sd_notify(false,
sd_notifyf(false,
"READY=1\n"
"STATUS=Reached " SPECIAL_BASIC_TARGET ".");
if (r < 0)
log_warning_errno(r, "Failed to send readiness notification, ignoring: %m");
m->ready_sent = true;
m->status_ready = false;
}
static void manager_send_ready(Manager *m) {
int r;
if (m->ready_sent && m->status_ready)
/* Skip the notification if nothing changed. */
return;
r = sd_notify(false,
"READY=1\n"
"STATUS=Ready.");
if (r < 0)
log_full_errno(m->ready_sent ? LOG_DEBUG : LOG_WARNING, r,
"Failed to send readiness notification, ignoring: %m");
sd_notifyf(false,
"%sSTATUS=Ready.",
m->ready_sent ? "READY=1\n" : "");
m->ready_sent = m->status_ready = true;
}

View File

@ -824,7 +824,7 @@ static int dump_list(int argc, char **argv, void *userdata) {
(void) table_set_empty_string(t, "-");
} else
pager_open(arg_pager_flags);
(void) pager_open(arg_pager_flags);
/* "info" without pattern implies "-1" */
if ((arg_rows_max == 1 && arg_reverse) || (verb_is_info && argc == 1)) {

View File

@ -649,7 +649,7 @@ static int run(int argc, char *argv[]) {
else if (arg_diff)
arg_flags |= SHOW_OVERRIDDEN;
pager_open(arg_pager_flags);
(void) pager_open(arg_pager_flags);
if (optind < argc) {
int i;

View File

@ -379,7 +379,7 @@ static int action_dissect(DissectedImage *m, LoopDevice *d) {
assert(d);
if (arg_json_format_flags & (JSON_FORMAT_OFF|JSON_FORMAT_PRETTY|JSON_FORMAT_PRETTY_AUTO))
pager_open(arg_pager_flags);
(void) pager_open(arg_pager_flags);
if (arg_json_format_flags & JSON_FORMAT_OFF)
printf(" Name: %s\n", basename(arg_image));

View File

@ -306,10 +306,3 @@ static inline size_t ALIGN_TO(size_t l, size_t ali) {
(l <= SIZE_MAX - (ali - 1)), /* overflow? */ \
((l) + (ali) - 1) & ~((ali) - 1), \
VOID_0)
#define UPDATE_FLAG(orig, flag, b) \
((b) ? ((orig) | (flag)) : ((orig) & ~(flag)))
#define SET_FLAG(v, flag, b) \
(v) = UPDATE_FLAG(v, flag, b)
#define FLAGS_SET(v, flags) \
((~(v) & (flags)) == 0)

View File

@ -613,7 +613,7 @@ static int inspect_home(int argc, char *argv[], void *userdata) {
int r, ret = 0;
char **items, **i;
pager_open(arg_pager_flags);
(void) pager_open(arg_pager_flags);
r = acquire_bus(&bus);
if (r < 0)
@ -2020,7 +2020,7 @@ static int help(int argc, char *argv[], void *userdata) {
_cleanup_free_ char *link = NULL;
int r;
pager_open(arg_pager_flags);
(void) pager_open(arg_pager_flags);
r = terminal_urlify_man("homectl", "1", &link);
if (r < 0)

View File

@ -327,7 +327,7 @@ static int help(void) {
_cleanup_free_ char *link = NULL;
int r;
pager_open(arg_pager_flags);
(void) pager_open(arg_pager_flags);
r = terminal_urlify_man("journalctl", "1", &link);
if (r < 0)
@ -1445,7 +1445,7 @@ static int list_boots(sd_journal *j) {
if (count == 0)
return count;
pager_open(arg_pager_flags);
(void) pager_open(arg_pager_flags);
/* numbers are one less, but we need an extra char for the sign */
w = DECIMAL_STR_WIDTH(count - 1) + 1;
@ -2193,7 +2193,7 @@ int main(int argc, char *argv[]) {
} else {
bool oneline = arg_action == ACTION_LIST_CATALOG;
pager_open(arg_pager_flags);
(void) pager_open(arg_pager_flags);
if (optind < argc)
r = catalog_list_items(stdout, database, oneline, argv + optind);
@ -2586,7 +2586,7 @@ int main(int argc, char *argv[]) {
need_seek = true;
if (!arg_follow)
pager_open(arg_pager_flags);
(void) pager_open(arg_pager_flags);
if (!arg_quiet && (arg_lines != 0 || arg_follow)) {
usec_t start, end;

View File

@ -1764,10 +1764,13 @@ static int dispatch_notify_event(sd_event_source *es, int fd, uint32_t revents,
* there's something to send it will be turned on again. */
if (!s->sent_notify_ready) {
static const char p[] = "READY=1\n"
static const char p[] =
"READY=1\n"
"STATUS=Processing requests...";
ssize_t l;
if (send(s->notify_fd, p, strlen(p), MSG_DONTWAIT) < 0) {
l = send(s->notify_fd, p, strlen(p), MSG_DONTWAIT);
if (l < 0) {
if (errno == EAGAIN)
return 0;
@ -1778,9 +1781,14 @@ static int dispatch_notify_event(sd_event_source *es, int fd, uint32_t revents,
log_debug("Sent READY=1 notification.");
} else if (s->send_watchdog) {
static const char p[] = "WATCHDOG=1";
if (send(s->notify_fd, p, strlen(p), MSG_DONTWAIT) < 0) {
static const char p[] =
"WATCHDOG=1";
ssize_t l;
l = send(s->notify_fd, p, strlen(p), MSG_DONTWAIT);
if (l < 0) {
if (errno == EAGAIN)
return 0;

View File

@ -193,7 +193,7 @@ static int list_locales(int argc, char **argv, void *userdata) {
if (r < 0)
return log_error_errno(r, "Failed to read list of locales: %m");
pager_open(arg_pager_flags);
(void) pager_open(arg_pager_flags);
strv_print(l);
return 0;
@ -233,7 +233,7 @@ static int list_vconsole_keymaps(int argc, char **argv, void *userdata) {
if (r < 0)
return log_error_errno(r, "Failed to read list of keymaps: %m");
pager_open(arg_pager_flags);
(void) pager_open(arg_pager_flags);
strv_print(l);
@ -362,7 +362,7 @@ static int list_x11_keymaps(int argc, char **argv, void *userdata) {
strv_sort(list);
strv_uniq(list);
pager_open(arg_pager_flags);
(void) pager_open(arg_pager_flags);
strv_print(list);
return 0;

View File

@ -70,7 +70,7 @@ static int print_inhibitors(sd_bus *bus) {
_cleanup_(table_unrefp) Table *table = NULL;
int r;
pager_open(arg_pager_flags);
(void) pager_open(arg_pager_flags);
r = sd_bus_call_method(
bus,

View File

@ -123,7 +123,7 @@ static int list_sessions(int argc, char *argv[], void *userdata) {
assert(bus);
assert(argv);
pager_open(arg_pager_flags);
(void) pager_open(arg_pager_flags);
r = bus_call_method(bus, bus_login_mgr, "ListSessions", &error, &reply, NULL);
if (r < 0)
@ -197,7 +197,7 @@ static int list_users(int argc, char *argv[], void *userdata) {
assert(bus);
assert(argv);
pager_open(arg_pager_flags);
(void) pager_open(arg_pager_flags);
r = bus_call_method(bus, bus_login_mgr, "ListUsers", &error, &reply, NULL);
if (r < 0)
@ -247,7 +247,7 @@ static int list_seats(int argc, char *argv[], void *userdata) {
assert(bus);
assert(argv);
pager_open(arg_pager_flags);
(void) pager_open(arg_pager_flags);
r = bus_call_method(bus, bus_login_mgr, "ListSeats", &error, &reply, NULL);
if (r < 0)
@ -810,7 +810,7 @@ static int show_session(int argc, char *argv[], void *userdata) {
properties = !strstr(argv[0], "status");
pager_open(arg_pager_flags);
(void) pager_open(arg_pager_flags);
if (argc <= 1) {
/* If no argument is specified inspect the manager itself */
@ -847,7 +847,7 @@ static int show_user(int argc, char *argv[], void *userdata) {
properties = !strstr(argv[0], "status");
pager_open(arg_pager_flags);
(void) pager_open(arg_pager_flags);
if (argc <= 1) {
/* If no argument is specified inspect the manager itself */
@ -904,7 +904,7 @@ static int show_seat(int argc, char *argv[], void *userdata) {
properties = !strstr(argv[0], "status");
pager_open(arg_pager_flags);
(void) pager_open(arg_pager_flags);
if (argc <= 1) {
/* If no argument is specified inspect the manager itself */
@ -1219,7 +1219,7 @@ static int help(int argc, char *argv[], void *userdata) {
_cleanup_free_ char *link = NULL;
int r;
pager_open(arg_pager_flags);
(void) pager_open(arg_pager_flags);
r = terminal_urlify_man("loginctl", "1", &link);
if (r < 0)

View File

@ -384,19 +384,14 @@ error:
}
void session_device_free(SessionDevice *sd) {
int r;
assert(sd);
/* Make sure to remove the pushed fd. */
if (sd->pushed_fd) {
r = sd_notifyf(false,
if (sd->pushed_fd)
(void) sd_notifyf(false,
"FDSTOREREMOVE=1\n"
"FDNAME=session-%s-device-%u-%u",
sd->session->id, major(sd->dev), minor(sd->dev));
if (r < 0)
log_warning_errno(r, "Failed to remove file descriptor from the store, ignoring: %m");
}
session_device_stop(sd);
session_device_notify(sd, SESSION_DEVICE_RELEASE);

View File

@ -440,7 +440,7 @@ static int deliver_fd(Manager *m, const char *fdname, int fd) {
static int manager_attach_fds(Manager *m) {
_cleanup_strv_free_ char **fdnames = NULL;
int r, n;
int n;
/* Upon restart, PID1 will send us back all fds of session devices that we previously opened. Each
* file descriptor is associated with a given session. The session ids are passed through FDNAMES. */
@ -461,11 +461,9 @@ static int manager_attach_fds(Manager *m) {
safe_close(fd);
/* Remove from fdstore as well */
r = sd_notifyf(false,
(void) sd_notifyf(false,
"FDSTOREREMOVE=1\n"
"FDNAME=%s", fdnames[i]);
if (r < 0)
log_warning_errno(r, "Failed to remove file descriptor from the store, ignoring: %m");
}
return 0;

View File

@ -273,7 +273,7 @@ static int list_machines(int argc, char *argv[], void *userdata) {
assert(bus);
pager_open(arg_pager_flags);
(void) pager_open(arg_pager_flags);
r = bus_call_method(bus, bus_machine_mgr, "ListMachines", &error, &reply, NULL);
if (r < 0)
@ -352,7 +352,7 @@ static int list_images(int argc, char *argv[], void *userdata) {
assert(bus);
pager_open(arg_pager_flags);
(void) pager_open(arg_pager_flags);
r = bus_call_method(bus, bus_machine_mgr, "ListImages", &error, &reply, NULL);
if (r < 0)
@ -705,7 +705,7 @@ static int show_machine(int argc, char *argv[], void *userdata) {
properties = !strstr(argv[0], "status");
pager_open(arg_pager_flags);
(void) pager_open(arg_pager_flags);
if (properties && argc <= 1) {
@ -1004,7 +1004,7 @@ static int show_image(int argc, char *argv[], void *userdata) {
properties = !strstr(argv[0], "status");
pager_open(arg_pager_flags);
(void) pager_open(arg_pager_flags);
if (argc <= 1) {
@ -2251,7 +2251,7 @@ static int list_transfers(int argc, char *argv[], void *userdata) {
double progress;
int r;
pager_open(arg_pager_flags);
(void) pager_open(arg_pager_flags);
r = bus_call_method(bus, bus_import_mgr, "ListTransfers", &error, &reply, NULL);
if (r < 0)
@ -2446,7 +2446,7 @@ static int help(int argc, char *argv[], void *userdata) {
_cleanup_free_ char *link = NULL;
int r;
pager_open(arg_pager_flags);
(void) pager_open(arg_pager_flags);
r = terminal_urlify_man("machinectl", "1", &link);
if (r < 0)

View File

@ -6,13 +6,14 @@
#include <sys/types.h>
#include <unistd.h>
#include "sd-daemon.h"
#include "alloc-util.h"
#include "bus-error.h"
#include "bus-locator.h"
#include "bus-log-control-api.h"
#include "bus-polkit.h"
#include "cgroup-util.h"
#include "daemon-util.h"
#include "dirent-util.h"
#include "discover-image.h"
#include "fd-util.h"
@ -351,14 +352,17 @@ static int run(int argc, char *argv[]) {
return log_error_errno(r, "Failed to fully start up daemon: %m");
log_debug("systemd-machined running as pid "PID_FMT, getpid_cached());
r = sd_notify(false, NOTIFY_READY);
if (r < 0)
log_warning_errno(r, "Failed to send readiness notification, ignoring: %m");
(void) sd_notify(false,
"READY=1\n"
"STATUS=Processing requests...");
r = manager_run(m);
(void) sd_notify(false, NOTIFY_STOPPING);
log_debug("systemd-machined stopped as pid "PID_FMT, getpid_cached());
(void) sd_notify(false,
"STOPPING=1\n"
"STATUS=Shutting down...");
return r;
}

View File

@ -1432,7 +1432,7 @@ static int list_devices(void) {
}
}
pager_open(arg_pager_flags);
(void) pager_open(arg_pager_flags);
r = table_print(table, NULL);
if (r < 0)

View File

@ -810,7 +810,7 @@ static int list_links(int argc, char *argv[], void *userdata) {
if (c < 0)
return c;
pager_open(arg_pager_flags);
(void) pager_open(arg_pager_flags);
table = table_new("idx", "link", "type", "operational", "setup");
if (!table)
@ -2394,7 +2394,7 @@ static int link_status(int argc, char *argv[], void *userdata) {
return dump_link_description(strv_skip(argv, 1));
}
pager_open(arg_pager_flags);
(void) pager_open(arg_pager_flags);
r = sd_bus_open_system(&bus);
if (r < 0)
@ -2493,7 +2493,7 @@ static int link_lldp_status(int argc, char *argv[], void *userdata) {
if (c < 0)
return c;
pager_open(arg_pager_flags);
(void) pager_open(arg_pager_flags);
table = table_new("link",
"chassis id",

View File

@ -304,7 +304,7 @@ static int help(void) {
_cleanup_free_ char *link = NULL;
int r;
pager_open(arg_pager_flags);
(void) pager_open(arg_pager_flags);
r = terminal_urlify_man("systemd-nspawn", "1", &link);
if (r < 0)
@ -4205,7 +4205,6 @@ static int nspawn_dispatch_notify_fd(sd_event_source *source, int fd, uint32_t r
ssize_t n;
pid_t inner_child_pid;
_cleanup_strv_free_ char **tags = NULL;
int r;
assert(userdata);
@ -4244,11 +4243,8 @@ static int nspawn_dispatch_notify_fd(sd_event_source *source, int fd, uint32_t r
if (!tags)
return log_oom();
if (strv_find(tags, "READY=1")) {
r = sd_notify(false, "READY=1\n");
if (r < 0)
log_warning_errno(r, "Failed to send readiness notification, ignoring: %m");
}
if (strv_find(tags, "READY=1"))
(void) sd_notifyf(false, "READY=1\n");
p = strv_find_startswith(tags, "STATUS=");
if (p)
@ -5138,11 +5134,8 @@ static int run_container(
(void) sd_notifyf(false,
"STATUS=Container running.\n"
"X_NSPAWN_LEADER_PID=" PID_FMT, *pid);
if (!arg_notify_ready) {
r = sd_notify(false, "READY=1\n");
if (r < 0)
log_warning_errno(r, "Failed to send readiness notification, ignoring: %m");
}
if (!arg_notify_ready)
(void) sd_notify(false, "READY=1\n");
if (arg_kill_signal > 0) {
/* Try to kill the init system on SIGINT or SIGTERM */

View File

@ -16,7 +16,7 @@ static int help(int argc, char *argv[], void *userdata) {
_cleanup_free_ char *link = NULL;
int r;
pager_open(arg_pager_flags);
(void) pager_open(arg_pager_flags);
r = terminal_urlify_man("oomctl", "1", &link);
if (r < 0)
@ -52,7 +52,7 @@ static int dump_state(int argc, char *argv[], void *userdata) {
if (r < 0)
return log_error_errno(r, "Failed to connect system bus: %m");
pager_open(arg_pager_flags);
(void) pager_open(arg_pager_flags);
r = sd_bus_call_method(
bus,

View File

@ -333,7 +333,7 @@ static int inspect_image(int argc, char *argv[], void *userdata) {
if (r < 0)
return bus_log_parse_error(r);
pager_open(arg_pager_flags);
(void) pager_open(arg_pager_flags);
if (arg_cat) {
printf("%s-- OS Release: --%s\n", ansi_highlight(), ansi_normal());
@ -1093,7 +1093,7 @@ static int help(int argc, char *argv[], void *userdata) {
_cleanup_free_ char *link = NULL;
int r;
pager_open(arg_pager_flags);
(void) pager_open(arg_pager_flags);
r = terminal_urlify_man("portablectl", "1", &link);
if (r < 0)

View File

@ -4,11 +4,11 @@
#include <sys/types.h>
#include "sd-bus.h"
#include "sd-daemon.h"
#include "alloc-util.h"
#include "bus-log-control-api.h"
#include "bus-polkit.h"
#include "daemon-util.h"
#include "def.h"
#include "main-func.h"
#include "portabled-bus.h"
@ -154,13 +154,15 @@ static int run(int argc, char *argv[]) {
return log_error_errno(r, "Failed to fully start up daemon: %m");
log_debug("systemd-portabled running as pid " PID_FMT, getpid_cached());
r = sd_notify(false, NOTIFY_READY);
if (r < 0)
log_warning_errno(r, "Failed to send readiness notification, ignoring: %m");
sd_notify(false,
"READY=1\n"
"STATUS=Processing requests...");
r = manager_run(m);
(void) sd_notify(false, NOTIFY_STOPPING);
(void) sd_notify(false,
"STOPPING=1\n"
"STATUS=Shutting down...");
log_debug("systemd-portabled stopped as pid " PID_FMT, getpid_cached());
return r;
}

View File

@ -1587,7 +1587,7 @@ static int status_ifindex(sd_bus *bus, int ifindex, const char *name, StatusMode
if (r < 0)
return log_error_errno(r, "Failed to get link data for %i: %s", ifindex, bus_error_message(&error, r));
pager_open(arg_pager_flags);
(void) pager_open(arg_pager_flags);
if (mode == STATUS_DNS)
return status_print_strv_ifindex(ifindex, name, link_info.dns_ex ?: link_info.dns);
@ -1851,7 +1851,7 @@ static int status_global(sd_bus *bus, StatusMode mode, bool *empty_line) {
if (r < 0)
return log_error_errno(r, "Failed to get global data: %s", bus_error_message(&error, r));
pager_open(arg_pager_flags);
(void) pager_open(arg_pager_flags);
if (mode == STATUS_DNS)
return status_print_strv_global(global_info.dns_ex ?: global_info.dns);

View File

@ -317,10 +317,7 @@ static int run(int argc, char *argv[]) {
if (!ready) {
/* Notify manager that we are now finished with processing whatever was
* queued */
r = sd_notify(false, "READY=1");
if (r < 0)
log_warning_errno(r, "Failed to send readiness notification, ignoring: %m");
(void) sd_notify(false, "READY=1");
ready = true;
}

View File

@ -2783,7 +2783,7 @@ int table_print_with_pager(
* the table header and logs about any error. */
if (json_format_flags & (JSON_FORMAT_OFF|JSON_FORMAT_PRETTY|JSON_FORMAT_PRETTY_AUTO))
pager_open(pager_flags);
(void) pager_open(pager_flags);
saved_header = t->header;
t->header = show_header;

View File

@ -83,23 +83,23 @@ static int no_quit_on_interrupt(int exe_name_fd, const char *less_opts) {
return r;
}
void pager_open(PagerFlags flags) {
int pager_open(PagerFlags flags) {
_cleanup_close_pair_ int fd[2] = { -1, -1 }, exe_name_pipe[2] = { -1, -1 };
_cleanup_strv_free_ char **pager_args = NULL;
const char *pager, *less_opts;
int r;
if (flags & PAGER_DISABLE)
return;
return 0;
if (pager_pid > 0)
return;
return 1;
if (terminal_is_dumb())
return;
return 0;
if (!is_main_thread())
return (void) log_error_errno(SYNTHETIC_ERRNO(EPERM), "Pager invoked from wrong thread.");
return log_error_errno(SYNTHETIC_ERRNO(EPERM), "Pager invoked from wrong thread.");
pager = getenv("SYSTEMD_PAGER");
if (!pager)
@ -108,11 +108,11 @@ void pager_open(PagerFlags flags) {
if (pager) {
pager_args = strv_split(pager, WHITESPACE);
if (!pager_args)
return (void) log_oom();
return log_oom();
/* If the pager is explicitly turned off, honour it */
if (strv_isempty(pager_args) || strv_equal(pager_args, STRV_MAKE("cat")))
return;
return 0;
}
/* Determine and cache number of columns/lines before we spawn the pager so that we get the value from the
@ -121,11 +121,11 @@ void pager_open(PagerFlags flags) {
(void) lines();
if (pipe2(fd, O_CLOEXEC) < 0)
return (void) log_error_errno(errno, "Failed to create pager pipe: %m");
return log_error_errno(errno, "Failed to create pager pipe: %m");
/* This is a pipe to feed the name of the executed pager binary into the parent */
if (pipe2(exe_name_pipe, O_CLOEXEC) < 0)
return (void) log_error_errno(errno, "Failed to create exe_name pipe: %m");
return log_error_errno(errno, "Failed to create exe_name pipe: %m");
/* Initialize a good set of less options */
less_opts = getenv("SYSTEMD_LESS");
@ -137,7 +137,7 @@ void pager_open(PagerFlags flags) {
/* We set SIGINT as PR_DEATHSIG signal here, to match the "K" parameter we set in $LESS, which enables SIGINT behaviour. */
r = safe_fork("(pager)", FORK_RESET_SIGNALS|FORK_DEATHSIG_SIGINT|FORK_RLIMIT_NOFILE_SAFE|FORK_LOG, &pager_pid);
if (r < 0)
return;
return r;
if (r == 0) {
const char *less_charset, *exe;
@ -245,22 +245,26 @@ void pager_open(PagerFlags flags) {
stored_stdout = fcntl(STDOUT_FILENO, F_DUPFD_CLOEXEC, 3);
if (dup2(fd[1], STDOUT_FILENO) < 0) {
stored_stdout = safe_close(stored_stdout);
return (void) log_error_errno(errno, "Failed to duplicate pager pipe: %m");
return log_error_errno(errno, "Failed to duplicate pager pipe: %m");
}
stdout_redirected = true;
stored_stderr = fcntl(STDERR_FILENO, F_DUPFD_CLOEXEC, 3);
if (dup2(fd[1], STDERR_FILENO) < 0) {
stored_stderr = safe_close(stored_stderr);
return (void) log_error_errno(errno, "Failed to duplicate pager pipe: %m");
return log_error_errno(errno, "Failed to duplicate pager pipe: %m");
}
stderr_redirected = true;
exe_name_pipe[1] = safe_close(exe_name_pipe[1]);
r = no_quit_on_interrupt(TAKE_FD(exe_name_pipe[0]), less_opts);
if (r < 0)
return r;
if (r > 0)
(void) ignore_signals(SIGINT);
return 1;
}
void pager_close(void) {

View File

@ -10,7 +10,7 @@ typedef enum PagerFlags {
PAGER_JUMP_TO_END = 1 << 1,
} PagerFlags;
void pager_open(PagerFlags flags);
int pager_open(PagerFlags flags);
void pager_close(void);
bool pager_have(void) _pure_;

View File

@ -410,7 +410,7 @@ static int run(int argc, char *argv[]) {
return log_error_errno(r, "Failed to enumerate sysctl.d files: %m");
if (arg_cat_config) {
pager_open(arg_pager_flags);
(void) pager_open(arg_pager_flags);
return cat_files(NULL, files, 0);
}

View File

@ -54,7 +54,7 @@ int cat(int argc, char *argv[], void *userdata) {
if (r < 0)
return r;
pager_open(arg_pager_flags);
(void) pager_open(arg_pager_flags);
STRV_FOREACH(name, names) {
_cleanup_free_ char *fragment_path = NULL;

View File

@ -157,7 +157,7 @@ int list_dependencies(int argc, char *argv[], void *userdata) {
return log_error_errno(r, "Failed to expand names: %m");
}
pager_open(arg_pager_flags);
(void) pager_open(arg_pager_flags);
STRV_FOREACH(u, units) {
if (u != units)

View File

@ -73,7 +73,7 @@ static int output_jobs_list(sd_bus *bus, const struct job_info* jobs, unsigned n
return 0;
}
pager_open(arg_pager_flags);
(void) pager_open(arg_pager_flags);
table = table_new("job", "unit", "type", "state");
if (!table)
@ -168,7 +168,7 @@ int list_jobs(int argc, char *argv[], void *userdata) {
if (r < 0)
return bus_log_parse_error(r);
pager_open(arg_pager_flags);
(void) pager_open(arg_pager_flags);
return output_jobs_list(bus, jobs, c, skipped);
}

View File

@ -232,7 +232,7 @@ int list_machines(int argc, char *argv[], void *userdata) {
if (r < 0)
return r;
pager_open(arg_pager_flags);
(void) pager_open(arg_pager_flags);
typesafe_qsort(machine_infos, r, compare_machine_info);
rc = output_machines_list(machine_infos, r);

View File

@ -255,7 +255,7 @@ int list_unit_files(int argc, char *argv[], void *userdata) {
return bus_log_parse_error(r);
}
pager_open(arg_pager_flags);
(void) pager_open(arg_pager_flags);
typesafe_qsort(units, c, compare_unit_file_list);
r = output_unit_file_list(units, c);

View File

@ -221,7 +221,7 @@ int list_units(int argc, char *argv[], void *userdata) {
if (r < 0)
return r;
pager_open(arg_pager_flags);
(void) pager_open(arg_pager_flags);
if (arg_with_dependencies) {
_cleanup_strv_free_ char **names = NULL;
@ -439,7 +439,7 @@ int list_sockets(int argc, char *argv[], void *userdata) {
if (r < 0)
return r;
pager_open(arg_pager_flags);
(void) pager_open(arg_pager_flags);
r = expand_unit_names(bus, strv_skip(argv, 1), ".socket", &sockets_with_suffix, NULL);
if (r < 0)
@ -703,7 +703,7 @@ int list_timers(int argc, char *argv[], void *userdata) {
if (r < 0)
return r;
pager_open(arg_pager_flags);
(void) pager_open(arg_pager_flags);
r = expand_unit_names(bus, strv_skip(argv, 1), ".timer", &timers_with_suffix, NULL);
if (r < 0)

View File

@ -36,7 +36,7 @@ int show_environment(int argc, char *argv[], void *userdata) {
if (r < 0)
return r;
pager_open(arg_pager_flags);
(void) pager_open(arg_pager_flags);
r = bus_get_property(bus, bus_systemd_mgr, "Environment", &error, &reply, "as");
if (r < 0)

View File

@ -2036,7 +2036,7 @@ static int show_all(
if (r < 0)
return r;
pager_open(arg_pager_flags);
(void) pager_open(arg_pager_flags);
c = (unsigned) r;
@ -2142,7 +2142,7 @@ int show(int argc, char *argv[], void *userdata) {
if (r < 0)
return r;
pager_open(arg_pager_flags);
(void) pager_open(arg_pager_flags);
/* If no argument is specified inspect the manager itself */
if (show_mode == SYSTEMCTL_SHOW_PROPERTIES && argc <= 1)

View File

@ -128,7 +128,7 @@ static int systemctl_help(void) {
_cleanup_free_ char *link = NULL;
int r;
pager_open(arg_pager_flags);
(void) pager_open(arg_pager_flags);
r = terminal_urlify_man("systemctl", "1", &link);
if (r < 0)

View File

@ -1807,7 +1807,7 @@ static int cat_config(void) {
if (r < 0)
return r;
pager_open(arg_pager_flags);
(void) pager_open(arg_pager_flags);
return cat_files(NULL, files, 0);
}

View File

@ -336,75 +336,6 @@ static void test_align_to(void) {
assert_cc(__builtin_types_compatible_p(typeof(CONST_ALIGN_TO(SIZE_MAX, 512)), void));
}
static void test_flags(void) {
enum {
F1 = 1 << 0,
F2 = 1 << 1,
F3 = 1 << 2,
F_ALL = F1 | F2 | F3
};
unsigned n, f;
log_info("/* %s */", __func__);
assert_se(FLAGS_SET(0, 0));
assert_se(FLAGS_SET(F1, F1));
assert_se(FLAGS_SET(F1 | F2, F1));
assert_se(FLAGS_SET(F1 | F3, F1 | F3));
assert_se(FLAGS_SET(F1 | F2 | F3, F_ALL));
assert_se(!FLAGS_SET(0, F1));
assert_se(!FLAGS_SET(F2, F1));
assert_se(!FLAGS_SET(F1 | F2, F3));
assert_se(!FLAGS_SET(F1 | F2, F1 | F3));
assert_se(!FLAGS_SET(F1 | F2 | F3, ~F_ALL));
// Check for no double eval.
n = F2;
f = F1;
assert_se(!FLAGS_SET(--n, ++f));
assert_se(n == F1);
assert_se(f == F2);
SET_FLAG(n, F3, true);
assert_se(n == (F1 | F3));
SET_FLAG(n, F2, false);
assert_se(n == (F1 | F3));
SET_FLAG(n, F3, false);
assert_se(n == F1);
SET_FLAG(n, F1, true);
assert_se(n == F1);
SET_FLAG(n, F1 | F3, true);
assert_se(n == (F1 | F3));
SET_FLAG(n, F_ALL, false);
assert_se(n == 0);
assert_se(UPDATE_FLAG(0, 0, true) == 0);
assert_se(UPDATE_FLAG(0, F1, true) == F1);
assert_se(UPDATE_FLAG(0, F1 | F2, true) == (F1 | F2));
assert_se(UPDATE_FLAG(F1, 0, true) == F1);
assert_se(UPDATE_FLAG(F1, F1, true) == F1);
assert_se(UPDATE_FLAG(F1, F3, true) == (F1 | F3));
assert_se(UPDATE_FLAG(F1, F1 | F3, true) == (F1 | F3));
assert_se(UPDATE_FLAG(F1, F_ALL, true) == F_ALL);
assert_se(UPDATE_FLAG(0, 0, false) == 0);
assert_se(UPDATE_FLAG(0, F1, false) == 0);
assert_se(UPDATE_FLAG(0, F1 | F2, false) == 0);
assert_se(UPDATE_FLAG(F1, 0, false) == F1);
assert_se(UPDATE_FLAG(F1, F1, false) == 0);
assert_se(UPDATE_FLAG(F1, F3, false) == F1);
assert_se(UPDATE_FLAG(F1, F1 | F3, false) == 0);
assert_se(UPDATE_FLAG(F1, F2 | F3, false) == F1);
assert_se(UPDATE_FLAG(F1, F_ALL, false) == 0);
assert_se(UPDATE_FLAG(F_ALL, F_ALL, false) == 0);
// Check for no double eval.
n = F2;
f = F1;
assert_se(UPDATE_FLAG(--n, ++f, true) == (F1 | F2));
assert_se(n == F1);
assert_se(f == F2);
}
int main(int argc, char *argv[]) {
test_setup_logging(LOG_INFO);
@ -416,7 +347,6 @@ int main(int argc, char *argv[]) {
test_foreach_pointer();
test_ptr_to_int();
test_align_to();
test_flags();
return 0;
}

View File

@ -315,7 +315,7 @@ static int list_timezones(int argc, char **argv, void *userdata) {
if (r < 0)
return bus_log_parse_error(r);
pager_open(arg_pager_flags);
(void) pager_open(arg_pager_flags);
strv_print(zones);
return 0;

View File

@ -915,7 +915,7 @@ void manager_disconnect(Manager *m) {
m->event_timeout = sd_event_source_unref(m->event_timeout);
sd_notify(false, "STATUS=Idle.");
sd_notifyf(false, "STATUS=Idle.");
}
void manager_flush_server_names(Manager *m, ServerType t) {

View File

@ -3754,7 +3754,7 @@ static int run(int argc, char *argv[]) {
}
if (arg_cat_config) {
pager_open(arg_pager_flags);
(void) pager_open(arg_pager_flags);
return cat_config(config_dirs, argv + optind);
}

View File

@ -315,18 +315,9 @@ static void manager_exit(Manager *manager) {
manager_kill_workers(manager, true);
}
static void notify_ready(void) {
int r;
r = sd_notifyf(false,
"READY=1\n"
"STATUS=Processing with %u children at max", arg_children_max);
if (r < 0)
log_warning_errno(r, "Failed to send readiness notification, ignoring: %m");
}
/* reload requested, HUP signal received, rules changed, builtin changed */
static void manager_reload(Manager *manager) {
assert(manager);
sd_notify(false,
@ -337,7 +328,9 @@ static void manager_reload(Manager *manager) {
manager->rules = udev_rules_free(manager->rules);
udev_builtin_exit();
notify_ready();
sd_notifyf(false,
"READY=1\n"
"STATUS=Processing with %u children at max", arg_children_max);
}
static int on_kill_workers_event(sd_event_source *s, uint64_t usec, void *userdata) {
@ -1206,7 +1199,9 @@ static int on_ctrl_msg(UdevCtrl *uctrl, UdevCtrlMessageType type, const UdevCtrl
log_debug("Received udev control message (SET_MAX_CHILDREN), setting children_max=%i", value->intval);
arg_children_max = value->intval;
notify_ready();
(void) sd_notifyf(false,
"READY=1\n"
"STATUS=Processing with %u children at max", arg_children_max);
break;
case UDEV_CTRL_PING:
log_debug("Received udev control message (PING)");
@ -1867,7 +1862,9 @@ static int main_loop(Manager *manager) {
if (r < 0)
log_error_errno(r, "Failed to apply permissions on static device nodes: %m");
notify_ready();
(void) sd_notifyf(false,
"READY=1\n"
"STATUS=Processing with %u children at max", arg_children_max);
r = sd_event_loop(manager->event);
if (r < 0)

View File

@ -574,7 +574,7 @@ static int help(int argc, char *argv[], void *userdata) {
_cleanup_free_ char *link = NULL;
int r;
pager_open(arg_pager_flags);
(void) pager_open(arg_pager_flags);
r = terminal_urlify_man("userdbctl", "1", &link);
if (r < 0)

View File

@ -1,31 +1,13 @@
# SPDX-License-Identifier: LGPL-2.1-or-later
files = [['README', ''],
['systemd-coredump.conf', 'ENABLE_COREDUMP'],
['systemd-oom.conf', 'ENABLE_OOMD']]
foreach pair : files
if not enable_sysusers
# do nothing
elif pair[1] == '' or conf.get(pair[1]) == 1
install_data(pair[0], install_dir : sysusersdir)
else
message('Not installing sysusers.d/@0@ because @1@ is @2@'
.format(pair[0], pair[1], conf.get(pair[1], 0)))
endif
endforeach
if enable_sysusers and conf.get('ENABLE_REMOTE') == 1 and conf.get('HAVE_MICROHTTPD') == 1
install_data('systemd-remote.conf', install_dir : sysusersdir)
if enable_sysusers
install_data('README', install_dir : sysusersdir)
endif
in_files = [['basic.conf', enable_sysusers],
['systemd-journal.conf', enable_sysusers],
['systemd-network.conf', enable_sysusers and conf.get('ENABLE_NETWORKD') == 1],
['systemd-resolve.conf', enable_sysusers and conf.get('ENABLE_RESOLVE') == 1],
['systemd-timesync.conf', enable_sysusers and conf.get('ENABLE_TIMESYNCD') == 1]]
['systemd.conf', enable_sysusers],
['systemd-remote.conf', enable_sysusers and
conf.get('ENABLE_REMOTE') == 1 and conf.get('HAVE_MICROHTTPD') == 1]]
foreach tuple : in_files
file = tuple[0]

View File

@ -1,8 +0,0 @@
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
u systemd-coredump - "systemd Core Dumper"

View File

@ -1,8 +0,0 @@
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
g systemd-journal {{SYSTEMD_JOURNAL_GID}} -

View File

@ -1,8 +0,0 @@
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
u systemd-network {{SYSTEMD_NETWORK_UID}} "systemd Network Management"

View File

@ -1,8 +0,0 @@
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
u systemd-oom - "systemd Userspace OOM Killer"

View File

@ -5,4 +5,6 @@
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
{% if HAVE_MICROHTTPD %}
u systemd-journal-remote - "systemd Journal Remote"
{% endif %}

View File

@ -1,8 +0,0 @@
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
u systemd-resolve {{SYSTEMD_RESOLVE_UID}} "systemd Resolver"

View File

@ -1,8 +0,0 @@
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
u systemd-timesync {{SYSTEMD_TIMESYNC_UID}} "systemd Time Synchronization"

View File

@ -0,0 +1,23 @@
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
g systemd-journal {{SYSTEMD_JOURNAL_GID}} -
{% if ENABLE_NETWORKD %}
u systemd-network {{SYSTEMD_NETWORK_UID}} "systemd Network Management"
{% endif %}
{% if ENABLE_OOMD %}
u systemd-oom - "systemd Userspace OOM Killer"
{% endif %}
{% if ENABLE_RESOLVE %}
u systemd-resolve {{SYSTEMD_RESOLVE_UID}} "systemd Resolver"
{% endif %}
{% if ENABLE_TIMESYNCD %}
u systemd-timesync {{SYSTEMD_TIMESYNC_UID}} "systemd Time Synchronization"
{% endif %}
{% if ENABLE_COREDUMP %}
u systemd-coredump - "systemd Core Dumper"
{% endif %}

View File

@ -1,12 +1,10 @@
#!/usr/bin/env python3
# SPDX-License-Identifier: LGPL-2.1-or-later
import ast
import jinja2
import re
import sys
import jinja2
def parse_config_h(filename):
# Parse config.h file generated by meson.
ans = {}
@ -16,7 +14,7 @@ def parse_config_h(filename):
continue
a, b = m.groups()
if b and b[0] in '0123456789"':
b = ast.literal_eval(b)
b = eval(b)
ans[a] = b
return ans