1 | /***************************************** |
---|
2 | * Computer Algebra System SINGULAR * |
---|
3 | *****************************************/ |
---|
4 | /* |
---|
5 | * ABSTRACT: wrappijng signal-interuptable system calls |
---|
6 | * AUTHOR: Alexander Dreyer, The PolyBoRi Team |
---|
7 | */ |
---|
8 | |
---|
9 | #include <signal.h> |
---|
10 | #include <errno.h> |
---|
11 | #include <sys/types.h> |
---|
12 | #include <sys/wait.h> |
---|
13 | |
---|
14 | #include <unistd.h> |
---|
15 | #include <sys/uio.h> |
---|
16 | #include <sys/stat.h> |
---|
17 | #include <fcntl.h> |
---|
18 | #include <sys/socket.h> |
---|
19 | #include <time.h> |
---|
20 | |
---|
21 | #ifndef SINGULAR_SI_SIGNALS_H |
---|
22 | #define SINGULAR_SI_SIGNALS_H |
---|
23 | |
---|
24 | #define SI_EINTR_SAVE_FUNC(return_type, func, decl, args) \ |
---|
25 | inline return_type si_##func decl \ |
---|
26 | { \ |
---|
27 | int res = -1; \ |
---|
28 | do \ |
---|
29 | { \ |
---|
30 | res = func args; \ |
---|
31 | } while((res < 0) && (errno == EINTR));\ |
---|
32 | return res; \ |
---|
33 | } |
---|
34 | |
---|
35 | |
---|
36 | SI_EINTR_SAVE_FUNC(int, select, |
---|
37 | (int nfds, fd_set *readfds, fd_set *writefds, |
---|
38 | fd_set *exceptfds, struct timeval *timeout), |
---|
39 | (nfds,readfds, writefds, exceptfds, timeout) |
---|
40 | ) |
---|
41 | |
---|
42 | SI_EINTR_SAVE_FUNC(int, pselect, |
---|
43 | (int nfds, fd_set *readfds, fd_set *writefds, |
---|
44 | fd_set *exceptfds, const struct timespec *timeout, |
---|
45 | const sigset_t *sigmask), |
---|
46 | (nfds, readfds, writefds, exceptfds, timeout,sigmask) |
---|
47 | ) |
---|
48 | |
---|
49 | SI_EINTR_SAVE_FUNC(pid_t, wait, (int *status), (status)) |
---|
50 | SI_EINTR_SAVE_FUNC(pid_t, waitpid, (pid_t pid, int *status, int options), |
---|
51 | (pid, status, options)) |
---|
52 | |
---|
53 | SI_EINTR_SAVE_FUNC(int, waitid, |
---|
54 | (idtype_t idtype, id_t id, siginfo_t *infop, int options), |
---|
55 | (idtype, id, infop, options)) |
---|
56 | |
---|
57 | SI_EINTR_SAVE_FUNC(ssize_t, read, (int fd, void *buf, size_t count), |
---|
58 | (fd, buf, count)) |
---|
59 | |
---|
60 | |
---|
61 | SI_EINTR_SAVE_FUNC(ssize_t, readv, |
---|
62 | (int fd, const struct iovec *iov, int iovcnt), |
---|
63 | (fd, iov,iovcnt)) |
---|
64 | |
---|
65 | SI_EINTR_SAVE_FUNC(ssize_t, write, (int fd, const void *buf, size_t count), |
---|
66 | (fd, buf, count)) |
---|
67 | |
---|
68 | SI_EINTR_SAVE_FUNC(ssize_t, writev, (int fd, const struct iovec *iov, int iovcnt), |
---|
69 | (fd, iov, iovcnt) ) |
---|
70 | |
---|
71 | SI_EINTR_SAVE_FUNC(int, open, (const char *pathname, int flags), |
---|
72 | (pathname, flags)) |
---|
73 | |
---|
74 | SI_EINTR_SAVE_FUNC(int, open, (const char *pathname, int flags, mode_t mode), |
---|
75 | (pathname, flags, mode)) |
---|
76 | |
---|
77 | SI_EINTR_SAVE_FUNC(int, close, (int fd), (fd)) |
---|
78 | |
---|
79 | SI_EINTR_SAVE_FUNC(int, accept, |
---|
80 | (int sockfd, struct sockaddr *addr, socklen_t *addrlen), |
---|
81 | (sockfd, addr, addrlen)) |
---|
82 | |
---|
83 | SI_EINTR_SAVE_FUNC(int, connect, |
---|
84 | (int sockfd, const struct sockaddr *addr, socklen_t addrlen), |
---|
85 | (sockfd, addr, addrlen)) |
---|
86 | |
---|
87 | SI_EINTR_SAVE_FUNC(int, nanosleep, |
---|
88 | (const struct timespec *req, struct timespec *rem), |
---|
89 | (req, rem)) |
---|
90 | |
---|
91 | inline unsigned int si_sleep(unsigned int seconds) |
---|
92 | { |
---|
93 | do |
---|
94 | { |
---|
95 | seconds = sleep(seconds); |
---|
96 | } while(seconds != 0); |
---|
97 | return 0; |
---|
98 | } |
---|
99 | |
---|
100 | // still todo: read,write,open in ./omalloc/Misc/dlmalloc |
---|
101 | /// TODO: wrap and replace the following system calls: from man 7 signal |
---|
102 | /// ???fread, fwrite, fopen, fdopen, popen, fclose |
---|
103 | |
---|
104 | |
---|
105 | /// |
---|
106 | /// regardless of the use of SA_RESTART: |
---|
107 | /// |
---|
108 | /// nanosleep(2), and usleep(3). |
---|
109 | /// sleep(3) |
---|
110 | |
---|
111 | |
---|
112 | |
---|
113 | |
---|
114 | |
---|
115 | #undef SI_EINTR_SAVE_FUNC |
---|
116 | |
---|
117 | |
---|
118 | #endif /* SINGULAR_SI_SIGNALS_H */ |
---|