[systemd-commits] 2 commits - src/nspawn src/shared
Zbigniew JÄdrzejewski-Szmek
zbyszek at kemper.freedesktop.org
Thu Dec 5 22:00:23 PST 2013
src/nspawn/nspawn.c | 47 +++++++++++++++++++++++++++--------------------
src/shared/util.c | 2 +-
2 files changed, 28 insertions(+), 21 deletions(-)
New commits:
commit 2ed4e5e0b89cd1cf128803a62c0a27dd78e1c12e
Author: Shawn Landden <shawn at churchofgit.com>
Date: Thu Dec 5 06:20:08 2013 -0800
nspawn: fix buggy mount_binds, now works for bind-mounted files
diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c
index dd7337b..eef0e9a 100644
--- a/src/nspawn/nspawn.c
+++ b/src/nspawn/nspawn.c
@@ -418,39 +418,46 @@ static int mount_binds(const char *dest, char **l, unsigned long flags) {
char **x, **y;
STRV_FOREACH_PAIR(x, y, l) {
- _cleanup_free_ char *where = NULL;
+ char *where;
struct stat source_st, dest_st;
+ int r;
if (stat(*x, &source_st) < 0) {
log_error("failed to stat %s: %m", *x);
return -errno;
}
- where = strjoin(dest, "/", *y, NULL);
- if (!where)
- return log_oom();
-
- if (stat(where, &dest_st) == 0) {
+ where = strappenda(dest, *y);
+ r = stat(where, &dest_st);
+ if (r == 0) {
if ((source_st.st_mode & S_IFMT) != (dest_st.st_mode & S_IFMT)) {
log_error("The file types of %s and %s do not match. Refusing bind mount",
*x, where);
return -EINVAL;
}
- } else {
- /* Create the mount point, but be conservative -- refuse to create block
- * and char devices. */
- if (S_ISDIR(source_st.st_mode))
- mkdir_p_label(where, 0755);
- else if (S_ISFIFO(source_st.st_mode))
- mkfifo(where, 0644);
- else if (S_ISSOCK(source_st.st_mode))
- mknod(where, 0644 | S_IFSOCK, 0);
- else if (S_ISREG(source_st.st_mode))
- touch(where);
- else {
- log_error("Refusing to create mountpoint for file: %s", *x);
- return -ENOTSUP;
+ } else if (errno == ENOENT) {
+ r = mkdir_parents_label(where, 0755);
+ if (r < 0) {
+ log_error("Failed to bind mount %s: %s", *x, strerror(-r));
+ return r;
}
+ } else {
+ log_error("Failed to bind mount %s: %s", *x, strerror(errno));
+ return -errno;
+ }
+ /* Create the mount point, but be conservative -- refuse to create block
+ * and char devices. */
+ if (S_ISDIR(source_st.st_mode))
+ mkdir_label(where, 0755);
+ else if (S_ISFIFO(source_st.st_mode))
+ mkfifo(where, 0644);
+ else if (S_ISSOCK(source_st.st_mode))
+ mknod(where, 0644 | S_IFSOCK, 0);
+ else if (S_ISREG(source_st.st_mode))
+ touch(where);
+ else {
+ log_error("Refusing to create mountpoint for file: %s", *x);
+ return -ENOTSUP;
}
if (mount(*x, where, "bind", MS_BIND, NULL) < 0) {
commit 85ca9433abc00d8cc641fceafe9e87dfcd92af4a
Author: Yuxuan Shui <yshuiv7 at gmail.com>
Date: Thu Dec 5 22:30:04 2013 +0800
util: fix misuse of memcmp
diff --git a/src/shared/util.c b/src/shared/util.c
index efd3468..c712931 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -5919,7 +5919,7 @@ int shall_restore_state(void) {
return 1;
FOREACH_WORD_QUOTED(w, l, line, state)
- if (l == 23 && memcmp(w, "systemd.restore_state=0", 23))
+ if (l == 23 && strneq(w, "systemd.restore_state=0", 23))
return 0;
return 1;
More information about the systemd-commits
mailing list