Blob Blame History Raw
autofs-5.1.7 - eliminate some strlen calls in offset handling

From: Ian Kent <raven@themaw.net>

There are a number of places where strlen() is used to re-calculate
the length of a string. Eliminate some of those by calculating the
length once and passing it to the functions that do the re-calculation.

Signed-off-by: Ian Kent <raven@themaw.net>
---
 CHANGELOG    |    1 +
 lib/mounts.c |   30 +++++++++++++++++-------------
 2 files changed, 18 insertions(+), 13 deletions(-)

--- autofs-5.1.4.orig/CHANGELOG
+++ autofs-5.1.4/CHANGELOG
@@ -20,6 +20,7 @@
 - fix inconsistent locking in parse_mount().
 - remove unused mount offset list lock functions.
 - eliminate count_mounts() from expire_proc_indirect().
+- eliminate some strlen calls in offset handling.
 
 xx/xx/2018 autofs-5.1.5
 - fix flag file permission.
--- autofs-5.1.4.orig/lib/mounts.c
+++ autofs-5.1.4/lib/mounts.c
@@ -2534,10 +2534,12 @@ static int rmdir_path_offset(struct auto
 	return ret;
 }
 
-static int do_umount_offset(struct autofs_point *ap, struct mapent *oe, const char *root);
+static int do_umount_offset(struct autofs_point *ap,
+			    struct mapent *oe, const char *root, int start);
 
 static int do_umount_multi_triggers(struct autofs_point *ap,
-				    struct mapent *me, const char *root, const char *base)
+				    struct mapent *me, const char *root,
+				    int start, const char *base)
 {
 	char path[PATH_MAX + 1];
 	char *offset;
@@ -2545,12 +2547,11 @@ static int do_umount_multi_triggers(stru
 	struct list_head *mm_root, *pos;
 	const char o_root[] = "/";
 	const char *mm_base;
-	int left, start;
+	int left;
 	unsigned int root_len;
 	unsigned int mm_base_len;
 
 	left = 0;
-	start = strlen(root);
 
 	mm_root = &me->multi->multi_list;
 
@@ -2586,13 +2587,14 @@ static int do_umount_multi_triggers(stru
 		if (!oe || (strlen(oe->key) - start) == 1)
 			continue;
 
-		left += do_umount_offset(ap, oe, root);
+		left += do_umount_offset(ap, oe, root, start);
 	}
 
 	return left;
 }
 
-static int do_umount_offset(struct autofs_point *ap, struct mapent *oe, const char *root)
+static int do_umount_offset(struct autofs_point *ap,
+			    struct mapent *oe, const char *root, int start)
 {
 	char *oe_base;
 	int left = 0;
@@ -2601,8 +2603,8 @@ static int do_umount_offset(struct autof
 	 * Check for and umount subtree offsets resulting from
 	 * nonstrict mount fail.
 	 */
-	oe_base = oe->key + strlen(root);
-	left += do_umount_multi_triggers(ap, oe, root, oe_base);
+	oe_base = oe->key + start;
+	left += do_umount_multi_triggers(ap, oe, root, start, oe_base);
 
 	/*
 	 * If an offset that has an active mount has been removed
@@ -2706,7 +2708,7 @@ int mount_multi_triggers(struct autofs_p
 			goto cont;
 		if (oe->age != me->multi->age) {
 			/* Best effort */
-			do_umount_offset(ap, oe, root);
+			do_umount_offset(ap, oe, root, start);
 			goto cont;
 		}
 
@@ -2720,7 +2722,7 @@ int mount_multi_triggers(struct autofs_p
 		if (ap->state == ST_READMAP && ap->flags & MOUNT_FLAG_REMOUNT) {
 			if (oe->ioctlfd != -1 ||
 			    is_mounted(oe->key, MNTS_REAL))
-				mount_multi_triggers(ap, oe, key, strlen(key), base);
+				mount_multi_triggers(ap, oe, key, key_len, base);
 		}
 cont:
 		offset = cache_get_offset(base,
@@ -2732,9 +2734,11 @@ cont:
 
 int umount_multi_triggers(struct autofs_point *ap, struct mapent *me, char *root, const char *base)
 {
-	int left;
+	int left, start;
+
+	start = strlen(root);
 
-	left = do_umount_multi_triggers(ap, me, root, base);
+	left = do_umount_multi_triggers(ap, me, root, start, base);
 
 	if (!left && me->multi == me) {
 		/*
@@ -2747,7 +2751,7 @@ int umount_multi_triggers(struct autofs_
 			info(ap->logopt, "unmounting dir = %s", root);
 			if (umount_ent(ap, root) &&
 			    is_mounted(root, MNTS_REAL)) {
-				if (mount_multi_triggers(ap, me, root, strlen(root), "/") < 0)
+				if (mount_multi_triggers(ap, me, root, start, "/") < 0)
 					warn(ap->logopt,
 					     "failed to remount offset triggers");
 				return ++left;