summaryrefslogtreecommitdiff
path: root/bin/mt
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2019-06-28 13:35:06 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2019-06-28 13:35:06 +0000
commit61656abc7ff84215165af1bd464bc053b3b66158 (patch)
treec7eabb0c4fa9faa024e724e99c240c40da07ca42 /bin/mt
parent18603ebf99fbb890ae9666cb0c4aa9f879e7edaa (diff)
When system calls indicate an error they return -1, not some arbitrary
value < 0. errno is only updated in this case. Change all (most?) callers of syscalls to follow this better, and let's see if this strictness helps us in the future.
Diffstat (limited to 'bin/mt')
-rw-r--r--bin/mt/mt.c8
-rw-r--r--bin/mt/mtrmt.c21
2 files changed, 11 insertions, 18 deletions
diff --git a/bin/mt/mt.c b/bin/mt/mt.c
index 2d60d2cc31e..29a74863491 100644
--- a/bin/mt/mt.c
+++ b/bin/mt/mt.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mt.c,v 1.40 2019/01/22 21:20:13 krw Exp $ */
+/* $OpenBSD: mt.c,v 1.41 2019/06/28 13:34:59 deraadt Exp $ */
/* $NetBSD: mt.c,v 1.14.2.1 1996/05/27 15:12:11 mrg Exp $ */
/*
@@ -122,7 +122,7 @@ _rmtstatus(int fd)
if (host)
return rmtstatus();
#endif
- if (ioctl(fd, MTIOCGET, &mt_status) < 0)
+ if (ioctl(fd, MTIOCGET, &mt_status) == -1)
err(2, "ioctl MTIOCGET");
return &mt_status;
}
@@ -217,7 +217,7 @@ main(int argc, char *argv[])
flags = comp->c_ronly ? O_RDONLY : O_WRONLY | O_CREAT;
/* NOTE: OPENDEV_PART required since cd(4) devices go through here. */
- if ((mtfd = _rmtopendev(tape, flags, OPENDEV_PART, &realtape)) < 0) {
+ if ((mtfd = _rmtopendev(tape, flags, OPENDEV_PART, &realtape)) == -1) {
if (errno != 0)
warn("%s", host ? tape : realtape);
exit(2);
@@ -231,7 +231,7 @@ main(int argc, char *argv[])
}
else
mt_com.mt_count = 1;
- if (_rmtmtioctop(mtfd, &mt_com) < 0) {
+ if (_rmtmtioctop(mtfd, &mt_com) == -1) {
if (eject)
err(2, "%s", tape);
else
diff --git a/bin/mt/mtrmt.c b/bin/mt/mtrmt.c
index 7e9bfe6c222..84e4dd57b40 100644
--- a/bin/mt/mtrmt.c
+++ b/bin/mt/mtrmt.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mtrmt.c,v 1.22 2018/07/09 19:38:29 deraadt Exp $ */
+/* $OpenBSD: mtrmt.c,v 1.23 2019/06/28 13:34:59 deraadt Exp $ */
/* $NetBSD: mtrmt.c,v 1.2 1996/03/06 06:22:07 scottr Exp $ */
/*-
@@ -104,7 +104,6 @@ void
rmtgetconn(void)
{
char *cp;
- static struct servent *sp = NULL;
static struct passwd *pwd = NULL;
#ifdef notdef
static int on = 1;
@@ -113,14 +112,6 @@ rmtgetconn(void)
int size;
int maxseg;
- if (sp == NULL) {
- sp = getservbyname("shell", "tcp");
- if (sp == NULL)
- errx(1, "shell/tcp: unknown service");
- pwd = getpwuid(getuid());
- if (pwd == NULL)
- errx(1, "who are you?");
- }
if ((cp = strchr(rmtpeer, '@')) != NULL) {
tuser = rmtpeer;
*cp = '\0';
@@ -130,7 +121,7 @@ rmtgetconn(void)
} else
tuser = pwd->pw_name;
- rmtape = rcmd(&rmtpeer, (u_short)sp->s_port, pwd->pw_name, tuser,
+ rmtape = rcmdsh(&rmtpeer, -1, pwd->pw_name, tuser,
_PATH_RMT, NULL);
if (rmtape == -1)
exit(1); /* rcmd already printed error message */
@@ -142,18 +133,20 @@ rmtgetconn(void)
size += 2 * 1024;
while (size > TP_BSIZE &&
- setsockopt(rmtape, SOL_SOCKET, SO_SNDBUF, &size, sizeof (size)) < 0)
+ setsockopt(rmtape, SOL_SOCKET, SO_SNDBUF, &size, sizeof (size)) == -1)
size -= TP_BSIZE;
(void)setsockopt(rmtape, SOL_SOCKET, SO_RCVBUF, &size, sizeof (size));
maxseg = 1024;
(void)setsockopt(rmtape, IPPROTO_TCP, TCP_MAXSEG, &maxseg,
- sizeof (maxseg));
+ sizeof (maxseg));
#ifdef notdef
- if (setsockopt(rmtape, IPPROTO_TCP, TCP_NODELAY, &on, sizeof (on)) < 0)
+ if (setsockopt(rmtape, IPPROTO_TCP, TCP_NODELAY, &on, sizeof (on)) == -1)
perror("TCP_NODELAY setsockopt");
#endif
+ if (pledge("stdio", NULL) == -1)
+ err(1, "pledge");
}
static int