[PATCH] udevd - switch socket path to abstract namespace

As Chris Friesen <chris_friesen@sympatico.ca> suggested, here we switch
the unix domains socket path to abstract namespace and get rid of the
socket file in the filesystem.

Hey, this was new to me today. So here a few words:
  Linux supports a abstract namespace for sockets. We don't need a
  physical file on the filesystem but only a unique string magically
  starting with the '\0' character.

  strace with real file:
    connect(3, {sa_family=AF_UNIX, path="/udev/.udevd.sock"}, 110)

  strace with abstract namespace:
    connect(3, {sa_family=AF_UNIX, path=@udevd}, 110)
This commit is contained in:
kay.sievers@vrfy.org 2004-02-05 01:35:15 -08:00 committed by Greg KH
parent 86590cd590
commit 872344c410
4 changed files with 5 additions and 6 deletions

View File

@ -241,7 +241,6 @@ udev_version.h:
@echo \#define UDEV_PERMISSION_FILE \"$(configdir)\udev.permissions\" >> $@ @echo \#define UDEV_PERMISSION_FILE \"$(configdir)\udev.permissions\" >> $@
@echo \#define UDEV_BIN \"$(DESTDIR)$(sbindir)/udev\" >> $@ @echo \#define UDEV_BIN \"$(DESTDIR)$(sbindir)/udev\" >> $@
@echo \#define UDEVD_BIN \"$(DESTDIR)$(sbindir)/udevd\" >> $@ @echo \#define UDEVD_BIN \"$(DESTDIR)$(sbindir)/udevd\" >> $@
@echo \#define UDEVD_SOCK \"$(udevdir)/\.udevd.sock\" >> $@
@echo \#define UDEVD_LOCK \"$(udevdir)/\.udevd.lock\" >> $@ @echo \#define UDEVD_LOCK \"$(udevdir)/\.udevd.lock\" >> $@
# config files automatically generated # config files automatically generated

View File

@ -325,7 +325,6 @@ static void sig_handler(int signum)
case SIGINT: case SIGINT:
case SIGTERM: case SIGTERM:
unlink(UDEVD_LOCK); unlink(UDEVD_LOCK);
unlink(UDEVD_SOCK);
exit(20 + signum); exit(20 + signum);
break; break;
default: default:
@ -378,9 +377,9 @@ int main(int argc, char *argv[])
memset(&saddr, 0x00, sizeof(saddr)); memset(&saddr, 0x00, sizeof(saddr));
saddr.sun_family = AF_LOCAL; saddr.sun_family = AF_LOCAL;
strcpy(saddr.sun_path, UDEVD_SOCK); /* use abstract namespace for socket path */
strcpy(&saddr.sun_path[1], UDEVD_SOCK_PATH);
unlink(UDEVD_SOCK);
ssock = socket(AF_LOCAL, SOCK_STREAM, 0); ssock = socket(AF_LOCAL, SOCK_STREAM, 0);
if (ssock == -1) { if (ssock == -1) {
dbg("error getting socket"); dbg("error getting socket");
@ -426,6 +425,5 @@ int main(int argc, char *argv[])
} }
exit: exit:
close(ssock); close(ssock);
unlink(UDEVD_SOCK);
exit(1); exit(1);
} }

View File

@ -27,6 +27,7 @@
#define UDEV_MAGIC "udevd_" UDEV_VERSION #define UDEV_MAGIC "udevd_" UDEV_VERSION
#define EVENT_TIMEOUT_SEC 5 #define EVENT_TIMEOUT_SEC 5
#define UDEVSEND_CONNECT_RETRY 20 /* x 100 millisec */ #define UDEVSEND_CONNECT_RETRY 20 /* x 100 millisec */
#define UDEVD_SOCK_PATH "udevd"
struct hotplug_msg { struct hotplug_msg {
char magic[20]; char magic[20];

View File

@ -161,7 +161,8 @@ int main(int argc, char* argv[])
memset(&saddr, 0x00, sizeof(saddr)); memset(&saddr, 0x00, sizeof(saddr));
saddr.sun_family = AF_LOCAL; saddr.sun_family = AF_LOCAL;
strcpy(saddr.sun_path, UDEVD_SOCK); /* use abstract namespace for socket path */
strcpy(&saddr.sun_path[1], UDEVD_SOCK_PATH);
/* try to connect, if it fails start daemon */ /* try to connect, if it fails start daemon */
retval = connect(sock, (struct sockaddr *) &saddr, sizeof(saddr)); retval = connect(sock, (struct sockaddr *) &saddr, sizeof(saddr));