Skip to contentSkip to conversation

debian patches merge (pass 1)

PATCH New Fabio M. Di Nitto 2 participants 5 messages Oct 13, 2009

lore
Share & tools
lore
#0 lore raw

Hi,

those 2 patches are ready to be merged.

the others are still being processed and will come later on.

Fabio

#1 lore raw

PATCH 1/2 configure.in: don't set default file owner and group

Per discussion on lvm-devel mailing list and part of debian patch set, don't set defaults for owner and group, since nobody seems to use them, and still allow override.

---
:100644 100644 5f06333... 6ff56b9... M WHATS_NEW
:100755 100755 eedc60c... 8542492... M configure
:100644 100644 fb99c9f... 116cf6b... M configure.in

 WHATS_NEW    |    1 +
 configure    |    4 ++--
 configure.in |    4 ++--
 3 files changed, 5 insertions(+), 4 deletions(-)
WHATS_NEW +1 -0
index 5f06333..6ff56b9 100644
@@ -1,5 +1,6 @@
 Version 2.02.54 -
 =====================================
+  Set default owner and group to null.
   Add dmeventd.static to the build.
   Disable realtime support code by default.
   Make clvmd return 0 on success rather than 1.
configure +2 -2
index eedc60c..8542492 100755
@@ -9078,7 +9078,7 @@ $as_echo "$STATIC_LINK" >&6; }
 ################################################################################
 { $as_echo "$as_me:$LINENO: checking file owner" >&5
 $as_echo_n "checking file owner... " >&6; }
-OWNER="root"
+OWNER=""
 
 
 # Check whether --with-user was given.
@@ -9096,7 +9096,7 @@ fi
 ################################################################################
 { $as_echo "$as_me:$LINENO: checking group owner" >&5
 $as_echo_n "checking group owner... " >&6; }
-GROUP="root"
+GROUP=""
 
 # Check whether --with-group was given.
 if test "${with_group+set}" = set; then
configure.in +2 -2
index fb99c9f..116cf6b 100644
@@ -144,7 +144,7 @@ AC_PREFIX_DEFAULT(/usr)
 ################################################################################
 dnl -- Setup the ownership of the files
 AC_MSG_CHECKING(file owner)
-OWNER="root"
+OWNER=""
 
 AC_ARG_WITH(user,
   [  --with-user=USER        Set the owner of installed files [[USER=root]] ],
@@ -158,7 +158,7 @@ fi
 ################################################################################
 dnl -- Setup the group ownership of the files
 AC_MSG_CHECKING(group owner)
-GROUP="root"
+GROUP=""
 AC_ARG_WITH(group,
   [  --with-group=GROUP      Set the group owner of installed files [[GROUP=root]] ],
   [ GROUP="$withval" ])
Signature · 1 line
1.5.4.3
#2 lore raw

PATCH 1/2 configure.in: don't set default file owner and group

Quoted 3 lines · Fabio M. Di Nitto

Per discussion on lvm-devel mailing list and part of debian patch set, don't set defaults for owner and group, since nobody seems to use them, and still allow override.

Ack.

Alasdair

#3 lore raw

PATCH 2/2 make the device node creation more atomic

In reply to Fabio M. Di Nitto

---
:100644 100644 248d3ac... 90e0907... M libdm/libdm-common.c

 libdm/libdm-common.c |   32 ++++++++++++++++++++++++--------
 1 files changed, 24 insertions(+), 8 deletions(-)
libdm/libdm-common.c +24 -8
index 248d3ac..90e0907 100644
@@ -403,12 +403,19 @@ int dm_set_selinux_context(const char *path, mode_t mode)
 static int _add_dev_node(const char *dev_name, uint32_t major, uint32_t minor,
 			 uid_t uid, gid_t gid, mode_t mode)
 {
-	char path[PATH_MAX];
+	char path[PATH_MAX], tmppath[PATH_MAX];
 	struct stat info;
 	dev_t dev = MKDEV(major, minor);
 	mode_t old_mask;
 
 	_build_dev_path(path, sizeof(path), dev_name);
+	_build_dev_path(tmppath, sizeof(tmppath), ".XXXXXX");
+
+	mktemp(tmppath);
+	if (strlen(tmppath) == 0) {
+		log_error("Unable to create name of temporary file");
+		return 0;
+	}
 
 	if (stat(path, &info) >= 0) {
 		if (!S_ISBLK(info.st_mode)) {
@@ -431,24 +438,33 @@ static int _add_dev_node(const char *dev_name, uint32_t major, uint32_t minor,
 			 "node creation.", path);
 
 	old_mask = umask(0);
-	if (mknod(path, S_IFBLK | mode, dev) < 0) {
+	if (mknod(tmppath, S_IFBLK | mode, dev) < 0) {
 		umask(old_mask);
 		log_error("Unable to make device node for '%s'", dev_name);
-		return 0;
+		goto error;
 	}
 	umask(old_mask);
 
-	if (chown(path, uid, gid) < 0) {
+	if (chown(tmppath, uid, gid) < 0) {
 		log_sys_error("chown", path);
-		return 0;
+		goto error;
 	}
 
-	log_debug("Created %s", path);
+	if (!dm_set_selinux_context(tmppath, S_IFBLK))
+		goto error;
 
-	if (!dm_set_selinux_context(path, S_IFBLK))
-		return 0;
+	if (rename(tmppath, path) < 0) {
+		log_error("Unable to replace device node for '%s'", dev_name);
+		goto error;
+	}
+
+	log_debug("Created %s", path);
 
 	return 1;
+
+error:
+	unlink(tmppath);
+	return 0;
 }
 
 static int _rm_dev_node(const char *dev_name)
Signature · 1 line
1.5.4.3
#4 lore raw

PATCH 2/2 make the device node creation more atomic

libdm/libdm-common.c int dm_set_selinux_context(const char *path, mode_t mode) · line 414

Quoted 2 lines · Fabio M. Di Nitto
libdm/libdm-common.c +2 -0
+	_build_dev_path(tmppath, sizeof(tmppath), ".XXXXXX");
+	mktemp(tmppath);

Unfortunately this still looks to have races because the actual lock is not acquired by the mktemp function, but only later, and there is no retry mechanism in this patch - if two parallel mktemps picked the same name the code would fail, introducing a failure mode that is not present in the existing code.

Normally you would use mkstemp rather than mktemp.

Options:
(1) introduce a ugly collision detection + retry mechanism;
(2) use mkstemp() to lock a related filename in a new namespace
e.g. .XXXXXX.lock and .XXXXXX.node and do the mknod on .XXXXXX.node while using the unique .XXXXXX.lock regular file as an exclusive lock;
(3) use the existing create_temp_name() function (moving it to libdm)
or write a variant that does mknod() checking for EEXIST instead of open();
(4) find some other solution.

My current preferrence would be (3) - to encapsulate the functionality required in a new 'create_temp_node' function.

Alasdair