Date: Mon, 22 Jun 1998 17:36:44 +0000 (GMT) From: Terry Lambert <tlambert@primenet.com> To: peter@netplex.com.au (Peter Wemm) Cc: tlambert@primenet.com, joelh@gnu.org, fenner@parc.xerox.com, current@FreeBSD.ORG Subject: Re: Bogus errno twiddling by lstat... Message-ID: <199806221736.KAA11829@usr06.primenet.com> In-Reply-To: <199806210727.PAA27276@spinner.netplex.com.au> from "Peter Wemm" at Jun 21, 98 03:27:17 pm
next in thread | previous in thread | raw e-mail | index | archive | help
> > Terry Lambert wrote: > > > If, however, you don't like our malloc's current implementation, and > > > think that errno should be saved and restored across a successful > > > call, and that the lost cycles would be worthwhile, then diffs would > > > be perfectly welcome, I'm sure. > > > > Since the malloc.conf file is unnecessarily being looked for in the > > printf case (since ld.so already caused it to be looked for, and didn't > > find it), I think the redundant call to llok for it is certainly worth > > removing. > > What redundant call??!? > > pwroot@spinner[2:59pm]/tmp-115# cat xx.c > #include <stdio.h> > #include <string.h> > #include <sys/stat.h> > #include <errno.h> > > main() > { > struct stat sb; > int saveerrno, saveerrno2; > int ret; > char *e; > > write(1, "1\n", 2); > errno = 0; > ret = lstat("foo", &sb); > saveerrno = errno; > > write(1, "2\n", 2); > e = strerror(saveerrno); > saveerrno2 = errno; > > write(1, "3\n", 2); > printf("lstat returned %d, errno = %d = %s\n", ret, saveerrno, e); > > write(1, "4\n", 2); > printf("errno is now: %d, saveerrno2 = %d\n", errno, saveerrno2); > write(1, "5\n", 2); > } > pwroot@spinner[2:59pm]/tmp-116# cc -o xx xx.c > pwroot@spinner[2:59pm]/tmp-117# ktrace ./xx > 1 > 2 > Also, since this is freebsd-current, so I assume you're talking about > -current. No. I am talking about 2.2.6. The __error weak symbol work was done in support of 2.2.6 -> current migration and interoperability. This just happened to come up in the context of something that won't ever be changed in 2.2.6, namely non-encapsulated errno twiddling. > So, first you blame lstat() I should have blamed readlink(). Big deal. > with a badly flawed test program as "evidence". For what definition of badly flawed? What about my atoi() example? If atoi was allowed to fiddle errno under the covers, then conversion errors would be undetectable. Please don't quote the C standard to me; quote instead 10.13 of the Single UNIX Specification. I'm not interested in the language idiocy in support of existing Microsoft Compilers (such as prototypes in scope to support the x86 specific "far" attribute, when by rights, the linker should throw improper argument usage errors, and the existance of segmentation should be made transparent to the programmer by the compiler writer). If you *insist* on quoting old standards: The value of errno is 0 at program startup, but is never set to 0 by any XSI function. This is *far* differrent than stating that the value is indeterminate in the success case, which is what people are claiming. > When challenged on it, you say "I knew that" and then claim that ld.so is > calling malloc. At the same time you claim that this is therefore violating > some ansi requirement for functions to not change errno, which somebody > else has pointed out that the specs say the opposite. When confronted with > that, you then come up with malloc not caching it's readlink() of > malloc.conf, which is clearly false and verifiable. > > What next? % cat fum.c #include <stdio.h> #include "errno.h" main() { int k; for(k=0; k < 10; k++) printf( "default errno is %d\n", errno); } % cc -o fum fum.c -lc_r % ktrace fum % kdump 22622 ktrace RET ktrace 0 22622 ktrace CALL readlink(0x806b652,0xefbfd38c,0x3f) 22622 ktrace NAMI "/etc/malloc.conf" **************************************** 22622 ktrace RET readlink -1 errno 2 No such file or directory 22622 ktrace CALL mmap(0,0x1000,0x3,0x1002,0xffffffff,0,0,0) 22622 ktrace RET mmap 134328320/0x801b000 22622 ktrace CALL break(0x5000) 22622 ktrace RET break 0 22622 ktrace CALL break(0x6000) 22622 ktrace RET break 0 ... 22622 ktrace NAMI "/usr/X11R6/bin/fum" 22622 ktrace RET execve -1 errno 2 No such file or directory 22622 ktrace CALL execve(0xefbfd438,0xefbfd8f8,0xefbfd900) 22622 ktrace NAMI "./fum" 22622 fum RET execve 0 22622 fum CALL open(0x109c,0,0) 22622 fum NAMI "/usr/libexec/ld.so" 22622 fum RET open 3 22622 fum CALL read(0x3,0xefbfd8a0,0x20) 22622 fum GIO fd 3 read 32 bytes "\M-L\0\M^F\M-@\0\M-`\0\0\0 \0\0$\0\0\0\0\0\0\0 \0\0\0\0\0\0\0\0\0\0\0" 22622 fum RET read 32/0x20 ... 22622 fum RET sigprocmask 0 22622 fum CALL sigprocmask(0x3,0) 22622 fum RET sigprocmask -65793/0xfffefeff 22622 fum CALL readlink(0x8072782,0xefbfd730,0x3f) 22622 fum NAMI "/etc/malloc.conf" **************************************** 22622 fum RET readlink -1 errno 2 No such file or directory 22622 fum CALL mmap(0,0x1000,0x3,0x1002,0xffffffff,0,0,0) 22622 fum RET mmap 134324224/0x801a000 > malloc() has been adjusted to preserve errno across the readlink(), so I > suggest you leave it at that rather than digging youself an even deeper > hole. :-) Thank you for making the change; however, you can clearly see that the /etc/malloc.conf file is beaing readlink'ed twice. Terry Lambert terry@lambert.org --- Any opinions in this posting are my own and not those of my present or previous employers. To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199806221736.KAA11829>