1
0
mirror of https://github.com/systemd/systemd synced 2025-12-31 13:24:45 +01:00

Compare commits

..

No commits in common. "e953dcab3956c2221b36339cdbb1cc4f128c1232" and "679dab6a8f286aec66969f34fe2d9e127c3d273d" have entirely different histories.

5 changed files with 53 additions and 74 deletions

View File

@ -17,7 +17,6 @@
#include "process-util.h" #include "process-util.h"
#include "selinux-util.h" #include "selinux-util.h"
#include "signal-util.h" #include "signal-util.h"
#include "stat-util.h"
#include "tmpfile-util.h" #include "tmpfile-util.h"
#include "util.h" #include "util.h"
@ -196,10 +195,10 @@ int import_fork_tar_c(const char *path, pid_t *ret) {
} }
int import_mangle_os_tree(const char *path) { 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_closedir_ DIR *d = NULL, *cd = NULL;
_cleanup_free_ char *child = NULL, *t = NULL;
const char *joined;
struct dirent *de; struct dirent *de;
struct stat st;
int r; int r;
assert(path); assert(path);
@ -241,24 +240,14 @@ int import_mangle_os_tree(const char *path) {
if (errno != 0) if (errno != 0)
return log_error_errno(errno, "Failed to iterate through directory '%s': %m", path); return log_error_errno(errno, "Failed to iterate through directory '%s': %m", path);
log_debug("Directory '%s' does not look like an OS tree, and has multiple children, leaving as it is.", path); log_debug("Directory '%s' does not look like a directory tree, and has multiple children, leaving as it is.", path);
return 0; return 0;
} }
if (fstatat(dirfd(d), child, &st, AT_SYMLINK_NOFOLLOW) < 0) joined = prefix_roota(path, child);
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); r = path_is_os_tree(joined);
if (r == -ENOTDIR) { if (r == -ENOTDIR) {
log_debug("Directory '%s' does not look like an OS tree, and contains a single regular file only, leaving as it is.", path); log_debug("Directory '%s' does not look like a directory tree, and contains a single regular file only, leaving as it is.", path);
return 0; return 0;
} }
if (r < 0) if (r < 0)
@ -304,14 +293,6 @@ int import_mangle_os_tree(const char *path) {
if (unlinkat(dirfd(d), t, AT_REMOVEDIR) < 0) if (unlinkat(dirfd(d), t, AT_REMOVEDIR) < 0)
return log_error_errno(errno, "Failed to remove temporary directory '%s/%s': %m", path, t); 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."); log_info("Successfully rearranged OS tree.");
return 0; return 0;

View File

@ -448,6 +448,7 @@ int device_new_from_strv(sd_device **ret, char **strv) {
int device_new_from_nulstr(sd_device **ret, uint8_t *nulstr, size_t len) { int device_new_from_nulstr(sd_device **ret, uint8_t *nulstr, size_t len) {
_cleanup_(sd_device_unrefp) sd_device *device = NULL; _cleanup_(sd_device_unrefp) sd_device *device = NULL;
const char *major = NULL, *minor = NULL; const char *major = NULL, *minor = NULL;
unsigned i = 0;
int r; int r;
assert(ret); assert(ret);
@ -458,11 +459,11 @@ int device_new_from_nulstr(sd_device **ret, uint8_t *nulstr, size_t len) {
if (r < 0) if (r < 0)
return r; return r;
for (size_t i = 0; i < len; ) { while (i < len) {
char *key; char *key;
const char *end; const char *end;
key = (char*) &nulstr[i]; key = (char*)&nulstr[i];
end = memchr(key, '\0', len - i); end = memchr(key, '\0', len - i);
if (!end) if (!end)
return log_device_debug_errno(device, SYNTHETIC_ERRNO(EINVAL), return log_device_debug_errno(device, SYNTHETIC_ERRNO(EINVAL),

View File

@ -65,9 +65,9 @@ static sd_device *device_free(sd_device *device) {
free(device->properties_strv); free(device->properties_strv);
free(device->properties_nulstr); free(device->properties_nulstr);
ordered_hashmap_free(device->properties); ordered_hashmap_free_free_free(device->properties);
ordered_hashmap_free(device->properties_db); ordered_hashmap_free_free_free(device->properties_db);
hashmap_free(device->sysattr_values); hashmap_free_free_free(device->sysattr_values);
set_free(device->sysattrs); set_free(device->sysattrs);
set_free(device->all_tags); set_free(device->all_tags);
set_free(device->current_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); 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; OrderedHashmap **properties;
assert(device); assert(device);
assert(key); assert(_key);
if (db) if (db)
properties = &device->properties_db; properties = &device->properties_db;
else else
properties = &device->properties; properties = &device->properties;
if (value) { if (_value) {
_cleanup_free_ char *new_key = NULL, *new_value = NULL, *old_key = NULL, *old_value = NULL; _cleanup_free_ char *key = NULL, *value = NULL, *old_key = NULL, *old_value = NULL;
int r; int r;
r = ordered_hashmap_ensure_allocated(properties, &string_hash_ops_free_free); r = ordered_hashmap_ensure_allocated(properties, &string_hash_ops);
if (r < 0) if (r < 0)
return r; return r;
new_key = strdup(key); key = strdup(_key);
if (!new_key) if (!key)
return -ENOMEM; return -ENOMEM;
new_value = strdup(value); value = strdup(_value);
if (!new_value) if (!value)
return -ENOMEM; return -ENOMEM;
old_value = ordered_hashmap_get2(*properties, key, (void**) &old_key); old_value = ordered_hashmap_get2(*properties, key, (void**) &old_key);
/* ordered_hashmap_replace() does not fail when the hashmap already has the entry. */ r = ordered_hashmap_replace(*properties, key, value);
r = ordered_hashmap_replace(*properties, new_key, new_value);
if (r < 0) if (r < 0)
return r; return r;
TAKE_PTR(new_key); key = NULL;
TAKE_PTR(new_value); value = NULL;
} else { } else {
_cleanup_free_ char *old_key = NULL, *old_value = NULL; _cleanup_free_ char *key = NULL;
_cleanup_free_ char *value = NULL;
old_value = ordered_hashmap_remove2(*properties, key, (void**) &old_key); value = ordered_hashmap_remove2(*properties, _key, (void**) &key);
} }
if (!db) { if (!db) {
@ -231,7 +231,8 @@ _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) { _public_ int sd_device_new_from_devnum(sd_device **ret, char type, dev_t devnum) {
char id[DECIMAL_STR_MAX(unsigned) * 2 + 1], *syspath; char *syspath;
char id[DECIMAL_STR_MAX(unsigned) * 2 + 1];
assert_return(ret, -EINVAL); assert_return(ret, -EINVAL);
assert_return(IN_SET(type, 'b', 'c'), -EINVAL); assert_return(IN_SET(type, 'b', 'c'), -EINVAL);
@ -398,7 +399,7 @@ int device_set_devmode(sd_device *device, const char *_devmode) {
} }
int device_set_devnum(sd_device *device, const char *major, const char *minor) { int device_set_devnum(sd_device *device, const char *major, const char *minor) {
unsigned maj, min = 0; unsigned maj = 0, min = 0;
int r; int r;
assert(device); assert(device);
@ -407,7 +408,7 @@ int device_set_devnum(sd_device *device, const char *major, const char *minor) {
r = safe_atou(major, &maj); r = safe_atou(major, &maj);
if (r < 0) if (r < 0)
return r; return r;
if (maj == 0) if (!maj)
return 0; return 0;
if (minor) { if (minor) {
@ -1779,28 +1780,30 @@ _public_ int sd_device_get_property_value(sd_device *device, const char *key, co
return 0; return 0;
} }
static int device_add_sysattr_value(sd_device *device, const char *key, char *value) { /* replaces the value if it already exists */
_cleanup_free_ char *new_key = NULL, *old_value = NULL; 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;
int r; int r;
assert(device); assert(device);
assert(key); assert(_key);
/* This takes the reference of the input value. The input value may be NULL. r = hashmap_ensure_allocated(&device->sysattr_values, &string_hash_ops);
* This replaces the value if it already exists. */
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_ensure_put(&device->sysattr_values, &string_hash_ops_free_free, new_key, value);
if (r < 0) if (r < 0)
return r; return r;
TAKE_PTR(new_key); value_old = hashmap_remove2(device->sysattr_values, _key, (void **)&key);
if (!key) {
key = strdup(_key);
if (!key)
return -ENOMEM;
}
r = hashmap_put(device->sysattr_values, key, value);
if (r < 0)
return r;
TAKE_PTR(key);
return 0; return 0;
} }

View File

@ -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, -EINVAL);
assert_return(m->hdr, -EINVAL); assert_return(m->hdr, -EINVAL);
assert_return(rtnl_message_type_is_link(m->hdr->nlmsg_type), -EINVAL); assert_return(rtnl_message_type_is_link(m->hdr->nlmsg_type), -EINVAL);
assert_return(change != 0, -EINVAL); assert_return(change, -EINVAL);
ifi = NLMSG_DATA(m->hdr); 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 sd_rtnl_message_new_addr_update(sd_netlink *rtnl, sd_netlink_message **ret,
int index, int family) { int index, int family) {
int r; int r;
r = sd_rtnl_message_new_addr(rtnl, ret, RTM_NEWADDR, index, family); r = sd_rtnl_message_new_addr(rtnl, ret, RTM_NEWADDR, index, family);

View File

@ -3429,16 +3429,10 @@ class NetworkdLLDPTests(unittest.TestCase, Utilities):
start_networkd() start_networkd()
self.wait_online(['veth99:degraded', 'veth-peer:degraded']) self.wait_online(['veth99:degraded', 'veth-peer:degraded'])
for trial in range(10): output = check_output(*networkctl_cmd, 'lldp', env=env)
if trial > 0: print(output)
time.sleep(1) self.assertRegex(output, 'veth-peer')
self.assertRegex(output, 'veth99')
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): class NetworkdRATests(unittest.TestCase, Utilities):
links = ['veth99'] links = ['veth99']