Esempio n. 1
0
void
ssh_userauth2(const char *local_user, const char *server_user, char *host,
    Sensitive *sensitive)
{
	Authctxt authctxt;
	int type;

	if (options.challenge_response_authentication)
		options.kbd_interactive_authentication = 1;

	packet_start(SSH2_MSG_SERVICE_REQUEST);
	packet_put_cstring("ssh-userauth");
	packet_send();
	debug("SSH2_MSG_SERVICE_REQUEST sent");
	packet_write_wait();
	type = packet_read();
	if (type != SSH2_MSG_SERVICE_ACCEPT)
		fatal("Server denied authentication request: %d", type);
	if (packet_remaining() > 0) {
		char *reply = packet_get_string(NULL);
		debug2("service_accept: %s", reply);
		xfree(reply);
	} else {
		debug2("buggy server: service_accept w/o service");
	}
	packet_check_eom();
	debug("SSH2_MSG_SERVICE_ACCEPT received");

	if (options.preferred_authentications == NULL)
		options.preferred_authentications = authmethods_get();

	/* setup authentication context */
	memset(&authctxt, 0, sizeof(authctxt));
	authctxt.agent = ssh_get_authentication_connection();
	authctxt.server_user = server_user;
	authctxt.local_user = local_user;
	authctxt.host = host;
	authctxt.service = "ssh-connection";		/* service name */
	authctxt.success = 0;
	authctxt.method = authmethod_lookup("none");
	authctxt.authlist = NULL;
	authctxt.sensitive = sensitive;
	authctxt.info_req_seen = 0;
	if (authctxt.method == NULL)
		fatal("ssh_userauth2: internal error: cannot send userauth none request");

	/* initial userauth request */
	userauth_none(&authctxt);

	dispatch_init(&input_userauth_error);
	dispatch_set(SSH2_MSG_USERAUTH_SUCCESS, &input_userauth_success);
	dispatch_set(SSH2_MSG_USERAUTH_FAILURE, &input_userauth_failure);
	dispatch_set(SSH2_MSG_USERAUTH_BANNER, &input_userauth_banner);
	dispatch_run(DISPATCH_BLOCK, &authctxt.success, &authctxt);	/* loop until success */

	if (authctxt.agent != NULL)
		ssh_close_authentication_connection(authctxt.agent);

	debug("Authentication succeeded (%s).", authctxt.method->name);
}
Esempio n. 2
0
Authctxt *
do_authentication2(void)
{
	Authctxt *authctxt = authctxt_new();

	x_authctxt = authctxt;		/*XXX*/

#ifdef HAVE_BSM
	fatal_add_cleanup(audit_failed_login_cleanup, authctxt);
#endif /* HAVE_BSM */

	/* challenge-response is implemented via keyboard interactive */
	if (options.challenge_response_authentication)
		options.kbd_interactive_authentication = 1;
	if (options.pam_authentication_via_kbd_int)
		options.kbd_interactive_authentication = 1;
	if (use_privsep)
		options.pam_authentication_via_kbd_int = 0;

	dispatch_init(&dispatch_protocol_error);
	dispatch_set(SSH2_MSG_SERVICE_REQUEST, &input_service_request);
	dispatch_run(DISPATCH_BLOCK, &authctxt->success, authctxt);

	return (authctxt);
}
Esempio n. 3
0
/*
 * loop until authctxt->success == TRUE
 */
void
do_authentication2(Authctxt *authctxt)
{
	dispatch_init(&dispatch_protocol_error);
	dispatch_set(SSH2_MSG_SERVICE_REQUEST, &input_service_request);
	dispatch_run(DISPATCH_BLOCK, &authctxt->success, authctxt);
}
Esempio n. 4
0
int main(const int argc, const char **argv){

	if (argc < 3){

		std::cerr << "Error: too few arguments." << std::endl;
		return 1;

	}

	const int64_t SIZE 		  = std::stoull(argv[1]);
	const int64_t NUM_THREADS = std::stoull(argv[2]);

	if (SIZE < 10 || NUM_THREADS < 1){

		std::cerr << "Error: Invalid aruments " << SIZE << " and " << NUM_THREADS << std::endl;
		return 1;

	}

	dispatch_init();

	std::cout << "Creating matricies..." << std::endl;
	std::cout << "Size: " << SIZE << ", Threads: " << NUM_THREADS << std::endl;

	const double createStart = getRealTime();

	Matrix *mat1 = createMatrix(SIZE);
	Matrix *mat2 = createMatrix(SIZE);
	Matrix *mat3 = createMatrix(SIZE);

	initMatrix(mat1);
	initMatrix(mat2);

	const double createEnd = getRealTime();
	const double createElapsed = createEnd - createStart;

	std::cout << "Matricies created. Took " << createElapsed << " seconds." << std::endl;
	std::cout << "Multiplying..." << std::endl;

	const double multiplyStart = getRealTime();

	multiplyParallel(mat1, mat2, mat3, NUM_THREADS);

	const double multiplyEnd = getRealTime();
	const double multiplyElapsed = multiplyEnd - multiplyStart;
	
	std::cout << "Multiply finished. Took " << multiplyElapsed << " seconds." << std::endl;

	destroyMatrix(mat1);
	destroyMatrix(mat2);
	destroyMatrix(mat3);

	disaptch_release();
	return 0;

}
Esempio n. 5
0
/**
 * @brief Creates the main user program as a main task
 * and sets it to run.
 *
 * This function is only called when the user program is
 * first run.
 *
 */
void sched_init(task_t* main_task)
{
	main_task->lambda =    (void *)0xa0000000;
	main_task->data = 0;
	main_task->stack_pos = (void *)0xa3000000;
	main_task->C = 1;
	main_task->T = 1; 
	tcb_init(main_task, &system_tcb[FIRST_MAIN_PRIO], FIRST_MAIN_PRIO);
	runqueue_add(&system_tcb[FIRST_MAIN_PRIO], FIRST_MAIN_PRIO);
	dispatch_init(&system_tcb[FIRST_MAIN_PRIO]);
}
Esempio n. 6
0
void CPPLIB( exc_setup )        // SETUP DISPATCH, EXCEPTION RECORDS
    ( DISPATCH_EXC* disp        // - dispatch record
    , THROW_RO* throw_ro        // - throw r/o block
    , rboolean is_zero          // - true ==> thrown object is zero constant
    , _RTCTL* rt_ctl            // - R/T control
    , void* object              // - thrown object
    , FsExcRec* rec )           // - exception record
{
    dispatch_init( disp, throw_ro, is_zero, rt_ctl );
    initFsExcRec( object, rec, disp );
}
Esempio n. 7
0
void register_cmd_internal(void) {
  dispatch_init(&internal);
  LVal cmds=0;
  cmds=add_command(cmds,"tar"     ,NULL,cmd_tar,0,1);
  cmds=add_command(cmds,"download",NULL,cmd_download,0,1);
  cmds=add_command(cmds,"uname",NULL,cmd_uname,0,1);
  cmds=add_command(cmds,"which",NULL,cmd_which,0,1);
  cmds=add_command(cmds,"impl",NULL,cmd_impl,0,1);
  cmds=add_command(cmds,"version",NULL,cmd_internal_version,0,1);
  cmds=add_command(cmds,"core-extention",NULL,cmd_internal_core_extention,0,1);
  internal.command=cmds;
}
Esempio n. 8
0
int main(void)
{
		bsp_init();
    dispatch_init();
    on_ready();
    while(1)
  	 {
        HCI_Process();
        dispatch();
			  loop();
    }
}
Esempio n. 9
0
/**@brief Function for the application main entry.
 */
int main(void)
{
  uint32_t err_code;

  load_app();
  gpio_init();
  ble_stack_init();
  device_manager_init();

  juma_init();
  
  // initialize Bluetooth Stack parameters.
  gap_params_init();
  advertising_init();
  services_init();
  dispatch_init();

  flash_init();
  
  if (app) {
			device_current_statue_set(DEVICE_STATUE_APP);
      data_storage_init();
      on_ready();
  } else {
			device_current_statue_set(DEVICE_STATUE_OTA);
      ble_device_set_name("OTA Mode");
      ota_init();
      ble_device_set_advertising_interval(200);
      ble_device_start_advertising();
  }
  
  // Enter main loop.
  for (;;)
  {
      watchDog_sys_SDK_dog1_RR();
    
      if(0 != enter_ota_mode_statue)
      {
        enter_ota_process(NULL);
      }
      else
      {
        dispatch();
      }
      
      serial_get();
      // Switch to a low power state until an event is available for the application
      err_code = sd_app_evt_wait();
      APP_ERROR_CHECK(err_code);
  }
}
Esempio n. 10
0
static void
server_init_dispatch_13(void)
{
	debug("server_init_dispatch_13");
	dispatch_init(NULL);
	dispatch_set(SSH_CMSG_EOF, &server_input_eof);
	dispatch_set(SSH_CMSG_STDIN_DATA, &server_input_stdin_data);
	dispatch_set(SSH_CMSG_WINDOW_SIZE, &server_input_window_size);
	dispatch_set(SSH_MSG_CHANNEL_CLOSE, &channel_input_close);
	dispatch_set(SSH_MSG_CHANNEL_CLOSE_CONFIRMATION, &channel_input_close_confirmation);
	dispatch_set(SSH_MSG_CHANNEL_DATA, &channel_input_data);
	dispatch_set(SSH_MSG_CHANNEL_OPEN_CONFIRMATION, &channel_input_open_confirmation);
	dispatch_set(SSH_MSG_CHANNEL_OPEN_FAILURE, &channel_input_open_failure);
	dispatch_set(SSH_MSG_PORT_OPEN, &channel_input_port_open);
}
Esempio n. 11
0
Authctxt *
do_authentication2(void)
{
	Authctxt *authctxt = authctxt_new();

	x_authctxt = authctxt;		/*XXX*/

#ifdef HAVE_BSM
	fatal_add_cleanup(audit_failed_login_cleanup, authctxt);
#endif /* HAVE_BSM */

	dispatch_init(&dispatch_protocol_error);
	dispatch_set(SSH2_MSG_SERVICE_REQUEST, &input_service_request);
	dispatch_run(DISPATCH_BLOCK, &authctxt->success, authctxt);

	return (authctxt);
}
Esempio n. 12
0
int main(void) {
    halInit();
    chSysInit();
    chRegSetThreadName("main");

    LocalStatus = &M2RStatus;

    /*sbp_state_init(&sbp_state);*/
    rockblock_init();
    dispatch_init();

    chThdCreateStatic(waThreadHB, sizeof(waThreadHB), LOWPRIO,
                      ThreadHeartbeat, NULL);

    /* Configure and enable the watchdog timer, stopped in debug halt */
    DBGMCU->APB1FZ |= DBGMCU_APB1_FZ_DBG_IWDG_STOP;
    IWDG->KR = 0x5555;
    IWDG->PR = 3;
    IWDG->KR = 0xCCCC;

    m2serial_shell = m2r_shell_run;
    M2SerialSD = &SD2;
    chThdCreateStatic(waM2Serial, sizeof(waM2Serial), HIGHPRIO,
                      m2serial_thread, NULL);

    chThdCreateStatic(waM2Status, sizeof(waM2Status), HIGHPRIO,
                      m2status_thread, NULL);

    chThdCreateStatic(waThreadUblox, sizeof(waThreadUblox), NORMALPRIO,
                      ublox_thread, NULL);

    chThdCreateStatic(waThreadRadio, sizeof(waThreadRadio), NORMALPRIO,
                      radio_thread, NULL);

    chThdCreateStatic(waDispatch, sizeof(waDispatch), NORMALPRIO,
                      dispatch_thread, NULL);

    chThdSetPriority(LOWPRIO);
    chThdSleep(TIME_INFINITE);

    return 0;
}
Esempio n. 13
0
static void
server_init_dispatch_20(void)
{
	debug("server_init_dispatch_20");
	dispatch_init(&dispatch_protocol_error);
	dispatch_set(SSH2_MSG_CHANNEL_CLOSE, &channel_input_oclose);
	dispatch_set(SSH2_MSG_CHANNEL_DATA, &channel_input_data);
	dispatch_set(SSH2_MSG_CHANNEL_EOF, &channel_input_ieof);
	dispatch_set(SSH2_MSG_CHANNEL_EXTENDED_DATA, &channel_input_extended_data);
	dispatch_set(SSH2_MSG_CHANNEL_OPEN, &server_input_channel_open);
	dispatch_set(SSH2_MSG_CHANNEL_OPEN_CONFIRMATION, &channel_input_open_confirmation);
	dispatch_set(SSH2_MSG_CHANNEL_OPEN_FAILURE, &channel_input_open_failure);
	dispatch_set(SSH2_MSG_CHANNEL_REQUEST, &server_input_channel_req);
	dispatch_set(SSH2_MSG_CHANNEL_WINDOW_ADJUST, &channel_input_window_adjust);
	dispatch_set(SSH2_MSG_GLOBAL_REQUEST, &server_input_global_request);
	/* client_alive */
	dispatch_set(SSH2_MSG_CHANNEL_FAILURE, &server_input_channel_failure);
	/* rekeying */
	dispatch_set(SSH2_MSG_KEXINIT, &kex_input_kexinit);
}
Esempio n. 14
0
int main ( int argc, char *argv[] )
{

  // Call sys_init with the created modules
  int SYS_INIT_ERR;
  int SHELL_ERR;
  int DATE_ERR;
  date_rec* tdf_date;
  
  // Initialize system date
  DATE_ERR = sys_set_date(tdf_date);
  
  SYS_INIT_ERR = sys_init (MODULE_R3);
  
  // Setting up registers for dispatch...
  dispatch_init();
  
  // Call the shell
  SHELL_ERR = shell();
  
  // Fin
  return 0;
}
Esempio n. 15
0
/**
 * @brief Allocate user-stacks and initializes the kernel contexts of the
 * given threads.
 *
 * This function assumes that:
 * - num_tasks < number of tasks allowed on the system.
 * - the tasks have already been deemed schedulable and have been appropriately
 *   scheduled.  In particular, this means that the task list is sorted in order
 *   of priority -- higher priority tasks come first.
 *
 * @param tasks  A list of scheduled task descriptors.
 * @param size   The number of tasks is the list.
 */
void allocate_tasks(task_t** tasks, size_t num_tasks)
{
  size_t i = 1;
  for(; i <= num_tasks; i++)
  {
    tcb_t *task_tcb = &(system_tcb[i]);
    task_tcb->native_prio = i;
    task_tcb->cur_prio = i;  

    // Context
    sched_context_t *ctx = &(task_tcb->context);
    ctx->r4 = (uint32_t) (tasks[i-1]->lambda);

    ctx->r5 = (uint32_t) (tasks[i-1]->data);
    ctx->r6 = (uint32_t) (tasks[i-1]->stack_pos);
    ctx->r8 = global_data;
    ctx->sp = ((char *)(task_tcb->kstack) + OS_KSTACK_SIZE);
    // Easy way to launch task fo first time
    ctx->lr = (void *)launch_task;

    task_tcb->holds_lock = 0;
    task_tcb->sleep_queue = (tcb_t *)0;

  }

  initialize_idle();
  runqueue_init();
  
  runqueue_add(&(system_tcb[IDLE_PRIO]), IDLE_PRIO);
  for(i=1; i <= num_tasks; i++)
  {
    runqueue_add(&(system_tcb[i]), i);
  }
  // Set current tcb as IDLE
  dispatch_init(&(system_tcb[IDLE_PRIO]));
  
}
Esempio n. 16
0
File: dispatch.c Progetto: gdhh/ffs
int main(const int argc, const char * argv[]) {
    watch_t w;
    watch_init(&w);

    watch_callback_t wc = {
        .data = NULL,
        .func = NULL,
    };

    watch_add(&w, "/dev/mqueue", IN_CREATE | IN_ATTRIB, &wc);

    dispatch_t d;
    dispatch_init(&d);

    dispatch_callback_t dc = {
        .data = NULL,
        .func = callback,
    };

    dispatch_add(&d, watch_fileno(&w), EPOLLIN, &dc);
    dispatch_wait(&d);

    return 0;
}
Esempio n. 17
0
int main() {

    static unsigned char alloc_buffer[4096*(1+1+4+1+32+1+256)];
    char json_buffer[4096];
    char print_buffer[4096];
    int ret;
    int readlen;
    int json_offset;
    void * root_node;
    void * findlist;
    void * memdb_template ;
    BYTE uuid[DIGEST_SIZE];
    int i;
    MSG_HEAD * msg_head;
    pthread_t  cube_thread;

    char * baseconfig[] =
    {
        "typelist.json",
        "subtypelist.json",
        "msghead.json",
        "login_struct.json",
        "headrecord.json",
        NULL
    };

    alloc_init(alloc_buffer);
    struct_deal_init();
    memdb_init();

// test namelist reading start

    for(i=0; baseconfig[i]!=NULL; i++)
    {
        ret=read_json_file(baseconfig[i]);
        if(ret<0)
            return ret;
        printf("read %d elem from file %s!\n",ret,baseconfig[i]);
    }

    void * record;

// test struct desc reading start

    msgfunc_init();

    void * message;
    void * policy;

    dispatch_init(NULL);
    policy=dispatch_policy_create();
    if(policy==NULL)
    {
        printf("create policy failed!\n");
        return -EINVAL;
    }

    ret=read_dispatch_file("dispatch_policy.json");

//	routine_start();
//	sleep(100000);

    return 0;

}
Esempio n. 18
0
int
main(int argc, char * argv[])
{
	/* State variables. */
	int * socks_s;
	int sock_t;
	struct wire_requestqueue * Q_t;
	struct dispatch_state * dstate;

	/* Command-line parameters. */
	intmax_t opt_n = 0;
	char * opt_p = NULL;
	char * opt_t = NULL;
	ADDRLIST opt_s;
	char * opt_s_1 = NULL;

	/* Working variables. */
	size_t opt_s_size;
	struct sock_addr ** sas;
	size_t i;
	const char * ch;

	WARNP_INIT;

	/* We have no addresses to listen on yet. */
	if ((opt_s = addrlist_init(0)) == NULL) {
		warnp("addrlist_init");
		exit(1);
	}

	/* Parse the command line. */
	while ((ch = GETOPT(argc, argv)) != NULL) {
		GETOPT_SWITCH(ch) {
		GETOPT_OPTARG("-n"):
			if (opt_n != 0)
				usage();
			if (PARSENUM(&opt_n, optarg, 0, 65535)) {
				warn0("Invalid option: -n %s", optarg);
				usage();
			}
			break;
		GETOPT_OPTARG("-p"):
			if (opt_p != NULL)
				usage();
			if ((opt_p = strdup(optarg)) == NULL)
				OPT_EPARSE(ch, optarg);
			break;
		GETOPT_OPTARG("-s"):
			/* Keep a copy of the path for pidfile generation. */
			if ((opt_s_1 == NULL) &&
			    ((opt_s_1 = strdup(optarg)) == NULL))
				OPT_EPARSE(ch, optarg);

			/* Attempt to resolve to a list of addresses. */
			if ((sas = sock_resolve(optarg)) == NULL) {
				warnp("Cannot resolve address: %s", optarg);
				exit(1);
			}
			if (sas[0] == NULL) {
				warn0("No addresses found for %s", optarg);
				exit(1);
			}

			/* Push pointers to addresses onto the list. */
			for (i = 0; sas[i] != NULL; i++) {
				if (addrlist_append(opt_s, &sas[i], 1))
					OPT_EPARSE(ch, optarg);
			}

			/* Free the array (but keep the addresses). */
			free(sas);
			break;
		GETOPT_OPTARG("-t"):
			if (opt_t != NULL)
				usage();
			if ((opt_t = strdup(optarg)) == NULL)
				OPT_EPARSE(ch, optarg);
			break;
		GETOPT_OPT("--version"):
			fprintf(stderr, "kivaloo-mux @VERSION@\n");
			exit(0);
		GETOPT_MISSING_ARG:
			warn0("Missing argument to %s\n", ch);
			usage();
		GETOPT_DEFAULT:
			warn0("illegal option -- %s\n", ch);
			usage();
		}
	}
	argc -= optind;
	argv += optind;

	/* We should have processed all the arguments. */
	if (argc != 0)
		usage();

	/* Sanity-check options. */
	if ((opt_s_size = addrlist_getsize(opt_s)) == 0)
		usage();
	if (opt_t == NULL)
		usage();

	/* Resolve target address. */
	if ((sas = sock_resolve(opt_t)) == NULL) {
		warnp("Error resolving socket address: %s", opt_t);
		exit(1);
	}
	if (sas[0] == NULL) {
		warn0("No addresses found for %s", opt_t);
		exit(1);
	}

	/* Connect to the target. */
	if ((sock_t = sock_connect(sas)) == -1)
		exit(1);

	/* Free the target address(es). */
	sock_addr_freelist(sas);

	/* Create a queue of requests to the target. */
	if ((Q_t = wire_requestqueue_init(sock_t)) == NULL) {
		warnp("Cannot create request queue");
		exit(1);
	}

	/* Allocate array of source sockets. */
	if ((socks_s = malloc(opt_s_size * sizeof(int))) == NULL) {
		warnp("malloc");
		exit(1);
	}

	/* Create listening sockets. */
	for (i = 0; i < opt_s_size; i++) {
		if ((socks_s[i] =
		    sock_listener(*addrlist_get(opt_s, i))) == -1)
			exit(1);
	}

	/* Initialize the dispatcher. */
	if ((dstate = dispatch_init(socks_s, opt_s_size,
	    Q_t, opt_n ? (size_t)opt_n : SIZE_MAX)) == NULL) {
		warnp("Failed to initialize dispatcher");
		exit(1);
	}

	/* Daemonize and write pid. */
	if (opt_p == NULL) {
		if (asprintf(&opt_p, "%s.pid", opt_s_1) == -1) {
			warnp("asprintf");
			exit(1);
		}
	}
	if (daemonize(opt_p)) {
		warnp("Failed to daemonize");
		exit(1);
	}

	/* Loop until the dispatcher is finished. */
	do {
		if (events_run()) {
			warnp("Error running event loop");
			exit(1);
		}
	} while (dispatch_alive(dstate));

	/* Clean up the dispatcher. */
	dispatch_done(dstate);

	/* Shut down the request queue. */
	wire_requestqueue_destroy(Q_t);
	wire_requestqueue_free(Q_t);

	/* Close sockets. */
	for (i = 0; i < opt_s_size; i++)
		close(socks_s[i]);
	free(socks_s);
	close(sock_t);

	/* Free source socket addresses. */
	for (i = 0; i < addrlist_getsize(opt_s); i++)
		sock_addr_free(*addrlist_get(opt_s, i));
	addrlist_free(opt_s);

	/* Shut down the event subsystem. */
	events_shutdown();

	/* Free option strings. */
	free(opt_p);
	free(opt_s_1);
	free(opt_t);

	/* Success! */
	return (0);
}
Esempio n. 19
0
int main(int argc,char **argv)
{

    struct tcloud_connector_hub * hub;
    struct tcloud_connector * temp_conn;
    int ret;
    int retval;
    void * message_box;
    int i,j;
    int argv_offset;	
    char namebuffer[DIGEST_SIZE*4];
    char * sys_plugin;		
    char * app_plugin;		
    char * base_define;
    char * cube_output;


    char json_buffer[4096];
    char print_buffer[4096];
    int readlen;
    int json_offset;
    void * memdb_template ;
    BYTE uuid[DIGEST_SIZE];
    void * main_proc; // point to the main proc's subject struct
    void * conn_proc; // point to the conn proc's subject struct
    void * router_proc; // point to the conn proc's subject struct
    char local_uuid[DIGEST_SIZE*2];

    FILE * fp;
    char audit_text[4096];
    char buffer[4096];
    void * root_node;
    void * temp_node;
    PROC_INIT plugin_proc; 

    char * baseconfig[] =
    {
	"namelist.json",
	"dispatchnamelist.json",
	"typelist.json",
	"subtypelist.json",
	"baseflag.json",
	"memdb.json",
	"msghead.json",
	"msgrecord.json",
	"expandrecord.json",
	"base_msg.json",
	"dispatchrecord.json",
	"exmoduledefine.json",
	"sys_conn.json",
	 NULL
    };

    struct start_para start_para;

    start_para.argc=argc;
    start_para.argv=argv;	

    int fd =open(msgaudit_file,O_CREAT|O_RDWR|O_TRUNC,0666);
    close(fd);
    audit_file_init();	
    sys_plugin=getenv("CUBE_SYS_PLUGIN");
//	alloc_init(alloc_buffer);
	struct_deal_init();
	memdb_init();

    	base_define=getenv("CUBE_BASE_DEFINE");
	for(i=0;baseconfig[i]!=NULL;i++)
	{
		Strcpy(namebuffer,base_define);
		Strcat(namebuffer,"/");
		Strcat(namebuffer,baseconfig[i]);
		ret=read_json_file(namebuffer);
		if(ret<0)
			return ret;
		print_cubeaudit("read %d elem from file %s!\n",ret,namebuffer);
	}

	msgfunc_init();
	dispatch_init();
	channel_init();

	ex_module_list_init();

    // init system
    system("mkdir lib");
    // init the main proc struct

    struct lib_para_struct * lib_para=NULL;
    fd=open(sys_config_file,O_RDONLY);
    if(fd>0)
    {

   	 ret=read_json_node(fd,&root_node);
  	 if(ret<0)
		return ret;	
    	 close(fd);
	

    	 ret=read_sys_cfg(&lib_para,root_node,NULL);
    	 if(ret<0)
		return ret;
    }	 		
    fd=open(main_config_file,O_RDONLY);
    if(fd<0)
	return -EINVAL;

    ret=read_json_node(fd,&root_node);
    if(ret<0)
	return ret;	
    close(fd);
	
    ret=read_main_cfg(lib_para,root_node);
    if(ret<0)
	return ret; 		

    ret=get_local_uuid(local_uuid);
    digest_to_uuid(local_uuid,buffer);
    buffer[64]=0;
    print_cubeaudit("this machine's local uuid is %s\n",buffer);
    proc_share_data_setvalue("uuid",local_uuid);

    // init all the proc database

    usleep(time_val.tv_usec);


    // init the connect proc	
    Strcpy(namebuffer,sys_plugin);
    Strcat(namebuffer,"/");
    Strcat(namebuffer,connector_plugin_file);
    plugin_proc.init =main_read_func(namebuffer,"proc_conn_init");
    if(plugin_proc.init==NULL)
	return -EINVAL;
    plugin_proc.start =main_read_func(namebuffer,"proc_conn_start");
    if(plugin_proc.start==NULL)
	return -EINVAL;
     plugin_proc.name=dup_str("connector_proc",0);	
     plugin_proc.type=MOD_TYPE_CONN;
	
     ret=ex_module_create("connector_proc",MOD_TYPE_CONN,NULL,&conn_proc);
    if(ret<0)
	    return ret;

    ex_module_setinitfunc(conn_proc,plugin_proc.init);
    ex_module_setstartfunc(conn_proc,plugin_proc.start);

    ex_module_init(conn_proc,connector_config_file);
    add_ex_module(conn_proc);

    // init the router proc	
    Strcpy(namebuffer,sys_plugin);
    Strcat(namebuffer,"/");
    Strcat(namebuffer,router_plugin_file);
    plugin_proc.init =main_read_func(namebuffer,"proc_router_init");
    if(plugin_proc.init==NULL)
	return -EINVAL;
    plugin_proc.start =main_read_func(namebuffer,"proc_router_start");
    if(plugin_proc.start==NULL)
	return -EINVAL;
     plugin_proc.name=dup_str("router_proc",0);	
     plugin_proc.type=MOD_TYPE_ROUTER;
	
    ret=ex_module_create("router_proc",MOD_TYPE_MONITOR,NULL,&router_proc);
    if(ret<0)
	    return ret;

    ex_module_setinitfunc(router_proc,plugin_proc.init);
    ex_module_setstartfunc(router_proc,plugin_proc.start);

    struct router_init_para
    {
		char * router_file;
		char * aspect_file;
    } router_init;
    router_init.router_file=router_config_file;
    router_init.aspect_file=aspect_config_file;
   	

    ex_module_init(router_proc,&router_init);
	
    print_cubeaudit("prepare the router proc\n");
    ret=add_ex_module(router_proc);
    if(ret<0)
	    return ret;

    // loop to init all the plugin's 

    void * ex_module;	

    fd=open(plugin_config_file,O_RDONLY);
    if(fd>0)
    {	

    	while(read_json_node(fd,&root_node)>0)
    	{  		
		ret=read_plugin_cfg(&ex_module,root_node);
		if(ret>=0)
    			add_ex_module(ex_module);
    	}
    }	
    
/*
    }
  */   
    usleep(time_val.tv_usec);
    print_cubeaudit("prepare the conn proc\n");
    ret=ex_module_start(conn_proc,NULL);
    if(ret<0)
	    return ret;

    // second loop:  start all the monitor process
       	
    ret=get_first_ex_module(&ex_module);

    if(ret<0)
	return ret;
    int active_module_no=0;
    while(ex_module!=NULL)
    {
	  if((ex_module_gettype(ex_module) == MOD_TYPE_MONITOR)
	  	||(ex_module_gettype(ex_module) == MOD_TYPE_PORT))
	  {
  		ret=ex_module_start(ex_module,NULL);
	  	if(ret<0)
  			return ret;
		print_cubeaudit("monitor ex_modulec %s started successfully!\n",ex_module_getname(ex_module));
	  }
	  else if(ex_module_gettype(ex_module) == MOD_TYPE_START)
	  {
  		ret=ex_module_start(ex_module,&start_para);
	  	if(ret<0)
  			return ret;
		print_cubeaudit("start ex_module %s started successfully!\n",ex_module_getname(ex_module));

	  }
	  	
    	  ret= get_next_ex_module(&ex_module);
	  active_module_no++;
    	  if(ret<0)
		return ret;
    }

    if(active_module_no==0)
	return 0;

    proc_share_data_setstate(PROC_LOCAL_START);

    // third loop:  test if any module exit
    int * thread_retval;
    thread_retval=malloc(sizeof(int)*active_module_no);
    if(thread_retval==NULL)
	return NULL;
/*
    i=0;
    while(1)
    {		 
	  usleep(time_val.tv_usec);		
  	  ret=get_first_ex_module(&ex_module);

   	  if(ret<0)
		return ret;
    	 while(ex_module!=NULL)
         {
		if(ex_module_tryjoin(ex_module,&thread_retval[i++])==0)
		{
			print_cubeaudit("monitor ex_modulec %s exited successfully!\n",ex_module_getname(ex_module));
			return thread_retval[i-1];
		}
    	  	ret= get_next_ex_module(&ex_module);
	  }
	  i=0;
	  	
    }
*/
    // third loop:  join all the non_system module 
       	
    ret=get_first_ex_module(&ex_module);

    if(ret<0)
	return ret;
    i=0;
    while(ex_module!=NULL)
    {
	  if((ex_module_gettype(ex_module) == MOD_TYPE_MONITOR)
	  	||(ex_module_gettype(ex_module) == MOD_TYPE_PORT)
	  	||(ex_module_gettype(ex_module) == MOD_TYPE_START))
	  {
		if(Strcmp(ex_module_getname(ex_module),"router_proc")!=0)
		{
    			ret=ex_module_join(ex_module,&thread_retval[i++]);
	  		if(ret<0)
			{
				print_cubeerr("%s module exit!\n",ex_module_getname(ex_module));
  				return ret;
			}
			print_cubeaudit("%s module exit!\n",ex_module_getname(ex_module));
		}
	  }
	  	
    	  ret= get_next_ex_module(&ex_module);
    	  if(ret<0)
		return ret;
    }

    printf("thread return value %d!\n",thread_retval[0]);
    return ret;
}
Esempio n. 20
0
int main() {

  	static unsigned char alloc_buffer[4096*(1+1+4+1+32+1+256)];	
	char json_buffer[4096];
	char print_buffer[4096];
	int ret;
	int readlen;
	int json_offset;
	void * root_node;
	void * findlist;
	void * memdb_template ;
	BYTE uuid[DIGEST_SIZE];
	int i;
	MSG_HEAD * msg_head;
	pthread_t  cube_thread;
	
	char * baseconfig[] =
	{
		"namelist.json",
		"dispatchnamelist.json",
		"typelist.json",
		"subtypelist.json",
		"msghead.json",
		"msgrecord.json",
		"expandrecord.json",
		"base_msg.json",
		"dispatchrecord.json",
		NULL
	};

//	alloc_init(alloc_buffer);
	struct_deal_init();
	memdb_init();

// test namelist reading start

	for(i=0;baseconfig[i]!=NULL;i++)
	{
		ret=read_json_file(baseconfig[i]);
		if(ret<0)
			return ret;
		printf("read %d elem from file %s!\n",ret,baseconfig[i]);
	}

	void * record;

// test struct desc reading start

	msgfunc_init();
	dispatch_init();
	
	void * message;
	void * policy;
	
	ret=read_dispatch_file("dispatch_policy.json");

	message=message_create(DTYPE_MESSAGE,SUBTYPE_BASE_MSG,NULL);	

	struct basic_message * base_msg;
	base_msg=Talloc0(sizeof(*base_msg));
	if(base_msg==NULL)
		return -ENOMEM;
	base_msg->message=dup_str("hello",0);

	message_add_record(message,base_msg);	
	ret=message_output_json(message,json_buffer);
	if(ret<0)
	{
		printf("message output json failed!\n");
		return ret;
	}

	printf("%s\n",json_buffer);

	ret=dispatch_policy_getfirst(&policy);
	while(policy!=NULL)
	{
		ret=dispatch_match_message(policy,message);
		if(ret==0)
		{
			printf("this message match the policy!\n");
			break;
		}
		ret=dispatch_policy_getnext(&policy);
	}

	if(policy!=NULL)
	{
		router_set_local_route(message,policy);	
		ret=message_output_json(message,json_buffer);
		if(ret<0)
		{
			printf("message output json failed!\n");
			return ret;
		}

		printf("%s\n",json_buffer);
	}

//	routine_start();
//	sleep(100000);
	
	return 0;

}
Esempio n. 21
0
int main(int argc, const char** argv)
{
    argv0 = argv[0];


    bool print_stats = false;


    U.start();

    // Set up smsh related error codes
    if (! (w_error_t::insert(
                "ss_m shell",
                smsh_error_list, SSH_MAX_ERROR - SSH_MIN_ERROR - 1))) {
        abort();
    }


    /*
     * The following section of code sets up all the various options
     * for the program.  The following steps are performed:
        - determine the name of the program
        - setup an option group for the program
        - initialize the ssm options
        - scan default option configuration files ($HOME/.shoreconfig .shoreconfig)
        - process any options found on the command line
        - use getopt() to process smsh specific flags on the command line
        - check that all required options are set before initializing sm
     */         

    // set prog_name to the file name of the program
    const char* prog_name = strrchr(argv[0], '/');
    if (prog_name == NULL) {
            prog_name = argv[0];
    } else {
            prog_name += 1; /* skip the '/' */
            if (prog_name[0] == '\0')  {
                    prog_name = argv[0];
            }
    }

    /*
     * Set up and option group (list of options) for use by
     * all layers of the system.  Level "smsh" indicates
     * that the program is a a part to the smsh test suite.
     * Level "server" indicates
     * the type of program (the smsh server program).  The third
     * level is the program name itself.
     */
    option_group_t options(3);
    W_COERCE(options.add_class_level("smsh"));
    W_COERCE(options.add_class_level("server"));
    W_COERCE(options.add_class_level(prog_name));

    /*
     * Set up and smsh option for the name of the tcl library directory
     * and the name of the .smshrc file.
     */
    option_t* smsh_libdir;
    option_t* smsh_smshrc;
    W_COERCE(options.add_option("smsh_libdir", "directory name", NULL,
                "directory for smsh tcl libraries",
                true, option_t::set_value_charstr, smsh_libdir));
    W_COERCE(options.add_option("smsh_smshrc", "rc file name", ".smshrc",
                "full path name of the .smshrc file",
                false, option_t::set_value_charstr, smsh_smshrc));

    // have the sm add its options to the group
    W_COERCE(ss_m::setup_options(&options));


    /*
     * Scan the default configuration files: $HOME/.shoreconfig, .shoreconfig.  Note
     * That OS errors are ignored since it is not an error
     * for this file to not be found.
     */
    rc_t        rc;
    {
    char                opt_file[ss_m::max_devname+1];
    for(int file_num = 0; file_num < 2 && !rc.is_error(); file_num++) {
        // scan default option files
        w_ostrstream        err_stream;
        const char*        config = ".shoreconfig";
        if (file_num == 0) {
            if (!getenv("HOME")) {
                // ignore it ...
                // cerr << "Error: environment variable $HOME is not set" << endl;
                // rc = RC(SSH_FAILURE);
                break;
            }
            if (sizeof(opt_file) <= strlen(getenv("HOME")) + strlen("/") + strlen(config) + 1) {
                cerr << "Error: environment variable $HOME is too long" << endl;
                rc = RC(SSH_FAILURE);
                break;
            }
            strcpy(opt_file, getenv("HOME"));
            strcat(opt_file, "/");
            strcat(opt_file, config);
        } else {
            w_assert3(file_num == 1);
            strcpy(opt_file, "./");
            strcat(opt_file, config);
        }
        {
            option_file_scan_t opt_scan(opt_file, &options);
            rc = opt_scan.scan(true, err_stream);
            err_stream << ends;
            if (rc.is_error()) {
                // ignore OS error messages
                if (rc.err_num() == fcOS) {
                    rc = RCOK;
                } else {
                    // this error message is kind of gross but is
                    // sufficient for now
                    cerr << "Error in reading option file: " << opt_file << endl;
                    //cerr << "\t" << w_error_t::error_string(rc.err_num()) << endl;
                    cerr << "\t" << err_stream.c_str() << endl;
                }
            }
        }
    }
    }

    /* 
     * Assuming there has been no error so far, the command line
     * is processed for any options in the option group "options".
     */
    if (!rc.is_error()) {
        // parse command line
        w_ostrstream        err_stream;
        rc = options.parse_command_line(argv, argc, 2, &err_stream);
        err_stream << ends;
        if (rc.is_error()) {
            cerr << "Error on command line " << endl;
            cerr << "\t" << w_error_t::error_string(rc.err_num()) << endl;
            cerr << "\t" << err_stream.c_str() << endl;
            print_usage(cerr, prog_name, false, options);
        }
    } 

    /* 
     * Assuming there has been no error so far, the command line
     * is processed for any smsh specific flags.
     */
    int option;
    //if (!rc) 
    {  // do even if error so that smsh -h can be recognized
        bool verbose_opt = false; // print verbose option values
        while ((option = getopt(argc, (char * const*) argv, "Cf:hLOsTvV")) != -1) {
            switch (option) {
            case 'T':
                extern bool logtrace;
                logtrace = true;
                break;
            case 'O':
                    // Force use of old sort
                cout << "Force use of old sort implementation." <<endl;
                newsort = false;
                break;

            case 'C':
                // force compression of btrees
                force_compress = true;
                break;

            case 's':
                print_stats = true;
                break;

            case 'f':
                f_arg = optarg;
                break;

            case 'L':
                // use log warning callback
                log_warn_callback = true;
                break;

            case 'h':
                // print a help message describing options and flags
                print_usage(cerr, prog_name, true, options);
                // free rc structure to avoid complaints on exit
                W_IGNORE(rc);
                goto done;
                break;
            case 'v':
                verbose_opt = true;
                break;
            case 'V':
                verbose = true;
                break;
            default:
                cerr << "unknown flag: " << option << endl;
                rc = RC(SSH_COMMAND_LINE);
            }
        }

        if (verbose_opt) {
            options.print_values(false, cerr);
        }
    }

    /*
     * Assuming no error so far, check that all required options
     * in option_group_t options are set.  
     */
    if (!rc.is_error()) {
        // check required options
        w_ostrstream        err_stream;
        rc = options.check_required(&err_stream);
        err_stream << ends;
        if (rc.is_error()) {
            cerr << "These required options are not set:" << endl;
            cerr << err_stream.c_str() << endl;
            print_usage(cerr, prog_name, false, options);
        }
    } 


    /* 
     * If there have been any problems so far, then exit
     */
    if (rc.is_error()) {
        // free the rc error structure to avoid complaints on exit
        W_IGNORE(rc);
        goto errordone;
    }

    /*
     * At this point, all options and flags have been properly
     * set.  What follows is initialization for the rest of
     * the program.  The ssm will be started by a tcl_thread.
     */


    // setup table of sm commands - doesn't involve the Tcl_Interp
    dispatch_init();

    // set up the linked variables
    // either these should be read-only or
    // they need to be made thread-safe.  We can assume for smsh they
    // are for all purposes read-only, since only the mama thread sets
    // them in the scripts.
    linked.sm_page_sz = ss_m::page_sz;
    linked.sm_max_exts = ss_m::max_exts;
    linked.sm_max_vols = ss_m::max_vols;
    linked.sm_max_servers = ss_m::max_servers;
    linked.sm_max_keycomp = ss_m::max_keycomp;
    linked.sm_max_dir_cache = ss_m::max_dir_cache;
    linked.sm_max_rec_len = ss_m::max_rec_len;
    linked.sm_srvid_map_sz = ss_m::srvid_map_sz;
    linked.verbose_flag = verbose?1:0;
    linked.verbose2_flag = verbose2?1:0;
    linked.instrument_flag = instrument?1:0;
    linked.compress_flag = force_compress?1:0;
    linked.log_warn_callback_flag = log_warn_callback?1:0;

    {
        int tty = isatty(0);
        interactive = tty && f_arg;
    }

    // Create the main tcl_thread
    {
        tcl_thread_t* tcl_thread = NULL;
        bool ok = true;

        if(ok) {
            if (f_arg) {
                TCL_AV char* av[2];
                av[0] = TCL_AV1 "source";
                av[1] = f_arg;
                // smsh -f <file>
                tcl_thread = new tcl_thread_t(2, av, 
                                smsh_libdir->value(),
                                smsh_smshrc->value()
                                );
            } else {
                // interactive
                /*
                cerr << __func__ << " " << __LINE__ << " " << __FILE__
                << " INTERACTIVE libdir " << smsh_libdir->value()
                << " msshrc " << smsh_smshrc->value()
                << endl;
                */
                tcl_thread = new tcl_thread_t(0, 0,
                                smsh_libdir->value(),
                                smsh_smshrc->value()
                                );
            }
            assert(tcl_thread);

            W_COERCE( tcl_thread->fork() );
            W_COERCE( tcl_thread->join() );

            delete tcl_thread;
        }
    }


    // Shutdown TCL and have it deallocate resources still held!
    Tcl_Finalize();

    U.stop(1); // 1 iteration

    if(print_stats) 
    {
        cout << "Thread stats" <<endl;
        sthread_t::dump_stats(cout);
        cout << endl;

        cout << "Unix stats for parent:" <<endl;
        cout << U << endl << endl;

    }
    cout << flush;

done:
    clean_up_shell();
    fprintf(stderr, "%d tcl threads ran\n", num_tcl_threads_ttl);
    return 0;

errordone:
    clean_up_shell();
    return 1;
}