My Project
Loading...
Searching...
No Matches
si_signals.h
Go to the documentation of this file.
1/*****************************************
2* Computer Algebra System SINGULAR *
3*****************************************/
4/*
5* ABSTRACT: wrappijng signal-interuptable system calls
6* AUTHOR: Alexander Dreyer, The PolyBoRi Team, 2013
7*/
8
9#include <signal.h>
10#include <errno.h>
11#include <sys/types.h>
12#include <sys/wait.h>
13#include <sys/select.h>
14
15#include <unistd.h>
16#include <sys/uio.h>
17#include <sys/stat.h>
18#include <fcntl.h>
19#include <sys/socket.h>
20#include <time.h>
21#include <stdio.h>
22#include <semaphore.h>
23#include <stdarg.h>
24#ifdef HAVE_POLL_H
25#include <poll.h>
26#endif
27
28#ifndef SINGULAR_SI_SIGNALS_H
29#define SINGULAR_SI_SIGNALS_H
30
31#define SI_EINTR_SAVE_FUNC_TEMPLATE(return_type, newfunc, func, decl, args, err_domain) \
32static inline return_type newfunc decl \
33{ \
34 int res = -1; \
35 do \
36 { \
37 res = func args; \
38 } while((res err_domain) && (errno == EINTR));\
39 return res; \
40}
41
42#define SI_EINTR_SAVE_FUNC(return_type, func, decl, args) \
43 SI_EINTR_SAVE_FUNC_TEMPLATE(return_type, si_##func, func, decl, args, < 0)
44
45#define SI_EINTR_SAVE_SCANF(return_type, func, decl, args) \
46 SI_EINTR_SAVE_FUNC_TEMPLATE(return_type, si_##func, func, decl, args, == EOF)
47
49 (int nfds, fd_set *readfds, fd_set *writefds,
50 fd_set *exceptfds, struct timeval *timeout),
51 (nfds,readfds, writefds, exceptfds, timeout)
52 )
53
54#ifdef HAVE_POLL
55SI_EINTR_SAVE_FUNC(int, poll,
56 (struct pollfd *fds, nfds_t nfds, int timeout),
57 (fds, nfds, timeout)
58 )
59#endif
60
62SI_EINTR_SAVE_FUNC(pid_t, waitpid, (pid_t pid, int *status, int options),
63 (pid, status, options))
64
65//SI_EINTR_SAVE_FUNC(int, waitid,
66// (idtype_t idtype, id_t id, siginfo_t *infop, int options),
67// (idtype, id, infop, options))
68
69SI_EINTR_SAVE_FUNC(ssize_t, read, (int fd, void *buf, size_t count),
70 (fd, buf, count))
71
72
73//SI_EINTR_SAVE_FUNC(ssize_t, readv,
74// (int fd, const struct iovec *iov, int iovcnt),
75// (fd, iov,iovcnt))
76
77SI_EINTR_SAVE_FUNC(ssize_t, write, (int fd, const void *buf, size_t count),
78 (fd, buf, count))
79
80//SI_EINTR_SAVE_FUNC(ssize_t, writev, (int fd, const struct iovec *iov, int iovcnt),
81// (fd, iov, iovcnt) )
82
84 (pathname, flags), < 0)
86 (const char *pathname, int flags, mode_t mode),
87 (pathname, flags, mode), < 0)
88
89/* Enulate overloading usung preprocessor (we need to be C-compatible) */
90#define SI_GET_FIFTH(_4,_3, _2, _1, N, ...) N
91#define si_open(...) SI_GET_FIFTH(X,##__VA_ARGS__, si_open2, si_open1)(__VA_ARGS__)
92
93//SI_EINTR_SAVE_FUNC(int, creat, (const char *pathname, mode_t mode),
94// (pathname, mode))
95
96
97SI_EINTR_SAVE_FUNC(int, close, (int fd), (fd))
98
99SI_EINTR_SAVE_FUNC(int, accept,
100 (int sockfd, struct sockaddr *addr, socklen_t *addrlen),
101 (sockfd, addr, addrlen))
102
103SI_EINTR_SAVE_FUNC(int, connect,
104 (int sockfd, const struct sockaddr *addr, socklen_t addrlen),
105 (sockfd, addr, addrlen))
106
107#if 0
108/* @note: We respect that the user may explicitly deactivate the
109 * restart feature by setting the second argument to NULL.
110 */
111static inline int
112si_nanosleep(const struct timespec *req, struct timespec *rem)
113{
114 int res = -1;
115 do
116 {
117 res = nanosleep(req, rem);
118 } while((rem != NULL) && (res < 0) && (errno == EINTR));
119 return res;
120}
121#endif
122
123static inline unsigned int
124si_sleep(unsigned int seconds)
125{
126 do
127 {
128 seconds = sleep(seconds);
129 } while(seconds != 0);
130 return 0;
131}
132
133//SI_EINTR_SAVE_FUNC(int, dup, (int oldfd), (oldfd))
134SI_EINTR_SAVE_FUNC(int, dup2, (int oldfd, int newfd), (oldfd, newfd))
135//SI_EINTR_SAVE_FUNC(int, dup3, (int oldfd, int newfd, int flags),
136// (oldfd, newfd, flags))
137
138SI_EINTR_SAVE_FUNC(int, unlink, (const char *pathname), (pathname))
139
140SI_EINTR_SAVE_SCANF(int, vscanf,
141 (const char *format, va_list ap),
142 (format, ap))
143
144static inline
145int si_scanf(const char *format, ...)
146{
147 va_list argptr;
148 va_start(argptr, format);
149 int res = si_vscanf(format, argptr);
150 va_end(argptr);
151 return res;
152}
153
154SI_EINTR_SAVE_SCANF(int, vfscanf,
155 (FILE *stream, const char *format, va_list ap),
156 (stream, format, ap))
157
158static inline int
159si_fscanf(FILE *stream, const char *format, ...)
160{
161 va_list argptr;
162 va_start(argptr, format);
163 int res = si_vfscanf(stream, format, argptr);
164 va_end(argptr);
165 return res;
166}
167
168SI_EINTR_SAVE_SCANF(int, vsscanf,
169 (const char *str, const char *format, va_list ap),
170 (str, format, ap))
171
172static inline int
173si_sscanf(const char *str, const char *format, ...)
174{
175 va_list argptr;
176 va_start(argptr, format);
177 int res = si_vsscanf(str, format, argptr);
178 va_end(argptr);
179 return res;
180}
181
182SI_EINTR_SAVE_FUNC(int, stat, (const char *path, struct stat *buf),
183 (path, buf))
184SI_EINTR_SAVE_FUNC(int, fstat, (int fd, struct stat *buf),
185 (fd, buf))
186SI_EINTR_SAVE_FUNC(int, lstat, (const char *path, struct stat *buf),
187 (path, buf))
188
189
190SI_EINTR_SAVE_FUNC(int, sigaction,
191 (int signum, const struct sigaction *act,
192 struct sigaction *oldact),
193 (signum, act, oldact))
194
195
196#ifdef HAVE_SIGINTERRUPT
197SI_EINTR_SAVE_FUNC(int, siginterrupt, (int sig, int flag),
198 (sig, flag))
199#else
200#define si_siginterrupt(arg1, arg2)
201#endif
202
203
204SI_EINTR_SAVE_FUNC(int, sem_wait, (sem_t *sem), (sem))
205SI_EINTR_SAVE_FUNC(int, sem_trywait, (sem_t *sem), (sem))
206//SI_EINTR_SAVE_FUNC(int, sem_timedwait,
207// (sem_t *sem, const struct timespec *abs_timeout),
208// (sem, abs_timeout))
209
210
211#undef SI_EINTR_SAVE_FUNC
212
213
214#endif /* SINGULAR_SI_SIGNALS_H */
void select(const ListCFList &ppi, int length, ListCFList &ppi1, ListCFList &ppi2)
CanonicalForm res
Definition facAbsFact.cc:60
#define const
Definition fegetopt.c:39
STATIC_VAR scmon act
Definition hdegree.cc:1138
void rem(unsigned long *a, unsigned long *q, unsigned long p, int &dega, int degq)
Definition minpoly.cc:572
Definition ap.h:40
#define NULL
Definition omList.c:12
int * status
Definition si_signals.h:61
#define SI_EINTR_SAVE_FUNC(return_type, func, decl, args)
Definition si_signals.h:42
int status read
Definition si_signals.h:69
#define SI_EINTR_SAVE_SCANF(return_type, func, decl, args)
Definition si_signals.h:45
#define SI_EINTR_SAVE_FUNC_TEMPLATE(return_type, newfunc, func, decl, args, err_domain)
Definition si_signals.h:31
int status int void size_t count const char int flags
Definition si_signals.h:83
int status int fd
Definition si_signals.h:69
int status int void size_t count open
Definition si_signals.h:83
int status int void size_t count si_open1
Definition si_signals.h:83
int status int void size_t count
Definition si_signals.h:69
int status int void size_t count const char * pathname
Definition si_signals.h:83
int status int void * buf
Definition si_signals.h:69
wait
Definition si_signals.h:61