chiark / gitweb /
[PATCH] udevd - switch socket path to abstract namespace
authorkay.sievers@vrfy.org <kay.sievers@vrfy.org>
Thu, 5 Feb 2004 09:35:15 +0000 (01:35 -0800)
committerGreg KH <gregkh@suse.de>
Wed, 27 Apr 2005 04:32:25 +0000 (21:32 -0700)
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)

Makefile
udevd.c
udevd.h
udevsend.c

index 618adad71eb77518dc2f2cd4cbe8c053576f16e2..35575806dbdc4c318f41924dd1a0adbc144a9c98 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -241,7 +241,6 @@ udev_version.h:
        @echo \#define UDEV_PERMISSION_FILE     \"$(configdir)\udev.permissions\" >> $@
        @echo \#define UDEV_BIN         \"$(DESTDIR)$(sbindir)/udev\" >> $@
        @echo \#define UDEVD_BIN        \"$(DESTDIR)$(sbindir)/udevd\" >> $@
        @echo \#define UDEV_PERMISSION_FILE     \"$(configdir)\udev.permissions\" >> $@
        @echo \#define UDEV_BIN         \"$(DESTDIR)$(sbindir)/udev\" >> $@
        @echo \#define UDEVD_BIN        \"$(DESTDIR)$(sbindir)/udevd\" >> $@
-       @echo \#define UDEVD_SOCK       \"$(udevdir)/\.udevd.sock\" >> $@
        @echo \#define UDEVD_LOCK       \"$(udevdir)/\.udevd.lock\" >> $@
 
 # config files automatically generated
        @echo \#define UDEVD_LOCK       \"$(udevdir)/\.udevd.lock\" >> $@
 
 # config files automatically generated
diff --git a/udevd.c b/udevd.c
index f8b8c27ee4ad51a0f6679aa7e71969247035198a..24cf9c9a7cf8c5a491c63483fff09f4a91455b70 100644 (file)
--- a/udevd.c
+++ b/udevd.c
@@ -325,7 +325,6 @@ static void sig_handler(int signum)
                case SIGINT:
                case SIGTERM:
                        unlink(UDEVD_LOCK);
                case SIGINT:
                case SIGTERM:
                        unlink(UDEVD_LOCK);
-                       unlink(UDEVD_SOCK);
                        exit(20 + signum);
                        break;
                default:
                        exit(20 + signum);
                        break;
                default:
@@ -378,9 +377,9 @@ int main(int argc, char *argv[])
 
        memset(&saddr, 0x00, sizeof(saddr));
        saddr.sun_family = AF_LOCAL;
 
        memset(&saddr, 0x00, sizeof(saddr));
        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);
        if (ssock == -1) {
                dbg("error getting socket");
        ssock = socket(AF_LOCAL, SOCK_STREAM, 0);
        if (ssock == -1) {
                dbg("error getting socket");
@@ -426,6 +425,5 @@ int main(int argc, char *argv[])
        }
 exit:
        close(ssock);
        }
 exit:
        close(ssock);
-       unlink(UDEVD_SOCK);
        exit(1);
 }
        exit(1);
 }
diff --git a/udevd.h b/udevd.h
index 6dbee3a29587c3f13ae3ad8b5c40af5190ccff63..8efe1d569c59f910e65fccf07e2bcebeff14db6e 100644 (file)
--- a/udevd.h
+++ b/udevd.h
@@ -27,6 +27,7 @@
 #define UDEV_MAGIC                     "udevd_" UDEV_VERSION
 #define EVENT_TIMEOUT_SEC              5
 #define UDEVSEND_CONNECT_RETRY         20 /* x 100 millisec */
 #define UDEV_MAGIC                     "udevd_" UDEV_VERSION
 #define EVENT_TIMEOUT_SEC              5
 #define UDEVSEND_CONNECT_RETRY         20 /* x 100 millisec */
+#define UDEVD_SOCK_PATH                        "udevd"
 
 struct hotplug_msg {
        char magic[20];
 
 struct hotplug_msg {
        char magic[20];
index 9dc2b2e841bb635cd3a30dc284e25224938b9f90..223647785d73a17af57fbf0b3481550e35e95dcc 100644 (file)
@@ -161,7 +161,8 @@ int main(int argc, char* argv[])
 
        memset(&saddr, 0x00, sizeof(saddr));
        saddr.sun_family = AF_LOCAL;
 
        memset(&saddr, 0x00, sizeof(saddr));
        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 */
        retval = connect(sock, (struct sockaddr *) &saddr, sizeof(saddr));
 
        /* try to connect, if it fails start daemon */
        retval = connect(sock, (struct sockaddr *) &saddr, sizeof(saddr));