Changeset b60bfe in git


Ignore:
Timestamp:
Aug 1, 2013, 9:25:23 AM (11 years ago)
Author:
Hans Schoenemann <hannes@…>
Branches:
(u'spielwiese', '4a9821a93ffdc22a6696668bd4f6b8c9de3e6c5f')
Children:
f57b6f18b1bcdf1314cd2a943565ec298e5e11f9
Parents:
01c0298072151ffa06aed1c49b5bdcc5d0c29690
Message:
fix: ssi/signal stuff from master
Location:
Singular
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • Singular/cntrlc.cc

    r01c0298 rb60bfe  
    1010#define _XOPEN_SOURCE_EXTENDED
    1111#endif /* MP3-Y2 0.022UF */
    12 
    1312#include <stdio.h>
    1413#include <stddef.h>
     
    2221#include "config.h"
    2322#endif /* HAVE_CONFIG_H */
     23
    2424#include <kernel/mod2.h>
    2525#include <omalloc/omalloc.h>
    26 
    27 #include <kernel/polys.h>
     26#include <Singular/tok.h>
     27#include <Singular/ipshell.h>
    2828#include <kernel/febase.h>
    2929void sig_chld_hdl(int sig); /*#include <Singular/links/ssiLink.h>*/
    30 //#include <Singular/feOpt.h>
    31 //#include <Singular/silink.h>
    32 //#include <Singular/ssiLink.h>
     30#include <Singular/cntrlc.h>
     31#include <Singular/feOpt.h>
    3332#include <Singular/si_signals.h>
    34 
    35 #include "tok.h"
    36 #include "ipshell.h"
    37 #include "cntrlc.h"
    38 #include "feOpt.h"
    39 #include "links/silink.h"
     33#include <Singular/links/silink.h>
     34#include <Singular/links/ssiLink.h>
    4035
    4136/* undef, if you don't want GDB to come up on error */
     37
     38#define CALL_GDB
    4239
    4340#if defined(__OPTIMIZE__) && defined(CALL_GDB)
     
    9390void sig_term_hdl(int /*sig*/)
    9491{
    95  while (ssiToBeClosed!=NULL)
    96  {
    97    slClose(ssiToBeClosed->l);
    98    if (ssiToBeClosed==NULL) break;
    99    ssiToBeClosed=(link_list)ssiToBeClosed->next;
    100  }
    101  exit(1);
     92  if (ssiToBeClosed_inactive)
     93  {
     94    ssiToBeClosed_inactive=FALSE;
     95    while (ssiToBeClosed!=NULL)
     96    {
     97      slClose(ssiToBeClosed->l);
     98      if (ssiToBeClosed==NULL) break;
     99      ssiToBeClosed=(link_list)ssiToBeClosed->next;
     100    }
     101    exit(1);
     102  }
     103  //else: we already shutting down: let's do m2_end ist work
    102104}
    103105
     
    121123 *
    122124 *---------------------------------------------------------------------*/
    123 void sigint_handler(int sig);
     125void sigint_handler(int /*sig*/);
    124126
    125127si_hdl_typ si_set_signal ( int sig, si_hdl_typ signal_handler);
     
    283285  exit(0);
    284286}
     287
    285288#else
    286289
     
    310313  #endif /* __OPTIMIZE__ */
    311314  #if defined(unix)
    312   /* debug(..) does not work under HPUX (because ptrace does not work..) */
    313315  #ifdef CALL_GDB
    314316  if (sig!=SIGINT) debug(STACK_TRACE);
     
    318320}
    319321#endif
     322
    320323
    321324/*2
  • Singular/links/s_buff.cc

    r01c0298 rb60bfe  
    77#include <signal.h>
    88
     9#include <kernel/mod2.h>
    910#include <coeffs/si_gmp.h>
    1011
     
    1213#include <Singular/links/s_buff.h>
    1314#include <Singular/si_signals.h>
     15
    1416//struct s_buff_s
    1517//{
     
    2527#define S_BUFF_LEN 4096
    2628
    27 sigset_t ssi_sigmask; // set in ssiLink.cc
    28 sigset_t ssi_oldmask; // set in ssiLink.cc
    29 
    30 #define SSI_BLOCK_CHLD sigprocmask(SIG_SETMASK, &ssi_sigmask, &ssi_oldmask)
    31 #define SSI_UNBLOCK_CHLD sigprocmask(SIG_SETMASK, &ssi_oldmask, NULL)
    32 
    3329s_buff s_open(int fd)
    3430{
    35   SSI_BLOCK_CHLD;
    3631  s_buff F=(s_buff)omAlloc0(sizeof(*F));
    3732  F->fd=fd;
    3833  F->buff=(char*)omAlloc(S_BUFF_LEN);
    39   SSI_UNBLOCK_CHLD;
    4034  return F;
    4135}
     
    4337s_buff s_open_by_name(const char *n)
    4438{
    45   SSI_BLOCK_CHLD;
    4639  int fd=si_open(n,O_RDONLY);
    47   SSI_UNBLOCK_CHLD;
    4840  return s_open(fd);
    4941}
    5042
    51 int    s_close(s_buff &F)
     43int    s_free(s_buff &F)
    5244{
    5345  if (F!=NULL)
    5446  {
    55     SSI_BLOCK_CHLD;
    5647    omFreeSize(F->buff,S_BUFF_LEN);
    57     int r=si_close(F->fd);
    5848    omFreeSize(F,sizeof(*F));
    5949    F=NULL;
    60     SSI_UNBLOCK_CHLD;
     50  }
     51  return 0;
     52}
     53
     54int    s_close(s_buff &F)
     55{
     56  if (F!=NULL)
     57  {
     58    int r=close(F->fd);
    6159    return r;
    6260  }
     
    7472  {
    7573    memset(F->buff,0,S_BUFF_LEN); /*debug*/
    76     SSI_BLOCK_CHLD;
    7774    int r=si_read(F->fd,F->buff,S_BUFF_LEN);
    78     SSI_UNBLOCK_CHLD;
    7975    if (r<=0)
    8076    {
  • Singular/links/s_buff.h

    r01c0298 rb60bfe  
    1717s_buff s_open(int fd);
    1818s_buff s_open_by_name(const char *n);
     19int    s_free(s_buff &f);
    1920int    s_close(s_buff &f);
    2021
  • Singular/links/silink.h

    r01c0298 rb60bfe  
    125125
    126126extern link_list ssiToBeClosed;
    127 extern BOOLEAN ssiToBeClosed_inactive;
     127extern volatile BOOLEAN ssiToBeClosed_inactive;
    128128#endif // SILINK_H
  • Singular/links/ssiLink.cc

    r01c0298 rb60bfe  
    2121#include <time.h>
    2222
    23 
    24 
    25 #ifdef HAVE_CONFIG_H
    26 #include "config.h"
    27 #endif /* HAVE_CONFIG_H */
    2823#include <kernel/mod2.h>
    2924#include <Singular/si_signals.h>
    30 
     25// #include "mod2.h"
     26
     27#include <Singular/tok.h>
     28#include <Singular/ipid.h>
     29#include <Singular/ipshell.h>
    3130#include <omalloc/omalloc.h>
    32 
    33 #include <misc/intvec.h>
    34 #include <misc/options.h>
    35 
    36 #include <polys/monomials/ring.h>
    37 #include <polys/matpol.h>
    38 
    39 #include <coeffs/bigintmat.h>
    40 
    41 #include <kernel/ideals.h>
    42 #include <kernel/polys.h>
    43 #include <kernel/longrat.h>
    44 #include <kernel/ideals.h>
     31#include <libpolys/polys/monomials/ring.h>
     32#include <libpolys/polys/matpol.h>
     33#include <libpolys/polys/simpleideals.h>
     34#include <libpolys/polys/monomials/p_polys.h>
     35#include <libpolys/coeffs/longrat.h>
     36#include <libpolys/misc/intvec.h>
     37#include <libpolys/coeffs/bigintmat.h>
     38#include <libpolys/misc/options.h>
    4539#include <kernel/timer.h>
    46 
    47 #include <Singular/tok.h>
    48 #include <Singular/ipshell.h>
    49 #include <Singular/ipid.h>
    50 
    5140#include <Singular/subexpr.h>
     41#include <Singular/links/silink.h>
    5242#include <Singular/cntrlc.h>
    5343#include <Singular/lists.h>
    5444#include <Singular/blackbox.h>
    55 
    56 #include <Singular/links/silink.h>
    5745#include <Singular/links/s_buff.h>
    5846#include <Singular/links/ssiLink.h>
    5947
    60 // TODO: use number n_InitMPZ(mpz_t n, coeffs_BIGINT) instead!?
    61 
    62 struct snumber_dummy
    63 {
    64   mpz_t z;
    65   mpz_t n;
    66   #if defined(LDEBUG)
    67   int debug;
    68   #endif
    69   BOOLEAN s;
    70 };
    71 typedef struct snumber_dummy  *number_dummy;
     48#ifdef HAVE_MPSR
     49#include <Singular/mpsr.h>
     50#endif
    7251
    7352#ifdef HAVE_SIMPLEIPC
    7453#include <Singular/links/simpleipc.h>
    7554#endif
    76 //#if (_POSIX_C_SOURCE >= 200112L) || (_XOPEN_SOURCE >= 600)
    77 //#define HAVE_PSELECT
    78 //#endif
     55
     56#include <Singular/si_signals.h>
    7957
    8058#define SSI_VERSION 5
     
    10684
    10785link_list ssiToBeClosed=NULL;
    108 BOOLEAN ssiToBeClosed_inactive=TRUE;
    109 #define SSI_BLOCK_CHLD sigprocmask(SIG_SETMASK, &ssi_sigmask, &ssi_oldmask)
    110 #define SSI_UNBLOCK_CHLD sigprocmask(SIG_SETMASK, &ssi_oldmask, NULL)
    111 
    112 #define SR_INT 1L
    113 #define SR_HDL(A) ((long)(A))
    114 #define SR_TO_INT(SR)   (((long)SR) >> 2)
     86volatile BOOLEAN ssiToBeClosed_inactive=TRUE;
    11587
    11688// the helper functions:
     
    133105void ssiWriteInt(ssiInfo *d,const int i)
    134106{
    135   SSI_BLOCK_CHLD;
    136107  fprintf(d->f_write,"%d ",i);
    137   SSI_UNBLOCK_CHLD;
    138108  //if (d->f_debug!=NULL) fprintf(d->f_debug,"int: %d ",i);
    139109}
     
    141111void ssiWriteString(ssiInfo *d,const char *s)
    142112{
    143   SSI_BLOCK_CHLD;
    144113  fprintf(d->f_write,"%d %s ",(int)strlen(s),s);
    145   SSI_UNBLOCK_CHLD;
    146114  //if (d->f_debug!=NULL) fprintf(d->f_debug,"stringi: %d \"%s\" ",strlen(s),s);
    147115}
     
    153121  // case 2 Q:     3 4 <int>
    154122  //        or     3 3 <mpz_t nominator>
    155   SSI_BLOCK_CHLD;
    156123  if(SR_HDL(n) & SR_INT)
    157124  {
     
    159126    //if (d->f_debug!=NULL) fprintf(d->f_debug,"bigint: short \"%ld\" ",SR_TO_INT(n));
    160127  }
    161   else if (((number_dummy)n)->s==3)
     128  else if (n->s==3)
    162129  {
    163130    fputs("3 ",d->f_write);
    164     mpz_out_str(d->f_write,10,((number_dummy)n)->z);
     131    mpz_out_str(d->f_write,10,n->z);
    165132    fputc(' ',d->f_write);
    166133    //gmp_fprintf(d->f_write,"3 %Zd ",n->z);
     
    168135  }
    169136  else WerrorS("illiegal bigint");
    170   SSI_UNBLOCK_CHLD;
    171137}
    172138
     
    182148  //        or     3 6 <mpz_t raw nom.> <mpz_t raw denom.>
    183149  //        or     3 7 <mpz_t raw nom.>
    184   SSI_BLOCK_CHLD;
    185150  if(rField_is_Zp(d->r))
    186151  {
     
    193158    {
    194159      #if SIZEOF_LONG == 4
    195       fprintf(d->f_write,"4 %d ",((LONG)SR_TO_INT(n)));
     160      fprintf(d->f_write,"4 %ld ",((LONG)SR_TO_INT(n)));
    196161      #else
    197162      long nn=SR_TO_INT(n);
    198163      if ((nn<POW_2_28)||(nn>= -POW_2_28))
    199         fprintf(d->f_write,"4 %d ",((LONG)nn)); // NOTE: use %ld once LONG can be long !!!
     164        fprintf(d->f_write,"4 %ld ",((LONG)nn));
    200165      else
    201166      {
    202167        mpz_t tmp;
    203         mpz_init_set_si(tmp,nn);
     168        mpz_init_set_si(tmp,nn);
    204169        fputs("8 ",d->f_write);
    205170        mpz_out_str (d->f_write,32, tmp);
    206171        fputc(' ',d->f_write);
    207         mpz_clear(tmp);
     172        mpz_clear(tmp);
    208173      }
    209174      #endif
    210175      //if (d->f_debug!=NULL) fprintf(d->f_debug,"number: short \"%ld\" ",SR_TO_INT(n));
    211176    }
    212     else if (((number_dummy)n)->s<2)
     177    else if (n->s<2)
    213178    {
    214179      //gmp_fprintf(d->f_write,"%d %Zd %Zd ",n->s,n->z,n->n);
    215       fprintf(d->f_write,"%d ",((number_dummy)n)->s+5);
    216       mpz_out_str (d->f_write,32, ((number_dummy)n)->z);
     180      fprintf(d->f_write,"%d ",n->s+5);
     181      mpz_out_str (d->f_write,32, n->z);
    217182      fputc(' ',d->f_write);
    218       mpz_out_str (d->f_write,32, ((number_dummy)n)->n);
     183      mpz_out_str (d->f_write,32, n->n);
    219184      fputc(' ',d->f_write);
    220185
     
    225190      //gmp_fprintf(d->f_write,"3 %Zd ",n->z);
    226191      fputs("8 ",d->f_write);
    227       mpz_out_str (d->f_write,32, ((number_dummy)n)->z);
     192      mpz_out_str (d->f_write,32, n->z);
    228193      fputc(' ',d->f_write);
    229194
     
    232197  }
    233198  else WerrorS("coeff field not implemented");
    234   SSI_UNBLOCK_CHLD;
    235199}
    236200
     
    241205  d->r=r;
    242206  d->r->ref++;
    243   SSI_BLOCK_CHLD;
    244207  fprintf(d->f_write,"%d %d ",n_GetChar(r->cf),r->N);
    245208
     
    284247    i++;
    285248  }
    286   SSI_UNBLOCK_CHLD;
    287 }
    288 
    289 void ssiWritePoly(ssiInfo *d, int /*typ*/, poly p)
    290 {
    291   SSI_BLOCK_CHLD;
     249}
     250
     251void ssiWritePoly(ssiInfo *d, int typ, poly p)
     252{
    292253  fprintf(d->f_write,"%d ",pLength(p));//number of terms
    293   SSI_UNBLOCK_CHLD;
    294   int j;
     254  int i;
    295255
    296256  while(p!=NULL)
     
    298258    ssiWriteNumber(d,pGetCoeff(p));
    299259    //nWrite(fich,pGetCoeff(p));
    300     SSI_BLOCK_CHLD;
    301260    fprintf(d->f_write,"%ld ",p_GetComp(p,d->r));//component
    302261
    303     for(j=1;j<=rVar(d->r);j++)
     262    for(int j=1;j<=rVar(d->r);j++)
    304263    {
    305264      fprintf(d->f_write,"%ld ",p_GetExp(p,j,d->r ));//x^j
    306265    }
    307266    pIter(p);
    308     SSI_UNBLOCK_CHLD;
    309267  }
    310268}
     
    316274   matrix M=(matrix)I;
    317275   int mn;
    318    SSI_BLOCK_CHLD;
    319276   if (typ==MATRIX_CMD)
    320277   {
     
    327284     fprintf(d->f_write,"%d ",IDELEMS(I));
    328285   }
    329     SSI_UNBLOCK_CHLD;
    330286
    331287   int i;
     
    344300  ssiInfo *d=(ssiInfo*)l->data;
    345301  // syntax: <num ops> <operation> <op1> <op2> ....
    346   SSI_BLOCK_CHLD;
    347302  fprintf(d->f_write,"%d %d ",D->argc,D->op);
    348   SSI_UNBLOCK_CHLD;
    349303  if (D->argc >0) ssiWrite(l, &(D->arg1));
    350304  if (D->argc < 4)
     
    369323  ssiInfo *d=(ssiInfo*)l->data;
    370324  int Ll=lSize(dd);
    371   SSI_BLOCK_CHLD;
    372325  fprintf(d->f_write,"%d ",Ll+1);
    373   SSI_UNBLOCK_CHLD;
    374326  int i;
    375327  for(i=0;i<=Ll;i++)
     
    380332void ssiWriteIntvec(ssiInfo *d,intvec * v)
    381333{
    382   SSI_BLOCK_CHLD;
    383334  fprintf(d->f_write,"%d ",v->length());
    384335  int i;
     
    387338    fprintf(d->f_write,"%d ",(*v)[i]);
    388339  }
    389   SSI_UNBLOCK_CHLD;
    390340}
    391341void ssiWriteIntmat(ssiInfo *d,intvec * v)
    392342{
    393   SSI_BLOCK_CHLD;
    394343  fprintf(d->f_write,"%d %d ",v->rows(),v->cols());
    395344  int i;
     
    398347    fprintf(d->f_write,"%d ",(*v)[i]);
    399348  }
    400   SSI_UNBLOCK_CHLD;
    401349}
    402350
    403351void ssiWriteBigintmat(ssiInfo *d,bigintmat * v)
    404352{
    405   SSI_BLOCK_CHLD;
    406353  fprintf(d->f_write,"%d %d ",v->rows(),v->cols());
    407354  int i;
     
    410357    ssiWriteBigInt(d,(*v)[i]);
    411358  }
    412   SSI_UNBLOCK_CHLD;
    413359}
    414360
     
    419365  l=s_readint(d->f_read);
    420366  buf=(char*)omAlloc0(l+1);
    421   /*int c =*/ (void) s_getc(d->f_read); /* skip ' '*/
    422   /*int ll=*/ (void) s_readbytes(buf,l,d->f_read);
     367  int c =s_getc(d->f_read); /* skip ' '*/
     368  int ll=s_readbytes(buf,l,d->f_read);
    423369  //if (ll!=l) printf("want %d, got %d bytes\n",l,ll);
    424370  buf[l]='\0';
     
    439385   case 3:
    440386     {// read int or mpz_t or mpz_t, mpz_t
    441        number n=(number)omAlloc0(sizeof(snumber_dummy));
    442        #ifdef LDEBUG
    443        ((number_dummy)n)->debug=123456;
    444        #endif
    445        s_readmpz(d->f_read,((number_dummy)n)->z);
    446        ((number_dummy)n)->s=sub_type;
     387       number n=nlRInit(0);
     388       s_readmpz(d->f_read,n->z);
     389       n->s=sub_type;
    447390       return n;
    448391     }
     
    451394       int dd;
    452395       dd=s_readint(d->f_read);
    453        return n_Init(dd,d->r->cf);
     396       return INT_TO_SR(dd);
    454397     }
    455398   default:
     
    468411     case 1:
    469412       {// read mpz_t, mpz_t
    470          number n=(number)omAlloc0(sizeof(snumber_dummy));
    471          #ifdef LDEBUG
    472          ((number_dummy)n)->debug=123456;
    473          #endif
    474          mpz_init(((number_dummy)n)->z);
    475          mpz_init(((number_dummy)n)->n);
    476          s_readmpz(d->f_read,((number_dummy)n)->z);
    477          s_readmpz(d->f_read,((number_dummy)n)->n);
    478          ((number_dummy)n)->s=sub_type;
     413         number n=nlRInit(0);
     414         mpz_init(n->n);
     415         s_readmpz(d->f_read,n->z);
     416         s_readmpz(d->f_read,n->n);
     417         n->s=sub_type;
    479418         return n;
    480419       }
     
    482421     case 3:
    483422       {// read mpz_t
    484          number n=(number)omAlloc0(sizeof(snumber_dummy));
    485          #ifdef LDEBUG
    486          ((number_dummy)n)->debug=123456;
    487          #endif
    488          mpz_init(((number_dummy)n)->z);
    489          s_readmpz(d->f_read,((number_dummy)n)->z);
    490          ((number_dummy)n)->s=3; /*sub_type*/
     423         number n=nlRInit(0);
     424         s_readmpz(d->f_read,n->z);
     425         n->s=3; /*sub_type*/
    491426         return n;
    492427       }
    493428     case 4:
    494429       {
    495          int dd=s_readint(d->f_read);
    496          return n_Init(dd,coeffs_BIGINT);
     430         LONG dd=s_readlong(d->f_read);
     431         //#if SIZEOF_LONG == 8
     432         return INT_TO_SR(dd);
     433         //#else
     434         //return nlInit(dd,NULL);
     435         //#endif
    497436       }
    498437     case 5:
    499438     case 6:
    500439       {// read raw mpz_t, mpz_t
    501          number n=(number)omAlloc0(sizeof(snumber_dummy));
    502          #ifdef LDEBUG
    503          ((number_dummy)n)->debug=123456;
    504          #endif
    505          mpz_init(((number_dummy)n)->z);
    506          mpz_init(((number_dummy)n)->n);
    507          s_readmpz_base (d->f_read,((number_dummy)n)->z, 32);
    508          s_readmpz_base (d->f_read,((number_dummy)n)->n, 32);
    509          ((number_dummy)n)->s=sub_type-5;
     440         number n=nlRInit(0);
     441         mpz_init(n->n);
     442         s_readmpz_base (d->f_read,n->z, 32);
     443         s_readmpz_base (d->f_read,n->n, 32);
     444         n->s=sub_type-5;
    510445         return n;
    511446       }
    512447     case 8:
    513448       {// read raw mpz_t
    514          number n=(number)omAlloc0(sizeof(snumber_dummy));
    515          #ifdef LDEBUG
    516          ((number_dummy)n)->debug=123456;
    517          #endif
    518          mpz_init(((number_dummy)n)->z);
    519          s_readmpz_base (d->f_read,((number_dummy)n)->z, 32);
    520          ((number_dummy)n)->s=sub_type=3; /*subtype-5*/
     449         number n=nlRInit(0);
     450         s_readmpz_base (d->f_read,n->z, 32);
     451         n->s=sub_type=3; /*subtype-5*/
    521452         return n;
    522453       }
     
    536467  {
    537468    // read int
    538     int dd=s_readint(d->f_read);
    539     return (number)dd;
     469    int dd;
     470    dd=s_readint(d->f_read);
     471    return (number)(long)dd;
    540472  }
    541473  else Werror("coeffs not implemented");
     
    546478{
    547479/* syntax is <ch> <N> <l1> <v1> ...<lN> <vN> <number of orderings> <ord1> <block0_1> <block1_1> .... */
    548   int ch, N,i/*,l*/;
     480  int ch, N,i,l;
    549481  char **names;
    550482  ch=s_readint(d->f_read);
     
    603535  //Print("poly: terms:%d\n",n);
    604536  poly p;
    605   // int j;
    606   // j=0;
     537  int j;
     538  j=0;
    607539  poly ret=NULL;
    608540  poly prev=NULL;
     
    612544    p=p_Init(D->r);
    613545    pGetCoeff(p)=ssiReadNumber(D);
    614     int d=s_readint(D->f_read);
     546    int d;
     547    d=s_readint(D->f_read);
    615548    p_SetComp(p,d,D->r);
    616549    for(i=1;i<=rVar(D->r);i++)
     
    630563ideal ssiReadIdeal(ssiInfo *d)
    631564{
    632   int i;
    633   int n=s_readint(d->f_read);
    634   ideal I=idInit(n,1);
     565  int n,i;
     566  ideal I;
     567  n=s_readint(d->f_read);
     568  I=idInit(n,1);
    635569  for(i=0;i<IDELEMS(I);i++) // read n terms
    636570  {
     
    642576matrix ssiReadMatrix(ssiInfo *d)
    643577{
    644   int m=s_readint(d->f_read);
    645   int n=s_readint(d->f_read);
     578  int n,m,i,j;
     579  m=s_readint(d->f_read);
     580  n=s_readint(d->f_read);
    646581  matrix M=mpNew(m,n);
    647582  poly p;
     
    714649{
    715650  ssiInfo *d=(ssiInfo*)l->data;
    716   int nr=s_readint(d->f_read);
     651  int nr;
     652  nr=s_readint(d->f_read);
    717653  lists L=(lists)omAlloc(sizeof(*L));
    718654  L->Init(nr);
     
    730666intvec* ssiReadIntvec(ssiInfo *d)
    731667{
    732   int nr=s_readint(d->f_read);
     668  int nr;
     669  nr=s_readint(d->f_read);
    733670  intvec *v=new intvec(nr);
    734671  for(int i=0;i<nr;i++)
     
    766703{
    767704  ssiInfo *d=(ssiInfo*)l->data;
    768   /*int throwaway=*/ (void) s_readint(d->f_read);
     705  int throwaway;
     706  throwaway=s_readint(d->f_read);
    769707  char *name=ssiReadString(d);
    770708  int tok;
     
    790728    const char *mode;
    791729    ssiInfo *d=(ssiInfo*)omAlloc0(sizeof(ssiInfo));
    792     sigprocmask(SIG_SETMASK, NULL, &ssi_sigmask);
    793     sigaddset(&ssi_sigmask, SIGCHLD);
    794730    if (flag & SI_LINK_OPEN)
    795731    {
     
    824760        int pc[2];
    825761        int cp[2];
    826         SSI_BLOCK_CHLD;
    827762        pipe(pc);
    828763        pipe(cp);
    829764        pid_t pid=fork();
    830         SSI_UNBLOCK_CHLD;
    831765        if (pid==0) /*fork: child*/
    832766        {
     767          /* block SIGINT */
     768          sigset_t sigint;
     769          sigemptyset(&sigint);
     770          sigaddset(&sigint, SIGINT);
     771          sigprocmask(SIG_BLOCK, &sigint, NULL);
     772
    833773          link_list hh=(link_list)ssiToBeClosed->next;
    834774          /* we know: l is the first entry in ssiToBeClosed-list */
     
    837777            SI_LINK_SET_CLOSE_P(hh->l);
    838778            ssiInfo *dd=(ssiInfo*)hh->l->data;
    839             SSI_BLOCK_CHLD;
    840779            s_close(dd->f_read);
     780            s_free(dd->f_read);
    841781            fclose(dd->f_write);
    842             SSI_UNBLOCK_CHLD;
    843782            if (dd->r!=NULL) rKill(dd->r);
    844783            omFreeSize((ADDRESS)dd,(sizeof *dd));
     
    849788          }
    850789          ssiToBeClosed->next=NULL;
    851           SSI_BLOCK_CHLD;
    852790          si_close(pc[1]); si_close(cp[0]);
    853791          d->f_write=fdopen(cp[1],"w");
    854           SSI_UNBLOCK_CHLD;
    855792          d->f_read=s_open(pc[0]);
    856793          d->fd_read=pc[0];
     
    886823        {
    887824          d->pid=pid;
    888           SSI_BLOCK_CHLD;
    889825          si_close(pc[0]); si_close(cp[1]);
    890826          d->f_write=fdopen(pc[1],"w");
    891           SSI_UNBLOCK_CHLD;
    892827          d->f_read=s_open(cp[0]);
    893828          d->fd_read=cp[0];
     
    909844        int sockfd, newsockfd, portno, clilen;
    910845        struct sockaddr_in serv_addr, cli_addr;
    911         // int n;
     846        int n;
    912847        sockfd = socket(AF_INET, SOCK_STREAM, 0);
    913848        if(sockfd < 0)
     
    970905        int sockfd, newsockfd, portno, clilen;
    971906        struct sockaddr_in serv_addr, cli_addr;
    972         // int n;
     907        int n;
    973908        sockfd = socket(AF_INET, SOCK_STREAM, 0);
    974909        if(sockfd < 0)
     
    1038973        d->fd_write = newsockfd;
    1039974        d->f_read = s_open(newsockfd);
    1040         SSI_BLOCK_CHLD;
    1041975        d->f_write = fdopen(newsockfd, "w");
    1042976        si_close(sockfd);
    1043         SSI_UNBLOCK_CHLD;
    1044977        SI_LINK_SET_RW_OPEN_P(l);
    1045978        d->send_quit_at_exit=1;
    1046         SSI_BLOCK_CHLD;
     979        link_list newlink=(link_list)omAlloc(sizeof(link_struct));
     980        newlink->u=u;
     981        newlink->l=l;
     982        newlink->next=(void *)ssiToBeClosed;
     983        ssiToBeClosed=newlink;
    1047984        fprintf(d->f_write,"98 %d %d %u %u\n",SSI_VERSION,MAX_TOK,si_opt_1,si_opt_2);
    1048         SSI_UNBLOCK_CHLD;
    1049985      }
    1050986      // ----------------------------------------------------------------------
     
    1052988      {
    1053989        char* host = (char*)omAlloc(256);
    1054         int sockfd, portno/*, n*/;
     990        int sockfd, portno, n;
    1055991        struct sockaddr_in serv_addr;
    1056992        struct hostent *server;
     
    10781014          d->fd_write=sockfd;
    10791015          SI_LINK_SET_RW_OPEN_P(l);
    1080           d->send_quit_at_exit=1;
    10811016          omFree(host);
    10821017        }
     
    11081043          }
    11091044        }
    1110         SSI_BLOCK_CHLD;
    11111045        outfile=myfopen(filename,mode);
    1112         SSI_UNBLOCK_CHLD;
    11131046        if (outfile!=NULL)
    11141047        {
    11151048          if (strcmp(l->mode,"r")==0)
    11161049          {
    1117             SSI_BLOCK_CHLD;
    11181050            fclose(outfile);
    11191051            d->f_read=s_open_by_name(filename);
    1120             SSI_UNBLOCK_CHLD;
    11211052          }
    11221053          else
    11231054          {
    1124             SSI_BLOCK_CHLD;
    11251055            d->f_write = outfile;
    11261056            fprintf(d->f_write,"98 %d %d %u %u\n",SSI_VERSION,MAX_TOK,si_opt_1,si_opt_2);
    1127             SSI_UNBLOCK_CHLD;
    11281057          }
    11291058        }
     
    11511080      if (d->send_quit_at_exit)
    11521081      {
    1153         SSI_BLOCK_CHLD;
    11541082        fputs("99\n",d->f_write);
    11551083        fflush(d->f_write);
    1156         SSI_UNBLOCK_CHLD;
    11571084      }
    11581085      d->quit_sent=1;
     
    11731100      && (d->quit_sent==0))
    11741101      {
    1175         SSI_BLOCK_CHLD;
    11761102        fputs("99\n",d->f_write);
    11771103        fflush(d->f_write);
    1178         SSI_UNBLOCK_CHLD;
    11791104      }
    11801105      if (d->r!=NULL) rKill(d->r);
     
    11851110        t.tv_sec=0;
    11861111        t.tv_nsec=50000000; // <=50 ms
    1187         int r=nanosleep(&t,NULL);
     1112        int r=si_nanosleep(&t,NULL);
    11881113        if((r==0) && (si_waitpid(d->pid,NULL,WNOHANG)==0))
    11891114        {
     
    11911116          t.tv_sec=0;
    11921117          t.tv_nsec=10000000; // <=10 ms
    1193           r=nanosleep(&t,NULL);
     1118          r=si_nanosleep(&t,NULL);
    11941119          if((r==0)&&(si_waitpid(d->pid,NULL,WNOHANG)==0))
    11951120          {
     
    12001125      }
    12011126      if (d->f_read!=NULL) s_close(d->f_read);
     1127      if (d->f_read!=NULL) s_free(d->f_read);
    12021128      if (d->f_write!=NULL) fclose(d->f_write);
    12031129      if ((strcmp(l->mode,"tcp")==0)
     
    12441170  {
    12451171    case 1:res->rtyp=INT_CMD;
    1246            res->data=(char *)ssiReadInt(d->f_read);
     1172           res->data=(char *)(long)ssiReadInt(d->f_read);
    12471173           break;
    12481174    case 2:res->rtyp=STRING_CMD;
     
    13181244    case 19: res->rtyp=BIGINTMAT_CMD;
    13191245             res->data=ssiReadBigintmat(d);
    1320              break;
     1246             break;
    13211247    case 20: ssiReadBlackbox(res,l);
    13221248             break;
     
    13401266                #endif
    13411267                si_opt_1=n98_o1;
    1342                 si_opt_2=n98_o2;
     1268                si_opt_2=n98_o2;
    13431269                return ssiRead1(l);
    13441270             }
     
    15031429  && (strcmp(request, "read") == 0))
    15041430  {
    1505     fd_set  mask/*, fdmask*/;
     1431    fd_set  mask, fdmask;
    15061432    struct timeval wt;
    15071433    if (s_isready(d->f_read)) return "ready";
     
    15651491  si_link l;
    15661492  ssiInfo *d;
     1493  #ifdef HAVE_MPSR
     1494  MP_Link_pt dd;
     1495  #endif
    15671496  int d_fd;
    15681497  fd_set  mask, fdmask;
     
    16071536        && (strcmp(l->mode,"launch")!=0) && (strcmp(l->mode,"connect")!=0)))
    16081537      {
    1609         WerrorS("all links must be of type ssi:fork, ssi:tcp, ssi:connect");
     1538        WerrorS("all links must be of type ssi:fork, ssi:tcp, ssi:connect,");
     1539        WerrorS(" MPtcp:fork or MPtcp:launch");
    16101540        return -2;
    16111541      }
     1542    #ifdef HAVE_MPSR
     1543      if (strcmp(l->m->type,"ssi")==0)
     1544      {
     1545        d=(ssiInfo*)l->data;
     1546        d_fd=d->fd_read;
     1547        if (!s_isready(d->f_read))
     1548        {
     1549          FD_SET(d_fd, &fdmask);
     1550          if (d_fd > max_fd) max_fd=d_fd;
     1551        }
     1552        else
     1553          return i+1;
     1554      }
     1555      else
     1556      {
     1557        dd=(MP_Link_pt)l->data;
     1558        d_fd=((MP_TCP_t *)dd->transp.private1)->sock;
     1559        FD_SET(d_fd, &fdmask);
     1560        if (d_fd > max_fd) max_fd=d_fd;
     1561      }
     1562    #else
    16121563      d=(ssiInfo*)l->data;
    16131564      d_fd=d->fd_read;
     
    16191570      else
    16201571        return i+1;
     1572    #endif
    16211573    }
    16221574  }
     
    16611613      {
    16621614        l=(si_link)L->m[i].Data();
     1615        #ifdef HAVE_MPSR
     1616        if (strcmp(l->m->type,"ssi")!=0)
     1617        {
     1618          // for MP links, return here:
     1619          dd=(MP_Link_pt)l->data;
     1620          d_fd=((MP_TCP_t *)dd->transp.private1)->sock;
     1621          if(j==d_fd) return i+1;
     1622        }
     1623        else
     1624        {
     1625          d=(ssiInfo*)l->data;
     1626          d_fd=d->fd_read;
     1627          if(j==d_fd) break;
     1628        }
     1629        #else
    16631630        d=(ssiInfo*)l->data;
    16641631        d_fd=d->fd_read;
    16651632        if(j==d_fd) break;
     1633        #endif
    16661634      }
    16671635    }
     
    17541722  }
    17551723  int portno;
    1756   // int n;
     1724  int n;
    17571725  ssiReserved_sockfd = socket(AF_INET, SOCK_STREAM, 0);
    17581726  if(ssiReserved_sockfd < 0)
     
    18261794  l->ref=1;
    18271795  ssiInfo *d=(ssiInfo*)omAlloc0(sizeof(ssiInfo));
    1828   sigprocmask(SIG_SETMASK, NULL, &ssi_sigmask);
    1829   sigaddset(&ssi_sigmask, SIGCHLD);
    18301796  l->data=d;
    18311797  d->fd_read = newsockfd;
     
    18561822**/
    18571823/*---------------------------------------------------------------------*/
    1858 void sig_chld_hdl(int /*sig*/)
     1824void sig_chld_hdl(int sig)
    18591825{
    18601826  pid_t kidpid;
     
    18751841    //printf("Child %ld terminated\n", kidpid);
    18761842    link_list hh=ssiToBeClosed;
    1877     while(hh!=NULL)
     1843    while((hh!=NULL)&&(ssiToBeClosed_inactive))
    18781844    {
    18791845      if((hh->l!=NULL) && (hh->l->m->Open==ssiOpen))
Note: See TracChangeset for help on using the changeset viewer.