mirror of
https://github.com/systemd/systemd
synced 2025-09-29 08:44:45 +02:00
Compare commits
14 Commits
679dab6a8f
...
e953dcab39
Author | SHA1 | Date | |
---|---|---|---|
![]() |
e953dcab39 | ||
![]() |
f0d87798ea | ||
![]() |
0de405873c | ||
![]() |
04a853848e | ||
![]() |
0ca04e5fdc | ||
![]() |
dda859f84c | ||
![]() |
49f2369377 | ||
![]() |
d6ae82bdd9 | ||
![]() |
22d33e8090 | ||
![]() |
ce634c4a4d | ||
![]() |
61c0972dad | ||
![]() |
327379f5f2 | ||
![]() |
4f1ef7f9e0 | ||
![]() |
dd75bbee43 |
@ -17,6 +17,7 @@
|
||||
#include "process-util.h"
|
||||
#include "selinux-util.h"
|
||||
#include "signal-util.h"
|
||||
#include "stat-util.h"
|
||||
#include "tmpfile-util.h"
|
||||
#include "util.h"
|
||||
|
||||
@ -195,10 +196,10 @@ int import_fork_tar_c(const char *path, pid_t *ret) {
|
||||
}
|
||||
|
||||
int import_mangle_os_tree(const char *path) {
|
||||
_cleanup_free_ char *child = NULL, *t = NULL, *joined = NULL;
|
||||
_cleanup_closedir_ DIR *d = NULL, *cd = NULL;
|
||||
_cleanup_free_ char *child = NULL, *t = NULL;
|
||||
const char *joined;
|
||||
struct dirent *de;
|
||||
struct stat st;
|
||||
int r;
|
||||
|
||||
assert(path);
|
||||
@ -240,14 +241,24 @@ int import_mangle_os_tree(const char *path) {
|
||||
if (errno != 0)
|
||||
return log_error_errno(errno, "Failed to iterate through directory '%s': %m", path);
|
||||
|
||||
log_debug("Directory '%s' does not look like a directory tree, and has multiple children, leaving as it is.", path);
|
||||
log_debug("Directory '%s' does not look like an OS tree, and has multiple children, leaving as it is.", path);
|
||||
return 0;
|
||||
}
|
||||
|
||||
joined = prefix_roota(path, child);
|
||||
if (fstatat(dirfd(d), child, &st, AT_SYMLINK_NOFOLLOW) < 0)
|
||||
return log_debug_errno(errno, "Failed to stat file '%s/%s': %m", path, child);
|
||||
r = stat_verify_directory(&st);
|
||||
if (r < 0) {
|
||||
log_debug_errno(r, "Child '%s' of directory '%s' is not a directory, leaving things as they are.", child, path);
|
||||
return 0;
|
||||
}
|
||||
|
||||
joined = path_join(path, child);
|
||||
if (!joined)
|
||||
return log_oom();
|
||||
r = path_is_os_tree(joined);
|
||||
if (r == -ENOTDIR) {
|
||||
log_debug("Directory '%s' does not look like a directory tree, and contains a single regular file only, leaving as it is.", path);
|
||||
log_debug("Directory '%s' does not look like an OS tree, and contains a single regular file only, leaving as it is.", path);
|
||||
return 0;
|
||||
}
|
||||
if (r < 0)
|
||||
@ -293,6 +304,14 @@ int import_mangle_os_tree(const char *path) {
|
||||
if (unlinkat(dirfd(d), t, AT_REMOVEDIR) < 0)
|
||||
return log_error_errno(errno, "Failed to remove temporary directory '%s/%s': %m", path, t);
|
||||
|
||||
r = futimens(dirfd(d), (struct timespec[2]) { st.st_atim, st.st_mtim });
|
||||
if (r < 0)
|
||||
log_debug_errno(r, "Failed to adjust top-level timestamps '%s', ignoring: %m", path);
|
||||
|
||||
r = fchmod_and_chown(dirfd(d), st.st_mode, st.st_uid, st.st_gid);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to adjust top-level directory mode/ownership '%s': %m", path);
|
||||
|
||||
log_info("Successfully rearranged OS tree.");
|
||||
|
||||
return 0;
|
||||
|
@ -448,7 +448,6 @@ int device_new_from_strv(sd_device **ret, char **strv) {
|
||||
int device_new_from_nulstr(sd_device **ret, uint8_t *nulstr, size_t len) {
|
||||
_cleanup_(sd_device_unrefp) sd_device *device = NULL;
|
||||
const char *major = NULL, *minor = NULL;
|
||||
unsigned i = 0;
|
||||
int r;
|
||||
|
||||
assert(ret);
|
||||
@ -459,11 +458,11 @@ int device_new_from_nulstr(sd_device **ret, uint8_t *nulstr, size_t len) {
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
while (i < len) {
|
||||
for (size_t i = 0; i < len; ) {
|
||||
char *key;
|
||||
const char *end;
|
||||
|
||||
key = (char*)&nulstr[i];
|
||||
key = (char*) &nulstr[i];
|
||||
end = memchr(key, '\0', len - i);
|
||||
if (!end)
|
||||
return log_device_debug_errno(device, SYNTHETIC_ERRNO(EINVAL),
|
||||
|
@ -65,9 +65,9 @@ static sd_device *device_free(sd_device *device) {
|
||||
free(device->properties_strv);
|
||||
free(device->properties_nulstr);
|
||||
|
||||
ordered_hashmap_free_free_free(device->properties);
|
||||
ordered_hashmap_free_free_free(device->properties_db);
|
||||
hashmap_free_free_free(device->sysattr_values);
|
||||
ordered_hashmap_free(device->properties);
|
||||
ordered_hashmap_free(device->properties_db);
|
||||
hashmap_free(device->sysattr_values);
|
||||
set_free(device->sysattrs);
|
||||
set_free(device->all_tags);
|
||||
set_free(device->current_tags);
|
||||
@ -78,46 +78,46 @@ static sd_device *device_free(sd_device *device) {
|
||||
|
||||
DEFINE_PUBLIC_TRIVIAL_REF_UNREF_FUNC(sd_device, sd_device, device_free);
|
||||
|
||||
int device_add_property_aux(sd_device *device, const char *_key, const char *_value, bool db) {
|
||||
int device_add_property_aux(sd_device *device, const char *key, const char *value, bool db) {
|
||||
OrderedHashmap **properties;
|
||||
|
||||
assert(device);
|
||||
assert(_key);
|
||||
assert(key);
|
||||
|
||||
if (db)
|
||||
properties = &device->properties_db;
|
||||
else
|
||||
properties = &device->properties;
|
||||
|
||||
if (_value) {
|
||||
_cleanup_free_ char *key = NULL, *value = NULL, *old_key = NULL, *old_value = NULL;
|
||||
if (value) {
|
||||
_cleanup_free_ char *new_key = NULL, *new_value = NULL, *old_key = NULL, *old_value = NULL;
|
||||
int r;
|
||||
|
||||
r = ordered_hashmap_ensure_allocated(properties, &string_hash_ops);
|
||||
r = ordered_hashmap_ensure_allocated(properties, &string_hash_ops_free_free);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
key = strdup(_key);
|
||||
if (!key)
|
||||
new_key = strdup(key);
|
||||
if (!new_key)
|
||||
return -ENOMEM;
|
||||
|
||||
value = strdup(_value);
|
||||
if (!value)
|
||||
new_value = strdup(value);
|
||||
if (!new_value)
|
||||
return -ENOMEM;
|
||||
|
||||
old_value = ordered_hashmap_get2(*properties, key, (void**) &old_key);
|
||||
|
||||
r = ordered_hashmap_replace(*properties, key, value);
|
||||
/* ordered_hashmap_replace() does not fail when the hashmap already has the entry. */
|
||||
r = ordered_hashmap_replace(*properties, new_key, new_value);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
key = NULL;
|
||||
value = NULL;
|
||||
TAKE_PTR(new_key);
|
||||
TAKE_PTR(new_value);
|
||||
} else {
|
||||
_cleanup_free_ char *key = NULL;
|
||||
_cleanup_free_ char *value = NULL;
|
||||
_cleanup_free_ char *old_key = NULL, *old_value = NULL;
|
||||
|
||||
value = ordered_hashmap_remove2(*properties, _key, (void**) &key);
|
||||
old_value = ordered_hashmap_remove2(*properties, key, (void**) &old_key);
|
||||
}
|
||||
|
||||
if (!db) {
|
||||
@ -231,8 +231,7 @@ _public_ int sd_device_new_from_syspath(sd_device **ret, const char *syspath) {
|
||||
}
|
||||
|
||||
_public_ int sd_device_new_from_devnum(sd_device **ret, char type, dev_t devnum) {
|
||||
char *syspath;
|
||||
char id[DECIMAL_STR_MAX(unsigned) * 2 + 1];
|
||||
char id[DECIMAL_STR_MAX(unsigned) * 2 + 1], *syspath;
|
||||
|
||||
assert_return(ret, -EINVAL);
|
||||
assert_return(IN_SET(type, 'b', 'c'), -EINVAL);
|
||||
@ -399,7 +398,7 @@ int device_set_devmode(sd_device *device, const char *_devmode) {
|
||||
}
|
||||
|
||||
int device_set_devnum(sd_device *device, const char *major, const char *minor) {
|
||||
unsigned maj = 0, min = 0;
|
||||
unsigned maj, min = 0;
|
||||
int r;
|
||||
|
||||
assert(device);
|
||||
@ -408,7 +407,7 @@ int device_set_devnum(sd_device *device, const char *major, const char *minor) {
|
||||
r = safe_atou(major, &maj);
|
||||
if (r < 0)
|
||||
return r;
|
||||
if (!maj)
|
||||
if (maj == 0)
|
||||
return 0;
|
||||
|
||||
if (minor) {
|
||||
@ -1780,30 +1779,28 @@ _public_ int sd_device_get_property_value(sd_device *device, const char *key, co
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* replaces the value if it already exists */
|
||||
static int device_add_sysattr_value(sd_device *device, const char *_key, char *value) {
|
||||
_cleanup_free_ char *key = NULL;
|
||||
_cleanup_free_ char *value_old = NULL;
|
||||
static int device_add_sysattr_value(sd_device *device, const char *key, char *value) {
|
||||
_cleanup_free_ char *new_key = NULL, *old_value = NULL;
|
||||
int r;
|
||||
|
||||
assert(device);
|
||||
assert(_key);
|
||||
assert(key);
|
||||
|
||||
r = hashmap_ensure_allocated(&device->sysattr_values, &string_hash_ops);
|
||||
if (r < 0)
|
||||
return r;
|
||||
/* This takes the reference of the input value. The input value may be NULL.
|
||||
* This replaces the value if it already exists. */
|
||||
|
||||
value_old = hashmap_remove2(device->sysattr_values, _key, (void **)&key);
|
||||
if (!key) {
|
||||
key = strdup(_key);
|
||||
if (!key)
|
||||
old_value = hashmap_remove2(device->sysattr_values, key, (void **) &new_key);
|
||||
if (!new_key) {
|
||||
new_key = strdup(key);
|
||||
if (!new_key)
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
r = hashmap_put(device->sysattr_values, key, value);
|
||||
r = hashmap_ensure_put(&device->sysattr_values, &string_hash_ops_free_free, new_key, value);
|
||||
if (r < 0)
|
||||
return r;
|
||||
TAKE_PTR(key);
|
||||
|
||||
TAKE_PTR(new_key);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -462,7 +462,7 @@ int sd_rtnl_message_link_set_flags(sd_netlink_message *m, unsigned flags, unsign
|
||||
assert_return(m, -EINVAL);
|
||||
assert_return(m->hdr, -EINVAL);
|
||||
assert_return(rtnl_message_type_is_link(m->hdr->nlmsg_type), -EINVAL);
|
||||
assert_return(change, -EINVAL);
|
||||
assert_return(change != 0, -EINVAL);
|
||||
|
||||
ifi = NLMSG_DATA(m->hdr);
|
||||
|
||||
@ -679,7 +679,7 @@ int sd_rtnl_message_new_addr(sd_netlink *rtnl, sd_netlink_message **ret,
|
||||
}
|
||||
|
||||
int sd_rtnl_message_new_addr_update(sd_netlink *rtnl, sd_netlink_message **ret,
|
||||
int index, int family) {
|
||||
int index, int family) {
|
||||
int r;
|
||||
|
||||
r = sd_rtnl_message_new_addr(rtnl, ret, RTM_NEWADDR, index, family);
|
||||
|
@ -3429,10 +3429,16 @@ class NetworkdLLDPTests(unittest.TestCase, Utilities):
|
||||
start_networkd()
|
||||
self.wait_online(['veth99:degraded', 'veth-peer:degraded'])
|
||||
|
||||
output = check_output(*networkctl_cmd, 'lldp', env=env)
|
||||
print(output)
|
||||
self.assertRegex(output, 'veth-peer')
|
||||
self.assertRegex(output, 'veth99')
|
||||
for trial in range(10):
|
||||
if trial > 0:
|
||||
time.sleep(1)
|
||||
|
||||
output = check_output(*networkctl_cmd, 'lldp', env=env)
|
||||
print(output)
|
||||
if re.search(r'veth99 .* veth-peer', output):
|
||||
break
|
||||
else:
|
||||
self.fail()
|
||||
|
||||
class NetworkdRATests(unittest.TestCase, Utilities):
|
||||
links = ['veth99']
|
||||
|
Loading…
x
Reference in New Issue
Block a user