Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: PATCH: Unix domain socket module



Clint Adams wrote:
> This implements the zsocket builtin for IPC via local Unix domain
> sockets.  Omitted is the ability to do SOCK_DGRAM.

Minor tweaks.  `sun' is predefined on hardware from a certain vendor.
The compiler didn't like the declaration `sockaddr_un 1'.

Looks like there's no way to close an fd opened for listening since this
is beyond 9?  We could add an EXTENDED_FD option to allow `11>&-', but I
suspect the parser is going to fight this all the way.  A quick and
dirty hack (not implemented) would be to allow `zsocket -c fd' to close
any old fd.

Are you going to commit the terminfo fix for 4.0?  That looks quite
serious.

Index: Src/Modules/socket.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Modules/socket.c,v
retrieving revision 1.1
diff -u -r1.1 socket.c
--- Src/Modules/socket.c	18 Aug 2002 02:12:39 -0000	1.1
+++ Src/Modules/socket.c	22 Aug 2002 11:25:49 -0000
@@ -63,7 +63,7 @@
     int err=1, verbose=0, test=0, targetfd=0;
     SOCKLEN_T len;
     char **dargs;
-    struct sockaddr_un sun;
+    struct sockaddr_un soun;
     int sfd;
 
     if (ops['v'])
@@ -101,12 +101,12 @@
 	    return 1;
 	}
 
-	sun.sun_family = AF_UNIX;
-	strncpy(sun.sun_path, localfn, UNIX_PATH_MAX);
+	soun.sun_family = AF_UNIX;
+	strncpy(soun.sun_path, localfn, UNIX_PATH_MAX);
 
-	if (bind(sfd, (struct sockaddr *)&sun, sizeof(struct sockaddr_un)))
+	if (bind(sfd, (struct sockaddr *)&soun, sizeof(struct sockaddr_un)))
 	{
-	    zwarnnam(nam, "could not bind to %s: %e", sun.sun_path, errno);
+	    zwarnnam(nam, "could not bind to %s: %e", soun.sun_path, errno);
 	    close(sfd);
 	    return 1;
 	}
@@ -130,7 +130,7 @@
 	setiparam("REPLY", sfd);
 
 	if (verbose)
-	    printf("%s listener is on fd %d\n", sun.sun_path, sfd);
+	    printf("%s listener is on fd %d\n", soun.sun_path, sfd);
 
 	return 0;
 
@@ -190,7 +190,8 @@
 #endif
 	}
 
-	if ((rfd = accept(lfd, (struct sockaddr *)&sun, &len)) == -1)
+	len = sizeof(soun);
+	if ((rfd = accept(lfd, (struct sockaddr *)&soun, &len)) == -1)
 	{
 	    zwarnnam(nam, "could not accept connection: %e", NULL, errno);
 	    return 1;
@@ -207,7 +208,7 @@
 	setiparam("REPLY", sfd);
 
 	if (verbose)
-	    printf("new connection from %s is on fd %d\n", sun.sun_path, sfd);
+	    printf("new connection from %s is on fd %d\n", soun.sun_path, sfd);
     }
     else
     {
@@ -223,10 +224,10 @@
 	    return 1;
 	}
 
-	sun.sun_family = AF_UNIX;
-	strncpy(sun.sun_path, dargs[0], UNIX_PATH_MAX);
+	soun.sun_family = AF_UNIX;
+	strncpy(soun.sun_path, dargs[0], UNIX_PATH_MAX);
 	
-	if ((err = connect(sfd, (struct sockaddr *)&sun, sizeof(struct sockaddr_un)))) {
+	if ((err = connect(sfd, (struct sockaddr *)&soun, sizeof(struct sockaddr_un)))) {
 	    zwarnnam(nam, "connection failed: %e", NULL, errno);
 	    close(sfd);
 	    return 1;
@@ -241,7 +242,7 @@
 	    setiparam("REPLY", sfd);
 
 	    if (verbose)
-		printf("%s is now on fd %d\n", sun.sun_path, sfd);
+		printf("%s is now on fd %d\n", soun.sun_path, sfd);
 	}
 	
     }
Index: Doc/Makefile.in
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Makefile.in,v
retrieving revision 1.15
diff -u -r1.15 Makefile.in
--- Doc/Makefile.in	12 May 2002 18:51:47 -0000	1.15
+++ Doc/Makefile.in	22 Aug 2002 11:25:49 -0000
@@ -59,7 +59,8 @@
 Zsh/mod_computil.yo \
 Zsh/mod_deltochar.yo Zsh/mod_example.yo Zsh/mod_files.yo \
 Zsh/mod_mapfile.yo Zsh/mod_mathfunc.yo Zsh/mod_parameter.yo Zsh/mod_pcre.yo \
-Zsh/mod_sched.yo Zsh/mod_stat.yo Zsh/mod_termcap.yo Zsh/mod_terminfo.yo \
+Zsh/mod_sched.yo Zsh/mod_socket.yo \
+Zsh/mod_stat.yo Zsh/mod_termcap.yo Zsh/mod_terminfo.yo \
 Zsh/mod_zftp.yo Zsh/mod_zle.yo Zsh/mod_zleparameter.yo \
 Zsh/mod_zprof.yo Zsh/mod_zpty.yo Zsh/mod_zselect.yo \
 Zsh/mod_zutil.yo Zsh/mod_tcp.yo
Index: Doc/Zsh/mod_socket.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/mod_socket.yo,v
retrieving revision 1.1
diff -u -r1.1 mod_socket.yo
--- Doc/Zsh/mod_socket.yo	18 Aug 2002 02:12:40 -0000	1.1
+++ Doc/Zsh/mod_socket.yo	22 Aug 2002 11:25:49 -0000
@@ -62,3 +62,4 @@
 In order to elicit more verbose output, use tt(-v).
 )
 enditem()
+)


**********************************************************************
The information transmitted is intended only for the person or
entity to which it is addressed and may contain confidential 
and/or privileged material. 
Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by 
persons or entities other than the intended recipient is 
prohibited.  
If you received this in error, please contact the sender and 
delete the material from any computer.
**********************************************************************



Messages sorted by: Reverse Date, Date, Thread, Author