mirror of
https://github.com/systemd/systemd.git
synced 2026-08-08 09:01:02 +00:00
sd-id128: introduce id128_get_machine() and id128_get_machine_at()
This commit is contained in:
@@ -32,6 +32,9 @@ static inline int id128_write(const char *path, Id128Flag f, sd_id128_t id) {
|
||||
return id128_write_at(AT_FDCWD, path, f, id);
|
||||
}
|
||||
|
||||
int id128_get_machine(const char *root, sd_id128_t *ret);
|
||||
int id128_get_machine_at(int rfd, sd_id128_t *ret);
|
||||
|
||||
void id128_hash_func(const sd_id128_t *p, struct siphash *state);
|
||||
int id128_compare_func(const sd_id128_t *a, const sd_id128_t *b) _pure_;
|
||||
extern const struct hash_ops id128_hash_ops;
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "sd-id128.h"
|
||||
|
||||
#include "alloc-util.h"
|
||||
#include "chase.h"
|
||||
#include "fd-util.h"
|
||||
#include "hexdecoct.h"
|
||||
#include "hmac.h"
|
||||
@@ -15,6 +16,7 @@
|
||||
#include "macro.h"
|
||||
#include "missing_syscall.h"
|
||||
#include "missing_threads.h"
|
||||
#include "path-util.h"
|
||||
#include "random-util.h"
|
||||
#include "stat-util.h"
|
||||
#include "user-util.h"
|
||||
@@ -136,6 +138,38 @@ _public_ int sd_id128_get_machine(sd_id128_t *ret) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int id128_get_machine_at(int rfd, sd_id128_t *ret) {
|
||||
_cleanup_close_ int fd = -EBADF;
|
||||
int r;
|
||||
|
||||
assert(rfd >= 0 || rfd == AT_FDCWD);
|
||||
|
||||
r = dir_fd_is_root_or_cwd(rfd);
|
||||
if (r < 0)
|
||||
return r;
|
||||
if (r > 0)
|
||||
return sd_id128_get_machine(ret);
|
||||
|
||||
fd = chase_and_openat(rfd, "/etc/machine-id", CHASE_AT_RESOLVE_IN_ROOT, O_RDONLY|O_CLOEXEC|O_NOCTTY, NULL);
|
||||
if (fd < 0)
|
||||
return fd;
|
||||
|
||||
return id128_read_fd(fd, ID128_FORMAT_PLAIN | ID128_REFUSE_NULL, ret);
|
||||
}
|
||||
|
||||
int id128_get_machine(const char *root, sd_id128_t *ret) {
|
||||
_cleanup_close_ int fd = -EBADF;
|
||||
|
||||
if (empty_or_root(root))
|
||||
return sd_id128_get_machine(ret);
|
||||
|
||||
fd = chase_and_open("/etc/machine-id", root, CHASE_PREFIX_ROOT, O_RDONLY|O_CLOEXEC|O_NOCTTY, NULL);
|
||||
if (fd < 0)
|
||||
return fd;
|
||||
|
||||
return id128_read_fd(fd, ID128_FORMAT_PLAIN | ID128_REFUSE_NULL, ret);
|
||||
}
|
||||
|
||||
_public_ int sd_id128_get_boot(sd_id128_t *ret) {
|
||||
static thread_local sd_id128_t saved_boot_id = {};
|
||||
int r;
|
||||
|
||||
Reference in New Issue
Block a user