summaryrefslogtreecommitdiffstats
path: root/monitor_fdpass.c
diff options
context:
space:
mode:
authorBen Lindstrom <mouring@eviladmin.org>2002-03-26 03:36:29 +0100
committerBen Lindstrom <mouring@eviladmin.org>2002-03-26 03:36:29 +0100
commit31ee7aeb1590431230ccdbb8060c56bd1b32dd1e (patch)
tree49d377d5df975cf69b7084bfb78668c1ff4827c8 /monitor_fdpass.c
parent - stevesk@cvs.openbsd.org 2002/03/24 17:27:03 (diff)
downloadopenssh-31ee7aeb1590431230ccdbb8060c56bd1b32dd1e.tar.xz
openssh-31ee7aeb1590431230ccdbb8060c56bd1b32dd1e.zip
- stevesk@cvs.openbsd.org 2002/03/24 17:53:16
[monitor_fdpass.c] minor cleanup and more error checking; ok markus@
Diffstat (limited to 'monitor_fdpass.c')
-rw-r--r--monitor_fdpass.c27
1 files changed, 17 insertions, 10 deletions
diff --git a/monitor_fdpass.c b/monitor_fdpass.c
index fd55a2776..eed1dc162 100644
--- a/monitor_fdpass.c
+++ b/monitor_fdpass.c
@@ -24,7 +24,7 @@
*/
#include "includes.h"
-RCSID("$OpenBSD: monitor_fdpass.c,v 1.1 2002/03/18 17:27:22 provos Exp $");
+RCSID("$OpenBSD: monitor_fdpass.c,v 1.2 2002/03/24 17:53:16 stevesk Exp $");
#include <sys/uio.h>
@@ -36,7 +36,8 @@ mm_send_fd(int socket, int fd)
{
struct msghdr msg;
struct iovec vec;
- char ch;
+ char ch = '\0';
+ int n;
#ifndef HAVE_ACCRIGHTS_IN_MSGHDR
char tmp[CMSG_SPACE(sizeof(int))];
struct cmsghdr *cmsg;
@@ -61,8 +62,12 @@ mm_send_fd(int socket, int fd)
msg.msg_iov = &vec;
msg.msg_iovlen = 1;
- if (sendmsg(socket, &msg, 0) == -1)
- fatal("%s: sendmsg(%d)", __FUNCTION__, fd);
+ if ((n = sendmsg(socket, &msg, 0)) == -1)
+ fatal("%s: sendmsg(%d): %s", __FUNCTION__, fd,
+ strerror(errno));
+ if (n != 1)
+ fatal("%s: sendmsg: expected sent 1 got %d",
+ __FUNCTION__, n);
}
int
@@ -71,11 +76,10 @@ mm_receive_fd(int socket)
struct msghdr msg;
struct iovec vec;
char ch;
+ int fd, n;
#ifndef HAVE_ACCRIGHTS_IN_MSGHDR
char tmp[CMSG_SPACE(sizeof(int))];
struct cmsghdr *cmsg;
-#else
- int fd;
#endif
memset(&msg, 0, sizeof(msg));
@@ -91,18 +95,21 @@ mm_receive_fd(int socket)
msg.msg_controllen = sizeof(tmp);
#endif
- if (recvmsg(socket, &msg, 0) == -1)
- fatal("%s: recvmsg", __FUNCTION__);
+ if ((n = recvmsg(socket, &msg, 0)) == -1)
+ fatal("%s: recvmsg: %s", __FUNCTION__, strerror(errno));
+ if (n != 1)
+ fatal("%s: recvmsg: expected received 1 got %d",
+ __FUNCTION__, n);
#ifdef HAVE_ACCRIGHTS_IN_MSGHDR
if (msg.msg_accrightslen != sizeof(fd))
fatal("%s: no fd", __FUNCTION__);
- return fd;
#else
cmsg = CMSG_FIRSTHDR(&msg);
if (cmsg->cmsg_type != SCM_RIGHTS)
fatal("%s: expected type %d got %d", __FUNCTION__,
SCM_RIGHTS, cmsg->cmsg_type);
- return (*(int *)CMSG_DATA(cmsg));
+ fd = (*(int *)CMSG_DATA(cmsg));
#endif
+ return fd;
}