Changeset a796fb in git


Ignore:
Timestamp:
Mar 30, 2011, 1:49:51 PM (13 years ago)
Author:
Hans Schoenemann <hannes@…>
Branches:
(u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
Children:
09b38e3ceb9920dc88bd2e2cdfd3d5940ea0c658
Parents:
166ebd23be74a96b55b07ae3ee7b95a6fff5d62a
Message:
block sigchild in system call, waitpid at close

git-svn-id: file:///usr/local/Singular/svn/trunk@14085 2c84dea3-7e68-4137-9b89-c4e89433aadc
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Singular/ssiLink.cc

    r166ebd2 ra796fb  
    1919#include <ctype.h>   /*for isdigit*/
    2020#include <netdb.h>
     21#include <sys/wait.h>
     22
    2123
    2224
     
    7678
    7779link_list ssiToBeClosed=NULL;
     80sigset_t ssi_sigmask;
     81sigset_t ssi_oldmask;
     82#define SSI_BLOCK_CHLD sigprocmask(SIG_SETMASK, &ssi_sigmask, &ssi_oldmask)
     83#define SSI_UNBLOCK_CHLD sigprocmask(SIG_SETMASK, &ssi_oldmask, NULL)
    7884
    7985// the helper functions:
     
    96102void ssiWriteInt(ssiInfo *d,const int i)
    97103{
     104  SSI_BLOCK_CHLD;
    98105  fprintf(d->f_write,"%d ",i);
     106  SSI_UNBLOCK_CHLD;
    99107  //if (d->f_debug!=NULL) fprintf(d->f_debug,"int: %d ",i);
    100108}
     
    102110void ssiWriteString(ssiInfo *d,const char *s)
    103111{
     112  SSI_BLOCK_CHLD;
    104113  fprintf(d->f_write,"%d %s ",strlen(s),s);
     114  SSI_UNBLOCK_CHLD;
    105115  //if (d->f_debug!=NULL) fprintf(d->f_debug,"stringi: %d \"%s\" ",strlen(s),s);
    106116}
     
    112122  // case 2 Q:     3 4 <int>
    113123  //        or     3 3 <mpz_t nominator>
     124  SSI_BLOCK_CHLD;
    114125  if(SR_HDL(n) & SR_INT)
    115126  {
     
    126137  }
    127138  else Werror("illiegal bigint");
     139  SSI_UNBLOCK_CHLD;
    128140}
    129141
     
    139151  //        or     3 6 <mpz_t raw nom.> <mpz_t raw denom.>
    140152  //        or     3 7 <mpz_t raw nom.>
     153  SSI_BLOCK_CHLD;
    141154  if(rField_is_Zp(d->r))
    142155  {
     
    173186  }
    174187  else WerrorS("coeff field not implemented");
     188  SSI_UNBLOCK_CHLD;
    175189}
    176190
    177191void ssiWriteRing(ssiInfo *d,const ring r)
    178192{
    179   /* 5 <ch> <N> <l1> <s1>....<ln> <sN> */
     193  /* 5 <ch> <N> <l1> <v1> ...<lN> <vN> <number of orderings> <ord1> <block0_1> <block1_1> .... */
    180194  if (d->r!=NULL) rKill(d->r);
    181195  d->r=r;
    182196  d->r->ref++;
     197  SSI_BLOCK_CHLD;
    183198  fprintf(d->f_write,"%d %d ",r->ch,r->N);
    184199
     
    199214    i++;
    200215  }
     216  SSI_UNBLOCK_CHLD;
    201217}
    202218
    203219void ssiWritePoly(ssiInfo *d, int typ, poly p)
    204220{
     221  SSI_BLOCK_CHLD;
    205222  fprintf(d->f_write,"%d ",pLength(p));//number of terms
     223  SSI_UNBLOCK_CHLD;
    206224  int i;
    207225
     
    210228    ssiWriteNumber(d,pGetCoeff(p));
    211229    //nWrite(fich,pGetCoeff(p));
     230    SSI_BLOCK_CHLD;
    212231    fprintf(d->f_write,"%ld ",p_GetComp(p,d->r));//component
    213232
     
    217236    }
    218237    pIter(p);
     238    SSI_UNBLOCK_CHLD;
    219239  }
    220240}
     
    225245   // syntax: 8 <rows> <cols> <poly 1> <poly2>.....
    226246   matrix M=(matrix)I;
     247   SSI_BLOCK_CHLD;
    227248   if (typ==MATRIX_CMD)
    228249        fprintf(d->f_write,"%d %d ", MATROWS(M),MATCOLS(M));
    229250   else
    230251     fprintf(d->f_write,"%d ",IDELEMS(I));
     252    SSI_UNBLOCK_CHLD;
    231253
    232254   int i;
     
    244266  ssiInfo *d=(ssiInfo*)l->data;
    245267  // syntax: <num ops> <operation> <op1> <op2> ....
     268  SSI_BLOCK_CHLD;
    246269  fprintf(d->f_write,"%d %d ",D->argc,D->op);
     270  SSI_UNBLOCK_CHLD;
    247271  if (D->argc >0) ssiWrite(l, &(D->arg1));
    248272  if (D->argc < 4)
     
    261285{
    262286  ssiInfo *d=(ssiInfo*)l->data;
     287  SSI_BLOCK_CHLD;
    263288  fprintf(d->f_write,"%d ",dd->nr+1);
     289  SSI_UNBLOCK_CHLD;
    264290  int i;
    265291  for(i=0;i<=dd->nr;i++)
     
    270296void ssiWriteIntvec(ssiInfo *d,intvec * v)
    271297{
     298  SSI_BLOCK_CHLD;
    272299  fprintf(d->f_write,"%d ",v->length());
    273300  int i;
     
    276303    fprintf(d->f_write,"%d ",(*v)[i]);
    277304  }
     305  SSI_UNBLOCK_CHLD;
    278306}
    279307
     
    282310  char *buf;
    283311  int l;
     312  SSI_BLOCK_CHLD;
    284313  fscanf(d->f_read,"%d ",&l);
     314  SSI_UNBLOCK_CHLD;
    285315  buf=(char*)omAlloc(l+1);
     316  SSI_BLOCK_CHLD;
    286317  fread(buf,1,l,d->f_read);
     318  SSI_UNBLOCK_CHLD;
    287319  buf[l]='\0';
    288320  return buf;
     
    292324{
    293325  int d;
     326  SSI_BLOCK_CHLD;
    294327  fscanf(fich,"%d",&d);
     328  SSI_UNBLOCK_CHLD;
    295329  return d;
    296330}
     
    298332number ssiReadBigInt(ssiInfo *d)
    299333{
    300    int sub_type=-1;
    301    fscanf(d->f_read,"%d",&sub_type);
    302    switch(sub_type)
    303    {
     334  int sub_type=-1;
     335  SSI_BLOCK_CHLD;
     336  fscanf(d->f_read,"%d",&sub_type);
     337  SSI_UNBLOCK_CHLD;
     338  switch(sub_type)
     339  {
    304340   case 3:
    305341     {// read int or mpz_t or mpz_t, mpz_t
    306342       number n=nlRInit(0);
     343       SSI_BLOCK_CHLD;
    307344       mpz_inp_str(n->z,d->f_read,0);
     345       SSI_UNBLOCK_CHLD;
    308346       n->s=sub_type;
    309347       return n;
    310348     }
    311    case 4: { int dd; fscanf(d->f_read,"%d",&dd); return INT_TO_SR(dd); }
    312    default: Werror("error in reading bigint: invalid subtype %d",sub_type);
    313             return NULL;
     349   case 4:
     350     {
     351       int dd;
     352       SSI_BLOCK_CHLD;
     353       fscanf(d->f_read,"%d",&dd);
     354       SSI_UNBLOCK_CHLD;
     355       return INT_TO_SR(dd);
     356     }
     357   default:
     358       Werror("error in reading bigint: invalid subtype %d",sub_type);
     359       return NULL;
    314360   }
    315361}
     
    320366  {
    321367     int sub_type=-1;
     368     SSI_BLOCK_CHLD;
    322369     fscanf(d->f_read,"%d",&sub_type);
     370     SSI_UNBLOCK_CHLD;
    323371     switch(sub_type)
    324372     {
     
    326374     case 1:
    327375       {// read mpz_t, mpz_t
    328         number n=nlRInit(0);
    329         mpz_init(n->n);
    330         gmp_fscanf(d->f_read,"%Zd %Zd",n->z,n->n);
    331         n->s=sub_type;
    332         return n;
     376         number n=nlRInit(0);
     377         mpz_init(n->n);
     378         SSI_BLOCK_CHLD;
     379         gmp_fscanf(d->f_read,"%Zd %Zd",n->z,n->n);
     380         SSI_UNBLOCK_CHLD;
     381         n->s=sub_type;
     382         return n;
    333383       }
    334384
     
    336386       {// read mpz_t
    337387         number n=nlRInit(0);
     388         SSI_BLOCK_CHLD;
    338389         gmp_fscanf(d->f_read,"%Zd",n->z);
     390         SSI_UNBLOCK_CHLD;
    339391         n->s=3; /*sub_type*/
    340392         return n;
    341393       }
    342      case 4: { int dd; fscanf(d->f_read,"%d",&dd); return INT_TO_SR(dd); }
     394     case 4:
     395       {
     396         int dd;
     397         SSI_BLOCK_CHLD;
     398         fscanf(d->f_read,"%d",&dd);
     399         SSI_UNBLOCK_CHLD;
     400         return INT_TO_SR(dd);
     401       }
    343402     case 5:
    344403     case 6:
    345404       {// read raw mpz_t, mpz_t
    346         number n=nlRInit(0);
    347         mpz_init(n->n);
    348         mpz_inp_str (n->z, d->f_read, 32);
    349         mpz_inp_str (n->n, d->f_read, 32);
    350         n->s=sub_type-5;
    351         return n;
     405         number n=nlRInit(0);
     406         mpz_init(n->n);
     407         SSI_BLOCK_CHLD;
     408         mpz_inp_str (n->z, d->f_read, 32);
     409         mpz_inp_str (n->n, d->f_read, 32);
     410         SSI_UNBLOCK_CHLD;
     411         n->s=sub_type-5;
     412         return n;
    352413       }
    353414     case 8:
    354415       {// read raw mpz_t
    355         number n=nlRInit(0);
    356         mpz_inp_str (n->z, d->f_read, 32);
    357         n->s=sub_type=3; /*subtype-5*/
    358         return n;
     416         number n=nlRInit(0);
     417         SSI_BLOCK_CHLD;
     418         mpz_inp_str (n->z, d->f_read, 32);
     419         SSI_UNBLOCK_CHLD;
     420         n->s=sub_type=3; /*subtype-5*/
     421         return n;
    359422       }
    360423
     
    367430    // read int
    368431    int dd;
     432    SSI_BLOCK_CHLD;
    369433    fscanf(d->f_read,"%d",&dd);
     434    SSI_UNBLOCK_CHLD;
    370435    return (number)dd;
    371436  }
     
    376441ring ssiReadRing(ssiInfo *d)
    377442{
    378 /* syntax is <ch> <N> <l1> <s1> ....<lN> <sN> */
     443/* syntax is <ch> <N> <l1> <v1> ...<lN> <vN> <number of orderings> <ord1> <block0_1> <block1_1> .... */
    379444  int ch, N,i,l;
    380445  char **names;
     446  SSI_BLOCK_CHLD;
    381447  fscanf(d->f_read,"%d %d ",&ch,&N);
     448  SSI_UNBLOCK_CHLD;
    382449  names=(char**)omAlloc(N*sizeof(char*));
    383450  for(i=0;i<N;i++)
     
    387454  // read the orderings:
    388455  int num_ord; // number of orderings
     456  SSI_BLOCK_CHLD;
    389457  fscanf(d->f_read,"%d",&num_ord);
     458  SSI_UNBLOCK_CHLD;
    390459  int *ord=(int *)omAlloc0((num_ord+1)*sizeof(int));
    391460  int *block0=(int *)omAlloc0((num_ord+1)*sizeof(int));
    392461  int *block1=(int *)omAlloc0((num_ord+1)*sizeof(int));
     462  SSI_BLOCK_CHLD;
    393463  for(i=0;i<num_ord;i++)
    394464  {
    395465     fscanf(d->f_read,"%d %d %d",&ord[i],&block0[i],&block1[i]);
    396466  }
     467  SSI_UNBLOCK_CHLD;
    397468  return rDefault(ch,N,names,num_ord,ord,block0,block1);
    398469}
     
    415486    pGetCoeff(p)=ssiReadNumber(D);
    416487    int d;
     488    SSI_BLOCK_CHLD;
    417489    fscanf(D->f_read,"%d",&d);
     490    SSI_UNBLOCK_CHLD;
    418491    p_SetComp(p,d,D->r);
    419492    for(i=1;i<=rVar(D->r);i++)
    420493    {
     494      SSI_BLOCK_CHLD;
    421495      fscanf(D->f_read,"%d",&d);
     496      SSI_UNBLOCK_CHLD;
    422497      p_SetExp(p,i,d,D->r);
    423498    }
     
    435510  int n,i;
    436511  ideal I;
     512  SSI_BLOCK_CHLD;
    437513  fscanf(d->f_read,"%d",&n);
     514  SSI_UNBLOCK_CHLD;
    438515  I=idInit(n,1);
    439516  for(i=0;i<IDELEMS(I);i++) // read n terms
     
    447524{
    448525  int n,m,i,j;
     526  SSI_BLOCK_CHLD;
    449527  fscanf(d->f_read,"%d %d",&m,&n);
     528  SSI_UNBLOCK_CHLD;
    450529  matrix M=mpNew(m,n);
    451530  poly p;
     
    465544  command D=(command)omAlloc0(sizeof(*D));
    466545  int argc,op;
     546  SSI_BLOCK_CHLD;
    467547  fscanf(d->f_read,"%d %d",&argc,&op);
     548  SSI_UNBLOCK_CHLD;
    468549  D->argc=argc; D->op=op;
    469550  leftv v;
     
    518599  ssiInfo *d=(ssiInfo*)l->data;
    519600  int nr;
     601  SSI_BLOCK_CHLD;
    520602  fscanf(d->f_read,"%d",&nr);
     603  SSI_UNBLOCK_CHLD;
    521604  lists L=(lists)omAlloc(sizeof(*L));
    522605  L->Init(nr);
     
    535618{
    536619  int nr;
     620  SSI_BLOCK_CHLD;
    537621  fscanf(d->f_read,"%d",&nr);
     622  SSI_UNBLOCK_CHLD;
    538623  intvec *v=new intvec(nr);
     624  SSI_BLOCK_CHLD;
    539625  for(int i=0;i<nr;i++)
    540626  {
    541627    fscanf(d->f_read,"%d",&((*v)[i]));
    542628  }
     629  SSI_UNBLOCK_CHLD;
    543630  return v;
    544631}
    545632
    546633//**************************************************************************/
     634
    547635BOOLEAN ssiOpen(si_link l, short flag, leftv u)
    548636{
    549637  const char *mode;
    550638  ssiInfo *d=(ssiInfo*)omAlloc0(sizeof(ssiInfo));
     639  sigprocmask(SIG_SETMASK, NULL, &ssi_sigmask);
     640  sigaddset(&ssi_sigmask, SIGCHLD);
    551641  if (flag & SI_LINK_OPEN)
    552642  {
     
    9111001    if (d->f_write!=NULL) fclose(d->f_write);
    9121002    if (d->r!=NULL) rKill(d->r);
    913     if (d->pid!=0) { kill(d->pid,15); kill(d->pid,9); }
     1003    if (d->pid!=0)
     1004    {
     1005      int status;
     1006      kill(d->pid,15);
     1007      kill(d->pid,9);
     1008      waitpid(d->pid,&status,0);
     1009    }
    9141010    omFreeSize((ADDRESS)d,(sizeof *d));
    9151011  }
     
    9261022  leftv res=(leftv)omAlloc0(sizeof(sleftv));
    9271023  int t=0;
     1024  SSI_BLOCK_CHLD;
    9281025  fscanf(d->f_read,"%d",&t);
     1026  SSI_UNBLOCK_CHLD;
    9291027  //Print("got type %d\n",t);
    9301028  switch(t)
     
    10051103                int n98_v,n98_m;
    10061104                BITSET n98_o1,n98_o2;
     1105                SSI_BLOCK_CHLD;
    10071106                fscanf(d->f_read,"%d %d %u %u\n",&n98_v,&n98_m,&n98_o1,&n98_o2);
     1107                SSI_UNBLOCK_CHLD;
    10081108                if ((n98_v!=SSI_VERSION) ||(n98_m!=MAX_TOK))
    10091109                {
     
    10331133  return res;
    10341134no_ring: WerrorS("no ring");
     1135  omFreeSize(res,sizeof(sleftv));
    10351136  return NULL;
    10361137}
     
    13191420  s = pselect(max_fd, &mask, NULL, NULL, wt_ptr, &sigmask);
    13201421  #else
    1321    sigset_t origsigmask;
    1322 
    1323    sigprocmask(SIG_SETMASK, &sigmask, &origsigmask);
    1324    s = select(max_fd, &mask, NULL, NULL, wt_ptr);
    1325    sigprocmask(SIG_SETMASK, &origsigmask, NULL);
    1326    #endif
     1422  SSI_BLOCK_CHLD;
     1423  s = select(max_fd, &mask, NULL, NULL, wt_ptr);
     1424  SSI_UNBLOCK_CHLD;
     1425  #endif
    13271426
    13281427  if (s==-1)
    1329   { 
     1428  {
    13301429    WerrorS("error in select call");
    13311430    return -2; /*error*/
Note: See TracChangeset for help on using the changeset viewer.