[PATCH][RESEND] apply the struct dirent penalty only when needed

[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

 



Hi,

attached is a patch that reduces the memory in use on all systems where 
BROKEN_ONE_BYTE_DIRENT_D_NAME is not defined.

It would be good if there was a ac_something variable that could be given to 
configure to tell it if this workaround is needed or not when cross compiling. 
We currently do it another way after running configure:

====
cat >>conftest.c <<EOF
#include <sys/types.h>
#include <dirent.h>
#include <assert.h>

int
main()
{
        struct dirent d;
        static_assert(sizeof(d.d_name) > sizeof(char), "struct to small");

        return 0;
}
EOF

${target_platform}-gcc ${optflags} conftest.c && \
        sed -ri 's/#define (BROKEN_ONE_BYTE_DIRENT_D_NAME) 1/#undef \1/' 
config.h
====

Of course that only works when one has a compiler that is new enough (what we 
can guarantee).

Greetings,

Eike
-- 
Rolf Eike Beer, emlix GmbH, http://www.emlix.com
Fon +49 551 30664-0, Fax +49 551 30664-11
Bertha-von-Suttner-Str. 9, 37085 Göttingen, Germany
Sitz der Gesellschaft: Göttingen, Amtsgericht Göttingen HR B 3160
Geschäftsführung: Heike Jordan, Dr. Uwe Kracke – Ust-IdNr.: DE 205 198 055

emlix – smart embedded open source
>From b72b5f79a19c0a3871fae2df4a8a618a40d3bcff Mon Sep 17 00:00:00 2001
From: Rolf Eike Beer <eb@xxxxxxxxx>
Date: Wed, 6 Jul 2016 09:11:22 +0200
Subject: [PATCH 1/3] apply the struct dirent penalty only when needed

Many systems have a struct dirent that already has enough space to hold the
entries names, others like Solaris have not. For the latter extra space needs
to be allocated, but this was also done for the former systems leading to
needlessly reserved memory.
---
 sftp-glob.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/sftp-glob.c b/sftp-glob.c
index 43a1beba..8edd28ac 100644
--- a/sftp-glob.c
+++ b/sftp-glob.c
@@ -64,9 +64,14 @@ fudge_opendir(const char *path)
 static struct dirent *
 fudge_readdir(struct SFTP_OPENDIR *od)
 {
+#ifdef BROKEN_ONE_BYTE_DIRENT_D_NAME
 	/* Solaris needs sizeof(dirent) + path length (see below) */
 	static char buf[sizeof(struct dirent) + MAXPATHLEN];
 	struct dirent *ret = (struct dirent *)buf;
+#else
+	static struct dirent buf;
+	struct dirent *ret = &buf;
+#endif
 #ifdef __GNU_LIBRARY__
 	static int inum = 1;
 #endif /* __GNU_LIBRARY__ */
@@ -74,7 +79,7 @@ fudge_readdir(struct SFTP_OPENDIR *od)
 	if (od->dir[od->offset] == NULL)
 		return(NULL);
 
-	memset(buf, 0, sizeof(buf));
+	memset(ret, 0, sizeof(buf));
 
 	/*
 	 * Solaris defines dirent->d_name as a one byte array and expects
-- 
2.14.2

Attachment: signature.asc
Description: This is a digitally signed message part.

_______________________________________________
openssh-unix-dev mailing list
openssh-unix-dev@xxxxxxxxxxx
https://lists.mindrot.org/mailman/listinfo/openssh-unix-dev

[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux