From mboxrd@z Thu Jan 1 00:00:00 1970 From: Kay Sievers Date: Thu, 05 Feb 2004 09:19:00 +0000 Subject: Re: [patch] udevd - switch socket path to abstract namespace Message-Id: <20040205091900.GA2123@vrfy.org> MIME-Version: 1 Content-Type: multipart/mixed; boundary="opJtzjQTFsWo+cga" List-Id: References: <20040205010748.GA1247@vrfy.org> In-Reply-To: <20040205010748.GA1247@vrfy.org> To: linux-hotplug@vger.kernel.org --opJtzjQTFsWo+cga Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Wed, Feb 04, 2004 at 05:37:35PM -0800, Greg KH wrote: > On Thu, Feb 05, 2004 at 02:07:48AM +0100, Kay Sievers wrote: > > > > As Chris Friesen 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) > > 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 --opJtzjQTFsWo+cga Content-Type: text/plain; charset=us-ascii Content-Disposition: inline; filename="01-socketpathlen.patch" ===== udevd.c 1.12 vs edited ===== --- 1.12/udevd.c Thu Feb 5 02:42:59 2004 +++ edited/udevd.c Thu Feb 5 09:32:51 2004 @@ -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 ===== --- 1.16/udevsend.c Thu Feb 5 02:41:47 2004 +++ edited/udevsend.c Thu Feb 5 09:40:58 2004 @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -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 { --opJtzjQTFsWo+cga-- ------------------------------------------------------- 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 Linux-hotplug-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel