Exemplo n.º 1
0
int main(int argc, char** argv) {
  register_handlers();
  sscanf(argv[0], "%d", &parent_pid);
  sscanf(argv[1], "%d", &fid);
  sscanf(argv[2], "%d", &mem_size);
#ifdef DEBUG
  printf("KBD: %d %d %d\n", parent_pid, mem_size, fid);
#endif
  mem_ptr = mmap((caddr_t)0, mem_size, PROT_READ|PROT_WRITE,
  		 MAP_SHARED, fid, (off_t)0);
  mem_buffer *buffer = (mem_buffer*) mem_ptr;
  char local_buffer[MEMBLOCK_SIZE];
  int index = 0;
  char kbd_in = '\0';
  unmask();
  while(1) { 
    kbd_in = getchar();
    putc(kbd_in, stdout);
    //echo back
    if (kbd_in != '\r' && index < MEMBLOCK_SIZE-1) {
      local_buffer[index++] = kbd_in;
    } else {
      local_buffer[index++] = '\0';
      while (buffer->flag != MEM_DONE)
        sleep(1); //1-sec polling
      strcpy(buffer->data, local_buffer);
      buffer->flag = MEM_READY;
      buffer->length = index;
      index = 0;
      kill(parent_pid, SIGUSR1);
    }
      
  }
return 0;
}
Exemplo n.º 2
0
PUBLIC
Jdb_pic::Jdb_pic()
{
  static Jdb_handler enter(at_enter);
  static Jdb_handler leave(at_leave);
  register_handlers(enter,leave);
}
Exemplo n.º 3
0
int main(int argc, char **argv)
{
	struct netns_entry *root;
	int netns_ok, err;

	arg_register_batch(options, ARRAY_SIZE(options));
	register_frontends();
	register_handlers();
	if ((err = arg_parse(argc, argv)))
		exit(err);

	if (!check_caps()) {
		fprintf(stderr, "Must be run under root (or with enough capabilities).\n");
		exit(1);
	}
	netns_ok = netns_switch_root();
	if (netns_ok > 0) {
		fprintf(stderr, "Cannot change to the root name space: %s\n", strerror(netns_ok));
		exit(1);
	}

	global_handler_init();
	if ((err = netns_list(&root, netns_ok == 0))) {
		fprintf(stderr, "ERROR: %s\n", strerror(err));
		exit(1);
	}
	if ((err = frontend_output(root))) {
		fprintf(stderr, "Invalid output format specified.\n");
		exit(1);
	}
	global_handler_cleanup(root);
	netns_list_free(root);

	return 0;
}
Exemplo n.º 4
0
int ikarus_main(int argc, char** argv, char* boot_file){
  if(! cpu_has_sse2()){
    fprintf(stderr, "Ikarus Scheme cannot run on your computer because\n");
    fprintf(stderr, "your CPU does not support the SSE2 instruction set.\n");
    fprintf(stderr, "Refer to the Ikarus Scheme User's Guide for the\n");
    fprintf(stderr, "minimum hardware requirements.\n");
    exit(-1);
  }
  if(sizeof(mp_limb_t) != sizeof(long int)){
    fprintf(stderr, "ERROR: limb size does not match\n");
    exit(-1);
  }
  if(mp_bits_per_limb != (8*sizeof(long int))){
    fprintf(stderr, "ERROR: invalid bits_per_limb=%d\n", mp_bits_per_limb);
    exit(-1);
  }
  ikpcb* pcb = ik_make_pcb();
  the_pcb = pcb;
  { /* set up arg_list */
    ikptr arg_list = null_object;
    int i = argc-1;
    while(i > 0){
      char* s = argv[i];
      int n = strlen(s);
      ikptr bv = ik_unsafe_alloc(pcb, align(disp_bytevector_data+n+1)) 
                 + bytevector_tag;
      ref(bv, off_bytevector_length) = fix(n);
      memcpy((char*)(bv+off_bytevector_data), s, n+1);
      ikptr p = ik_unsafe_alloc(pcb, pair_size);
      ref(p, disp_car) = bv;
      ref(p, disp_cdr) = arg_list;
      arg_list = p+pair_tag;
      i--;
    }
    pcb->arg_list = arg_list;
  }
  register_handlers();
  register_alt_stack();
  ik_fasl_load(pcb, boot_file);
  /*
  fprintf(stderr, "collect time: %d.%03d utime, %d.%03d stime (%d collections)\n", 
                  pcb->collect_utime.tv_sec, 
                  pcb->collect_utime.tv_usec/1000, 
                  pcb->collect_stime.tv_sec, 
                  pcb->collect_stime.tv_usec/1000,
                  pcb->collection_id );
                  */
  ik_delete_pcb(pcb);
  return 0;
}
Exemplo n.º 5
0
int main(int argc, char **argv)
{
	int i;
	pid_t pid;

	if(argc < 4) {
		printf("Usage: fork_stochastic seed max n\n");
		return 0;
	}

        register_handlers();

	int seed = strtol(argv[1], NULL, 10);
	int max = strtol(argv[2], NULL, 10);
	int n = strtol(argv[3], NULL, 10);

	int p = getpid();
	printf("%d\n", p);
	fflush(stdout);

	srand(seed);

	int r = rand();
	int count = r % max;

	char new_seed[4];
	char new_n[4];
	snprintf(new_n, sizeof(new_n), "%d", n - 1);	

	for(i = 0; i < count && n > 0; i++) {

		snprintf(new_seed, sizeof(new_seed), "%d", r + i);	

    		pid = fork();
    		if(pid == 0){
    			execl("./fork_stochastic", "./fork_stochastic", new_seed, argv[2], new_n, NULL);
    		}
	}
 
    	while(1) 
    		;

	return 0;
}
Exemplo n.º 6
0
int main () {
  mca_status_t status;
  mcapi_param_t parms;
  mcapi_info_t version;

  mcapi_set_debug_level(1);
 
  /* create a node */
  mcapi_initialize(DOMAIN,NODE,NULL,&parms,&version,&status);
  if (status != MCAPI_SUCCESS) {
    fprintf(stderr,"FAILED 1: mcapi_initialize NODE=%i, status=%s",NODE,mcapi_display_status(status,status_buff,sizeof(status_buff)));
    return -1;
  }
  
  register_handlers();
 
  raise(SIGINT);
  
 return 0;
}
Exemplo n.º 7
0
int interface_main(int argc, char *argv[])
{
	if (argc < 2) return 1;

	int *const daemons = find_daemon(argv[1]), *current_socket = daemons;
	if (!daemons) return 1;

	register_handlers();

	unsigned int return_value = 0x00, single_value = 0x00;
	static char input_data[PARAM_MAX_INPUT_SECTION];
	char *working = NULL, *current = NULL;

	if (*current_socket) do
	{
	FILE *new_stream = fdopen(*current_socket, "r+");
	if (!new_stream)
	 {
	fprintf(stderr, "%s: couldn't connect to daemon '%s': %s\n", argv[0], argv[1],
	  strerror(errno));
	shutdown(*current_socket, SHUT_RDWR);
	return_value |= event_bad_target;
	continue;
	 }

	int I;
	for (I = 2; I < argc; I++)
	fprintf(new_stream, "%s\n", argv[I]);

	fflush(new_stream);
	shutdown(*current_socket, SHUT_WR);

	while (fgets(input_data, PARAM_MAX_INPUT_SECTION, new_stream))
	 {
	if (strlen(input_data)) input_data[ strlen(input_data) - 1 ] = 0x00;
	if (!strlen(input_data)) continue;
	current = input_data;

	if (!(working = strsep(&current, " "))) continue;

	if (strcmp(working, "\\") == 0)
	fprintf(stdout, "%s\n", current);

	else if (parse_integer16(working, &single_value))
	  {
	return_value |= single_value;
	if (!current) continue;
	fprintf(stderr, "%s\n", current);
	if (!--I) break;
	  }

	else fprintf(stderr, "(bad response data received)\n");
	 }

	shutdown(*current_socket, SHUT_RDWR);
	fclose(new_stream);
	}
	while (*++current_socket);

	free(daemons);

	return return_value;
}
Exemplo n.º 8
0
	BrokerMessageHandler::BrokerMessageHandler()
	{
		register_handlers();
	}
Exemplo n.º 9
0
int
main (int argc, char **argv)
{
  int c, status;
  char *domain;

  progname = strrchr (argv[0], '/');
  if (!progname)
    progname = argv[0];
  
  while ((c = getopt (argc, argv, "b:f:p:to:")) != EOF)
    {
      switch (c)
	{
	case 'b':
	  switch (optarg[0])
	    {
	    case 'd':
	      smtp_mode = 1;
	      break;

	    default:
	      /*FIXME*/;
	    }
	  break;
	  
	case 'f':
	  from_person = optarg;
	  break;
	  
	case 'p':
	  port = strtoul (optarg, NULL, 0);
	  break;
	  
	case 't':
	  read_recipients = 1;
	  break;

	case 'o':
	  switch (optarg[0])
	    {
	    case 'i':
	      dot = 0;
	      break;

	    default:
	      /* FIXME */ ;
	    }
	  break;

	default:
	  exit (1);
	}
    }

  if (!diag)
    {
      char *name = getenv ("MTA_DIAG");
      if (name)
	{
	  char *mode = getenv ("MTA_APPEND") ? "a" : "w";
	  diag = fopen (name, mode);
	  if (!diag)
	    {
	      mu_error ("%s: can't open diagnostic output: %s",
			progname, name);
	      return 1;
	    }
	}
      else
	diag = stdout;
    }
  
  register_handlers ();

  domain = getenv ("MTA_DOMAIN");
  mu_set_user_email_domain (domain ? domain : "localhost");
  
  argc -= optind;
  argv += optind;
  if (smtp_mode)
    status = mta_smtp (argc, argv);
  else
    status = mta_stdin (argc, argv);
  fclose (diag);
  return status;
}
Exemplo n.º 10
0
// initialize the shared library
void initialize(void)
{
  register_handlers();
}
Exemplo n.º 11
0
/* #define SERVER_DEBUG 1   */
int
main( int, char ** ) {

    int status;
    rsComm_t rsComm;
    char *tmpStr;

    ProcessType = AGENT_PT;

    // capture server properties
    irods::server_properties& props = irods::server_properties::getInstance();
    irods::error result = props.capture_if_needed();
    if ( !result.ok() ) {
        irods::log( PASSMSG( "failed to read server configuration", result ) );
    }

#ifdef windows_platform
    iRODSNtAgentInit( argc, argv );
#endif

#ifndef windows_platform
    signal( SIGINT, signalExit );
    signal( SIGHUP, signalExit );
    signal( SIGTERM, signalExit );
    /* set to SIG_DFL as recommended by andy.salnikov so that system()
     * call returns real values instead of 1 */
    signal( SIGCHLD, SIG_DFL );
    signal( SIGUSR1, signalExit );
    signal( SIGPIPE, SIG_IGN );

    // register irods signal handlers
    register_handlers();
#endif

#ifndef windows_platform
#ifdef SERVER_DEBUG
    if ( isPath( "/tmp/rodsdebug" ) ) {
        sleep( 20 );
    }
#endif
#endif

    memset( &rsComm, 0, sizeof( rsComm ) );
    rsComm.thread_ctx = ( thread_context* )malloc( sizeof( thread_context ) );

    status = initRsCommWithStartupPack( &rsComm, NULL );

    // =-=-=-=-=-=-=-
    // manufacture a network object for comms
    irods::network_object_ptr net_obj;
    irods::error ret = irods::network_factory( &rsComm, net_obj );
    if ( !ret.ok() ) {
        irods::log( PASS( ret ) );
    }

    if ( status < 0 ) {
        sendVersion( net_obj, status, 0, NULL, 0 );
        cleanupAndExit( status );
    }

    /* Handle option to log sql commands */
    tmpStr = getenv( SP_LOG_SQL );
    if ( tmpStr != NULL ) {
#ifdef SYSLOG
        int j = atoi( tmpStr );
        rodsLogSqlReq( j );
#else
        rodsLogSqlReq( 1 );
#endif
    }

    /* Set the logging level */
    tmpStr = getenv( SP_LOG_LEVEL );
    if ( tmpStr != NULL ) {
        int i;
        i = atoi( tmpStr );
        rodsLogLevel( i );
    }
    else {
        rodsLogLevel( LOG_NOTICE ); /* default */
    }

#ifdef SYSLOG
    /* Open a connection to syslog */
    openlog( "rodsAgent", LOG_ODELAY | LOG_PID, LOG_DAEMON );
#endif
    status = getRodsEnv( &rsComm.myEnv );

    if ( status < 0 ) {
        rodsLog( LOG_ERROR, "agentMain :: getRodsEnv failed" );
        sendVersion( net_obj, SYS_AGENT_INIT_ERR, 0, NULL, 0 );
        cleanupAndExit( status );
    }

    ret = setRECacheSaltFromEnv();
    if ( !ret.ok() ) {
        rodsLog( LOG_ERROR, "rodsAgent::main: Failed to set RE cache mutex name\n%s", ret.result().c_str() );
        exit( 1 );
    }

    // =-=-=-=-=-=-=-
    // load server side pluggable api entries
    irods::api_entry_table&  RsApiTable   = irods::get_server_api_table();
    irods::pack_entry_table& ApiPackTable = irods::get_pack_table();
    ret = irods::init_api_table(
              RsApiTable,
              ApiPackTable,
              false );
    if ( !ret.ok() ) {
        irods::log( PASS( ret ) );
        return 1;
    }

    // =-=-=-=-=-=-=-
    // load client side pluggable api entries
    irods::api_entry_table&  RcApiTable = irods::get_client_api_table();
    ret = irods::init_api_table(
              RcApiTable,
              ApiPackTable,
              true );
    if ( !ret.ok() ) {
        irods::log( PASS( ret ) );
        return 1;
    }




#if RODS_CAT
    if ( strstr( rsComm.myEnv.rodsDebug, "CAT" ) != NULL ) {
        chlDebug( rsComm.myEnv.rodsDebug );
    }
#endif

    status = initAgent( RULE_ENGINE_TRY_CACHE, &rsComm );

    if ( status < 0 ) {
        rodsLog( LOG_ERROR, "agentMain :: initAgent failed: %d", status );
        sendVersion( net_obj, SYS_AGENT_INIT_ERR, 0, NULL, 0 );
        cleanupAndExit( status );
    }

    /* move configConnectControl behind initAgent for now. need zoneName if
     * the user does not specify one in the input */
    initConnectControl();

    if ( rsComm.clientUser.userName[0] != '\0' ) {
        status = chkAllowedUser( rsComm.clientUser.userName,
                                 rsComm.clientUser.rodsZone );

        if ( status < 0 ) {
            sendVersion( net_obj, status, 0, NULL, 0 );
            cleanupAndExit( status );
        }
    }

    // =-=-=-=-=-=-=-
    // handle negotiations with the client regarding TLS if requested
    // this scope block makes valgrind happy
    {
        std::string neg_results;
        ret = irods::client_server_negotiation_for_server( net_obj, neg_results );
        if ( !ret.ok() || neg_results == irods::CS_NEG_FAILURE ) {
            irods::log( PASS( ret ) );
            // =-=-=-=-=-=-=-
            // send a 'we failed to negotiate' message here??
            // or use the error stack rule engine thingie
            irods::log( PASS( ret ) );
            sendVersion( net_obj, SYS_AGENT_INIT_ERR, 0, NULL, 0 );
            cleanupAndExit( ret.code() );

        }
        else {
            // =-=-=-=-=-=-=-
            // copy negotiation results to comm for action by network objects
            snprintf( rsComm.negotiation_results, sizeof( rsComm.negotiation_results ), "%s", neg_results.c_str() );
            //rsComm.ssl_do_accept = 1;

        }
    }

    /* send the server version and atatus as part of the protocol. Put
     * rsComm.reconnPort as the status */
    ret = sendVersion( net_obj, status, rsComm.reconnPort,
                       rsComm.reconnAddr, rsComm.cookie );

    if ( !ret.ok() ) {
        irods::log( PASS( ret ) );
        sendVersion( net_obj, SYS_AGENT_INIT_ERR, 0, NULL, 0 );
        cleanupAndExit( status );
    }

    logAgentProc( &rsComm );

    // call initialization for network plugin as negotiated
    irods::network_object_ptr new_net_obj;
    ret = irods::network_factory( &rsComm, new_net_obj );
    if ( !ret.ok() ) {
        return ret.code();
    }

    ret = sockAgentStart( new_net_obj );
    if ( !ret.ok() ) {
        irods::log( PASS( ret ) );
        return ret.code();
    }

    new_net_obj->to_server( &rsComm );
    status = agentMain( &rsComm );

    // call initialization for network plugin as negotiated
    ret = sockAgentStop( new_net_obj );
    if ( !ret.ok() ) {
        irods::log( PASS( ret ) );
        return ret.code();
    }

    new_net_obj->to_server( &rsComm );
    cleanup();
    free( rsComm.thread_ctx );
    free( rsComm.auth_scheme );
    rodsLog( LOG_NOTICE, "Agent exiting with status = %d", status );
    return status;
}