1
0
mirror of https://github.com/systemd/systemd synced 2026-03-30 19:54:51 +02:00

Compare commits

..

No commits in common. "b98416e1002bccfa2cf576a290d321fdf1ce254e" and "a94aa2b9c174b8cbb6a5b3701626f777dd3d1557" have entirely different histories.

9 changed files with 41 additions and 52 deletions

View File

@ -1412,7 +1412,7 @@ static int verb_log_control(int argc, char *argv[], void *userdata) {
_cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
int r;
assert(IN_SET(argc, 1, 2));
assert(argc == 1 || argc == 2);
r = acquire_bus(&bus, NULL);
if (r < 0)
@ -2284,7 +2284,7 @@ static int do_security(int argc, char *argv[], void *userdata) {
if (r < 0 && r != -ENOENT)
return r;
if (f) {
if (f != NULL) {
r = json_parse_file(f, pp, /*flags=*/ 0, &policy, &line, &column);
if (r < 0)
return log_error_errno(r, "[%s:%u:%u] Failed to parse JSON policy: %m", pp, line, column);

View File

@ -5,12 +5,22 @@
#include "dirent-util.h"
#include "path-util.h"
#include "stat-util.h"
#include "string-util.h"
int stat_mode_to_dirent_type(mode_t mode) {
return
S_ISREG(mode) ? DT_REG :
S_ISDIR(mode) ? DT_DIR :
S_ISLNK(mode) ? DT_LNK :
S_ISFIFO(mode) ? DT_FIFO :
S_ISSOCK(mode) ? DT_SOCK :
S_ISCHR(mode) ? DT_CHR :
S_ISBLK(mode) ? DT_BLK :
DT_UNKNOWN;
}
static int dirent_ensure_type(DIR *d, struct dirent *de) {
STRUCT_STATX_DEFINE(sx);
int r;
struct stat st;
assert(d);
assert(de);
@ -23,17 +33,10 @@ static int dirent_ensure_type(DIR *d, struct dirent *de) {
return 0;
}
/* Let's ask only for the type, nothing else. */
r = statx_fallback(dirfd(d), de->d_name, AT_SYMLINK_NOFOLLOW|AT_NO_AUTOMOUNT, STATX_TYPE, &sx);
if (r < 0)
return r;
if (fstatat(dirfd(d), de->d_name, &st, AT_SYMLINK_NOFOLLOW) < 0)
return -errno;
assert(FLAGS_SET(sx.stx_mask, STATX_TYPE));
de->d_type = IFTODT(sx.stx_mode);
/* If the inode is passed too, update the field, i.e. report most recent data */
if (FLAGS_SET(sx.stx_mask, STATX_INO))
de->d_ino = sx.stx_ino;
de->d_type = stat_mode_to_dirent_type(st.st_mode);
return 0;
}
@ -66,40 +69,24 @@ bool dirent_is_file_with_suffix(const struct dirent *de, const char *suffix) {
}
struct dirent *readdir_ensure_type(DIR *d) {
int r;
struct dirent *de;
assert(d);
/* Like readdir(), but fills in .d_type if it is DT_UNKNOWN */
for (;;) {
struct dirent *de;
errno = 0;
de = readdir(d);
if (!de)
return NULL;
r = dirent_ensure_type(d, de);
if (r >= 0)
return de;
if (r != -ENOENT) {
errno = -r; /* We want to be compatible with readdir(), hence propagate error via errno here */
return NULL;
}
/* Vanished by now? Then skip immedately to next */
}
errno = 0;
de = readdir(d);
if (de)
(void) dirent_ensure_type(d, de);
return de;
}
struct dirent *readdir_no_dot(DIR *d) {
assert(d);
struct dirent *readdir_no_dot(DIR *dirp) {
struct dirent *d;
for (;;) {
struct dirent *de;
de = readdir_ensure_type(d);
if (!de || !dot_or_dot_dot(de->d_name))
return de;
d = readdir_ensure_type(dirp);
if (d && dot_or_dot_dot(d->d_name))
continue;
return d;
}
}

View File

@ -8,6 +8,8 @@
#include "macro.h"
#include "path-util.h"
int stat_mode_to_dirent_type(mode_t mode);
bool dirent_is_file(const struct dirent *de) _pure_;
bool dirent_is_file_with_suffix(const struct dirent *de, const char *suffix) _pure_;

View File

@ -290,7 +290,7 @@ int recurse_dir(
/* Copy over the data we acquired through statx() if we acquired any */
if (sx.stx_mask & STATX_TYPE) {
assert(!!subdir == !!S_ISDIR(sx.stx_mode));
de[i]->d_type = IFTODT(sx.stx_mode);
de[i]->d_type = stat_mode_to_dirent_type(sx.stx_mode);
}
if (sx.stx_mask & STATX_INO)

View File

@ -1004,7 +1004,7 @@ static int attach_luks2_by_pkcs11(
bool headless,
uint32_t flags) {
int r = -EOPNOTSUPP;
int r = -ENOTSUP;
#if HAVE_LIBCRYPTSETUP_PLUGINS
if (!crypt_get_type(cd) || strcmp(crypt_get_type(cd), CRYPT_LUKS2))
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Automatic PKCS#11 metadata requires LUKS2 device.");
@ -1198,7 +1198,7 @@ static int attach_luks2_by_tpm2(
.device = arg_tpm2_device
};
if (!crypt_token_external_path())
if (crypt_token_external_path() == NULL)
return log_debug_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
"Libcryptsetup has external plugins support disabled.");

View File

@ -2540,7 +2540,7 @@ static int verb_log_level(int argc, char *argv[], void *userdata) {
sd_bus *bus = userdata;
assert(bus);
assert(IN_SET(argc, 1, 2));
assert(argc == 1 || argc == 2);
return verb_log_control_common(bus, "org.freedesktop.resolve1", argv[0], argc == 2 ? argv[1] : NULL);
}

View File

@ -1596,7 +1596,7 @@ int dissect_image(
}
if (m->verity_ready)
m->verity_sig_ready = verity->root_hash_sig;
m->verity_sig_ready = !!verity->root_hash_sig;
} else if (m->partitions[verity->designator == PARTITION_USR ? PARTITION_USR_VERITY_SIG : PARTITION_ROOT_VERITY_SIG].found) {

View File

@ -529,7 +529,7 @@ int fork_agent(const char *name, int except[], size_t n_except, pid_t *ret_pid,
* stdin around. */
fd = open("/dev/tty", O_WRONLY);
if (fd < 0) {
if (errno != ENXIO) {
if (errno != -ENXIO) {
log_error_errno(errno, "Failed to open /dev/tty: %m");
_exit(EXIT_FAILURE);
}

View File

@ -219,9 +219,9 @@ int pkcs11_token_login_by_pin(
return log_error_errno(SYNTHETIC_ERRNO(EIO),
"Failed to log into security token '%s': %s", token_label, p11_kit_strerror(rv));
return log_notice_errno(SYNTHETIC_ERRNO(ENOLCK),
"PIN for token '%s' is incorrect, please try again.",
token_label);
log_notice("PIN for token '%s' is incorrect, please try again.", token_label);
return -ENOLCK;
}
int pkcs11_token_login(