[PATCH] syslogd +realpath
Denis Vlasenko
vda.linux at googlemail.com
Thu Feb 8 12:51:33 PST 2007
On Thursday 08 February 2007 20:39, Marc Leeman wrote:
> > I tried. /dev/log is created by bind() of AF_UNIX.
>
> doh, on a RO fs?
It is indeed created with bind(), but on RO fs it fails.
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
int main(int argc, char **argv)
{
struct sockaddr_un sunx;
socklen_t addr_len;
int sock_fd;
// unlink(argv[1]);
memset(&sunx, 0, sizeof(sunx));
sunx.sun_family = AF_UNIX;
strncpy(sunx.sun_path, argv[1], sizeof(sunx.sun_path));
sock_fd = socket(AF_UNIX, SOCK_DGRAM, 0);
if (sock_fd < 0) return 1;
addr_len = sizeof(sunx.sun_family) + strlen(sunx.sun_path);
bind(sock_fd, (struct sockaddr *) &sunx, addr_len);
return 0;
}
Testing by stracing "testprog /dev/log2"
...
socket(PF_FILE, SOCK_DGRAM, 0) = 4
bind(4, {sa_family=AF_FILE, path="/dev/log2"}, 11) = 0
exit_group(0)
and also now I see /dev/log2 socket.
Running that again:
...
socket(PF_FILE, SOCK_DGRAM, 0) = 4
bind(4, {sa_family=AF_FILE, path="/dev/log2"}, 11) = -1 EADDRINUSE (Address already in use)
exit_group(0)
On RO fs (my / in RO, so I just do "testprog /bin/log2")
socket(PF_FILE, SOCK_DGRAM, 0) = 4
bind(4, {sa_family=AF_FILE, path="/bin/log2"}, 11) = -1 EROFS (Read-only file system)
exit_group(0)
> > If it exists, bind() will fail, even if no other process did bind().
> > That's why removing /dev/log is really needed.
>
> No, /dev/ is not normally mounted on a rw filesystem (tmpfs). That's
> probably why a symlink was used in the firsts place (to /tmp/log)
Of sourse you may want to symlink /dev/log, and that's exactly why syslogd
tries to resolve the symlink - it needs to remove the socket, or else
it won't be able to bind to it.
--
vda
More information about the busybox
mailing list