tech-net archive

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

why not remove AF_LOCAL sockets on last close?



Can anyone tell me why, exactly, we shouldn't remove bound AF_LOCAL
sockets from the filesystem on last close?  The following test program
produces "second socket bind failed" on every system I've tested it on,
and seems to cover the only possible use case for this "feature"...

#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <stdio.h>
#include <err.h>
#include <sysexits.h>

main()
{

    int s = socket(PF_LOCAL, SOCK_DGRAM, 0);

    struct sockaddr_un sun;

    sun.sun_family = AF_UNIX;
    sun.sun_len = sizeof(sun);
    strlcpy(sun.sun_path, "/tmp/testdir/skt", sizeof(sun.sun_path));

    mkdir("/tmp/testdir", 0700);

    if (bind(s, (struct sockaddr *)&sun, sun.sun_len)) {
        err(EX_OSERR, "first socket bind failed");
    }

    close(s);
    s = socket(PF_LOCAL, SOCK_DGRAM, 0);

    chmod("/tmp/testdir", 0500);
    if (bind(s, (struct sockaddr *)&sun, sun.sun_len)) {
        err(EX_NOPERM, "second socket bind failed");
    }
}



Home | Main Index | Thread Index | Old Index