My Project
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
25#ifndef SINGULAR_SI_SIGNALS_H
26#define SINGULAR_SI_SIGNALS_H
27
28#define SI_EINTR_SAVE_FUNC_TEMPLATE(return_type, newfunc, func, decl, args, err_domain) \
29static inline return_type newfunc decl \
30{ \
31 int res = -1; \
32 do \
33 { \
34 res = func args; \
35 } while((res err_domain) && (errno == EINTR));\
36 return res; \
37}
38
39#define SI_EINTR_SAVE_FUNC(return_type, func, decl, args) \
40 SI_EINTR_SAVE_FUNC_TEMPLATE(return_type, si_##func, func, decl, args, < 0)
41
42#define SI_EINTR_SAVE_SCANF(return_type, func, decl, args) \
43 SI_EINTR_SAVE_FUNC_TEMPLATE(return_type, si_##func, func, decl, args, == EOF)
44
46 (int nfds, fd_set *readfds, fd_set *writefds,
47 fd_set *exceptfds, struct timeval *timeout),
48 (nfds,readfds, writefds, exceptfds, timeout)
49 )
50
52SI_EINTR_SAVE_FUNC(pid_t, waitpid, (pid_t pid, int *status, int options),
53 (pid, status, options))
54
55//SI_EINTR_SAVE_FUNC(int, waitid,
56// (idtype_t idtype, id_t id, siginfo_t *infop, int options),
57// (idtype, id, infop, options))
58
59SI_EINTR_SAVE_FUNC(ssize_t, read, (int fd, void *buf, size_t count),
60 (fd, buf, count))
61
62
63SI_EINTR_SAVE_FUNC(ssize_t, readv,
64 (int fd, const struct iovec *iov, int iovcnt),
65 (fd, iov,iovcnt))
66
67SI_EINTR_SAVE_FUNC(ssize_t, write, (int fd, const void *buf, size_t count),
68 (fd, buf, count))
69
70SI_EINTR_SAVE_FUNC(ssize_t, writev, (int fd, const struct iovec *iov, int iovcnt),
71 (fd, iov, iovcnt) )
72
74 (pathname, flags), < 0)
76 (const char *pathname, int flags, mode_t mode),
77 (pathname, flags, mode), < 0)
78
79/* Enulate overloading usung preprocessor (we need to be C-compatible) */
80#define SI_GET_FIFTH(_4,_3, _2, _1, N, ...) N
81#define si_open(...) SI_GET_FIFTH(X,##__VA_ARGS__, si_open2, si_open1)(__VA_ARGS__)
82
83SI_EINTR_SAVE_FUNC(int, creat, (const char *pathname, mode_t mode),
84 (pathname, mode))
85
86
87SI_EINTR_SAVE_FUNC(int, close, (int fd), (fd))
88
89SI_EINTR_SAVE_FUNC(int, accept,
90 (int sockfd, struct sockaddr *addr, socklen_t *addrlen),
91 (sockfd, addr, addrlen))
92
93SI_EINTR_SAVE_FUNC(int, connect,
94 (int sockfd, const struct sockaddr *addr, socklen_t addrlen),
95 (sockfd, addr, addrlen))
96
97/* @note: We respect that the user may explictely deactivate the
98 * restart feature by setting the second argumetn to NULL.
99 */
100static inline int
101si_nanosleep(const struct timespec *req, struct timespec *rem) {
102
103 int res = -1;
104 do
105 {
106 res = nanosleep(req, rem);
107 } while((rem != NULL) && (res < 0) && (errno == EINTR));
108 return res;
109}
110
111static inline unsigned int
112si_sleep(unsigned int seconds)
113{
114 do
115 {
116 seconds = sleep(seconds);
117 } while(seconds != 0);
118 return 0;
119}
120
121SI_EINTR_SAVE_FUNC(int, dup, (int oldfd), (oldfd))
122SI_EINTR_SAVE_FUNC(int, dup2, (int oldfd, int newfd), (oldfd, newfd))
123//SI_EINTR_SAVE_FUNC(int, dup3, (int oldfd, int newfd, int flags),
124// (oldfd, newfd, flags))
125
126SI_EINTR_SAVE_FUNC(int, unlink, (const char *pathname), (pathname))
127
128SI_EINTR_SAVE_SCANF(int, vscanf,
129 (const char *format, va_list ap),
130 (format, ap))
131
132static inline
133int si_scanf(const char *format, ...)
134{
135 va_list argptr;
136 va_start(argptr, format);
137 int res = si_vscanf(format, argptr);
138 va_end(argptr);
139 return res;
140}
141
142SI_EINTR_SAVE_SCANF(int, vfscanf,
143 (FILE *stream, const char *format, va_list ap),
144 (stream, format, ap))
145
146static inline int
147si_fscanf(FILE *stream, const char *format, ...)
148{
149 va_list argptr;
150 va_start(argptr, format);
151 int res = si_vfscanf(stream, format, argptr);
152 va_end(argptr);
153 return res;
154}
155
156SI_EINTR_SAVE_SCANF(int, vsscanf,
157 (const char *str, const char *format, va_list ap),
158 (str, format, ap))
159
160static inline int
161si_sscanf(const char *str, const char *format, ...)
162{
163 va_list argptr;
164 va_start(argptr, format);
165 int res = si_vsscanf(str, format, argptr);
166 va_end(argptr);
167 return res;
168}
169
170SI_EINTR_SAVE_FUNC(int, stat, (const char *path, struct stat *buf),
171 (path, buf))
172SI_EINTR_SAVE_FUNC(int, fstat, (int fd, struct stat *buf),
173 (fd, buf))
174SI_EINTR_SAVE_FUNC(int, lstat, (const char *path, struct stat *buf),
175 (path, buf))
176
177
178SI_EINTR_SAVE_FUNC(int, sigaction,
179 (int signum, const struct sigaction *act,
180 struct sigaction *oldact),
181 (signum, act, oldact))
182
183
184#ifdef HAVE_SIGINTERRUPT
185SI_EINTR_SAVE_FUNC(int, siginterrupt, (int sig, int flag),
186 (sig, flag))
187#else
188#define si_siginterrupt(arg1, arg2)
189#endif
190
191
192SI_EINTR_SAVE_FUNC(int, sem_wait, (sem_t *sem), (sem))
193SI_EINTR_SAVE_FUNC(int, sem_trywait, (sem_t *sem), (sem))
194//SI_EINTR_SAVE_FUNC(int, sem_timedwait,
195// (sem_t *sem, const struct timespec *abs_timeout),
196// (sem, abs_timeout))
197
198
199#undef SI_EINTR_SAVE_FUNC
200
201
202#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:1174
void rem(unsigned long *a, unsigned long *q, unsigned long p, int &dega, int degq)
Definition: minpoly.cc:572
char * str(leftv arg)
Definition: shared.cc:704
Definition: ap.h:40
#define NULL
Definition: omList.c:12
int * status
Definition: si_signals.h:51
int status int void size_t count write
Definition: si_signals.h:67
#define SI_EINTR_SAVE_FUNC(return_type, func, decl, args)
Definition: si_signals.h:39
int status read
Definition: si_signals.h:59
#define SI_EINTR_SAVE_SCANF(return_type, func, decl, args)
Definition: si_signals.h:42
#define SI_EINTR_SAVE_FUNC_TEMPLATE(return_type, newfunc, func, decl, args, err_domain)
Definition: si_signals.h:28
int status int void size_t count int const void size_t count const char int flags
Definition: si_signals.h:73
int status int void size_t count
Definition: si_signals.h:59
int status int void * buf
Definition: si_signals.h:59
int status int void size_t count int const void size_t count open
Definition: si_signals.h:73
int status int void size_t count int const void size_t count si_open1
Definition: si_signals.h:73
wait
Definition: si_signals.h:51
int status int fd
Definition: si_signals.h:59
int status int void size_t count int const void size_t count const char * pathname
Definition: si_signals.h:73