File: fm_getaddrinfo.c

package info (click to toggle)
fetchmail 6.4.16-4%2Bdeb11u1
  • links: PTS
  • area: main
  • in suites: bullseye
  • size: 10,068 kB
  • sloc: ansic: 30,318; sh: 6,255; perl: 3,181; python: 2,212; yacc: 460; lex: 285; makefile: 251; awk: 124; lisp: 84; exp: 43; sed: 16
file content (40 lines) | stat: -rw-r--r-- 1,004 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include "config.h"
#include "fetchmail.h"
#include "i18n.h"

#include <signal.h>
#include <errno.h>
#include <string.h>

/** This is a getaddrinfo() replacement that blocks SIGALRM,
 * to avoid issues with non-reentrant getaddrinfo() implementations
 * after SIGALRM timeouts, for instance on MacOS X or NetBSD. */
int fm_getaddrinfo(const char *node, const char *serv, const struct addrinfo *hints, struct addrinfo **res)
{
    int rc;

#ifndef GETADDRINFO_ASYNCSAFE
    sigset_t ss, os;

    sigemptyset(&ss);
    sigaddset(&ss, SIGALRM);

    if (sigprocmask(SIG_BLOCK, &ss, &os))
	report(stderr, GT_("Cannot modify signal mask: %s"), strerror(errno));
#endif

    rc = getaddrinfo(node, serv, hints, res);

#ifndef GETADDRINFO_ASYNCSAFE
    if (sigprocmask(SIG_SETMASK, &os, NULL))
	report(stderr, GT_("Cannot modify signal mask: %s"), strerror(errno));
#endif

    return rc;
}

/** this is a debugging freeaddrinfo() wrapper. */
void fm_freeaddrinfo(struct addrinfo *ai)
{
    freeaddrinfo(ai);
}