Date: Tue, 25 Sep 2001 21:16:39 +0300 From: Ruslan Ermilov <ru@FreeBSD.org> To: Matt Dillon <dillon@FreeBSD.org> Cc: cvs-committers@FreeBSD.org, cvs-all@FreeBSD.org Subject: Re: cvs commit: src/bin/cat cat.1 cat.c Message-ID: <20010925211639.C57333@sunbay.com> In-Reply-To: <200109150039.f8F0dFZ41705@freefall.freebsd.org>; from dillon@FreeBSD.org on Fri, Sep 14, 2001 at 05:39:14PM -0700 References: <200109150039.f8F0dFZ41705@freefall.freebsd.org>
next in thread | previous in thread | raw e-mail | index | archive | help
How about testing with stat(2) that an argument is a socket
thus eliminating the need to open(2) sockets and connect(2)
to non-sockets?
Index: cat.c
===================================================================
RCS file: /home/ncvs/src/bin/cat/cat.c,v
retrieving revision 1.17
diff -u -p -r1.17 cat.c
--- cat.c 2001/09/15 00:39:14 1.17
+++ cat.c 2001/09/25 18:17:30
@@ -135,6 +135,9 @@ scanfiles(argv, cooked)
{
int i = 0;
char *path;
+#ifndef NO_UDOM_SUPPORT
+ struct stat sb;
+#endif
while ((path = argv[i]) != NULL || i == 0) {
int fd;
@@ -144,10 +147,15 @@ scanfiles(argv, cooked)
fd = 0;
} else {
filename = path;
- fd = open(path, O_RDONLY);
+#ifndef NO_UDOM_SUPPORT
+ if ((fd = stat(path, &sb)) == 0) {
+ if (S_ISSOCK(sb.st_mode))
+ fd = udom_open(path, O_RDONLY, 0);
+ else
+#endif
+ fd = open(path, O_RDONLY);
#ifndef NO_UDOM_SUPPORT
- if (fd < 0 && errno == EOPNOTSUPP)
- fd = udom_open(path, O_RDONLY, 0);
+ }
#endif
}
if (fd < 0) {
On Fri, Sep 14, 2001 at 05:39:14PM -0700, Matt Dillon wrote:
> dillon 2001/09/14 17:39:14 PDT
>
> Modified files:
> bin/cat cat.1 cat.c
> Log:
> Give /bin/cat the ability to connect to and read unix-domain sockets
>
> MFC after: 1 week
>
> Revision Changes Path
> 1.18 +7 -2 src/bin/cat/cat.1
> 1.17 +103 -56 src/bin/cat/cat.c
--
Ruslan Ermilov Oracle Developer/DBA,
ru@sunbay.com Sunbay Software AG,
ru@FreeBSD.org FreeBSD committer,
+380.652.512.251 Simferopol, Ukraine
http://www.FreeBSD.org The Power To Serve
http://www.oracle.com Enabling The Information Age
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe cvs-all" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010925211639.C57333>
