[PATCH] syslogd +realpath
Denis Vlasenko
vda.linux at googlemail.com
Wed Feb 7 22:19:04 UTC 2007
On Wednesday 07 February 2007 17:58, Marc Leeman wrote:
> On Wed, Feb 07, 2007 at 05:35:07PM +0100, Marc Leeman wrote:
> > > The link is replaced with a socket (/ fs is RW).
> >
> > Forgot to mention that I am using uclibc on powerpc.:
>
>
> adding:
>
> char *xmalloc_realpath(const char *path)
> {
> #if defined(__GLIBC__) && !defined(__UCLIBC__)
> /* glibc provides a non-standard extension */
> return realpath(path, NULL);
> #else
> char buf[PATH_MAX+1];
>
> fprintf(stdout,"realpath returns %s\n",realpath(path,buf));
> fprintf(stdout,"realpath buf is %s\n",buf);
> /* on error returns NULL (xstrdup(NULL) ==NULL) */
> return xstrdup(realpath(path, buf));
> #endif
> }
>
> results in:
>
> $ /sbin/syslogd -n -m 0 -C16
> realpath returns (null)
> realpath buf is /tmp/log
> syslogd: bind: Address already in use
>
> oeps!
>
> let's blatantly ignore the comment about "on error":
>
> char *xmalloc_realpath(const char *path)
> {
> #if defined(__GLIBC__) && !defined(__UCLIBC__)
> /* glibc provides a non-standard extension */
> return realpath(path, NULL);
> #else
> char buf[PATH_MAX+1];
>
> fprintf(stdout,"realpath returns %s\n",realpath(path,buf));
> fprintf(stdout,"realpath buf is %s\n",buf);
> /* on error returns NULL (xstrdup(NULL) ==NULL) */
> return xstrdup(buf);
> #endif
> }
>
> $ ls -al /tmp/log
> srw-rw-rw- 1 0 0 0 Jan 1 00:00 /tmp/log
>
> this seems to give us what we expect :)
Yeah, strange... but think about what will happen when realpath REALLY
will fail. We will xstrdup and return... something bogus?
Maybe you should look into uclibc. Why it returned NULL?
My manpage says:
RETURN VALUE
If there is no error, realpath() returns a pointer to the
resolved_path.
Otherwise it returns a NULL pointer, and the contents
of the array resolved_path are undefined. The global
variable errno is set to indicate the error.
Yet another question is why syslogd even bothers to do this
remove/recreate cycle? What will happen if it will just
bind to /dev/log? (the code will be smaller too)
--
vda
More information about the busybox
mailing list