static int _mas_init_pid( mas_options_t * popts, const char *shash_name ) { EVAL_PREPARE; int r = 0; char *pidpath = NULL; r = 0; pidpath = mas_strdup( popts->dir.pids ); pidpath = mas_strcat_x( pidpath, shash_name ); r = cref( pidpath, popts->dir.pids ); if ( r == -999 ) r = cref( pidpath, popts->dir.pids ); HMSG( "(%d)PIDPATH 1 : %s", r, pidpath ); if ( r < 0 ) { r = 0; IEVAL( r, mas_open( pidpath, O_RDWR | O_EXCL, S_IWUSR | S_IRUSR ) ); } if ( r >= 0 ) { CTRL_PREPARE; ctrl.pidfd = r; { int er = 0; IEVALE( r, lockf( ctrl.pidfd, F_TLOCK, 0 ), &er ); HMSG( "(%d:%d)PIDLCK : %s - %s before", r, errno, pidpath, r < 0 && ( er == EACCES || er == EAGAIN ) ? "LOCKED" : "UNLOCKED" ); } if ( r >= 0 ) { ssize_t lb; char buf[64]; lb = snprintf( buf, sizeof( buf ), "%u", getpid( ) ); IEVAL( r, ftruncate( ctrl.pidfd, 0 ) ); IEVAL( r, write( ctrl.pidfd, buf, lb ) ); HMSG( "PIDWRT: %d pid:%u W:%ld", r, ctrl.threads.n.main.pid, lb ); ctrl.pidfilesv.c = mas_add_argv_arg_nodup( ctrl.pidfilesv.c, &ctrl.pidfilesv.v, pidpath ); pidpath = NULL; } else { if ( ctrl.pidfd >= 0 ) mas_close( ctrl.pidfd ); ctrl.pidfd = r; } } if ( pidpath ) mas_free( pidpath ); HMSG( "(%d)INIT PID", r ); return r; }
/* naming : cancel + join = stop */ int mas_ticker_stop( void ) { CTRL_PREPARE; int r = 0; if ( ctrl.threads.n.ticker.thread ) { WMSG( "CANCEL TICKER" ); MAS_LOG( "stopping (cancelling) ticker [%lx]", ctrl.threads.n.ticker.thread ); mas_pthread_cancel( ctrl.threads.n.ticker.thread ); mas_xpthread_join( ctrl.threads.n.ticker.thread ); /* mas_pthread_detach( ctrl.threads.n.ticker.thread ); */ mMSG( "JOINED ticker" ); MAS_LOG( "stopped ticker" ); ctrl.threads.n.ticker.thread = ( pthread_t ) 0; HMSG( "- TICKER" ); EMSG( "TICKER STOPPED" ); MFP( "\x1b]2;stopped ticker; mode:%d\x7", ctrl.ticker_mode ); } else { MAS_LOG( "ticker already cancelled" ); } return r; }
/*-------------------------------------------------------------------*/ int HelpMessage(char *msg) { char *help[][4] = { { HMSG(HHC01415), "This message displays the build data and time of the Hercules executables.", "Information.", "None." }, { NULL, NULL, NULL, NULL } }; int i; char id[9]; strlcpy(id, "HHC",sizeof(id)); strncpy(&id[3], &msg[3], 5); id[8] = 0; for(i = 0; help[i][0] && strncmp(help[i][0], id, 8); i++); if(help[i][0]) WRMSG(HHC00017, "I", help[i][0], help[i][1], help[i][2], help[i][3]); else WRMSG(HHC01607, "I", id); return(-1); }
static void mas_logger_clean_queue( void ) { CTRL_PREPARE; mas_loginfo_t *li = NULL; mas_loginfo_list_head_t *log_list; log_list = mas_logger_queue( 0 ); ctrl.keep_logging = 0; while ( log_list && !MAS_LIST_EMPTY( log_list ) && ( li = MAS_LIST_FIRST( log_list ) ) ) { #ifndef MAS_NO_THREADS /* mas_pthread_mutex_lock( &logger_queue_mutex ); */ pthread_rwlock_wrlock( &logger_queue_rwlock ); #endif MAS_LIST_REMOVE_HEAD( log_list, next ); ctrl.log_q_gone++; #ifndef MAS_NO_THREADS pthread_rwlock_unlock( &logger_queue_rwlock ); /* mas_pthread_mutex_unlock( &logger_queue_mutex ); */ #endif mas_logger_delete_loginfo( li ); } HMSG( "CLEARED logger queue : %d [%lu-%lu=%ld]", mas_logger_queue( 0 ) ? 1 : 0, ctrl.log_q_came, ctrl.log_q_gone, ctrl.log_q_came - ctrl.log_q_gone ); /* HMSG( "cleaned logger queue : %d [%lu-%lu=%ld]", mas_logger_queue( 0 ) ? 1 : 0, ctrl.log_q_came, ctrl.log_q_gone, */ /* ctrl.log_q_came - ctrl.log_q_gone ); */ }
static int mas_master_daemon_main( const mas_options_t * popts, int argc, char *argv[], char *env[] ) { EVAL_PREPARE; int r = 0; mas_control_t *this = &ctrl; MSTAGE( DAEMON ); HMSG( "BUNCH DO DAEMON" ); IEVAL( r, mas_master_main( popts ) ); #ifdef MAS_TRACEMEM { extern unsigned long memory_balance; mMSG( "bunch end, memory_balance:%lu - Ticker:%lx;Logger:%lx;", memory_balance, ctrl.threads.n.ticker.thread, ctrl.threads.n.logger.thread ); MAS_LOG( "bunch end, m/b:%lu", memory_balance ); # if 0 if ( print_memlist( FL, ctrl.stderrfile ) < 0 ) if ( print_memlist( FL, ctrl.old_stderrfile ) < 0 ) if ( print_memlist( FL, ctrl.msgfile ) < 0 ) print_memlist( FL, stderr ); # endif } #endif mas_thself_set_name( popts->thname.daemon_bunchx, "zocDaeBunchX" ); return r; }
static int cref( const char *pidpath, const char *dir ) { EVAL_PREPARE; int r = 0; /* mas_clear_last_error( ); */ YEVALM( r, mas_open( pidpath, O_CREAT | O_RDWR | O_EXCL, S_IWUSR | S_IRUSR ), "(%d) file:%s", pidpath ); if ( r < 0 ) { const mas_std_error_t *e; /* char errbuf[1024]; */ /* char *se = NULL; */ e = mas_get_last_error( ); if ( e ) { switch ( e->merrno ) { case ENOENT: r = 0; HMSG( "(%d)CREF - NO DIR : %s", r, pidpath ); IEVAL( r, mkdir( dir, S_IWUSR | S_IRUSR | S_IXUSR ) ); if ( r >= 0 ) r = -999; break; } /* se = strerror_r( e->merrno, errbuf, sizeof( errbuf ) ); */ /* HMSG( "(%d)CREF 1 : %s [errno:%d] %s", r, pidpath, e->merrno, se ); */ } } return r; }
void mas_atexit( void ) { CTRL_PREPARE; /* extern mas_options_t g_opts; */ extern mas_options_t *gpopts; { int rn = 0; char name_buffer[32] = "?"; IEVAL( rn, prctl( PR_GET_NAME, ( unsigned long ) name_buffer ) ); IEVAL( rn, prctl( PR_SET_NAME, ( unsigned long ) "zocMainAtexit" ) ); HMSG( "AT EXIT %s: logQ: %lu - %lu = %lu", name_buffer, ctrl.log_q_came, ctrl.log_q_gone, ctrl.log_q_came - ctrl.log_q_gone ); } mas_server_destroy( gpopts ); /* mas_server_destroy( MAS_PASS_OPTS_REF ); */ #ifdef MAS_TRACEMEM { extern unsigned long memory_balance; /* IMSG( "AT EXIT, memory_balance:%ld", memory_balance ); */ /* IMSG( "AT EXIT, memory_balance:%ld : logQ: %lu - %lu = %lu", memory_balance, ctrl.log_q_came, ctrl.log_q_gone, */ /* ctrl.log_q_came - ctrl.log_q_gone ); */ /* print_memlist_any( FL, 4, ctrl.stderrfile, ctrl.old_stderrfile, ctrl.msgfile, stderr ); */ print_memlist_any( FL, 4, ctrl.msgfile, ctrl.stderrfile, ctrl.old_stderrfile, stderr ); IMSG( "(1)AT EXIT, memory_balance:%ld : logQ: %lu - %lu = %lu", memory_balance, ctrl.log_q_came, ctrl.log_q_gone, ctrl.log_q_came - ctrl.log_q_gone ); } #else IMSG( "AT EXIT" ); #endif IMSG( "=====[%u @ %u]=================================================================", getpid( ), getppid( ) ); if ( ctrl.msgfile ) { IMSG( "CLOSE MSG" ); fclose( ctrl.msgfile ); ctrl.msgfile = NULL; } { extern unsigned long memory_balance; int rn = 0; char name_buffer[32] = "?"; IEVAL( rn, prctl( PR_GET_NAME, ( unsigned long ) name_buffer ) ); IEVAL( rn, prctl( PR_SET_NAME, ( unsigned long ) "zocMainAtexit" ) ); /* EMSG( "AT EXIT %s: logQ: %lu - %lu = %lu", name_buffer, ctrl.log_q_came, ctrl.log_q_gone, ctrl.log_q_came - ctrl.log_q_gone ); */ IMSG( "(2)AT EXIT, memory_balance:%ld : logQ: %lu - %lu = %lu", memory_balance, ctrl.log_q_came, ctrl.log_q_gone, ctrl.log_q_came - ctrl.log_q_gone ); } sync( ); /* sleep( 3 ); */ _exit( 0 ); /* exit_group( 0 ); */ }
static int mas_master_parent_main( const mas_options_t * popts, int argc, char *argv[], char *env[] ) { CTRL_PREPARE; mas_control_t *this = &ctrl; MSTAGE( PARENT ); HMSG( "PARENT to exit" ); mas_thself_set_name( popts->thname.parent_bunchx, "zocParBunchX" ); return 0; }
static int mas_master_bunch_main( const mas_options_t * popts, int argc, char *argv[], char *env[] ) { EVAL_PREPARE; int r = 0; mas_control_t *this = &ctrl; MSTAGE( BUNCH ); r = ctrl.is_parent ? mas_master_parent_main( popts, argc, argv, env ) : mas_master_daemon_main( popts, argc, argv, env ); HMSG( "BUNCH (%s) TO END", ctrl.is_parent ? "parent" : "daemon" ); return r; }
int mas_proto_main( mas_rcontrol_t * prcontrol, const void *place_holder ) { int r = 0; mas_http_t *http = NULL; /* const char *string = ( const char * ) place_holder; */ // GET / HTTP/1.1 // Host: mastarink.net:5002 // User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.11) Gecko/20100101 Firefox/10.0.11 // Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 // Accept-Language: uk,ru;q=0.8,en-us;q=0.5,en;q=0.3 // Accept-Encoding: gzip, deflate // DNT: 1 // Connection: keep-alive // Referer: http://mastarink.net:5003/ // If-None-Match: 26555b-fd-4aaaaa685c746 // /* * The Do Not Track (DNT) header */ HMSG( "HTTP main" ); /* MAS_LOG( "http?: to create rq :(%lu) %s", strlen( string ), string ); */ MAS_LOG( "http?: to create rq" ); http = mas_proto_http_create_request( prcontrol ); prcontrol->h.substatus = MAS_SUBSTATUS_INIT; MAS_LOG( "http?: to parse rq" ); if ( http ) http = mas_proto_http_parse_request( prcontrol, http ); MAS_LOG( "http?: parsed rq : %s", prcontrol->proto_desc ? prcontrol->proto_desc->name : "?" ); if ( http ) r = mas_proto_make( prcontrol, http ); HMSG( "HTTP r:%d", r ); prcontrol->h.substatus = MAS_SUBSTATUS_END; return r; }
mas_content_type_t mas_unidata_parse_content_type( const char *ct ) { const char *p; mas_content_type_t ict = MAS_CONTENT_BAD; p = ct; while ( p && *p && *p != '/' ) p++; HMSG( "UNIDATA parse ct 1 %s", ct ); if ( p && *p == '/' ) { char *c1 = NULL, *c2 = NULL; c1 = mas_strndup( ct, p - ct ); p++; if ( p && *p ) c2 = mas_strdup( p ); if ( c1 && c2 ) for ( int it = 0; it < sizeof( content_types ) / sizeof( content_types[0] ); it++ ) { HMSG( "UNIDATA parse ct 2 %s ? %s :: %s ? %s", content_types[it].mtype, c1, content_types[it].dtype, c2 ); if ( 0 == strcmp( content_types[it].mtype, c1 ) && 0 == strcmp( content_types[it].dtype, c2 ) ) { ict = content_types[it].ctype; HMSG( "UNIDATA found #%d : %d", it, ict ); break; } } if ( c2 ) mas_free( c2 ); if ( c1 ) mas_free( c1 ); } HMSG( "UNIDATA return %d", ict ); return ict; }
int mas_master_bunch( mas_options_t * popts, int argc, char *argv[], char *env[] ) { EVAL_PREPARE; int r = 0; IEVAL( r, mas_master_bunch_create( popts, argc, argv, env ) ); IEVAL( r, mas_master_bunch_main( popts, argc, argv, env ) ); mas_master_bunch_destroy( ); WMSG( "BUNCH END DATA master:[%lx] log:[%lx] t[%lx] w[%lx] %d", ctrl.threads.n.master.thread, ctrl.threads.n.logger.thread, ctrl.threads.n.ticker.thread, ctrl.threads.n.watcher.thread, ctrl.lcontrols_list ? 1 : 0 ); HMSG( "BUNCH (%s) END", ctrl.is_parent ? "parent" : "daemon" ); return r; }
/* naming : pthread_create = start */ int mas_ticker_start( const mas_options_t * popts ) { CTRL_PREPARE; /* EVAL_PREPARE; */ int r = 0; MFP( "\x1b]2;starting ticker; mode:%d\x7", ctrl.ticker_mode ); if ( !ctrl.threads.n.ticker.thread ) { { ( void ) /* r = */ pthread_attr_getstack( &ctrl.thglob.ticker_attr, &ticker_stackaddr, &ticker_stacksize ); tMSG( "creating ticker thread stack:%lu @ %p", ( unsigned long ) ticker_stacksize, ticker_stackaddr ); HMSG( "+ TICKER mode %d", ctrl.ticker_mode ); } /* if ( !tmp ) */ /* tmp = mas_malloc( 4321 ); */ MAS_LOG( "starting ticker th." ); /* r = mas_xpthread_create( &ctrl.threads.n.ticker.thread, mas_ticker_th, MAS_THREAD_TICKER, NULL ); */ r = pthread_create( &ctrl.threads.n.ticker.thread, &ctrl.thglob.ticker_attr, mas_ticker_th, NULL ); #ifdef SCHED_IDLE { int policy, rs; struct sched_param sched; rs = pthread_getschedparam( ctrl.threads.n.ticker.thread, &policy, &sched ); /* SCHED_IDLE ... SCHED_RR */ rs = pthread_setschedparam( ctrl.threads.n.ticker.thread, SCHED_IDLE, &sched ); /* rs = pthread_getschedparam( ctrl.threads.n.ticker.thread, &policy, &sched ); */ MAS_LOG( "(%d) created(?) ticker thread [%lx] %d - %d (%d)", r, ctrl.threads.n.ticker.thread, policy, sched.sched_priority, rs ); tMSG( "(%d) created(?) ticker thread [%lx] %d - %d (%d)", r, ctrl.threads.n.ticker.thread, policy, sched.sched_priority, rs ); } #else MAS_LOG( "(%d) created(?) ticker thread [%lx]", r, ctrl.threads.n.ticker.thread ); #endif } else { MAS_LOG( "running w/o ticker th." ); } return r; }
int resource_simulation(xsim_node_t *node, xsim_msg_list_t **NIC_msg_list_output, sim_time *next_time_for_resource) { if (work > 0) { xsim_msg_t *msg = xsim_msg_new(); int target; do { target = rand()%(node->nb_nodes); } while (target == (int) node->node_id); xsim_targets_set(&msg->targets, target); msg->stamp_time = node->current_time; memset(msg->payload, 1, sizeof(uint8_t)*XSIM_MAX_PAYLOAD); msg->size = (rand() % MEAN_PACKET_SIZE) + 1;//XSIM_MAX_PAYLOAD) + 1; msg->type = xsim_has_payload; int send_iface = rand() % node->nb_iface; msg->x_id = send_iface; DMSG("[%d] (%03llu t) try to send a message on iface %d to node %d with size %"PRIu32"!\n", node->node_id, (unsigned long long ) node->current_time, send_iface, target, msg->size); xsim_msg_list_add(NIC_msg_list_output[send_iface], msg); node->iface[send_iface]->msg_send = 1; sim_time jump = 1; do { jump = poisson_generator_knuth(LAMBDA); } while (jump <= 0); *next_time_for_resource = node->current_time + jump; HMSG("[%d] Next time for resource: %llu t\n", node->node_id, *next_time_for_resource); work = 0; } return work; }
void avl_balance(avl_tree_t **root){ HMSG("balance() ... \n"); switch( (*root)->flags ){ case AVL_FLAGS_LEFT_UNBAL: { avl_tree_t *left_root = (*root)->left; switch(left_root->flags){ case AVL_FLAGS_BALANCED: IMSG("Balanced sub-tree\n"); break; case AVL_FLAGS_LEFT_HEAVY: /* Nothing to do ... */ HMSG("LEFT LEFT\n"); break; case AVL_FLAGS_RIGHT_HEAVY: HMSG("LEFT RIGHT\n"); avl_left_rotate( &((*root)->left)); break; case AVL_FLAGS_LEFT_UNBAL: case AVL_FLAGS_RIGHT_UNBAL: EMSG("Unbalanced sub-tree !!!\n"); break; default: EMSG("Inconsistent Flags\n"); } avl_right_rotate(root); } break; case AVL_FLAGS_RIGHT_UNBAL: { avl_tree_t *right_root = (*root)->right; switch(right_root->flags){ case AVL_FLAGS_BALANCED: IMSG("Balanced sub-tree\n"); break; case AVL_FLAGS_LEFT_HEAVY: HMSG("RIGHT LEFT\n"); avl_right_rotate( &((*root)->right)); break; case AVL_FLAGS_RIGHT_HEAVY: /* Nothing to do ... */ HMSG("RIGHT RIGHT\n"); break; case AVL_FLAGS_LEFT_UNBAL: case AVL_FLAGS_RIGHT_UNBAL: EMSG("Unbalanced sub-tree !!!\n"); break; default: EMSG("Inconsistent Flags\n"); } avl_left_rotate(root); } break; case AVL_FLAGS_BALANCED: case AVL_FLAGS_LEFT_HEAVY: case AVL_FLAGS_RIGHT_HEAVY: EMSG("useless call of avl_balance()\n"); break; default: EMSG("Inconsistent Flags\n"); } }
static int mas_master_bunch_create( mas_options_t * popts, int argc, char *argv[], char *env[] ) { EVAL_PREPARE; int r = 0, rn = 0; mas_control_t *this = &ctrl; HMSG( "BUNCH CREATE e:%d", errno ); MAS_LOG( "bunch start e:%d", errno ); MSTAGE( BUNCH_CREATE ); IEVAL( rn, mas_thself_set_name( ctrl.is_parent ? popts->thname.parent_bunchi : popts->thname.daemon_bunchi, ctrl.is_parent ? "zocParBunchI" : "zocDaeBunchI" ) ); MAS_LOG( "(%d) bunch: to init +", r ); #if 0 /* r = mas_init_plus( argc, argv, env, mas_pids_init, mas_daemon_init, mas_threads_init, mas_init_load_protos, mas_lcontrols_list_create, */ /* NULL ); */ /* uuid BEFORE opt_files !! */ IEVAL( r, mas_init_plus( popts, argc, argv, env, mas_proc_init, mas_uuid_init, mas_init_opt_files, mas_sig_init, mas_cli_options_init, mas_ctrl_init, mas_init_set_msg_file, mas_message_init, mas_daemon_init, mas_pids_init, mas_threads_init, mas_init_load_protos, mas_lcontrols_init, mas_post_init, NULL ) ); #else /* INIT_HANDLER's */ static mas_init_fun_t init_funcs[] = { /* Moved to mas_control.c constructor */ /* mas_proc_init, */ mas_opt_files_init, mas_cliopts_data_init, mas_cliopts_argv_init, mas_cliopts_init, mas_ctrl_init, mas_msg_file_init, mas_message_init, mas_sig_init, mas_daemon_init, mas_pids_init, mas_threads_init, mas_protos_init, mas_lcontrols_init, mas_uuid_init, mas_post_init, NULL }; # if 0 { for ( int i = 0; i < argc; i++ ) { HMSG( "argv[%d]='%s'", i, argv[i] ); } } # endif HMSG( "INIT+ %s : %s", ctrl.is_server ? "SERVER" : "CLIENT", !ctrl.is_client ? "SERVER" : "CLIENT" ); IEVAL( r, mas_init( popts, argc, argv, env ) ); // IEVAL( r, mas_init_set_n( popts, /* argc, argv, env, */ sizeof( init_funcs ) / sizeof( init_funcs[0] ), init_funcs ) ); HMSG( "INIT SET Z" ); IEVAL( r, mas_init_set_z( popts, /* argc, argv, env, */ init_funcs ) ); #endif if ( r >= 0 ) { IEVAL( rn, mas_thself_set_name( ctrl.is_parent ? popts->thname.parent_bunchm : popts->thname.daemon_bunchm, ctrl.is_parent ? "zocParBunch" : "zocDaeBunch" ) ); } MAS_LOG( "(%d) bunch: init + done", r ); return r; }
static void http_destructor( void ) { HMSG( "DESTRUCTOR proto http" ); if ( proto_variables ) mas_variables_delete( proto_variables ); }
static int mas_proto_make( mas_rcontrol_t * prcontrol, mas_http_t * http ) { int r = -1; prcontrol->h.substatus = MAS_SUBSTATUS_MAKE; prcontrol->h.subpoint = __LINE__; MAS_LOG( "http: to make docroot" ); if ( http ) mas_http_make_docroot( prcontrol, http ); prcontrol->h.subpoint = __LINE__; if ( http ) { HMSG( "HTTP make URL %s", http->URI ); if ( http->URI ) { #ifdef MAS_HTTP_USE_FILEINFO if ( 0 == strncmp( http->URI, "/xcromas/", 9 ) ) { prcontrol->h.subpoint = __LINE__; HMSG( "HTTP make /xcromas" ); MAS_LOG( "HTTP make /xcromas" ); http->reply_content = mas_fileinfo_init( http->reply_content, http->docroot, http->URI, mas_evaluate_command_slash_plus, ( const void * ) prcontrol ); MAS_LOG( "HTTP 1 make /xcromas" ); mas_fileinfo_set_icontent_type( http->reply_content, MAS_CONTENT_TEXT ); MAS_LOG( "HTTP / make /xcromas" ); } else #endif { prcontrol->h.subpoint = __LINE__; MAS_LOG( "HTTP make at docroot" ); /* TODO : sendfile ; replace fileinfo with autoobject lib */ #ifdef MAS_HTTP_USE_FILEINFO http->reply_content = mas_fileinfo_init( http->reply_content, http->docroot, http->URI, mas_load_filename_at_fd, ( const void * ) NULL /* prcontrol */ ); #elif defined( MAS_HTTP_USE_AUTOOBJECT ) /* mas_autoobject_set_icontent_type( http->reply_content, MAS_CONTENT_TEXT ); */ http->reply_content = mas_lcontrol_get_autoobject( prcontrol->plcontrol, http->docroot, http->URI ); #endif MAS_LOG( "HTTP / make at docroot" ); } } } prcontrol->h.subpoint = __LINE__; MAS_LOG( "http: protocol-specific" ); if ( http ) switch ( http->imethod ) { case MAS_HTTP_METHOD_BAD: case MAS_HTTP_METHOD_NONE: /* Not HTTP */ mas_proto_http_delete_request( http ); http = NULL; break; case MAS_HTTP_METHOD_PUT: case MAS_HTTP_METHOD_UNKNOWN: http->status_code = MAS_HTTP_CODE_NOT_IMPLEMENTED; http = mas_http_make_out_header( http, "Title", "%d %s", http->status_code, mas_http_status_code_message( prcontrol, http ) ); http = mas_http_make_out_header_simple( http, "Allow", "GET,HEAD,OPTIONS" ); http = mas_http_make_data_auto( prcontrol, http ); /* http = mas_http_make_body_simple( prcontrol, http ); */ break; case MAS_HTTP_METHOD_OPTIONS: http->status_code = MAS_HTTP_CODE_OK; http = mas_http_make_out_header_simple( http, "Allow", "GET,HEAD,OPTIONS" ); break; case MAS_HTTP_METHOD_GET: case MAS_HTTP_METHOD_HEAD: case MAS_HTTP_METHOD_POST: MAS_LOG( "http: get/head/post" ); break; } prcontrol->h.subpoint = __LINE__; /* if ( http ) */ /* http = mas_http_make_out_std_headers( prcontrol, http ); */ /* if ( http && http->status_code == MAS_HTTP_CODE_NONE ) */ /* { */ /* if ( http->reply_content && http->reply_content->filesize ) */ /* http->status_code = MAS_HTTP_CODE_OK; */ /* else */ /* http->status_code = MAS_HTTP_CODE_NOT_FOUND; */ /* } */ if ( http ) http = mas_http_reply( prcontrol, http ); prcontrol->h.substatus = MAS_SUBSTATUS_MAKE; prcontrol->h.subpoint = __LINE__; HMSG( "WRITTEN %lu", http ? http->written : 0 ); MAS_LOG( "WRITTEN %lu", http ? http->written : 0 ); r = http ? 1 : 0; if ( http ) mas_proto_http_delete_request( http ); prcontrol->h.subpoint = __LINE__; prcontrol->h.subresult1 = http->written_header; prcontrol->h.subresult2 = http->written_body; return r; }
static void http_constructor( void ) { HMSG( "CONSTRUCTOR proto http" ); ( void ) _mas_opts_restore_relative( mas_options_t * popts, "proto/http.conf", NULL /*popts */ , opt_table, sizeof( opt_table ) / sizeof( opt_table[0] ), NULL, NULL, NULL, NULL /* arg */ ); }
mas_evaluated_t * _mas_evaluate_cmd( STD_CMD_ARGS, const char *modpath ) { int r = 0; mas_evaluated_t *answer = NULL; /* char *sanswer = NULL; */ if ( prcontrol ) { prcontrol->qbin = MSG_BIN_NONE; if ( !pqopts ) pqopts = prcontrol->plcontrol->popts; } /* if ( !modpath ) */ /* modpath = ( pqopts ? pqopts->dir.mods : NULL ); */ MAS_LOG( "evaluate: cmd %p", ( void * ) this_command ); if ( this_command ) { WMSG( "EVAL %s", this_command->name ); } else { this_command = &root_command; MAS_LOG( "evaluate: ROOT %s cmd %p subtab:%p", this_command ? this_command->name : NULL, ( void * ) this_command, ( void * ) this_command->subtable ); WMSG( "EVAL ROOT %s", this_command->name ); } if ( this_command ) { MAS_LOG( "evaluate: '%s' args: '%s' cmd:%p", this_command->name, args, ( void * ) ( unsigned long ) this_command ); /* missing function ptr (this_command->function): */ fprintf( stderr, ">>>>>> %d:%s\n", __LINE__, __FILE__ ); if ( !this_command->function && this_command->name && *( this_command->name ) ) { MAS_LOG( "{%p} must set fun/sbt for module %s.%s : %d : %p", ( void * ) this_command, this_command->libname, this_command->name, this_command->function ? 1 : 0, ( void * ) this_command->subtable ); r = _missing_funsetup( this_command, level, modpath ); MAS_LOG( "evaluate : missing function - '%s' args: '%s'", this_command->name, args ); } fprintf( stderr, ">>>>>> %d:%s\n", __LINE__, __FILE__ ); tMSG( "(%d) function:%d", r, this_command->function ? 1 : 0 ); if ( r >= 0 && this_command->function ) { tMSG( "eval %d. %s : %d : %d", this_command->id, this_command->name, this_command->function ? 1 : 0, this_command->function == _universal_complex_cmd ); /* EVALUATING COMMAND */ HMSG( "EVAL %s", this_command->name ); fprintf( stderr, ">>>>>> %d:%s\n", __LINE__, __FILE__ ); answer = ( this_command->function ) ( STD_CMD_PASS ); /* tMSG( "eval'd A(%s) B(%d)", answer ? ( answer == ( char * ) -1L ? "-" : answer ) : NULL, prcontrol ? prcontrol->qbin : 0 ); */ HMSG( "QUIT (%s)", this_command->name ); } else { fprintf( stderr, ">>>>>> %d:%s - no function\n", __LINE__, __FILE__ ); } { FILE *file = NULL; size_t sz = 0; /* switch ( this_command->evaluate_type ) */ switch ( answer ? answer->type : this_command->evaluate_type ) { case MAS_CMD_PCHAR: break; case MAS_CMD_CONST_PCHAR: /* ??????? */ if ( !( MAS_VALID_ANSWER( answer ) ) ) answer->data = mas_strdup( ( char * ) answer->data ); break; case MAS_CMD_CONST_FNAME_LOAD: { char *fname; fname = answer ? answer->data : mas_strdup( ( char * ) this_command->vid ); answer->data = mas_load_filename_fd( fname, 0, &sz, NULL, NULL, NULL ); mas_free( fname ); } break; case MAS_CMD_FILE_LOAD: file = ( FILE * ) args; if ( file ) answer->data = mas_load_file( file, 0, &sz, NULL, NULL, NULL ); break; } if ( file ) fclose( file ); if ( MAS_VALID_ANSWER( answer ) ) { /* cMSG( "answer for %s : %s", this_command->name, level == 1 ? answer : "SKIPPED" ); */ MAS_LOG( "(lev.%d) evaluated: %s(%s); answer: '%s'", level, this_command->name, args, level == 1 ? ( const char * ) answer->data : "SKIPPED" ); } else if ( !this_command->function ) { EMSG( "no function (cmd id=%d; cmdname='%s') libname:'%s'", this_command->id, this_command->name, this_command->libname ); MAS_LOG( "no function (cmd id=%d; cmdname='%s') libname:'%s'", this_command->id, this_command->name, this_command->libname ); if ( answer ) answer->data = MAS_INVALID_ANSWER; } } } else { fprintf( stderr, ">>>>>> %d:%s\n", __LINE__, __FILE__ ); } return answer; }
static int _missing_funsetup( mas_cmd_t * pcommand, unsigned level, const char *modpath ) { int r = -1; if ( pcommand ) { const char *libname; const char *name; mas_cmd_fun_t cmd_fun = NULL; mas_cmd_t *loaded_subtable = NULL; name = pcommand->name; libname = pcommand->libname; HMSG( "MISSING FUNC for %s [sub:%d]", name, pcommand->subtable ? 1 : 0 ); if ( !libname ) { HMSG( "LIB by CMD %s", name ); libname = name; name = ""; } MAS_LOG( "to look for module %s.%s : %d", libname, name, pcommand->function ? 1 : 0 ); tMSG( "to look for module %s : %s", libname, name ); { HMSG( "CMD NAME %s.%s L%d", libname, name, level ); if ( name && *name ) { } { /* char *full_libname = NULL; */ /* */ /* full_libname = mas_strdup( "mas_cmdmod_" ); */ /* tMSG( "lib %s + %s", full_libname, libname ); */ /* MAS_LOG( "lib %s + %s", full_libname, libname ); */ /* full_libname = mas_strcat_x( full_libname, libname ); */ if ( 0 && name && *name ) { char *full_fun_name = NULL; MAS_LOG( "loading func. %s:%s (%s)", libname, full_fun_name, modpath ); /* cmd_fun = _load_cmd_func( pqopts, libname, full_fun_name, modpath ); */ cmd_fun = __load_cmd_func( libname, full_fun_name, modpath ); mas_free( full_fun_name ); } if ( !cmd_fun ) { /* load dl.symbol "subcmdtable" from library `libname`; look at `modpath` */ loaded_subtable = _load_subtable_from( libname, modpath ); if ( loaded_subtable ) { cmd_fun = _universal_complex_cmd; WMSG( "SET UNI for %s", name ); MAS_LOG( "universal command for %s {%p}", libname, ( void * ) ( unsigned long ) cmd_fun ); tMSG( "universal command for %s.%s", libname, name ); } else { EMSG( "No subtable at %s.%s ( modpath: '%s' )", libname, name, modpath ); } } /* mas_free( full_libname ); */ } } tMSG( "cmd_fun:%d", cmd_fun ? 1 : 0 ); if ( cmd_fun ) { if ( pcommand ) { pcommand->function = cmd_fun; pcommand->subtable = loaded_subtable; /* MAS_LOG( "cmd_fun:%p ; subtable:%p", ( void * ) ( unsigned long ) cmd_fun, ( void * ) loaded_subtable ); */ MAS_LOG( "{%p} set fun/sbt for module %s.%s : %d : %p", ( void * ) pcommand, libname, name, pcommand->function ? 1 : 0, ( void * ) pcommand->subtable ); r = 0; } } else if ( pcommand ) { EMSG( "no function (cmd id=%d; cmdname='%s') libname:'%s'", pcommand->id, name, libname ); MAS_LOG( "no function (cmd id=%d; cmdname='%s') libname:'%s'", pcommand->id, name, libname ); r = -1; } } return r; }
int mas_master_core( const mas_options_t * popts ) { CTRL_PREPARE; int r = 0, rn = 0; mas_control_t *this = &ctrl; MSTAGE( CORE ); HMSG( "MASTER START : pid:%u %c%c%c", getpid( ), OPT_QFLAG( popts, log_run ) ? 'L' : 'l', !OPT_QFLAG( popts, woticker ) ? 'T' : 't', !OPT_QFLAG( popts, wowatcher ) ? 'W' : 'w' ); MAS_LOG( "to start spec. threads" ); if ( OPT_QFLAG( popts, log_run ) ) { HMSG( "LOGGER TO START" ); mas_logger_start( ); } else { HMSG( "NO LOGGER" ); } if ( !OPT_QFLAG( popts, woticker ) ) { HMSG( "TICKER TO START" ); mas_ticker_start( popts ); } else { MAS_LOG( "running w/o ticker" ); HMSG( "NO TICKER" ); } if ( OPT_QFLAG( popts, wowatcher ) ) { HMSG( "WATCHER TO START" ); mas_watcher_start( popts ); } else { MAS_LOG( "running w/o watcher" ); HMSG( "NO WATCHER" ); } if ( popts->womaster ) { HMSG( "NO MASTER" ); sleep( popts->womaster ); } else if ( popts->wolistener ) { MAS_LOG( "stopped run w/o listeners" ); sleep( popts->wolistener ); } else { if ( popts->hostsv.c > 0 && popts->hostsv.v ) { HMSG( "TO MASTER LOOP r:%d; ctrl.keep_listening:%d; ctrl.fatal:%d; flag-quit:%d", r, ctrl.keep_listening, ctrl.fatal, OPT_QFLAG( popts, quit ) ); while ( r >= 0 && ctrl.keep_listening && !ctrl.fatal && !OPT_QFLAG( popts, quit ) ) r = mas_listeners_main( popts ); thMSG( "just out of server main loop" ); MAS_LOG( "just out of server main loop" ); } else { HMSG( "MASTER C.3" ); EMSG( "hosts not defined" ); MAS_LOG( "hosts not defined" ); } } HMSG( "MASTER D" ); if ( popts->exitsleep ) sleep( popts->exitsleep ); MAS_LOG( "to stop spec. threads" ); WMSG( "TO STOP LOGGER" ); mas_logger_stop( ); WMSG( "TO STOP TICKER" ); mas_ticker_stop( ); MAS_LOG( "stopped spec. threads" ); /* mas_watcher_stop( ); */ ctrl.watcher_stop = 1; MAS_LOG( "exiting master server" ); HMSG( "MASTER TO END : %d", r ); { EVAL_PREPARE; /* Set the name of the calling thread, using the value in the location pointed to by (char *) arg2. The name can be up to 16 bytes long, and should be null-terminated if it contains fewer bytes. This is the same attribute that can be set via pthread_setname_np(3) and retrieved using pthread_getname_np(3). The attribute is likewise accessible via /proc/self/task/[tid]/comm, where tid is the name of the calling thread. */ IEVAL( rn, mas_thself_set_name( ctrl.is_parent ? popts->thname.parent_masterx : popts->thname.daemon_masterx, "zocMasterX" ) ); } return r; }