CVS commit: src/lib/librmt

2011-06-21 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Tue Jun 21 09:35:23 UTC 2011

Modified Files:
src/lib/librmt: rmtlib.c

Log Message:
add a missing  to a string literal in some #if'd out code that GCC 4.5 found.


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/lib/librmt/rmtlib.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/librmt/rmtlib.c
diff -u src/lib/librmt/rmtlib.c:1.24 src/lib/librmt/rmtlib.c:1.25
--- src/lib/librmt/rmtlib.c:1.24	Tue May 31 12:24:33 2011
+++ src/lib/librmt/rmtlib.c	Tue Jun 21 09:35:23 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: rmtlib.c,v 1.24 2011/05/31 12:24:33 christos Exp $	*/
+/*	$NetBSD: rmtlib.c,v 1.25 2011/06/21 09:35:23 mrg Exp $	*/
 
 /*
  *	rmt --- remote tape emulator subroutines
@@ -28,7 +28,7 @@
  */
 
 #include sys/cdefs.h
-__RCSID($NetBSD: rmtlib.c,v 1.24 2011/05/31 12:24:33 christos Exp $);
+__RCSID($NetBSD: rmtlib.c,v 1.25 2011/06/21 09:35:23 mrg Exp $);
 
 #define RMTIOCTL	1
 /* #define USE_REXEC	1 */	/* rexec code courtesy of Dan Kegel, srs!dan */
@@ -224,7 +224,7 @@
 
 	rexecserv = getservbyname(exec, tcp);
 	if (rexecserv == NULL)
-		errx(1, exec/tcp: service not available.);
+		errx(1, exec/tcp: service not available.);
 	if ((user != NULL)  *user == '\0')
 		user = NULL;
 	return rexec(host, rexecserv-s_port, user, NULL,



CVS commit: src/lib/librmt

2011-05-31 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue May 31 12:24:33 UTC 2011

Modified Files:
src/lib/librmt: rmtlib.c

Log Message:
PR/38413: Takahiro Kambe: mt(1) print some junk output when using remote tape
Not all fields are valid in the ioctl to get tape info in the rmt protocol.
Zero out the struct so that we don't print junk.
While here, KNF.


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/lib/librmt/rmtlib.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/librmt/rmtlib.c
diff -u src/lib/librmt/rmtlib.c:1.23 src/lib/librmt/rmtlib.c:1.24
--- src/lib/librmt/rmtlib.c:1.23	Fri Feb 18 11:10:09 2011
+++ src/lib/librmt/rmtlib.c	Tue May 31 08:24:33 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: rmtlib.c,v 1.23 2011/02/18 16:10:09 pooka Exp $	*/
+/*	$NetBSD: rmtlib.c,v 1.24 2011/05/31 12:24:33 christos Exp $	*/
 
 /*
  *	rmt --- remote tape emulator subroutines
@@ -28,7 +28,7 @@
  */
 
 #include sys/cdefs.h
-__RCSID($NetBSD: rmtlib.c,v 1.23 2011/02/18 16:10:09 pooka Exp $);
+__RCSID($NetBSD: rmtlib.c,v 1.24 2011/05/31 12:24:33 christos Exp $);
 
 #define RMTIOCTL	1
 /* #define USE_REXEC	1 */	/* rexec code courtesy of Dan Kegel, srs!dan */
@@ -50,6 +50,7 @@
 #include stdlib.h
 #include string.h
 #include unistd.h
+#include err.h
 
 #ifdef USE_REXEC
 #include netdb.h
@@ -66,7 +67,7 @@
 static	int	_rmt_open(const char *, int, int);
 static	ssize_t	_rmt_read(int, void *, size_t);
 static	ssize_t	_rmt_write(int, const void *, size_t);
-static	int	command(int, char *);
+static	int	command(int, const char *);
 static	int	remdev(const char *);
 static	void	rmtabort(int);
 static	int	status(int);
@@ -100,10 +101,10 @@
  *	command --- attempt to perform a remote tape command
  */
 static int
-command(int fildes, char *buf)
+command(int fildes, const char *buf)
 {
 	size_t blen;
-	void (*pstat)(int);
+	sig_t pstat;
 
 	_DIAGASSERT(buf != NULL);
 
@@ -115,7 +116,7 @@
 	pstat = signal(SIGPIPE, SIG_IGN);
 	if (write(WRITE(fildes), buf, blen) == blen) {
 		signal(SIGPIPE, pstat);
-		return (0);
+		return 0;
 	}
 
 /*
@@ -126,7 +127,7 @@
 	rmtabort(fildes);
 
 	errno = EIO;
-	return (-1);
+	return -1;
 }
 
 
@@ -148,7 +149,7 @@
 		if (read(READ(fildes), cp, 1) != 1) {
 			rmtabort(fildes);
 			errno = EIO;
-			return (-1);
+			return -1;
 		}
 		if (*cp == '\n') {
 			*cp = 0;
@@ -159,7 +160,7 @@
 	if (i == BUFMAGIC) {
 		rmtabort(fildes);
 		errno = EIO;
-		return (-1);
+		return -1;
 	}
 
 /*
@@ -179,7 +180,7 @@
 		if (*cp == 'F')
 			rmtabort(fildes);
 
-		return (-1);
+		return -1;
 	}
 
 /*
@@ -189,10 +190,10 @@
 	if (*cp != 'A') {
 		rmtabort(fildes);
 		errno = EIO;
-		return (-1);
+		return -1;
 	}
 
-	return (atoi(cp + 1));
+	return atoi(cp + 1);
 }
 
 
@@ -222,14 +223,12 @@
 	/* user may be NULL */
 
 	rexecserv = getservbyname(exec, tcp);
-	if (rexecserv == NULL) {
-		fprintf(stderr, ? exec/tcp: service not available.);
-		exit(1);
-	}
+	if (rexecserv == NULL)
+		errx(1, exec/tcp: service not available.);
 	if ((user != NULL)  *user == '\0')
 		user = NULL;
-	return (rexec(host, rexecserv-s_port, user, NULL,
-	/etc/rmt, NULL));
+	return rexec(host, rexecserv-s_port, user, NULL,
+	/etc/rmt, NULL);
 }
 #endif /* USE_REXEC */
 
@@ -249,12 +248,13 @@
 /*ARGSUSED*/
 _rmt_open(const char *path, int oflag, int mode)
 {
-	int i, rc;
+	int i;
 	char buffer[BUFMAGIC];
 	char host[MAXHOSTLEN];
 	char device[BUFMAGIC];
 	char login[BUFMAGIC];
 	char *sys, *dev, *user;
+	char *rshpath, *rsh;
 
 	_DIAGASSERT(path != NULL);
 
@@ -272,7 +272,7 @@
 
 	if (i == MAXUNIT) {
 		errno = EMFILE;
-		return (-1);
+		return -1;
 	}
 
 /*
@@ -324,21 +324,20 @@
  */
 	READ(i) = WRITE(i) = _rmt_rexec(host, login);
 	if (READ(i)  0)
-		return (-1);
+		return -1;
 #else
 /*
  *	setup the pipes for the 'rsh' command and fork
  */
 
 	if (pipe(Ptc[i]) == -1 || pipe(Ctp[i]) == -1)
-		return (-1);
-
-	if ((rc = fork()) == -1)
-		return (-1);
+		return -1;
 
-	if (rc == 0) {
-		char	*rshpath, *rsh;
+	switch (fork()) {
+	case -1:
+		return -1;
 
+	case 0:
 		close(0);
 		dup(Ptc[i][0]);
 		close(Ptc[i][0]); close(Ptc[i][1]);
@@ -356,19 +355,19 @@
 			rsh++;
 
 		if (*login) {
-			execl(rshpath, rsh, host, -l, login,
-			_PATH_RMT, NULL);
+			execl(rshpath, rsh, host, -l, login, _PATH_RMT, NULL);
 		} else {
-			execl(rshpath, rsh, host,
-			_PATH_RMT, NULL);
+			execl(rshpath, rsh, host, _PATH_RMT, NULL);
 		}
 
 /*
  *	bad problems if we get here
  */
 
-		perror(exec);
-		exit(1);
+		err(1, Cannnot exec %s, rshpath);
+		/*FALLTHROUGH*/
+	default:
+		break;
 	}
 
 	close(Ptc[i][0]); close(Ctp[i][1]);
@@ -380,9 +379,9 @@
 
 	(void)snprintf(buffer, sizeof(buffer), O%s\n%d\n, device, oflag);
 	if (command(i, buffer) == -1 || status(i) == -1)
-		return (-1);
+		return -1;
 
-	return (i);
+	return i;
 }
 
 
@@ -398,10 +397,10 @@
 		rc = status(fildes);
 
 		rmtabort(fildes);
-		return (rc);
+		return rc;
 	}
 
-	

CVS commit: src/lib/librmt

2011-02-18 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Fri Feb 18 16:10:10 UTC 2011

Modified Files:
src/lib/librmt: rmtlib.c

Log Message:
Improve isrmt() check: it cannot be a rmt fd if there are no pipes
open for the fd.  Prevents collision with rumphijack.

Also, prevent potential hyperspace memory access.

Does someone want to write tests for this facility?


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/lib/librmt/rmtlib.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/librmt/rmtlib.c
diff -u src/lib/librmt/rmtlib.c:1.22 src/lib/librmt/rmtlib.c:1.23
--- src/lib/librmt/rmtlib.c:1.22	Tue Aug 31 05:12:35 2010
+++ src/lib/librmt/rmtlib.c	Fri Feb 18 16:10:09 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: rmtlib.c,v 1.22 2010/08/31 05:12:35 enami Exp $	*/
+/*	$NetBSD: rmtlib.c,v 1.23 2011/02/18 16:10:09 pooka Exp $	*/
 
 /*
  *	rmt --- remote tape emulator subroutines
@@ -28,7 +28,7 @@
  */
 
 #include sys/cdefs.h
-__RCSID($NetBSD: rmtlib.c,v 1.22 2010/08/31 05:12:35 enami Exp $);
+__RCSID($NetBSD: rmtlib.c,v 1.23 2011/02/18 16:10:09 pooka Exp $);
 
 #define RMTIOCTL	1
 /* #define USE_REXEC	1 */	/* rexec code courtesy of Dan Kegel, srs!dan */
@@ -670,8 +670,10 @@
 int
 isrmt(int fd)
 {
+	int unbias = fd - REM_BIAS;
 
-	return (fd = REM_BIAS);
+	return (fd = REM_BIAS)  unbias  MAXUNIT 
+	(WRITE(unbias) != -1 || READ(unbias) != -1);
 }
 
 



CVS commit: src/lib/librmt

2009-04-11 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Sat Apr 11 17:10:57 UTC 2009

Modified Files:
src/lib/librmt: rmtops.3

Log Message:
Remove redundant .Pp.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/lib/librmt/rmtops.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/librmt/rmtops.3
diff -u src/lib/librmt/rmtops.3:1.12 src/lib/librmt/rmtops.3:1.13
--- src/lib/librmt/rmtops.3:1.12	Sat Apr 11 16:59:05 2009
+++ src/lib/librmt/rmtops.3	Sat Apr 11 17:10:57 2009
@@ -1,4 +1,4 @@
-.\	$NetBSD: rmtops.3,v 1.12 2009/04/11 16:59:05 wiz Exp $
+.\	$NetBSD: rmtops.3,v 1.13 2009/04/11 17:10:57 joerg Exp $
 .\
 .Dd October 16, 2001
 .Dt RMTOPS 3
@@ -79,7 +79,6 @@
 For transparency, the user should include the file
 .Aq Pa rmt.h ,
 which has the following defines in it:
-.Pp
 .Bd -literal
 #define access	rmtaccess
 #define close	rmtclose