1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2025-03-08 20:58:20 +03:00

portable: make PortableChangeType enum anonymous

Same reasons as previous commit.
This commit is contained in:
Lennart Poettering 2021-02-17 10:47:30 +01:00
parent 93419a9601
commit ba5b6c5925
4 changed files with 23 additions and 12 deletions

View File

@ -10,6 +10,7 @@
#include "dirent-util.h"
#include "discover-image.h"
#include "dissect-image.h"
#include "errno-list.h"
#include "fd-util.h"
#include "fileio.h"
#include "fs-util.h"
@ -591,7 +592,7 @@ static int unit_file_is_active(
static int portable_changes_add(
PortableChange **changes,
size_t *n_changes,
PortableChangeType type,
int type_or_errno, /* PORTABLE_COPY, PORTABLE_SYMLINK, … if positive, or errno if negative */
const char *path,
const char *source) {
@ -601,6 +602,11 @@ static int portable_changes_add(
assert(path);
assert(!changes == !n_changes);
if (type_or_errno >= 0)
assert(type_or_errno < _PORTABLE_CHANGE_TYPE_MAX);
else
assert(type_or_errno >= -ERRNO_MAX);
if (!changes)
return 0;
@ -624,7 +630,7 @@ static int portable_changes_add(
}
c[(*n_changes)++] = (PortableChange) {
.type = type,
.type_or_errno = type_or_errno,
.path = TAKE_PTR(p),
.source = TAKE_PTR(s),
};
@ -635,7 +641,7 @@ static int portable_changes_add(
static int portable_changes_add_with_prefix(
PortableChange **changes,
size_t *n_changes,
PortableChangeType type,
int type_or_errno,
const char *prefix,
const char *path,
const char *source) {
@ -653,7 +659,7 @@ static int portable_changes_add_with_prefix(
source = prefix_roota(prefix, source);
}
return portable_changes_add(changes, n_changes, type, path, source);
return portable_changes_add(changes, n_changes, type_or_errno, path, source);
}
void portable_changes_free(PortableChange *changes, size_t n_changes) {
@ -1417,7 +1423,7 @@ static const char* const portable_change_type_table[_PORTABLE_CHANGE_TYPE_MAX] =
[PORTABLE_WRITE] = "write",
};
DEFINE_STRING_TABLE_LOOKUP(portable_change_type, PortableChangeType);
DEFINE_STRING_TABLE_LOOKUP(portable_change_type, int);
static const char* const portable_state_table[_PORTABLE_STATE_MAX] = {
[PORTABLE_DETACHED] = "detached",

View File

@ -24,7 +24,9 @@ typedef enum PortableFlags {
PORTABLE_REATTACH = 1 << 3,
} PortableFlags;
typedef enum PortableChangeType {
/* This enum is anonymous, since we usually store it in an 'int', as we overload it with negative errno
* values. */
enum {
PORTABLE_COPY,
PORTABLE_SYMLINK,
PORTABLE_UNLINK,
@ -32,7 +34,7 @@ typedef enum PortableChangeType {
PORTABLE_MKDIR,
_PORTABLE_CHANGE_TYPE_MAX,
_PORTABLE_CHANGE_TYPE_INVALID = -EINVAL,
} PortableChangeType;
};
typedef enum PortableState {
PORTABLE_DETACHED,
@ -47,7 +49,7 @@ typedef enum PortableState {
} PortableState;
typedef struct PortableChange {
int type; /* PortableFileChangeType or negative error number */
int type_or_errno; /* PORTABLE_COPY, PORTABLE_SYMLINK, … if positive, errno if negative */
char *path;
char *source;
} PortableChange;
@ -68,8 +70,8 @@ int portable_get_profiles(char ***ret);
void portable_changes_free(PortableChange *changes, size_t n_changes);
const char *portable_change_type_to_string(PortableChangeType t) _const_;
PortableChangeType portable_change_type_from_string(const char *t) _pure_;
const char *portable_change_type_to_string(int t) _const_;
int portable_change_type_from_string(const char *t) _pure_;
const char *portable_state_to_string(PortableState t) _const_;
PortableState portable_state_from_string(const char *t) _pure_;

View File

@ -457,8 +457,11 @@ static int reply_portable_compose_message(sd_bus_message *reply, const PortableC
return r;
for (i = 0; i < n_changes; i++) {
if (changes[i].type_or_errno < 0)
continue;
r = sd_bus_message_append(reply, "(sss)",
portable_change_type_to_string(changes[i].type),
portable_change_type_to_string(changes[i].type_or_errno),
changes[i].path,
changes[i].source);
if (r < 0)

View File

@ -483,7 +483,7 @@ static int normalize_portable_changes(
}
changes[n_changes++] = (PortableChange) {
.type = changes_detached[i].type,
.type_or_errno = changes_detached[i].type_or_errno,
.path = TAKE_PTR(path),
.source = TAKE_PTR(source),
};