Changeset bc0d32 in git


Ignore:
Timestamp:
Apr 9, 2013, 3:33:02 PM (11 years ago)
Author:
Hans Schoenemann <hannes@…>
Branches:
(u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
Children:
bdda8c2a271e7650c11462d22c70cd15d21d34f1
Parents:
f8565ac2b56eae4e46fb63670efa1bc402ae3628
git-author:
Hans Schoenemann <hannes@mathematik.uni-kl.de>2013-04-09 15:33:02+02:00
git-committer:
Hans Schoenemann <hannes@mathematik.uni-kl.de>2013-04-09 15:33:47+02:00
Message:
add: handling signals in systyem calls
Location:
Singular
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • Singular/links/ndbm.cc

    rf8565a rbc0d32  
    1515
    1616#include "config.h"
     17#include <Singular/si_signals.h>
    1718#include <kernel/mod2.h>
    1819#ifdef HAVE_DBM
     
    8687  strcpy(db->dbm_pagbuf, file);
    8788  strcat(db->dbm_pagbuf, ".pag");
    88   db->dbm_pagf = open(db->dbm_pagbuf, flags, mode);
     89  db->dbm_pagf = si_open(db->dbm_pagbuf, flags, mode);
    8990  if (db->dbm_pagf < 0)
    9091    goto bad;
    9192  strcpy(db->dbm_pagbuf, file);
    9293  strcat(db->dbm_pagbuf, ".dir");
    93   db->dbm_dirf = open(db->dbm_pagbuf, flags, mode);
     94  db->dbm_dirf = si_open(db->dbm_pagbuf, flags, mode);
    9495  if (db->dbm_dirf < 0)
    9596    goto bad1;
     
    99100  return (db);
    100101bad1:
    101   (void) close(db->dbm_pagf);
     102  (void) si_close(db->dbm_pagf);
    102103bad:
    103104  free((char *)db);
     
    107108void dbm_close(DBM *db)
    108109{
    109   (void) close(db->dbm_dirf);
    110   (void) close(db->dbm_pagf);
     110  (void) si_close(db->dbm_dirf);
     111  (void) si_close(db->dbm_pagf);
    111112  free((char *)db);
    112113}
     
    166167  db->dbm_pagbno = db->dbm_blkno;
    167168  (void) lseek(db->dbm_pagf, db->dbm_blkno*PBLKSIZ, L_SET);
    168   if (write(db->dbm_pagf, db->dbm_pagbuf, PBLKSIZ) != PBLKSIZ)
     169  if (si_write(db->dbm_pagf, db->dbm_pagbuf, PBLKSIZ) != PBLKSIZ)
    169170  {
    170171  err:
     
    206207  db->dbm_pagbno = db->dbm_blkno;
    207208  (void) lseek(db->dbm_pagf, db->dbm_blkno*PBLKSIZ, L_SET);
    208   if ( (ret=write(db->dbm_pagf, db->dbm_pagbuf, PBLKSIZ)) != PBLKSIZ)
     209  if ( (ret=si_write(db->dbm_pagf, db->dbm_pagbuf, PBLKSIZ)) != PBLKSIZ)
    209210  {
    210211    db->dbm_flags |= _DBM_IOERR;
     
    245246  db->dbm_pagbno = db->dbm_blkno;
    246247  (void) lseek(db->dbm_pagf, db->dbm_blkno*PBLKSIZ, L_SET);
    247   if (write(db->dbm_pagf, db->dbm_pagbuf, PBLKSIZ) != PBLKSIZ)
     248  if (si_write(db->dbm_pagf, db->dbm_pagbuf, PBLKSIZ) != PBLKSIZ)
    248249  {
    249250    db->dbm_flags |= _DBM_IOERR;
     
    251252  }
    252253  (void) lseek(db->dbm_pagf, (db->dbm_blkno+db->dbm_hmask+1)*PBLKSIZ, L_SET);
    253   if (write(db->dbm_pagf, ovfbuf, PBLKSIZ) != PBLKSIZ)
     254  if (si_write(db->dbm_pagf, ovfbuf, PBLKSIZ) != PBLKSIZ)
    254255  {
    255256    db->dbm_flags |= _DBM_IOERR;
     
    284285      db->dbm_pagbno = db->dbm_blkptr;
    285286      (void) lseek(db->dbm_pagf, db->dbm_blkptr*PBLKSIZ, L_SET);
    286       if (read(db->dbm_pagf, db->dbm_pagbuf, PBLKSIZ) != PBLKSIZ)
     287      if (si_read(db->dbm_pagf, db->dbm_pagbuf, PBLKSIZ) != PBLKSIZ)
    287288        memset(db->dbm_pagbuf, 0, PBLKSIZ);
    288289#ifdef DEBUG
     
    323324    db->dbm_pagbno = db->dbm_blkno;
    324325    (void) lseek(db->dbm_pagf, db->dbm_blkno*PBLKSIZ, L_SET);
    325     if (read(db->dbm_pagf, db->dbm_pagbuf, PBLKSIZ) != PBLKSIZ)
     326    if (si_read(db->dbm_pagf, db->dbm_pagbuf, PBLKSIZ) != PBLKSIZ)
    326327      memset(db->dbm_pagbuf, 0, PBLKSIZ);
    327328#ifdef DEBUG
     
    348349    db->dbm_dirbno = b;
    349350    (void) lseek(db->dbm_dirf, (long)b*DBLKSIZ, L_SET);
    350     if (read(db->dbm_dirf, db->dbm_dirbuf, DBLKSIZ) != DBLKSIZ)
     351    if (si_read(db->dbm_dirf, db->dbm_dirbuf, DBLKSIZ) != DBLKSIZ)
    351352      memset(db->dbm_dirbuf, 0, DBLKSIZ);
    352353  }
     
    369370    db->dbm_dirbno = b;
    370371    (void) lseek(db->dbm_dirf, (long)b*DBLKSIZ, L_SET);
    371     if (read(db->dbm_dirf, db->dbm_dirbuf, DBLKSIZ) != DBLKSIZ)
     372    if (si_read(db->dbm_dirf, db->dbm_dirbuf, DBLKSIZ) != DBLKSIZ)
    372373      memset(db->dbm_dirbuf, 0, DBLKSIZ);
    373374  }
     
    375376  db->dbm_dirbno = b;
    376377  (void) lseek(db->dbm_dirf, (long)b*DBLKSIZ, L_SET);
    377   if (write(db->dbm_dirf, db->dbm_dirbuf, DBLKSIZ) != DBLKSIZ)
     378  if (si_write(db->dbm_dirf, db->dbm_dirbuf, DBLKSIZ) != DBLKSIZ)
    378379    db->dbm_flags |= _DBM_IOERR;
    379380}
  • Singular/links/pipeLink.cc

    rf8565a rbc0d32  
    2727#include "lists.h"
    2828#include "pipeLink.h"
     29#include <Singular/si_signals.h>
    2930
    3031typedef struct
     
    5354  {
    5455    /* close unnecessary pipe descriptors for a clean environment */
    55     close(pc[1]); close(cp[0]);
     56    si_close(pc[1]); si_close(cp[0]);
    5657    /* dup pipe read/write to stdin/stdout */
    57     dup2( pc[0], STDIN_FILENO );
    58     dup2( cp[1], STDOUT_FILENO  );
     58    si_dup2( pc[0], STDIN_FILENO );
     59    si_dup2( cp[1], STDOUT_FILENO  );
    5960    int r=system(l->name);
    60     close(pc[0]);
    61     close(cp[1]);
     61    si_close(pc[0]);
     62    si_close(cp[1]);
    6263    exit(r);
    6364        /* never reached*/
     
    6667  {
    6768    d->pid=pid;
    68     close(pc[0]); close(cp[1]);
     69    si_close(pc[0]); si_close(cp[1]);
    6970    d->f_read=fdopen(cp[0],"r");
    7071    d->fd_read=cp[0];
     
    176177      //Print("test fd %d\n",d->fd_read);
    177178      /* check with select: chars waiting: no -> not ready */
    178       s=select(d->fd_read+1, &mask, NULL, NULL, &wt);
     179      s=si_select(d->fd_read+1, &mask, NULL, NULL, &wt);
    179180    }
    180181    switch (s)
  • Singular/links/s_buff.cc

    rf8565a rbc0d32  
    1111#include <omalloc/omalloc.h>
    1212#include <Singular/links/s_buff.h>
     13#include <Singular/si_signals.h>
    1314//struct s_buff_s
    1415//{
     
    4344{
    4445  SSI_BLOCK_CHLD;
    45   int fd=open(n,O_RDONLY);
     46  int fd=si_open(n,O_RDONLY);
    4647  SSI_UNBLOCK_CHLD;
    4748  return s_open(fd);
     
    5455    SSI_BLOCK_CHLD;
    5556    omFreeSize(F->buff,S_BUFF_LEN);
    56     int r=close(F->fd);
     57    int r=si_close(F->fd);
    5758    omFreeSize(F,sizeof(*F));
    5859    F=NULL;
     
    7475    memset(F->buff,0,S_BUFF_LEN); /*debug*/
    7576    SSI_BLOCK_CHLD;
    76     int r=read(F->fd,F->buff,S_BUFF_LEN);
     77    int r=si_read(F->fd,F->buff,S_BUFF_LEN);
    7778    SSI_UNBLOCK_CHLD;
    7879    if (r<=0)
  • Singular/links/ssiLink.cc

    rf8565a rbc0d32  
    2525#include "config.h"
    2626#include <kernel/mod2.h>
     27#include <Singular/si_signals.h>
    2728
    2829#include <omalloc/omalloc.h>
     
    832833          ssiToBeClosed->next=NULL;
    833834          SSI_BLOCK_CHLD;
    834           close(pc[1]); close(cp[0]);
     835          si_close(pc[1]); si_close(cp[0]);
    835836          d->f_write=fdopen(cp[1],"w");
    836837          SSI_UNBLOCK_CHLD;
     
    869870          d->pid=pid;
    870871          SSI_BLOCK_CHLD;
    871           close(pc[0]); close(cp[1]);
     872          si_close(pc[0]); si_close(cp[1]);
    872873          d->f_write=fdopen(pc[1],"w");
    873874          SSI_UNBLOCK_CHLD;
     
    919920        Print("waiting on port %d\n", portno);mflush();
    920921        listen(sockfd,1);
    921         newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr, (socklen_t *)&clilen);
     922        newsockfd = si_accept(sockfd, (struct sockaddr *) &cli_addr, (socklen_t *)&clilen);
    922923        if(newsockfd < 0)
    923924        {
     
    933934        d->f_write = fdopen(newsockfd, "w");
    934935        SI_LINK_SET_RW_OPEN_P(l);
    935         close(sockfd);
     936        si_close(sockfd);
    936937      }
    937938      // no ssi-Link on stdin or stdout
     
    10081009        omFree(ser_host);
    10091010        clilen = sizeof(cli_addr);
    1010         newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr, (socklen_t *)&clilen);
     1011        newsockfd = si_accept(sockfd, (struct sockaddr *) &cli_addr, (socklen_t *)&clilen);
    10111012        if(newsockfd < 0)
    10121013        {
     
    10221023        SSI_BLOCK_CHLD;
    10231024        d->f_write = fdopen(newsockfd, "w");
    1024         close(sockfd);
     1025        si_close(sockfd);
    10251026        SSI_UNBLOCK_CHLD;
    10261027        SI_LINK_SET_RW_OPEN_P(l);
     
    10521053                server->h_length);
    10531054          serv_addr.sin_port = htons(portno);
    1054           if (connect(sockfd,(sockaddr*)&serv_addr,sizeof(serv_addr)) < 0)
     1055          if (si_connect(sockfd,(sockaddr*)&serv_addr,sizeof(serv_addr)) < 0)
    10551056          { Werror("ERROR connecting(errno=%d)",errno); return TRUE; }
    10561057          //PrintS("connected\n");mflush();
     
    11621163      if (d->r!=NULL) rKill(d->r);
    11631164      if ((d->pid!=0)
    1164       && (waitpid(d->pid,NULL,WNOHANG)==0))
     1165      && (si_waitpid(d->pid,NULL,WNOHANG)==0))
    11651166      {
    11661167        struct timespec t;
     
    11681169        t.tv_nsec=50000000; // <=50 ms
    11691170        int r=nanosleep(&t,NULL);
    1170         if((r==0) && (waitpid(d->pid,NULL,WNOHANG)==0))
     1171        if((r==0) && (si_waitpid(d->pid,NULL,WNOHANG)==0))
    11711172        {
    11721173          kill(d->pid,15);
     
    11741175          t.tv_nsec=10000000; // <=10 ms
    11751176          r=nanosleep(&t,NULL);
    1176           if((r==0)&&(waitpid(d->pid,NULL,WNOHANG)==0))
     1177          if((r==0)&&(si_waitpid(d->pid,NULL,WNOHANG)==0))
    11771178          {
    11781179            kill(d->pid,9); // just to be sure
    1179             waitpid(d->pid,NULL,0);
     1180            si_waitpid(d->pid,NULL,0);
    11801181          }
    11811182        }
     
    14981499      //Print("test fd %d\n",d->fd_read);
    14991500    /* check with select: chars waiting: no -> not ready */
    1500       switch (select(d->fd_read+1, &mask, NULL, NULL, &wt))
     1501      switch (si_select(d->fd_read+1, &mask, NULL, NULL, &wt))
    15011502      {
    15021503        case 0: /* not ready */ return "not ready";
     
    16691670  #endif
    16701671  #ifdef HAVE_PSELECT
    1671   s = pselect(max_fd, &mask, NULL, NULL, wt_ptr, &sigmask);
     1672  s = si_pselect(max_fd, &mask, NULL, NULL, wt_ptr, &sigmask);
    16721673  #else
    16731674  SSI_BLOCK_CHLD;
    1674   s = select(max_fd, &mask, NULL, NULL, wt_ptr);
     1675  s = si_select(max_fd, &mask, NULL, NULL, wt_ptr);
    16751676  SSI_UNBLOCK_CHLD;
    16761677  #endif
     
    18481849  struct sockaddr_in cli_addr;
    18491850  int clilen = sizeof(cli_addr);
    1850   int newsockfd = accept(ssiReserved_sockfd, (struct sockaddr *) &cli_addr, (socklen_t *)&clilen);
     1851  int newsockfd = si_accept(ssiReserved_sockfd, (struct sockaddr *) &cli_addr, (socklen_t *)&clilen);
    18511852  if(newsockfd < 0)
    18521853  {
     
    18941895  {
    18951896    ssiReserved_P=0;
    1896     close(ssiReserved_sockfd);
     1897    si_close(ssiReserved_sockfd);
    18971898  }
    18981899  return l;
     
    19191920  loop
    19201921  {
    1921     kidpid = waitpid(-1, &status, WNOHANG);
     1922    kidpid = si_waitpid(-1, &status, WNOHANG);
    19221923    if (kidpid==-1)
    19231924    {
  • Singular/sdb.cc

    rf8565a rbc0d32  
    138138        PrintS("cannot get the procedure body\n");
    139139        fclose(fp);
    140         unlink(filename);
     140        si_unlink(filename);
    141141        omFree(filename);
    142142        return;
     
    190190    }
    191191  }
    192   unlink(filename);
     192  si_unlink(filename);
    193193  omFree(filename);
    194194}
  • Singular/si_signals.h

    rf8565a rbc0d32  
    44/*
    55* ABSTRACT: wrappijng signal-interuptable system calls
    6 * AUTHOR: Alexander Dreyer, The PolyBoRi Team
     6* AUTHOR: Alexander Dreyer, The PolyBoRi Team, 2013
    77*/
    88
     
    1818#include <sys/socket.h>
    1919#include <time.h>
     20#include <stdio.h>
     21#include <semaphore.h>
     22#include <stdarg.h>
    2023
    2124#ifndef SINGULAR_SI_SIGNALS_H
    2225#define SINGULAR_SI_SIGNALS_H
    2326
    24 #define SI_EINTR_SAVE_FUNC(return_type, func, decl, args)       \
    25 inline return_type si_##func decl        \
     27#define SI_EINTR_SAVE_FUNC_TEMPLATE(return_type, newfunc, func, decl, args, err_domain) \
     28static inline return_type newfunc decl   \
    2629{                                        \
    2730  int res = -1;                          \
     
    2932  {                                      \
    3033    res = func args;                     \
    31   } while((res < 0) && (errno == EINTR));\
     34  } while((res err_domain) && (errno == EINTR));\
    3235  return res;                            \
    3336}
    3437
     38#define SI_EINTR_SAVE_FUNC(return_type, func, decl, args) \
     39  SI_EINTR_SAVE_FUNC_TEMPLATE(return_type, si_##func, func, decl, args, < 0)
     40
     41#define SI_EINTR_SAVE_SCANF(return_type, func, decl, args) \
     42  SI_EINTR_SAVE_FUNC_TEMPLATE(return_type, si_##func, func, decl, args, == EOF)
    3543
    3644SI_EINTR_SAVE_FUNC(int, select,
     
    4048                   )
    4149
     50#ifdef HAVE_PSELECT
    4251SI_EINTR_SAVE_FUNC(int, pselect,
    4352                   (int nfds, fd_set *readfds, fd_set *writefds,
     
    4655                   (nfds, readfds, writefds, exceptfds, timeout,sigmask)
    4756                   )
     57#endif
    4858
    4959SI_EINTR_SAVE_FUNC(pid_t, wait, (int *status), (status))
     
    5161                   (pid, status, options))
    5262
    53 SI_EINTR_SAVE_FUNC(int, waitid,
    54                    (idtype_t idtype, id_t id, siginfo_t *infop, int options),
    55                    (idtype, id, infop, options))
     63//SI_EINTR_SAVE_FUNC(int, waitid,
     64//                   (idtype_t idtype, id_t id, siginfo_t *infop, int options),
     65//                   (idtype, id, infop, options))
    5666
    5767SI_EINTR_SAVE_FUNC(ssize_t,  read, (int fd, void *buf, size_t count),
     
    6878SI_EINTR_SAVE_FUNC(ssize_t, writev, (int fd, const struct iovec *iov, int iovcnt),
    6979                   (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))
     80
     81SI_EINTR_SAVE_FUNC_TEMPLATE(int, si_open1, open, (const char *pathname, int flags),
     82                            (pathname, flags), < 0)
     83SI_EINTR_SAVE_FUNC_TEMPLATE(int, si_open2, open,
     84                            (const char *pathname, int flags, mode_t mode),
     85                            (pathname, flags, mode), < 0)
     86
     87/* Enulate overloading usung preprocessor (we need to be C-compatible) */
     88#define SI_GET_FIFTH(_4,_3, _2, _1, N, ...) N
     89#define si_open(...) SI_GET_FIFTH(X,##__VA_ARGS__, si_open2, si_open1)(__VA_ARGS__)
     90
     91SI_EINTR_SAVE_FUNC(int, creat, (const char *pathname, mode_t mode),
     92                   (pathname, mode))
     93
    7694
    7795SI_EINTR_SAVE_FUNC(int, close, (int fd), (fd))
     
    8098                   (int sockfd, struct sockaddr *addr, socklen_t *addrlen),
    8199                   (sockfd, addr, addrlen))
    82                    
     100
    83101SI_EINTR_SAVE_FUNC(int, connect,
    84102                   (int sockfd, const struct sockaddr *addr, socklen_t addrlen),
    85103                   (sockfd, addr, addrlen))
    86104
    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)
     105/* @note: We respect that the user may explictely deactivate the
     106 * restart feature by setting the second argumetn to NULL.
     107 */
     108static inline int
     109si_nanosleep(const struct timespec *req, struct timespec *rem) {
     110
     111  int res = -1;
     112  do
     113  {
     114    res = nanosleep(req, rem);
     115  } while((rem != NULL) && (res < 0) && (errno == EINTR));
     116  return res;   
     117}
     118
     119static inline unsigned int
     120si_sleep(unsigned int seconds)
    92121{
    93122  do
     
    98127}
    99128
    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 
     129SI_EINTR_SAVE_FUNC(int, dup, (int oldfd), (oldfd))
     130SI_EINTR_SAVE_FUNC(int, dup2, (int oldfd, int newfd), (oldfd, newfd))
     131//SI_EINTR_SAVE_FUNC(int, dup3, (int oldfd, int newfd, int flags),
     132//                 (oldfd, newfd, flags))
     133
     134SI_EINTR_SAVE_FUNC(int, unlink, (const char *pathname), (pathname))
     135
     136SI_EINTR_SAVE_SCANF(int, vscanf,
     137                   (const char *format, va_list ap),
     138                   (format, ap))
     139
     140static inline
     141int si_scanf(const char *format, ...)
     142{
     143  va_list argptr;
     144  va_start(argptr, format);
     145  int res = si_vscanf(format, argptr);
     146  va_end(argptr);
     147  return res;
     148}
     149
     150SI_EINTR_SAVE_SCANF(int, vfscanf,
     151                   (FILE *stream, const char *format, va_list ap),
     152                   (stream, format, ap))
     153
     154static inline int
     155si_fscanf(FILE *stream, const char *format, ...)
     156{
     157  va_list argptr;
     158  va_start(argptr, format);
     159  int res = si_vfscanf(stream, format, argptr);
     160  va_end(argptr);
     161  return res;
     162}
     163
     164SI_EINTR_SAVE_SCANF(int, vsscanf,
     165                   (const char *str, const char *format, va_list ap),
     166                   (str, format, ap))
     167
     168static inline int
     169si_sscanf(const char *str, const char *format, ...)
     170{
     171  va_list argptr;
     172  va_start(argptr, format);
     173  int res = si_vsscanf(str, format, argptr);
     174  va_end(argptr);
     175  return res;
     176}
     177
     178SI_EINTR_SAVE_FUNC(int, stat, (const char *path, struct stat *buf),
     179                   (path, buf))
     180SI_EINTR_SAVE_FUNC(int, fstat, (int fd, struct stat *buf),
     181                   (fd, buf))
     182SI_EINTR_SAVE_FUNC(int, lstat, (const char *path, struct stat *buf),
     183                   (path, buf))
     184
     185
     186SI_EINTR_SAVE_FUNC(int, sigaction,
     187                   (int signum, const struct sigaction *act,
     188                    struct sigaction *oldact),
     189                   (signum, act, oldact))
     190
     191
     192#ifdef HAVE_SIGINTERRUPT
     193SI_EINTR_SAVE_FUNC(int, siginterrupt, (int sig, int flag),
     194                   (sig, flag))
     195#else
     196#define si_siginterrupt(arg1, arg2)
     197#endif
     198
     199
     200SI_EINTR_SAVE_FUNC(int, sem_wait, (sem_t *sem), (sem))
     201SI_EINTR_SAVE_FUNC(int, sem_trywait, (sem_t *sem), (sem))
     202//SI_EINTR_SAVE_FUNC(int, sem_timedwait,
     203//                   (sem_t *sem, const struct timespec *abs_timeout),
     204//                   (sem, abs_timeout))
    113205
    114206
Note: See TracChangeset for help on using the changeset viewer.