summaryrefslogtreecommitdiff
path: root/usr.bin/ssh/monitor_fdpass.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr.bin/ssh/monitor_fdpass.c')
-rw-r--r--usr.bin/ssh/monitor_fdpass.c44
1 files changed, 30 insertions, 14 deletions
diff --git a/usr.bin/ssh/monitor_fdpass.c b/usr.bin/ssh/monitor_fdpass.c
index cb2001e6d41..c760a2150b0 100644
--- a/usr.bin/ssh/monitor_fdpass.c
+++ b/usr.bin/ssh/monitor_fdpass.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: monitor_fdpass.c,v 1.12 2006/08/03 03:34:42 deraadt Exp $ */
+/* $OpenBSD: monitor_fdpass.c,v 1.13 2007/09/04 03:21:03 djm Exp $ */
/*
* Copyright 2001 Niels Provos <provos@citi.umich.edu>
* All rights reserved.
@@ -35,7 +35,7 @@
#include "log.h"
#include "monitor_fdpass.h"
-void
+int
mm_send_fd(int sock, int fd)
{
struct msghdr msg;
@@ -59,12 +59,18 @@ mm_send_fd(int sock, int fd)
msg.msg_iov = &vec;
msg.msg_iovlen = 1;
- if ((n = sendmsg(sock, &msg, 0)) == -1)
- fatal("%s: sendmsg(%d): %s", __func__, fd,
+ if ((n = sendmsg(sock, &msg, 0)) == -1) {
+ error("%s: sendmsg(%d): %s", __func__, fd,
strerror(errno));
- if (n != 1)
- fatal("%s: sendmsg: expected sent 1 got %ld",
+ return -1;
+ }
+
+ if (n != 1) {
+ error("%s: sendmsg: expected sent 1 got %ld",
__func__, (long)n);
+ return -1;
+ }
+ return 0;
}
int
@@ -86,18 +92,28 @@ mm_receive_fd(int sock)
msg.msg_control = tmp;
msg.msg_controllen = sizeof(tmp);
- if ((n = recvmsg(sock, &msg, 0)) == -1)
- fatal("%s: recvmsg: %s", __func__, strerror(errno));
- if (n != 1)
- fatal("%s: recvmsg: expected received 1 got %ld",
+ if ((n = recvmsg(sock, &msg, 0)) == -1) {
+ error("%s: recvmsg: %s", __func__, strerror(errno));
+ return -1;
+ }
+
+ if (n != 1) {
+ error("%s: recvmsg: expected received 1 got %ld",
__func__, (long)n);
+ return -1;
+ }
cmsg = CMSG_FIRSTHDR(&msg);
- if (cmsg == NULL)
- fatal("%s: no message header", __func__);
- if (cmsg->cmsg_type != SCM_RIGHTS)
- fatal("%s: expected type %d got %d", __func__,
+ if (cmsg == NULL) {
+ error("%s: no message header", __func__);
+ return -1;
+ }
+
+ if (cmsg->cmsg_type != SCM_RIGHTS) {
+ error("%s: expected type %d got %d", __func__,
SCM_RIGHTS, cmsg->cmsg_type);
+ return -1;
+ }
fd = (*(int *)CMSG_DATA(cmsg));
return fd;
}