~ubuntu-branches/ubuntu/lucid/openssh/lucid

« back to all changes in this revision

Viewing changes to atomicio.c

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson
  • Date: 2008-09-30 23:09:58 UTC
  • mfrom: (1.13.3 upstream) (29 hardy)
  • mto: This revision was merged to the branch mainline in revision 43.
  • Revision ID: james.westby@ubuntu.com-20080930230958-o6vsgn8c4mm959s0
Tags: 1:5.1p1-3
* Remove unnecessary ssh-vulnkey output in non-verbose mode when no
  compromised or unknown keys were found (closes: #496495).
* Configure with --disable-strip; dh_strip will deal with stripping
  binaries and will honour DEB_BUILD_OPTIONS (thanks, Bernhard R. Link;
  closes: #498681).
* Fix handling of zero-length server banners (thanks, Tomas Mraz; closes:
  #497026).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $OpenBSD: atomicio.c,v 1.23 2006/08/03 03:34:41 deraadt Exp $ */
 
1
/* $OpenBSD: atomicio.c,v 1.25 2007/06/25 12:02:27 dtucker Exp $ */
2
2
/*
3
3
 * Copyright (c) 2006 Damien Miller. All rights reserved.
4
4
 * Copyright (c) 2005 Anil Madhavapeddy. All rights reserved.
32
32
#include <sys/uio.h>
33
33
 
34
34
#include <errno.h>
 
35
#ifdef HAVE_POLL_H
 
36
#include <poll.h>
 
37
#else
 
38
# ifdef HAVE_SYS_POLL_H
 
39
#  include <sys/poll.h>
 
40
# endif
 
41
#endif
35
42
#include <string.h>
 
43
#include <unistd.h>
36
44
 
37
45
#include "atomicio.h"
38
46
 
45
53
        char *s = _s;
46
54
        size_t pos = 0;
47
55
        ssize_t res;
 
56
        struct pollfd pfd;
48
57
 
 
58
        pfd.fd = fd;
 
59
        pfd.events = f == read ? POLLIN : POLLOUT;
49
60
        while (n > pos) {
50
61
                res = (f) (fd, s + pos, n - pos);
51
62
                switch (res) {
52
63
                case -1:
53
 
#ifdef EWOULDBLOCK
54
 
                        if (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK)
55
 
#else
56
 
                        if (errno == EINTR || errno == EAGAIN)
57
 
#endif
58
 
                                continue;
 
64
                        if (errno == EINTR)
 
65
                                continue;
 
66
                        if (errno == EAGAIN || errno == EWOULDBLOCK) {
 
67
                                (void)poll(&pfd, 1, -1);
 
68
                                continue;
 
69
                        }
59
70
                        return 0;
60
71
                case 0:
61
72
                        errno = EPIPE;
77
88
        size_t pos = 0, rem;
78
89
        ssize_t res;
79
90
        struct iovec iov_array[IOV_MAX], *iov = iov_array;
 
91
        struct pollfd pfd;
80
92
 
81
93
        if (iovcnt > IOV_MAX) {
82
94
                errno = EINVAL;
85
97
        /* Make a copy of the iov array because we may modify it below */
86
98
        memcpy(iov, _iov, iovcnt * sizeof(*_iov));
87
99
 
 
100
#ifndef BROKEN_READV_COMPARISON
 
101
        pfd.fd = fd;
 
102
        pfd.events = f == readv ? POLLIN : POLLOUT;
 
103
#endif
88
104
        for (; iovcnt > 0 && iov[0].iov_len > 0;) {
89
105
                res = (f) (fd, iov, iovcnt);
90
106
                switch (res) {
91
107
                case -1:
92
 
                        if (errno == EINTR || errno == EAGAIN)
93
 
                                continue;
 
108
                        if (errno == EINTR)
 
109
                                continue;
 
110
                        if (errno == EAGAIN || errno == EWOULDBLOCK) {
 
111
#ifndef BROKEN_READV_COMPARISON
 
112
                                (void)poll(&pfd, 1, -1);
 
113
#endif
 
114
                                continue;
 
115
                        }
94
116
                        return 0;
95
117
                case 0:
96
118
                        errno = EPIPE;