Changeset 5184 for trunk/oscam.c
- Timestamp:
- 05/06/11 07:01:26 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/oscam.c
r5176 r5184 32 32 int32_t cs_restart_mode=1; //Restartmode: 0=off, no restart fork, 1=(default)restart fork, restart by webif, 2=like=1, but also restart on segfaults 33 33 #endif 34 int32_t cs_capture_SEGV=0; 34 int32_t cs_capture_SEGV=0; 35 35 char cs_tmpdir[200]={0x00}; 36 36 pthread_mutex_t gethostbyname_lock; … … 250 250 #endif 251 251 fprintf(stderr, "\n\n"); 252 fprintf(stderr, "oscam [-b] [- c <config dir>] [-t <tmp dir>] [-d <level>] [-r <level>] [-h]");252 fprintf(stderr, "oscam [-b] [-s] [-c <config dir>] [-t <tmp dir>] [-d <level>] [-r <level>] [-h]"); 253 253 fprintf(stderr, "\n\n\t-b : start in background\n"); 254 fprintf(stderr, "\t-s : capture SEGFAULTS\n"); 254 255 fprintf(stderr, "\t-c <dir> : read configuration from <dir>\n"); 255 256 fprintf(stderr, "\t default = %s\n", CS_CONFDIR); … … 536 537 if(cl && !cl->cleaned){ //cleaned=0 537 538 cl->cleaned++; //cleaned=1 538 539 539 540 //kill_thread also removes this client, so here just to get sure client is removed: 540 541 struct s_client *prev, *cl2; … … 544 545 if (cl == cl2) 545 546 prev->next = cl2->next; //remove client from list 546 547 547 548 cs_sleepms(500); //just wait a bit that really really nobody is accessing client data 548 549 549 550 if(cl->typ == 'c' && ph[cl->ctyp].cleanup) 550 551 ph[cl->ctyp].cleanup(cl); … … 557 558 cs_statistics(cl); 558 559 } 559 560 560 561 if(cl->pfd) nullclose(&cl->pfd); //Closing Network socket 561 562 if(cl->fd_m2c_c) nullclose(&cl->fd_m2c_c); //Closing client read fd 562 563 if(cl->fd_m2c) nullclose(&cl->fd_m2c); //Closing client read fd 563 564 564 565 if(cl->typ == 'r' && cl->reader){ 565 566 // Maybe we also need a "nullclose" mechanism here... … … 586 587 cfg.lb_save = 0; //this is for avoiding duplicate saves 587 588 } 588 589 589 590 done_share(); 590 591 591 592 //cleanup clients: 592 593 struct s_client *cl; … … 598 599 } 599 600 } 600 601 601 602 //cleanup readers: 602 603 struct s_reader *rdr; … … 606 607 } 607 608 first_active_reader = NULL; 608 609 609 610 init_free_userdb(cfg.account); 610 611 cfg.account = NULL; … … 725 726 if(!cl->ncd_server) 726 727 cl->ftab = account->ftab; // Ident 727 728 728 729 cl->sidtabok = account->sidtabok; // services 729 730 cl->sidtabno = account->sidtabno; // services 730 731 cl->failban = account->failban; 731 732 732 733 memcpy(&cl->ctab, &account->ctab, sizeof(cl->ctab)); 733 734 memcpy(&cl->ttab, &account->ttab, sizeof(cl->ttab)); 734 735 735 736 int32_t i; 736 737 for(i = 0; i < CS_ECM_RINGBUFFER_MAX; i++) … … 867 868 set_signal_handler(SIGUSR2, 1, cs_card_info); 868 869 set_signal_handler(SIGCONT, 1, SIG_IGN); 869 870 870 871 if (cs_capture_SEGV) 871 872 set_signal_handler(SIGSEGV, 1, cs_exit); 872 873 873 874 cs_log("signal handling initialized (type=%s)", 874 875 #ifdef CS_SIGBSD … … 926 927 if(!strncmp(ptr, months[month], 3)) break; 927 928 } 928 if(month > 11) month = 0; 929 if(month > 11) month = 0; 929 930 memset(&timeinfo, 0, sizeof(timeinfo)); 930 931 timeinfo.tm_mday = day; … … 1113 1114 } 1114 1115 1115 #pragma GCC diagnostic ignored "-Wempty-body" 1116 #pragma GCC diagnostic ignored "-Wempty-body" 1116 1117 void *clientthread_init(void * init){ 1117 1118 struct s_clientinit clientinit; 1118 1119 memcpy(&clientinit, init, sizeof(struct s_clientinit)); //copy to stack to free init pointer 1119 free(init); 1120 free(init); 1120 1121 #ifndef NO_PTHREAD_CLEANUP_PUSH 1121 1122 pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL); … … 1130 1131 return NULL; 1131 1132 } 1132 #pragma GCC diagnostic warning "-Wempty-body" 1133 #pragma GCC diagnostic warning "-Wempty-body" 1133 1134 1134 1135 void start_thread(void * startroutine, char * nameroutine) { … … 1187 1188 void kill_thread(struct s_client *cl) { //cs_exit is used to let thread kill itself, this routine is for a thread to kill other thread 1188 1189 pthread_mutex_lock(&system_lock); 1189 kill_thread_int(cl); 1190 kill_thread_int(cl); 1190 1191 pthread_mutex_unlock(&system_lock); 1191 1192 } … … 1235 1236 1236 1237 if (restart) { 1237 //remove from list: 1238 //remove from list: 1238 1239 remove_reader_from_active(rdr); 1239 1240 } … … 1287 1288 pthread_attr_setstacksize(&attr, PTHREAD_STACK_SIZE); 1288 1289 #endif 1289 1290 1290 1291 if (pthread_create(&cl->thread, &attr, start_cardreader, (void *)rdr)) { 1291 1292 cs_log("ERROR: can't create thread for %s", rdr->label); … … 1296 1297 pthread_detach(cl->thread); 1297 1298 pthread_attr_destroy(&attr); 1298 1299 1299 1300 if (restart) { 1300 1301 //add to list … … 1371 1372 } 1372 1373 if (cfg.dropdups) 1373 cs_disconnect_client(client); 1374 cs_disconnect_client(client); 1374 1375 break; 1375 1376 } … … 1454 1455 client->fchid = account->fchid; // CHID filter 1455 1456 client->sidtabok= account->sidtabok; // services 1456 client->sidtabno= account->sidtabno; // services 1457 client->sidtabno= account->sidtabno; // services 1457 1458 memcpy(&client->ttab, &account->ttab, sizeof(client->ttab)); 1458 1459 #ifdef CS_ANTICASC … … 1751 1752 * causing problems in file name 1752 1753 */ 1753 1754 1754 1755 char *name=get_servicename(cur_client(), er->srvid, er->caid); 1755 1756 cs_strncpy(srvname, name, sizeof(srvname)); … … 1758 1759 for (i = 0; srvname[i]; i++) 1759 1760 if (srvname[i] == ' ') srvname[i] = '_'; 1760 1761 1761 1762 /* calc log file name */ 1762 1763 time(&t); … … 1807 1808 ECM_REQUEST *ecm; 1808 1809 int32_t n, i, pending; 1809 1810 1810 1811 er->rc = rc; 1811 1812 … … 1819 1820 if (ecm->rc >= E_99) { 1820 1821 pending++; 1821 if (ecm->ecmcacheptr == er->ecmcacheptr) { 1822 if (ecm->ecmcacheptr == er->ecmcacheptr) { 1822 1823 er->cpti = ecm->cpti; 1823 1824 //cs_log("distribute %04X:%06X:%04X cpti %d to client %s", ecm->caid, ecm->prid, ecm->srvid, ecm->cpti, username(cl)); … … 1992 1993 1993 1994 snprintf(uname,sizeof(uname)-1, "%s", username(client)); 1994 1995 1995 1996 if (er->rc == E_FOUND||er->rc == E_CACHE1||er->rc == E_CACHE2) 1996 1997 checkCW(er); 1997 1998 1998 1999 struct s_reader *er_reader = er->selected_reader; //responding reader 1999 2000 if (!er_reader) er_reader = ll_has_elements(er->matching_rdr); //no reader? use first reader 2000 2001 2001 2002 if (er_reader) 2002 2003 { … … 2234 2235 } 2235 2236 break; 2236 2237 2237 2238 default: 2238 2239 for (i=0;i<CS_MAXCAIDTAB;i++) { … … 2323 2324 cl->account->cwtun++; 2324 2325 first_client->cwtun++; 2325 2326 2326 2327 cs_debug_mask(D_TRACE, "ECM converted from: 0x%X to BetaCrypt: 0x%X for service id:0x%X", 2327 2328 caidfrom, caidto, er->srvid); … … 2334 2335 struct s_client *cl = cur_client(); 2335 2336 uint32_t mask_all = 0xFFFF; 2336 2337 2337 2338 TUNTAB *ttab; 2338 2339 ttab = &cl->ttab; … … 2343 2344 for (n = 0; n<ttab->n; n++) { 2344 2345 if ((er->caid==ttab->bt_caidfrom[n]) && ((er->srvid==ttab->bt_srvid[n]) || (ttab->bt_srvid[n])==mask_all)) { 2345 2346 2346 2347 convert_to_beta(cl, er, ttab->bt_caidto[n]); 2347 2348 2348 2349 return; 2349 2350 } … … 3173 3174 pthread_attr_setstacksize(&attr, PTHREAD_STACK_SIZE); 3174 3175 #endif 3175 //We need memory here, because when on stack and we leave the function, stack is overwritten, 3176 //We need memory here, because when on stack and we leave the function, stack is overwritten, 3176 3177 //but assigned to the thread 3177 3178 //So alloc memory for the init data and free them in clientthread_init: 3178 struct s_clientinit *init = cs_malloc(&init, sizeof(struct s_clientinit), 0); 3179 struct s_clientinit *init = cs_malloc(&init, sizeof(struct s_clientinit), 0); 3179 3180 init->handler = ph[i].s_handler; 3180 3181 init->client = cl; … … 3224 3225 #endif 3225 3226 3226 //We need memory here, because when on stack and we leave the function, stack is overwritten, 3227 //We need memory here, because when on stack and we leave the function, stack is overwritten, 3227 3228 //but assigned to the thread 3228 3229 //So alloc memory for the init data and free them in clientthread_init: 3229 3230 struct s_clientinit *init = cs_malloc(&init, sizeof(struct s_clientinit), 0); 3230 3231 init->handler = ph[i].s_handler; 3231 init->client = cl; 3232 init->client = cl; 3232 3233 if (pthread_create(&cl->thread, &attr, clientthread_init, (void*) init)) { 3233 3234 cs_log("ERROR: can't create thread for TCP client from %s", inet_ntoa(*(struct in_addr *)&cad.sin_addr.s_addr));
Note:
See TracChangeset
for help on using the changeset viewer.