- stevesk@cvs.openbsd.org 2002/03/24 17:53:16
[monitor_fdpass.c]
minor cleanup and more error checking; ok markus@
diff --git a/ChangeLog b/ChangeLog
index cc73ee7..526edb9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -13,6 +13,9 @@
- stevesk@cvs.openbsd.org 2002/03/24 17:27:03
[kexgex.c]
typo; ok markus@
+ - stevesk@cvs.openbsd.org 2002/03/24 17:53:16
+ [monitor_fdpass.c]
+ minor cleanup and more error checking; ok markus@
20020324
- (stevesk) [session.c] disable LOGIN_NEEDS_TERM until we are sure
@@ -8027,4 +8030,4 @@
- Wrote replacements for strlcpy and mkdtemp
- Released 1.0pre1
-$Id: ChangeLog,v 1.1981 2002/03/26 02:20:06 mouring Exp $
+$Id: ChangeLog,v 1.1982 2002/03/26 02:36:29 mouring Exp $
diff --git a/monitor_fdpass.c b/monitor_fdpass.c
index fd55a27..eed1dc1 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 @@
{
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 @@
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 @@
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 @@
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;
}