summaryrefslogtreecommitdiff
path: root/monitor_fdpass.c
diff options
context:
space:
mode:
authorBen Lindstrom <mouring@eviladmin.org>2002-03-26 02:36:29 +0000
committerBen Lindstrom <mouring@eviladmin.org>2002-03-26 02:36:29 +0000
commit31ee7aeb1590431230ccdbb8060c56bd1b32dd1e (patch)
tree49d377d5df975cf69b7084bfb78668c1ff4827c8 /monitor_fdpass.c
parentfcad1c92c97de782ab8132e7b6174cc64ef48a89 (diff)
- 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 @@
24 */ 24 */
25 25
26#include "includes.h" 26#include "includes.h"
27RCSID("$OpenBSD: monitor_fdpass.c,v 1.1 2002/03/18 17:27:22 provos Exp $"); 27RCSID("$OpenBSD: monitor_fdpass.c,v 1.2 2002/03/24 17:53:16 stevesk Exp $");
28 28
29#include <sys/uio.h> 29#include <sys/uio.h>
30 30
@@ -36,7 +36,8 @@ mm_send_fd(int socket, int fd)
36{ 36{
37 struct msghdr msg; 37 struct msghdr msg;
38 struct iovec vec; 38 struct iovec vec;
39 char ch; 39 char ch = '\0';
40 int n;
40#ifndef HAVE_ACCRIGHTS_IN_MSGHDR 41#ifndef HAVE_ACCRIGHTS_IN_MSGHDR
41 char tmp[CMSG_SPACE(sizeof(int))]; 42 char tmp[CMSG_SPACE(sizeof(int))];
42 struct cmsghdr *cmsg; 43 struct cmsghdr *cmsg;
@@ -61,8 +62,12 @@ mm_send_fd(int socket, int fd)
61 msg.msg_iov = &vec; 62 msg.msg_iov = &vec;
62 msg.msg_iovlen = 1; 63 msg.msg_iovlen = 1;
63 64
64 if (sendmsg(socket, &msg, 0) == -1) 65 if ((n = sendmsg(socket, &msg, 0)) == -1)
65 fatal("%s: sendmsg(%d)", __FUNCTION__, fd); 66 fatal("%s: sendmsg(%d): %s", __FUNCTION__, fd,
67 strerror(errno));
68 if (n != 1)
69 fatal("%s: sendmsg: expected sent 1 got %d",
70 __FUNCTION__, n);
66} 71}
67 72
68int 73int
@@ -71,11 +76,10 @@ mm_receive_fd(int socket)
71 struct msghdr msg; 76 struct msghdr msg;
72 struct iovec vec; 77 struct iovec vec;
73 char ch; 78 char ch;
79 int fd, n;
74#ifndef HAVE_ACCRIGHTS_IN_MSGHDR 80#ifndef HAVE_ACCRIGHTS_IN_MSGHDR
75 char tmp[CMSG_SPACE(sizeof(int))]; 81 char tmp[CMSG_SPACE(sizeof(int))];
76 struct cmsghdr *cmsg; 82 struct cmsghdr *cmsg;
77#else
78 int fd;
79#endif 83#endif
80 84
81 memset(&msg, 0, sizeof(msg)); 85 memset(&msg, 0, sizeof(msg));
@@ -91,18 +95,21 @@ mm_receive_fd(int socket)
91 msg.msg_controllen = sizeof(tmp); 95 msg.msg_controllen = sizeof(tmp);
92#endif 96#endif
93 97
94 if (recvmsg(socket, &msg, 0) == -1) 98 if ((n = recvmsg(socket, &msg, 0)) == -1)
95 fatal("%s: recvmsg", __FUNCTION__); 99 fatal("%s: recvmsg: %s", __FUNCTION__, strerror(errno));
100 if (n != 1)
101 fatal("%s: recvmsg: expected received 1 got %d",
102 __FUNCTION__, n);
96 103
97#ifdef HAVE_ACCRIGHTS_IN_MSGHDR 104#ifdef HAVE_ACCRIGHTS_IN_MSGHDR
98 if (msg.msg_accrightslen != sizeof(fd)) 105 if (msg.msg_accrightslen != sizeof(fd))
99 fatal("%s: no fd", __FUNCTION__); 106 fatal("%s: no fd", __FUNCTION__);
100 return fd;
101#else 107#else
102 cmsg = CMSG_FIRSTHDR(&msg); 108 cmsg = CMSG_FIRSTHDR(&msg);
103 if (cmsg->cmsg_type != SCM_RIGHTS) 109 if (cmsg->cmsg_type != SCM_RIGHTS)
104 fatal("%s: expected type %d got %d", __FUNCTION__, 110 fatal("%s: expected type %d got %d", __FUNCTION__,
105 SCM_RIGHTS, cmsg->cmsg_type); 111 SCM_RIGHTS, cmsg->cmsg_type);
106 return (*(int *)CMSG_DATA(cmsg)); 112 fd = (*(int *)CMSG_DATA(cmsg));
107#endif 113#endif
114 return fd;
108} 115}