[systemd-commits] 2 commits - src/libudev src/readahead src/shared src/tmpfiles
Dave Reisner
dreisner at kemper.freedesktop.org
Mon Apr 21 06:57:09 PDT 2014
src/libudev/libudev-monitor.c | 6 ++----
src/readahead/readahead-common.c | 6 ++----
src/shared/cgroup-util.c | 10 +++-------
src/shared/path-util.c | 3 +--
src/shared/util.h | 6 ++++++
src/tmpfiles/tmpfiles.c | 11 ++++-------
6 files changed, 18 insertions(+), 24 deletions(-)
New commits:
commit 370c860f748d149097710dc7952a64f627db9de7
Author: Dave Reisner <dreisner at archlinux.org>
Date: Sat Apr 19 13:22:35 2014 -0400
implement a union to pad out file_handle
Cases where name_to_handle_at is used allocated the full struct to be
MAX_HANDLE_SZ, and assigned this size to handle_bytes. This is wrong
since handle_bytes should describe the length of the flexible array
member and not the whole struct.
Define a union type which includes sufficient padding to allow
assignment of MAX_HANDLE_SZ to be correct.
diff --git a/src/libudev/libudev-monitor.c b/src/libudev/libudev-monitor.c
index 3f7436b..0a2ab82 100644
--- a/src/libudev/libudev-monitor.c
+++ b/src/libudev/libudev-monitor.c
@@ -108,15 +108,13 @@ static struct udev_monitor *udev_monitor_new(struct udev *udev)
/* we consider udev running when /dev is on devtmpfs */
static bool udev_has_devtmpfs(struct udev *udev) {
- struct file_handle *h;
+ union file_handle_union h = { .handle.handle_bytes = MAX_HANDLE_SZ, };
int mount_id;
_cleanup_fclose_ FILE *f = NULL;
char line[LINE_MAX], *e;
int r;
- h = alloca(MAX_HANDLE_SZ);
- h->handle_bytes = MAX_HANDLE_SZ;
- r = name_to_handle_at(AT_FDCWD, "/dev", h, &mount_id, 0);
+ r = name_to_handle_at(AT_FDCWD, "/dev", &h.handle, &mount_id, 0);
if (r < 0)
return false;
diff --git a/src/readahead/readahead-common.c b/src/readahead/readahead-common.c
index 5ffa88b..49679fc 100644
--- a/src/readahead/readahead-common.c
+++ b/src/readahead/readahead-common.c
@@ -75,7 +75,7 @@ int fs_on_ssd(const char *p) {
if (major(st.st_dev) == 0) {
_cleanup_fclose_ FILE *f = NULL;
int mount_id;
- struct file_handle *h;
+ union file_handle_union h = { .handle.handle_bytes = MAX_HANDLE_SZ, };
/* Might be btrfs, which exposes "ssd" as mount flag if it is on ssd.
*
@@ -83,9 +83,7 @@ int fs_on_ssd(const char *p) {
* and then lookup the mount ID in mountinfo to find
* the mount options. */
- h = alloca(MAX_HANDLE_SZ);
- h->handle_bytes = MAX_HANDLE_SZ;
- r = name_to_handle_at(AT_FDCWD, p, h, &mount_id, AT_SYMLINK_FOLLOW);
+ r = name_to_handle_at(AT_FDCWD, p, &h.handle, &mount_id, AT_SYMLINK_FOLLOW);
if (r < 0)
return false;
diff --git a/src/shared/util.h b/src/shared/util.h
index 900f1cf..891848a 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -22,6 +22,7 @@
***/
#include <alloca.h>
+#include <fcntl.h>
#include <inttypes.h>
#include <time.h>
#include <sys/time.h>
@@ -914,3 +915,8 @@ uint64_t physical_memory(void);
char* mount_test_option(const char *haystack, const char *needle);
void hexdump(FILE *f, const void *p, size_t s);
+
+union file_handle_union {
+ struct file_handle handle;
+ char padding[sizeof(struct file_handle) + MAX_HANDLE_SZ];
+};
diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c
index 33e7cbc..04b472d 100644
--- a/src/tmpfiles/tmpfiles.c
+++ b/src/tmpfiles/tmpfiles.c
@@ -217,19 +217,16 @@ static bool unix_socket_alive(const char *fn) {
}
static int dir_is_mount_point(DIR *d, const char *subdir) {
- struct file_handle *h;
+ union file_handle_union h = { .handle.handle_bytes = MAX_HANDLE_SZ };
int mount_id_parent, mount_id;
int r_p, r;
- h = alloca(MAX_HANDLE_SZ);
-
- h->handle_bytes = MAX_HANDLE_SZ;
- r_p = name_to_handle_at(dirfd(d), ".", h, &mount_id_parent, 0);
+ r_p = name_to_handle_at(dirfd(d), ".", &h.handle, &mount_id_parent, 0);
if (r_p < 0)
r_p = -errno;
- h->handle_bytes = MAX_HANDLE_SZ;
- r = name_to_handle_at(dirfd(d), subdir, h, &mount_id, 0);
+ h.handle.handle_bytes = MAX_HANDLE_SZ;
+ r = name_to_handle_at(dirfd(d), subdir, &h.handle, &mount_id, 0);
if (r < 0)
r = -errno;
commit dbb9401dba0bd5157d021e695a47bf52b2d74a2d
Author: Dave Reisner <dreisner at archlinux.org>
Date: Tue Apr 15 22:16:40 2014 -0400
condense assignment and path_kill_slashes calls
diff --git a/src/shared/cgroup-util.c b/src/shared/cgroup-util.c
index 9d50890..139888c 100644
--- a/src/shared/cgroup-util.c
+++ b/src/shared/cgroup-util.c
@@ -472,9 +472,7 @@ static int join_path(const char *controller, const char *path, const char *suffi
if (!t)
return -ENOMEM;
- path_kill_slashes(t);
-
- *fs = t;
+ *fs = path_kill_slashes(t);
return 0;
}
@@ -957,8 +955,7 @@ int cg_split_spec(const char *spec, char **controller, char **path) {
if (!t)
return -ENOMEM;
- path_kill_slashes(t);
- *path = t;
+ *path = path_kill_slashes(t);
}
if (controller)
@@ -1048,8 +1045,7 @@ int cg_mangle_path(const char *path, char **result) {
if (!t)
return -ENOMEM;
- path_kill_slashes(t);
- *result = t;
+ *result = path_kill_slashes(t);
return 0;
}
diff --git a/src/shared/path-util.c b/src/shared/path-util.c
index e35d7f8..373dd7a 100644
--- a/src/shared/path-util.c
+++ b/src/shared/path-util.c
@@ -464,8 +464,7 @@ int find_binary(const char *name, char **filename) {
continue;
if (filename) {
- path_kill_slashes(p);
- *filename = p;
+ *filename = path_kill_slashes(p);
p = NULL;
}
More information about the systemd-commits
mailing list