Changeset b60bfe in git
- Timestamp:
- Aug 1, 2013, 9:25:23 AM (10 years ago)
- Branches:
- (u'jengelh-datetime', 'ceac47cbc86fe4a15902392bdbb9bd2ae0ea02c6')(u'spielwiese', 'a800fe4b3e9d37a38c5a10cc0ae9dfa0c15a4ee6')
- Children:
- f57b6f18b1bcdf1314cd2a943565ec298e5e11f9
- Parents:
- 01c0298072151ffa06aed1c49b5bdcc5d0c29690
- Location:
- Singular
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
Singular/cntrlc.cc
r01c0298 rb60bfe 10 10 #define _XOPEN_SOURCE_EXTENDED 11 11 #endif /* MP3-Y2 0.022UF */ 12 13 12 #include <stdio.h> 14 13 #include <stddef.h> … … 22 21 #include "config.h" 23 22 #endif /* HAVE_CONFIG_H */ 23 24 24 #include <kernel/mod2.h> 25 25 #include <omalloc/omalloc.h> 26 27 #include < kernel/polys.h>26 #include <Singular/tok.h> 27 #include <Singular/ipshell.h> 28 28 #include <kernel/febase.h> 29 29 void 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> 33 32 #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> 40 35 41 36 /* undef, if you don't want GDB to come up on error */ 37 38 #define CALL_GDB 42 39 43 40 #if defined(__OPTIMIZE__) && defined(CALL_GDB) … … 93 90 void sig_term_hdl(int /*sig*/) 94 91 { 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 102 104 } 103 105 … … 121 123 * 122 124 *---------------------------------------------------------------------*/ 123 void sigint_handler(int sig);125 void sigint_handler(int /*sig*/); 124 126 125 127 si_hdl_typ si_set_signal ( int sig, si_hdl_typ signal_handler); … … 283 285 exit(0); 284 286 } 287 285 288 #else 286 289 … … 310 313 #endif /* __OPTIMIZE__ */ 311 314 #if defined(unix) 312 /* debug(..) does not work under HPUX (because ptrace does not work..) */313 315 #ifdef CALL_GDB 314 316 if (sig!=SIGINT) debug(STACK_TRACE); … … 318 320 } 319 321 #endif 322 320 323 321 324 /*2 -
Singular/links/s_buff.cc
r01c0298 rb60bfe 7 7 #include <signal.h> 8 8 9 #include <kernel/mod2.h> 9 10 #include <coeffs/si_gmp.h> 10 11 … … 12 13 #include <Singular/links/s_buff.h> 13 14 #include <Singular/si_signals.h> 15 14 16 //struct s_buff_s 15 17 //{ … … 25 27 #define S_BUFF_LEN 4096 26 28 27 sigset_t ssi_sigmask; // set in ssiLink.cc28 sigset_t ssi_oldmask; // set in ssiLink.cc29 30 #define SSI_BLOCK_CHLD sigprocmask(SIG_SETMASK, &ssi_sigmask, &ssi_oldmask)31 #define SSI_UNBLOCK_CHLD sigprocmask(SIG_SETMASK, &ssi_oldmask, NULL)32 33 29 s_buff s_open(int fd) 34 30 { 35 SSI_BLOCK_CHLD;36 31 s_buff F=(s_buff)omAlloc0(sizeof(*F)); 37 32 F->fd=fd; 38 33 F->buff=(char*)omAlloc(S_BUFF_LEN); 39 SSI_UNBLOCK_CHLD;40 34 return F; 41 35 } … … 43 37 s_buff s_open_by_name(const char *n) 44 38 { 45 SSI_BLOCK_CHLD;46 39 int fd=si_open(n,O_RDONLY); 47 SSI_UNBLOCK_CHLD;48 40 return s_open(fd); 49 41 } 50 42 51 int s_ close(s_buff &F)43 int s_free(s_buff &F) 52 44 { 53 45 if (F!=NULL) 54 46 { 55 SSI_BLOCK_CHLD;56 47 omFreeSize(F->buff,S_BUFF_LEN); 57 int r=si_close(F->fd);58 48 omFreeSize(F,sizeof(*F)); 59 49 F=NULL; 60 SSI_UNBLOCK_CHLD; 50 } 51 return 0; 52 } 53 54 int s_close(s_buff &F) 55 { 56 if (F!=NULL) 57 { 58 int r=close(F->fd); 61 59 return r; 62 60 } … … 74 72 { 75 73 memset(F->buff,0,S_BUFF_LEN); /*debug*/ 76 SSI_BLOCK_CHLD;77 74 int r=si_read(F->fd,F->buff,S_BUFF_LEN); 78 SSI_UNBLOCK_CHLD;79 75 if (r<=0) 80 76 { -
Singular/links/s_buff.h
r01c0298 rb60bfe 17 17 s_buff s_open(int fd); 18 18 s_buff s_open_by_name(const char *n); 19 int s_free(s_buff &f); 19 20 int s_close(s_buff &f); 20 21 -
Singular/links/silink.h
r01c0298 rb60bfe 125 125 126 126 extern link_list ssiToBeClosed; 127 extern BOOLEAN ssiToBeClosed_inactive;127 extern volatile BOOLEAN ssiToBeClosed_inactive; 128 128 #endif // SILINK_H -
Singular/links/ssiLink.cc
r01c0298 rb60bfe 21 21 #include <time.h> 22 22 23 24 25 #ifdef HAVE_CONFIG_H26 #include "config.h"27 #endif /* HAVE_CONFIG_H */28 23 #include <kernel/mod2.h> 29 24 #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> 31 30 #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> 45 39 #include <kernel/timer.h> 46 47 #include <Singular/tok.h>48 #include <Singular/ipshell.h>49 #include <Singular/ipid.h>50 51 40 #include <Singular/subexpr.h> 41 #include <Singular/links/silink.h> 52 42 #include <Singular/cntrlc.h> 53 43 #include <Singular/lists.h> 54 44 #include <Singular/blackbox.h> 55 56 #include <Singular/links/silink.h>57 45 #include <Singular/links/s_buff.h> 58 46 #include <Singular/links/ssiLink.h> 59 47 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 72 51 73 52 #ifdef HAVE_SIMPLEIPC 74 53 #include <Singular/links/simpleipc.h> 75 54 #endif 76 //#if (_POSIX_C_SOURCE >= 200112L) || (_XOPEN_SOURCE >= 600) 77 //#define HAVE_PSELECT 78 //#endif 55 56 #include <Singular/si_signals.h> 79 57 80 58 #define SSI_VERSION 5 … … 106 84 107 85 link_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) 86 volatile BOOLEAN ssiToBeClosed_inactive=TRUE; 115 87 116 88 // the helper functions: … … 133 105 void ssiWriteInt(ssiInfo *d,const int i) 134 106 { 135 SSI_BLOCK_CHLD;136 107 fprintf(d->f_write,"%d ",i); 137 SSI_UNBLOCK_CHLD;138 108 //if (d->f_debug!=NULL) fprintf(d->f_debug,"int: %d ",i); 139 109 } … … 141 111 void ssiWriteString(ssiInfo *d,const char *s) 142 112 { 143 SSI_BLOCK_CHLD;144 113 fprintf(d->f_write,"%d %s ",(int)strlen(s),s); 145 SSI_UNBLOCK_CHLD;146 114 //if (d->f_debug!=NULL) fprintf(d->f_debug,"stringi: %d \"%s\" ",strlen(s),s); 147 115 } … … 153 121 // case 2 Q: 3 4 <int> 154 122 // or 3 3 <mpz_t nominator> 155 SSI_BLOCK_CHLD;156 123 if(SR_HDL(n) & SR_INT) 157 124 { … … 159 126 //if (d->f_debug!=NULL) fprintf(d->f_debug,"bigint: short \"%ld\" ",SR_TO_INT(n)); 160 127 } 161 else if ( ((number_dummy)n)->s==3)128 else if (n->s==3) 162 129 { 163 130 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); 165 132 fputc(' ',d->f_write); 166 133 //gmp_fprintf(d->f_write,"3 %Zd ",n->z); … … 168 135 } 169 136 else WerrorS("illiegal bigint"); 170 SSI_UNBLOCK_CHLD;171 137 } 172 138 … … 182 148 // or 3 6 <mpz_t raw nom.> <mpz_t raw denom.> 183 149 // or 3 7 <mpz_t raw nom.> 184 SSI_BLOCK_CHLD;185 150 if(rField_is_Zp(d->r)) 186 151 { … … 193 158 { 194 159 #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))); 196 161 #else 197 162 long nn=SR_TO_INT(n); 198 163 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)); 200 165 else 201 166 { 202 167 mpz_t tmp; 203 168 mpz_init_set_si(tmp,nn); 204 169 fputs("8 ",d->f_write); 205 170 mpz_out_str (d->f_write,32, tmp); 206 171 fputc(' ',d->f_write); 207 172 mpz_clear(tmp); 208 173 } 209 174 #endif 210 175 //if (d->f_debug!=NULL) fprintf(d->f_debug,"number: short \"%ld\" ",SR_TO_INT(n)); 211 176 } 212 else if ( ((number_dummy)n)->s<2)177 else if (n->s<2) 213 178 { 214 179 //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); 217 182 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); 219 184 fputc(' ',d->f_write); 220 185 … … 225 190 //gmp_fprintf(d->f_write,"3 %Zd ",n->z); 226 191 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); 228 193 fputc(' ',d->f_write); 229 194 … … 232 197 } 233 198 else WerrorS("coeff field not implemented"); 234 SSI_UNBLOCK_CHLD;235 199 } 236 200 … … 241 205 d->r=r; 242 206 d->r->ref++; 243 SSI_BLOCK_CHLD;244 207 fprintf(d->f_write,"%d %d ",n_GetChar(r->cf),r->N); 245 208 … … 284 247 i++; 285 248 } 286 SSI_UNBLOCK_CHLD; 287 } 288 289 void ssiWritePoly(ssiInfo *d, int /*typ*/, poly p) 290 { 291 SSI_BLOCK_CHLD; 249 } 250 251 void ssiWritePoly(ssiInfo *d, int typ, poly p) 252 { 292 253 fprintf(d->f_write,"%d ",pLength(p));//number of terms 293 SSI_UNBLOCK_CHLD; 294 int j; 254 int i; 295 255 296 256 while(p!=NULL) … … 298 258 ssiWriteNumber(d,pGetCoeff(p)); 299 259 //nWrite(fich,pGetCoeff(p)); 300 SSI_BLOCK_CHLD;301 260 fprintf(d->f_write,"%ld ",p_GetComp(p,d->r));//component 302 261 303 for( j=1;j<=rVar(d->r);j++)262 for(int j=1;j<=rVar(d->r);j++) 304 263 { 305 264 fprintf(d->f_write,"%ld ",p_GetExp(p,j,d->r ));//x^j 306 265 } 307 266 pIter(p); 308 SSI_UNBLOCK_CHLD;309 267 } 310 268 } … … 316 274 matrix M=(matrix)I; 317 275 int mn; 318 SSI_BLOCK_CHLD;319 276 if (typ==MATRIX_CMD) 320 277 { … … 327 284 fprintf(d->f_write,"%d ",IDELEMS(I)); 328 285 } 329 SSI_UNBLOCK_CHLD;330 286 331 287 int i; … … 344 300 ssiInfo *d=(ssiInfo*)l->data; 345 301 // syntax: <num ops> <operation> <op1> <op2> .... 346 SSI_BLOCK_CHLD;347 302 fprintf(d->f_write,"%d %d ",D->argc,D->op); 348 SSI_UNBLOCK_CHLD;349 303 if (D->argc >0) ssiWrite(l, &(D->arg1)); 350 304 if (D->argc < 4) … … 369 323 ssiInfo *d=(ssiInfo*)l->data; 370 324 int Ll=lSize(dd); 371 SSI_BLOCK_CHLD;372 325 fprintf(d->f_write,"%d ",Ll+1); 373 SSI_UNBLOCK_CHLD;374 326 int i; 375 327 for(i=0;i<=Ll;i++) … … 380 332 void ssiWriteIntvec(ssiInfo *d,intvec * v) 381 333 { 382 SSI_BLOCK_CHLD;383 334 fprintf(d->f_write,"%d ",v->length()); 384 335 int i; … … 387 338 fprintf(d->f_write,"%d ",(*v)[i]); 388 339 } 389 SSI_UNBLOCK_CHLD;390 340 } 391 341 void ssiWriteIntmat(ssiInfo *d,intvec * v) 392 342 { 393 SSI_BLOCK_CHLD;394 343 fprintf(d->f_write,"%d %d ",v->rows(),v->cols()); 395 344 int i; … … 398 347 fprintf(d->f_write,"%d ",(*v)[i]); 399 348 } 400 SSI_UNBLOCK_CHLD;401 349 } 402 350 403 351 void ssiWriteBigintmat(ssiInfo *d,bigintmat * v) 404 352 { 405 SSI_BLOCK_CHLD;406 353 fprintf(d->f_write,"%d %d ",v->rows(),v->cols()); 407 354 int i; … … 410 357 ssiWriteBigInt(d,(*v)[i]); 411 358 } 412 SSI_UNBLOCK_CHLD;413 359 } 414 360 … … 419 365 l=s_readint(d->f_read); 420 366 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); 423 369 //if (ll!=l) printf("want %d, got %d bytes\n",l,ll); 424 370 buf[l]='\0'; … … 439 385 case 3: 440 386 {// 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; 447 390 return n; 448 391 } … … 451 394 int dd; 452 395 dd=s_readint(d->f_read); 453 return n_Init(dd,d->r->cf);396 return INT_TO_SR(dd); 454 397 } 455 398 default: … … 468 411 case 1: 469 412 {// 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; 479 418 return n; 480 419 } … … 482 421 case 3: 483 422 {// 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*/ 491 426 return n; 492 427 } 493 428 case 4: 494 429 { 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 497 436 } 498 437 case 5: 499 438 case 6: 500 439 {// 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; 510 445 return n; 511 446 } 512 447 case 8: 513 448 {// 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*/ 521 452 return n; 522 453 } … … 536 467 { 537 468 // 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; 540 472 } 541 473 else Werror("coeffs not implemented"); … … 546 478 { 547 479 /* 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; 549 481 char **names; 550 482 ch=s_readint(d->f_read); … … 603 535 //Print("poly: terms:%d\n",n); 604 536 poly p; 605 //int j;606 //j=0;537 int j; 538 j=0; 607 539 poly ret=NULL; 608 540 poly prev=NULL; … … 612 544 p=p_Init(D->r); 613 545 pGetCoeff(p)=ssiReadNumber(D); 614 int d=s_readint(D->f_read); 546 int d; 547 d=s_readint(D->f_read); 615 548 p_SetComp(p,d,D->r); 616 549 for(i=1;i<=rVar(D->r);i++) … … 630 563 ideal ssiReadIdeal(ssiInfo *d) 631 564 { 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); 635 569 for(i=0;i<IDELEMS(I);i++) // read n terms 636 570 { … … 642 576 matrix ssiReadMatrix(ssiInfo *d) 643 577 { 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); 646 581 matrix M=mpNew(m,n); 647 582 poly p; … … 714 649 { 715 650 ssiInfo *d=(ssiInfo*)l->data; 716 int nr=s_readint(d->f_read); 651 int nr; 652 nr=s_readint(d->f_read); 717 653 lists L=(lists)omAlloc(sizeof(*L)); 718 654 L->Init(nr); … … 730 666 intvec* ssiReadIntvec(ssiInfo *d) 731 667 { 732 int nr=s_readint(d->f_read); 668 int nr; 669 nr=s_readint(d->f_read); 733 670 intvec *v=new intvec(nr); 734 671 for(int i=0;i<nr;i++) … … 766 703 { 767 704 ssiInfo *d=(ssiInfo*)l->data; 768 /*int throwaway=*/ (void) s_readint(d->f_read); 705 int throwaway; 706 throwaway=s_readint(d->f_read); 769 707 char *name=ssiReadString(d); 770 708 int tok; … … 790 728 const char *mode; 791 729 ssiInfo *d=(ssiInfo*)omAlloc0(sizeof(ssiInfo)); 792 sigprocmask(SIG_SETMASK, NULL, &ssi_sigmask);793 sigaddset(&ssi_sigmask, SIGCHLD);794 730 if (flag & SI_LINK_OPEN) 795 731 { … … 824 760 int pc[2]; 825 761 int cp[2]; 826 SSI_BLOCK_CHLD;827 762 pipe(pc); 828 763 pipe(cp); 829 764 pid_t pid=fork(); 830 SSI_UNBLOCK_CHLD;831 765 if (pid==0) /*fork: child*/ 832 766 { 767 /* block SIGINT */ 768 sigset_t sigint; 769 sigemptyset(&sigint); 770 sigaddset(&sigint, SIGINT); 771 sigprocmask(SIG_BLOCK, &sigint, NULL); 772 833 773 link_list hh=(link_list)ssiToBeClosed->next; 834 774 /* we know: l is the first entry in ssiToBeClosed-list */ … … 837 777 SI_LINK_SET_CLOSE_P(hh->l); 838 778 ssiInfo *dd=(ssiInfo*)hh->l->data; 839 SSI_BLOCK_CHLD;840 779 s_close(dd->f_read); 780 s_free(dd->f_read); 841 781 fclose(dd->f_write); 842 SSI_UNBLOCK_CHLD;843 782 if (dd->r!=NULL) rKill(dd->r); 844 783 omFreeSize((ADDRESS)dd,(sizeof *dd)); … … 849 788 } 850 789 ssiToBeClosed->next=NULL; 851 SSI_BLOCK_CHLD;852 790 si_close(pc[1]); si_close(cp[0]); 853 791 d->f_write=fdopen(cp[1],"w"); 854 SSI_UNBLOCK_CHLD;855 792 d->f_read=s_open(pc[0]); 856 793 d->fd_read=pc[0]; … … 886 823 { 887 824 d->pid=pid; 888 SSI_BLOCK_CHLD;889 825 si_close(pc[0]); si_close(cp[1]); 890 826 d->f_write=fdopen(pc[1],"w"); 891 SSI_UNBLOCK_CHLD;892 827 d->f_read=s_open(cp[0]); 893 828 d->fd_read=cp[0]; … … 909 844 int sockfd, newsockfd, portno, clilen; 910 845 struct sockaddr_in serv_addr, cli_addr; 911 //int n;846 int n; 912 847 sockfd = socket(AF_INET, SOCK_STREAM, 0); 913 848 if(sockfd < 0) … … 970 905 int sockfd, newsockfd, portno, clilen; 971 906 struct sockaddr_in serv_addr, cli_addr; 972 //int n;907 int n; 973 908 sockfd = socket(AF_INET, SOCK_STREAM, 0); 974 909 if(sockfd < 0) … … 1038 973 d->fd_write = newsockfd; 1039 974 d->f_read = s_open(newsockfd); 1040 SSI_BLOCK_CHLD;1041 975 d->f_write = fdopen(newsockfd, "w"); 1042 976 si_close(sockfd); 1043 SSI_UNBLOCK_CHLD;1044 977 SI_LINK_SET_RW_OPEN_P(l); 1045 978 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; 1047 984 fprintf(d->f_write,"98 %d %d %u %u\n",SSI_VERSION,MAX_TOK,si_opt_1,si_opt_2); 1048 SSI_UNBLOCK_CHLD;1049 985 } 1050 986 // ---------------------------------------------------------------------- … … 1052 988 { 1053 989 char* host = (char*)omAlloc(256); 1054 int sockfd, portno /*, n*/;990 int sockfd, portno, n; 1055 991 struct sockaddr_in serv_addr; 1056 992 struct hostent *server; … … 1078 1014 d->fd_write=sockfd; 1079 1015 SI_LINK_SET_RW_OPEN_P(l); 1080 d->send_quit_at_exit=1;1081 1016 omFree(host); 1082 1017 } … … 1108 1043 } 1109 1044 } 1110 SSI_BLOCK_CHLD;1111 1045 outfile=myfopen(filename,mode); 1112 SSI_UNBLOCK_CHLD;1113 1046 if (outfile!=NULL) 1114 1047 { 1115 1048 if (strcmp(l->mode,"r")==0) 1116 1049 { 1117 SSI_BLOCK_CHLD;1118 1050 fclose(outfile); 1119 1051 d->f_read=s_open_by_name(filename); 1120 SSI_UNBLOCK_CHLD;1121 1052 } 1122 1053 else 1123 1054 { 1124 SSI_BLOCK_CHLD;1125 1055 d->f_write = outfile; 1126 1056 fprintf(d->f_write,"98 %d %d %u %u\n",SSI_VERSION,MAX_TOK,si_opt_1,si_opt_2); 1127 SSI_UNBLOCK_CHLD;1128 1057 } 1129 1058 } … … 1151 1080 if (d->send_quit_at_exit) 1152 1081 { 1153 SSI_BLOCK_CHLD;1154 1082 fputs("99\n",d->f_write); 1155 1083 fflush(d->f_write); 1156 SSI_UNBLOCK_CHLD;1157 1084 } 1158 1085 d->quit_sent=1; … … 1173 1100 && (d->quit_sent==0)) 1174 1101 { 1175 SSI_BLOCK_CHLD;1176 1102 fputs("99\n",d->f_write); 1177 1103 fflush(d->f_write); 1178 SSI_UNBLOCK_CHLD;1179 1104 } 1180 1105 if (d->r!=NULL) rKill(d->r); … … 1185 1110 t.tv_sec=0; 1186 1111 t.tv_nsec=50000000; // <=50 ms 1187 int r= nanosleep(&t,NULL);1112 int r=si_nanosleep(&t,NULL); 1188 1113 if((r==0) && (si_waitpid(d->pid,NULL,WNOHANG)==0)) 1189 1114 { … … 1191 1116 t.tv_sec=0; 1192 1117 t.tv_nsec=10000000; // <=10 ms 1193 r= nanosleep(&t,NULL);1118 r=si_nanosleep(&t,NULL); 1194 1119 if((r==0)&&(si_waitpid(d->pid,NULL,WNOHANG)==0)) 1195 1120 { … … 1200 1125 } 1201 1126 if (d->f_read!=NULL) s_close(d->f_read); 1127 if (d->f_read!=NULL) s_free(d->f_read); 1202 1128 if (d->f_write!=NULL) fclose(d->f_write); 1203 1129 if ((strcmp(l->mode,"tcp")==0) … … 1244 1170 { 1245 1171 case 1:res->rtyp=INT_CMD; 1246 res->data=(char *) ssiReadInt(d->f_read);1172 res->data=(char *)(long)ssiReadInt(d->f_read); 1247 1173 break; 1248 1174 case 2:res->rtyp=STRING_CMD; … … 1318 1244 case 19: res->rtyp=BIGINTMAT_CMD; 1319 1245 res->data=ssiReadBigintmat(d); 1320 1246 break; 1321 1247 case 20: ssiReadBlackbox(res,l); 1322 1248 break; … … 1340 1266 #endif 1341 1267 si_opt_1=n98_o1; 1342 1268 si_opt_2=n98_o2; 1343 1269 return ssiRead1(l); 1344 1270 } … … 1503 1429 && (strcmp(request, "read") == 0)) 1504 1430 { 1505 fd_set mask /*, fdmask*/;1431 fd_set mask, fdmask; 1506 1432 struct timeval wt; 1507 1433 if (s_isready(d->f_read)) return "ready"; … … 1565 1491 si_link l; 1566 1492 ssiInfo *d; 1493 #ifdef HAVE_MPSR 1494 MP_Link_pt dd; 1495 #endif 1567 1496 int d_fd; 1568 1497 fd_set mask, fdmask; … … 1607 1536 && (strcmp(l->mode,"launch")!=0) && (strcmp(l->mode,"connect")!=0))) 1608 1537 { 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"); 1610 1540 return -2; 1611 1541 } 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 1612 1563 d=(ssiInfo*)l->data; 1613 1564 d_fd=d->fd_read; … … 1619 1570 else 1620 1571 return i+1; 1572 #endif 1621 1573 } 1622 1574 } … … 1661 1613 { 1662 1614 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 1663 1630 d=(ssiInfo*)l->data; 1664 1631 d_fd=d->fd_read; 1665 1632 if(j==d_fd) break; 1633 #endif 1666 1634 } 1667 1635 } … … 1754 1722 } 1755 1723 int portno; 1756 //int n;1724 int n; 1757 1725 ssiReserved_sockfd = socket(AF_INET, SOCK_STREAM, 0); 1758 1726 if(ssiReserved_sockfd < 0) … … 1826 1794 l->ref=1; 1827 1795 ssiInfo *d=(ssiInfo*)omAlloc0(sizeof(ssiInfo)); 1828 sigprocmask(SIG_SETMASK, NULL, &ssi_sigmask);1829 sigaddset(&ssi_sigmask, SIGCHLD);1830 1796 l->data=d; 1831 1797 d->fd_read = newsockfd; … … 1856 1822 **/ 1857 1823 /*---------------------------------------------------------------------*/ 1858 void sig_chld_hdl(int /*sig*/)1824 void sig_chld_hdl(int sig) 1859 1825 { 1860 1826 pid_t kidpid; … … 1875 1841 //printf("Child %ld terminated\n", kidpid); 1876 1842 link_list hh=ssiToBeClosed; 1877 while( hh!=NULL)1843 while((hh!=NULL)&&(ssiToBeClosed_inactive)) 1878 1844 { 1879 1845 if((hh->l!=NULL) && (hh->l->m->Open==ssiOpen))
Note: See TracChangeset
for help on using the changeset viewer.