source: git/Singular/si_signals.h @ f8565a

spielwiese
Last change on this file since f8565a was f8565a, checked in by Alexander Dreyer <adreyer@…>, 11 years ago
Replaced some system calls by safely wrapped versions from master
  • Property mode set to 100644
File size: 3.4 KB
Line 
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)       \
25inline 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
36SI_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
42SI_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
49SI_EINTR_SAVE_FUNC(pid_t, wait, (int *status), (status))
50SI_EINTR_SAVE_FUNC(pid_t, waitpid, (pid_t pid, int *status, int options),
51                   (pid, status, options))
52
53SI_EINTR_SAVE_FUNC(int, waitid, 
54                   (idtype_t idtype, id_t id, siginfo_t *infop, int options),
55                   (idtype, id, infop, options))
56
57SI_EINTR_SAVE_FUNC(ssize_t,  read, (int fd, void *buf, size_t count), 
58                   (fd, buf, count))
59
60
61SI_EINTR_SAVE_FUNC(ssize_t, readv,
62                   (int fd, const struct iovec *iov, int iovcnt),
63                   (fd, iov,iovcnt))
64
65SI_EINTR_SAVE_FUNC(ssize_t, write, (int fd, const void *buf, size_t count),
66                   (fd, buf, count))
67
68SI_EINTR_SAVE_FUNC(ssize_t, writev, (int fd, const struct iovec *iov, int iovcnt),
69                   (fd, iov, iovcnt) )
70 
71SI_EINTR_SAVE_FUNC(int, open, (const char *pathname, int flags),
72                   (pathname, flags))
73
74SI_EINTR_SAVE_FUNC(int, open, (const char *pathname, int flags, mode_t mode),
75                   (pathname, flags, mode))
76
77SI_EINTR_SAVE_FUNC(int, close, (int fd), (fd))
78
79SI_EINTR_SAVE_FUNC(int, accept,
80                   (int sockfd, struct sockaddr *addr, socklen_t *addrlen),
81                   (sockfd, addr, addrlen))
82                   
83SI_EINTR_SAVE_FUNC(int, connect,
84                   (int sockfd, const struct sockaddr *addr, socklen_t addrlen),
85                   (sockfd, addr, addrlen))
86
87SI_EINTR_SAVE_FUNC(int, nanosleep,
88                   (const struct timespec *req, struct timespec *rem),
89                   (req, rem))
90
91inline 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 */
Note: See TracBrowser for help on using the repository browser.