~ubuntu-branches/ubuntu/vivid/postfix/vivid-proposed

« back to all changes in this revision

Viewing changes to src/util/sane_socketpair.c

  • Committer: Bazaar Package Importer
  • Author(s): LaMont Jones
  • Date: 2005-02-27 09:33:07 UTC
  • Revision ID: james.westby@ubuntu.com-20050227093307-cn789t27ibnlh6tf
Tags: upstream-2.1.5
ImportĀ upstreamĀ versionĀ 2.1.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*++
 
2
/* NAME
 
3
/*      sane_socketpair 3
 
4
/* SUMMARY
 
5
/*      sanitize socketpair() error returns
 
6
/* SYNOPSIS
 
7
/*      #include <sane_socketpair.h>
 
8
/*
 
9
/*      int     sane_socketpair(domain, type, protocol, result)
 
10
/*      int     domain;
 
11
/*      int     type;
 
12
/*      int     protocol;
 
13
/*      int     *result;
 
14
/* DESCRIPTION
 
15
/*      sane_socketpair() implements the socketpair(2) socket call, and
 
16
/*      skips over silly error results such as EINTR.
 
17
/* BUGS
 
18
/*      Bizarre systems may have other harmless error results. Such
 
19
/*      systems encourage programers to ignore error results, and
 
20
/*      penalizes programmers who code defensively.
 
21
/* LICENSE
 
22
/* .ad
 
23
/* .fi
 
24
/*      The Secure Mailer license must be distributed with this software.
 
25
/* AUTHOR(S)
 
26
/*      Wietse Venema
 
27
/*      IBM T.J. Watson Research
 
28
/*      P.O. Box 704
 
29
/*      Yorktown Heights, NY 10598, USA
 
30
/*--*/
 
31
 
 
32
/* System library. */
 
33
 
 
34
#include "sys_defs.h"
 
35
#include <sys/socket.h>
 
36
#include <unistd.h>
 
37
#include <errno.h>
 
38
 
 
39
/* Utility library. */
 
40
 
 
41
#include "msg.h"
 
42
#include "sane_socketpair.h"
 
43
 
 
44
/* sane_socketpair - sanitize socketpair() error returns */
 
45
 
 
46
int     sane_socketpair(int domain, int type, int protocol, int *result)
 
47
{
 
48
    static int socketpair_ok_errors[] = {
 
49
        EINTR,
 
50
        0,
 
51
    };
 
52
    int     count;
 
53
    int     err;
 
54
    int     ret;
 
55
 
 
56
    /*
 
57
     * Solaris socketpair() can fail with EINTR.
 
58
     */
 
59
    while ((ret = socketpair(domain, type, protocol, result)) < 0) {
 
60
        for (count = 0; /* void */ ; count++) {
 
61
            if ((err = socketpair_ok_errors[count]) == 0)
 
62
                return (ret);
 
63
            if (errno == err) {
 
64
                msg_warn("socketpair: %m (trying again)");
 
65
                sleep(1);
 
66
                break;
 
67
            }
 
68
        }
 
69
    }
 
70
    return (ret);
 
71
}