autofs/SOURCES/autofs-5.1.7-add-a-len-field-to-struct-autofs_point.patch
2021-12-08 12:28:52 +00:00

123 lines
3.7 KiB
Diff

autofs-5.1.7 - add a len field to struct autofs_point
From: Ian Kent <raven@themaw.net>
Add a path length field to struct autofs_point since the path length
is needed at various times avoiding additional strlen() calls.
Signed-off-by: Ian Kent <raven@themaw.net>
---
CHANGELOG | 1 +
daemon/lookup.c | 2 +-
daemon/master.c | 1 +
include/automount.h | 1 +
lib/mounts.c | 6 +++---
modules/parse_amd.c | 4 ++--
modules/parse_sun.c | 4 ++--
7 files changed, 11 insertions(+), 8 deletions(-)
--- autofs-5.1.4.orig/CHANGELOG
+++ autofs-5.1.4/CHANGELOG
@@ -30,6 +30,7 @@
- fix program map multi-mount lookup after mount fail.
- add some multi-mount macros.
- remove unused functions cache_dump_multi() and cache_dump_cache().
+- add a len field to struct autofs_point.
xx/xx/2018 autofs-5.1.5
- fix flag file permission.
--- autofs-5.1.4.orig/daemon/lookup.c
+++ autofs-5.1.4/daemon/lookup.c
@@ -851,7 +851,7 @@ static int lookup_amd_instance(struct au
return NSS_STATUS_UNKNOWN;
}
- m_key = malloc(strlen(ap->path) + strlen(MM_ROOT(me)->key) + 2);
+ m_key = malloc(ap->len + strlen(MM_ROOT(me)->key) + 2);
if (!m_key) {
error(ap->logopt,
"failed to allocate storage for search key");
--- autofs-5.1.4.orig/daemon/master.c
+++ autofs-5.1.4/daemon/master.c
@@ -86,6 +86,7 @@ int master_add_autofs_point(struct maste
free(ap);
return 0;
}
+ ap->len = strlen(ap->path);
ap->pref = NULL;
ap->entry = entry;
--- autofs-5.1.4.orig/include/automount.h
+++ autofs-5.1.4/include/automount.h
@@ -547,6 +547,7 @@ struct kernel_mod_version {
struct autofs_point {
pthread_t thid;
char *path; /* Mount point name */
+ size_t len; /* Length of mount point name */
mode_t mode; /* Mount point mode */
char *pref; /* amd prefix */
int pipefd; /* File descriptor for pipe */
--- autofs-5.1.4.orig/lib/mounts.c
+++ autofs-5.1.4/lib/mounts.c
@@ -1158,7 +1158,7 @@ struct mnt_list *mnts_add_mount(struct a
if (!mp)
goto fail;
} else {
- int len = strlen(ap->path) + strlen(name) + 2;
+ int len = ap->len + strlen(name) + 2;
mp = malloc(len);
if (!mp)
@@ -2489,9 +2489,9 @@ static int rmdir_path_offset(struct auto
dir = strdup(oe->key);
if (ap->flags & MOUNT_FLAG_GHOST)
- split = strlen(ap->path) + strlen(MM_ROOT(oe)->key) + 1;
+ split = ap->len + strlen(MM_ROOT(oe)->key) + 1;
else
- split = strlen(ap->path);
+ split = ap->len;
dir[split] = '\0';
path = &dir[split + 1];
--- autofs-5.1.4.orig/modules/parse_amd.c
+++ autofs-5.1.4/modules/parse_amd.c
@@ -147,7 +147,7 @@ static struct substvar *add_lookup_vars(
struct mapent *me;
int len;
- len = strlen(ap->path) + 1 + key_len + 1;
+ len = ap->len + 1 + key_len + 1;
if (len > PATH_MAX) {
error(ap->logopt, MODPREFIX
"error: lookup key is greater than PATH_MAX");
@@ -1319,7 +1319,7 @@ static int do_host_mount(struct autofs_p
char *target;
size_t len;
- len = strlen(ap->path) + strlen(entry->rhost) + 2;
+ len = ap->len + strlen(entry->rhost) + 2;
target = malloc(len);
if (!target) {
warn(ap->logopt, MODPREFIX
--- autofs-5.1.4.orig/modules/parse_sun.c
+++ autofs-5.1.4/modules/parse_sun.c
@@ -1156,7 +1156,7 @@ static int mount_subtree(struct autofs_p
mm_root = mm_key;
start = strlen(mm_key);
} else {
- start = strlen(ap->path) + strlen(mm_key) + 1;
+ start = ap->len + strlen(mm_key) + 1;
mm_root = alloca(start + 3);
strcpy(mm_root, ap->path);
strcat(mm_root, "/");
@@ -1479,7 +1479,7 @@ dont_expand:
}
strcpy(m_root, name);
} else {
- m_root_len = strlen(ap->path) + name_len + 1;
+ m_root_len = ap->len + name_len + 1;
m_root = alloca(m_root_len + 1);
if (!m_root) {
char *estr = strerror_r(errno, buf, MAX_ERR_BUF);