udevd - switch socket path to abstract namespace
PATCH 1/1 udevd - switch socket path to abstract namespace
As Chris Friesen <[email protected]> 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)thanks,
Kay
===== Makefile 1.102 vs edited =====
Makefile +0 -1
@@ -241,7 +241,6 @@ @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
===== udevd.c 1.11 vs edited =====
udevd.c +2 -4
@@ -325,7 +325,6 @@case SIGINT :case SIGTERM :unlink (UDEVD_LOCK ); -unlink (UDEVD_SOCK );exit (20 + signum);break ;default :
@@ -378,9 +377,9 @@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" );
@@ -426,6 +425,5 @@ } exit:close (ssock); -unlink (UDEVD_SOCK );exit (1 ); }
===== udevd.h 1.6 vs edited =====
udevd.h +1 -0
@@ -27,6 +27,7 @@#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 ];
===== udevsend.c 1.15 vs edited =====
udevsend.c +2 -1
@@ -161,7 +161,8 @@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));
Greg KH
AppliedQuoted 10 lines · Kay Sievers
As Chris Friesen <[email protected]> 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.
Quoted 5 lines
strace with real file:
connect(3, {sa_family¯_UNIX, path="/udev/.udevd.sock"}, 110)strace with abstract namespace:
connect(3, {sa_family¯_UNIX, path=@udevd}, 110)
That's nice to know.
Applied, thanks.
greg k-h
-------------------------------------------------------
The SF.Net email is sponsored by EclipseCon 2004
Premiere Conference on Open Tools Development and Integration See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
http://www.eclipsecon.org/osdn
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
Quoted 11 lines · Greg KH
Quoted 10 lines · Kay Sievers
As Chris Friesen <[email protected]> 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.
Quoted 7 lines
Quoted 5 lines
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)That's nice to know.
It seems that the guys are no longer differ about the right size of the socket address :)
The kernel simply takes all bytes until the specified length as the name, so the real length should be enough.
thanks,
Kay
===== udevd.c 1.12 vs edited =====
udevd.c +3 -1
@@ -360,6 +360,7 @@int csock;struct sockaddr_un saddr;struct sockaddr_un caddr; +socklen_t addrlen;socklen_t clen;pthread_t cli_tid;pthread_t mgr_msg_tid;
@@ -379,6 +380,7 @@ saddr.sun_family =AF_LOCAL ;/* use abstract namespace for socket path */ strcpy (&saddr.sun_path[1 ],UDEVD_SOCK_PATH ); + addrlen = offsetof(struct sockaddr_un , sun_path) +strlen (saddr.sun_path+1 ) +1 ; ssock =socket (AF_LOCAL ,SOCK_STREAM ,0 );if (ssock ==-1 ) {
@@ -386,7 +388,7 @@exit (1 ); } - retval =bind (ssock, &saddr,sizeof (saddr)); + retval =bind (ssock, &saddr, addrlen);if (retval <0 ) {dbg ("bind failed\n" ); goto exit;
===== udevsend.c 1.16 vs edited =====
udevsend.c +4 -1
@@ -29,6 +29,7 @@#include <errno.h> #include <stdio.h> #include <stdlib.h> +#include <stddef.h> #include <string.h> #include <unistd.h> #include <time.h>
@@ -124,6 +125,7 @@struct timespec tspec;int sock;struct sockaddr_un saddr; +socklen_t addrlen;#ifdef DEBUG init_logging ("udevsend" );
@@ -163,9 +165,10 @@ saddr.sun_family =AF_LOCAL ;/* use abstract namespace for socket path */ strcpy (&saddr.sun_path[1 ],UDEVD_SOCK_PATH ); + addrlen = offsetof(struct sockaddr_un , sun_path) +strlen (saddr.sun_path+1 ) +1 ;/* try to connect, if it fails start daemon */ - retval =connect (sock, (struct sockaddr *) &saddr,sizeof (saddr)); + retval =connect (sock, (struct sockaddr *) &saddr, addrlen);if (retval !=-1 ) { goto send; }else {
Greg KH
AppliedQuoted 6 lines · Kay Sievers
It seems that the guys are no longer differ about the right size of the socket address :)
The kernel simply takes all bytes until the specified length as the name, so the real length should be enough.
Applied, thanks.
greg k-h
-------------------------------------------------------
The SF.Net email is sponsored by EclipseCon 2004
Premiere Conference on Open Tools Development and Integration See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
http://www.eclipsecon.org/osdn
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel