From: Christian Brauner Date: Tue, 1 Aug 2017 20:46:14 +0000 (+0200) Subject: conf: mount_entry() X-Git-Tag: lxc-2.1.0~33^2~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0ac4b28a48db6c7251caf3e17e2ed95834cc6856;p=thirdparty%2Flxc.git conf: mount_entry() non-functional changes Signed-off-by: Christian Brauner --- diff --git a/src/lxc/conf.c b/src/lxc/conf.c index 1a672d886..c3a5d839e 100644 --- a/src/lxc/conf.c +++ b/src/lxc/conf.c @@ -1726,77 +1726,91 @@ static char *get_field(char *src, int nfields) static int mount_entry(const char *fsname, const char *target, const char *fstype, unsigned long mountflags, - const char *data, int optional, int dev, const char *rootfs) + const char *data, int optional, int dev, + const char *rootfs) { + int ret; #ifdef HAVE_STATVFS struct statvfs sb; #endif - if (safe_mount(fsname, target, fstype, mountflags & ~MS_REMOUNT, data, rootfs)) { + ret = safe_mount(fsname, target, fstype, mountflags & ~MS_REMOUNT, data, + rootfs); + if (ret < 0) { if (optional) { - INFO("failed to mount '%s' on '%s' (optional): %s", fsname, - target, strerror(errno)); + INFO("Failed to mount \"%s\" on \"%s\" (optional): %s", + fsname, target, strerror(errno)); return 0; } - else { - SYSERROR("failed to mount '%s' on '%s'", fsname, target); - return -1; - } + + SYSERROR("Failed to mount \"%s\" on \"%s\"", fsname, target); + return -1; } if ((mountflags & MS_REMOUNT) || (mountflags & MS_BIND)) { - DEBUG("remounting %s on %s to respect bind or remount options", - fsname ? fsname : "(none)", target ? target : "(none)"); unsigned long rqd_flags = 0; + + DEBUG("Remounting \"%s\" on \"%s\" to respect bind or remount " + "options", + fsname ? fsname : "(none)", target ? target : "(none)"); + if (mountflags & MS_RDONLY) rqd_flags |= MS_RDONLY; #ifdef HAVE_STATVFS if (statvfs(fsname, &sb) == 0) { unsigned long required_flags = rqd_flags; + if (sb.f_flag & MS_NOSUID) required_flags |= MS_NOSUID; + if (sb.f_flag & MS_NODEV && !dev) required_flags |= MS_NODEV; + if (sb.f_flag & MS_RDONLY) required_flags |= MS_RDONLY; + if (sb.f_flag & MS_NOEXEC) required_flags |= MS_NOEXEC; - DEBUG("(at remount) flags for %s was %lu, required extra flags are %lu", fsname, sb.f_flag, required_flags); - /* - * If this was a bind mount request, and required_flags + + DEBUG("Flags for \"%s\" were %lu, required extra flags " + "are %lu", fsname, sb.f_flag, required_flags); + + /* If this was a bind mount request, and required_flags * does not have any flags which are not already in - * mountflags, then skip the remount + * mountflags, then skip the remount. */ if (!(mountflags & MS_REMOUNT)) { - if (!(required_flags & ~mountflags) && rqd_flags == 0) { - DEBUG("mountflags already was %lu, skipping remount", - mountflags); + if (!(required_flags & ~mountflags) && + rqd_flags == 0) { + DEBUG("Mountflags already were %lu, " + "skipping remount", mountflags); goto skipremount; } } + mountflags |= required_flags; } #endif - if (mount(fsname, target, fstype, - mountflags | MS_REMOUNT, data) < 0) { + ret = mount(fsname, target, fstype, mountflags | MS_REMOUNT, data); + if (ret < 0) { if (optional) { - INFO("failed to mount '%s' on '%s' (optional): %s", - fsname, target, strerror(errno)); + INFO("Failed to mount \"%s\" on \"%s\" " + "(optional): %s", fsname, target, + strerror(errno)); return 0; } - else { - SYSERROR("failed to mount '%s' on '%s'", - fsname, target); - return -1; - } + + SYSERROR("Failed to mount \"%s\" on \"%s\"", fsname, target); + return -1; } } #ifdef HAVE_STATVFS skipremount: #endif - DEBUG("mounted '%s' on '%s', type '%s'", fsname, target, fstype); + DEBUG("Mounted \"%s\" on \"%s\" with filesystem type \"%s\"", fsname, + target, fstype); return 0; }