- Timestamp:
- Feb 3, 2015, 6:38:21 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PublicaMundi_David-devel/zoo-project/zoo-kernel/zoo_loader.c
r549 r553 62 62 #include <glib.h> 63 63 #include <sys/stat.h> 64 #include <ctype.h> 65 64 66 } 65 67 … … 476 478 main (int argc, char *argv[]) 477 479 { 478 maps *main_config; 479 int max_requests, start_servers; 480 start_servers = 10; 481 max_requests= 100; 482 main_config = (maps *) malloc (MAP_SIZE); 483 conf_read ("main.cfg", main_config); 484 char ntmp[1024]; 485 #ifndef WIN32 486 getcwd (ntmp, 1024); 487 #else 488 _getcwd (ntmp, 1024); 489 #endif 490 char *rootDir = "/var/www/zoo-wps/cgi-bin"; 480 481 482 int debug_flag = 0; 483 int background_flag = 0; 484 char *file_value = NULL; 485 int index; 486 int c; 487 488 opterr = 0; 489 while ((c = getopt (argc, argv, "dbhf:")) != -1) 490 switch (c) 491 { 492 case 'd': 493 debug_flag = 1; 494 break; 495 case 'b': 496 background_flag = 1; 497 break; 498 case 'h': 499 fprintf(stderr,"TODO: need to print help\n"); 500 fflush(stderr); 501 return 0; 502 case 'f': 503 file_value = optarg; 504 break; 505 case '?': 506 if (optopt == 'f') 507 fprintf (stderr, "Option -%c requires an argument.\n", optopt); 508 else if (isprint (optopt)) 509 fprintf (stderr, "Unknown option `-%c'.\n", optopt); 510 else 511 fprintf (stderr,"Unknown option character `\\x%x'.\n",optopt); 512 return 1; 513 default: 514 abort (); 515 } 516 517 518 maps *conf; 519 conf = (maps *) malloc (MAPS_SIZE); 520 521 int ret = conf_read (file_value, conf); 522 if ( ret == 2){ 523 //a verifier mais conf_read ne renvoie jamais 0 524 fprintf(stderr,"Erreur lors de la lecture de %s\n",file_value); 525 return 1; 526 } 527 528 char *rootDir; 529 map *m_rootDir = getMapFromMaps (conf, "server", "rootDir"); 530 if (m_rootDir == NULL){ 531 fprintf(stderr,"Configuration error: rootDir"); 532 return 2; 533 } 534 else { 535 rootDir = (char*)malloc((strlen(m_rootDir->value) +1)*sizeof(char*)); 536 strncpy(rootDir,m_rootDir->value,strlen(m_rootDir->value)); 537 rootDir[strlen(m_rootDir->value)] = '\0'; 538 //freeMap(&m_rootDir); 539 } 540 541 int req_worker; 542 map *m_req_worker = getMapFromMaps (conf, "server", "req_worker"); 543 if (m_req_worker == NULL){ 544 fprintf(stderr,"Configuration error: req_worker not found"); 545 return 2; 546 } 547 else { 548 req_worker=atoi(m_req_worker->value); 549 //freeMap(&m_req_worker); 550 if (req_worker == 0){ 551 fprintf(stderr,"Configuration error: req_worker"); 552 return 2; 553 } 554 } 555 556 int async_worker; 557 map *m_async_worker = getMapFromMaps (conf, "server", "async_worker"); 558 if (m_async_worker == NULL){ 559 fprintf(stderr,"Configuration error: async_worker not found"); 560 return 2; 561 } 562 else { 563 async_worker = atoi(m_async_worker->value); 564 //freeMap(&m_async_worker); 565 if (async_worker == 0){ 566 fprintf(stderr,"Configuration error: req_worker"); 567 return 2; 568 } 569 } 570 571 int max_requests; 572 map *m_max_requests = getMapFromMaps (conf, "server", "max_requests"); 573 if (m_max_requests == NULL){ 574 fprintf(stderr,"Configuration error: max_requests"); 575 return 2; 576 } 577 else { 578 max_requests = atoi(m_max_requests->value); 579 //freeMap(&m_max_requests); 580 if (max_requests == 0){ 581 fprintf(stderr,"Configuration error: max_requests"); 582 return 2; 583 } 584 } 585 586 map *m_listen = getMapFromMaps (conf, "server", "listen"); 587 char *listen; 588 if (m_listen == NULL){ 589 fprintf(stderr,"Configuration error: listen not found"); 590 return 2; 591 } 592 else { 593 listen = (char *)malloc((strlen(m_listen->value) +1)*sizeof(char*)); 594 strncpy(listen,m_listen->value,strlen(m_listen->value)); 595 listen[strlen(m_listen->value)] = '\0'; 596 //freeMap(&m_listen); 597 } 598 int listen_owner; 599 map *m_listen_owner = getMapFromMaps (conf, "server", "listen_owner"); 600 if (m_listen_owner == NULL){ 601 fprintf(stderr,"Configuration error: listen_owner"); 602 return 2; 603 } 604 else { 605 listen_owner = atoi(m_listen_owner->value); 606 //freeMap(&m_listen_owner); 607 if (listen_owner == 0){ 608 fprintf(stderr,"Configuration error: listen_owner"); 609 return 2; 610 } 611 } 612 613 int listen_group; 614 map *m_listen_group = getMapFromMaps (conf, "server", "listen_group"); 615 if (m_listen_group == NULL){ 616 fprintf(stderr,"Configuration error: listen_group"); 617 return 2; 618 } 619 else { 620 listen_group = atoi(m_listen_group->value); 621 //freeMap(&m_listen_group); 622 if (listen_group == 0){ 623 fprintf(stderr,"Configuration error: listen_group"); 624 return 2; 625 } 626 } 627 628 char * listen_mode; 629 map *m_listen_mode = getMapFromMaps (conf, "server", "listen_mode"); 630 if (m_listen_mode == NULL){ 631 fprintf(stderr,"Configuration error: listen_mode"); 632 return 2; 633 } 634 else { 635 listen_mode = (char *)malloc((strlen(m_listen_mode->value) +1)*sizeof(char*)); 636 strncpy(listen_mode,m_listen_mode->value,strlen(m_listen_mode->value)); 637 listen_mode[strlen(m_listen_mode->value)] = '\0'; 638 //freeMap(&m_listen_mode); 639 } 640 641 int listen_queue; 642 map *m_listen_queue = getMapFromMaps (conf, "server", "listen_queue"); 643 if (m_listen_queue == NULL){ 644 fprintf(stderr,"Configuration error: listen_queue"); 645 return 2; 646 } 647 else { 648 listen_queue = atoi(m_listen_queue->value); 649 //freeMap(&m_listen_queue); 650 if (listen_queue == 0){ 651 fprintf(stderr,"Configuration error: listen_queue"); 652 return 2; 653 } 654 } 655 656 int id_user; 657 map *m_user = getMapFromMaps (conf, "server", "uid"); 658 if (m_user == NULL){ 659 fprintf(stderr,"Configuration error: id_user"); 660 return 2; 661 } 662 else { 663 id_user = atoi(m_user->value); 664 //freeMap(&m_user); 665 if (id_user == 0){ 666 fprintf(stderr,"Configuration error: id_user"); 667 return 2; 668 } 669 } 670 671 672 int id_group; 673 map *m_group = getMapFromMaps (conf, "server", "gid"); 674 if (m_group == NULL){ 675 fprintf(stderr,"Configuration error: gid"); 676 return 2; 677 } 678 else { 679 id_group = atoi(m_group->value); 680 //freeMap(&m_group); 681 if (id_group == 0){ 682 fprintf(stderr,"Configuration error: id_group"); 683 return 2; 684 } 685 } 686 687 int sock = FCGX_OpenSocket(listen, listen_queue); 688 init_services_conf (rootDir); 689 690 ret = chown(listen, listen_owner, listen_group); 691 if (ret != 0){ 692 fprintf(stderr,"Change owner error on : %s\n",listen); 693 return 3; 694 } 695 696 ret = setgid(id_group); 697 if (ret != 0){ 698 fprintf(stderr,"Change gid error\n"); 699 return 3; 700 } 701 702 ret = setuid(id_user); 703 if (ret != 0){ 704 fprintf(stderr,"Change uid error\n"); 705 return 3; 706 } 707 491 708 int fork_status = fork(); 492 709 if (fork_status == 0){ 493 710 //child 494 711 int forker_pid = getpid(); 495 init_services_conf (rootDir);496 int sock = FCGX_OpenSocket(PATH_SOCKET, 1000);497 712 FCGX_Init(); 498 713 FCGX_Request request; … … 500 715 int i; 501 716 int count_request = 0; 502 for (i = 0; i< start_servers; i++){717 for (i = 0; i< req_worker; i++){ 503 718 fork_status = fork(); 504 719 if (fork_status == 0){ … … 532 747 while(1); 533 748 534 535 536 749 } 537 750
Note: See TracChangeset
for help on using the changeset viewer.