[go: up one dir, main page]

File: ppoll_compat.c

package info (click to toggle)
cctools 9.9-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 44,624 kB
  • sloc: ansic: 192,539; python: 20,827; cpp: 20,199; sh: 11,719; perl: 4,106; xml: 3,688; makefile: 1,224
file content (46 lines) | stat: -rw-r--r-- 1,002 bytes parent folder | download
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
41
42
43
44
45
46
/*
Copyright (C) 2020- The University of Notre Dame
This software is distributed under the GNU General Public License.
See the file COPYING for details.
*/

#include <assert.h>
#include <signal.h>
#include <poll.h>
#include <time.h>
#include <errno.h>

#include "ppoll_compat.h"

static void noop(int sig) {}

int ppoll_compat(struct pollfd fds[], nfds_t nfds, int stoptime) {
	assert(fds);
	sigset_t mask;
	sigemptyset(&mask);
	int timeout = stoptime - time(NULL);
	if (timeout < 0) return 0;

#ifdef HAS_PPOLL
	struct timespec s;
	s.tv_nsec = 0;
	s.tv_sec = timeout;
	return ppoll(fds, nfds, &s, &mask);
#else
	sigset_t origmask;
	sigprocmask(SIG_SETMASK, &mask, &origmask);
	int rc = poll(fds, nfds, timeout*1000);
	int saved_errno = errno;
	sigprocmask(SIG_SETMASK, &origmask, NULL);
	errno = saved_errno;
	return rc;
#endif
}

void ppoll_compat_set_up_sigchld(void) {
	sigset_t mask;
	sigemptyset(&mask);
	sigaddset(&mask, SIGCHLD);
	sigprocmask(SIG_BLOCK, &mask, NULL);
	signal(SIGCHLD, noop);
}