コード例 #1
0
int main(int argc, char **argv)
{
    int ins_pid;

    init_arguments (&argc, &argv);

    //打开锁文件
    lockfile = open (LOCKFILE, O_RDWR | O_CREAT , LOCKMODE);
    if (lockfile < 0){
        perror ("Lockfile");
        exit(EXIT_FAILURE);
    }

    if ( (ins_pid = program_running_check ()) ) {
        fprintf(stderr,"@@ERROR: zRuijie Already "
                            "Running with PID %d\n", ins_pid);
        exit(EXIT_SUCCESS);
    }
    init_info();
    init_device();
    init_frames ();

    signal (SIGINT, signal_interrupted);
    signal (SIGTERM, signal_interrupted);
    signal (SIGALRM, signal_alarm);

    show_local_info();

    send_eap_packet (EAPOL_START);
    alarm(5);

	pcap_loop (handle, -1, get_packet, NULL);   /* main loop */
    pcap_close (handle);
    return 0;
}
コード例 #2
0
/*=============================================================================================*/
int prova_setup(void){
	init_arguments();
	new_reader = init_reader("reader0\0", 10);
	addElement(parm1->reader_list, (void*)new_reader);

	parametri_reader* parametri = (parametri_reader*)malloc(sizeof(parametri_reader));
	parametri->reader = new_reader;
	parametri->lista_reader_struct = parm->lista_reader_contes;
	pthread_create(new_reader->tid_reader, NULL, reader_thread,(void*)parametri);
	
	buffer_provider = buffer_init(10);
	numero_messaggi = 6;
	init_provider_agruments();

	pthread_t provider_thread;
	pthread_create(&provider_thread, NULL,create_messages, (void*)provider_struct);
	

	dispatcher_param = (parametri_dispatcher*)malloc(sizeof(parametri_dispatcher));
	dispatcher_param->provider_struct =  provider_struct;
	dispatcher_param->requests_list_struct = parm;

	pthread_t dispatcher;
	pthread_create(&dispatcher, NULL,dispatcher_thread, (void*)dispatcher_param);
	
	pthread_join(dispatcher,(void*)&codRitThread_dispatcher);
	pthread_join(provider_thread,NULL);
	pthread_join(*(new_reader->tid_reader),&cod_rit_red_thd);
	return 0;
}
コード例 #3
0
ファイル: main.c プロジェクト: NoSuchProcess/phantomuserland
int main(int argc, char *argv[], char *envp[])
{
    (void) envp;

    // TODO bring in good malloc/free and implement sbrk()!
    //static char arena[1024*1024];
    //init_malloc( arena, sizeof(arena) );

    printf("Phantom Simple Unix Box Shell is running, pid %d\n", getpid());

#if 0
    printf("ac = %d\n", argc );
    char **avp = argv;
    while( *avp )
    {
        printf("arg = %p\n", *avp );
        printf("arg = '%s'\n", *avp++ );
    }
#endif


    init_vars();
    init_statements();
    init_arguments(argc,argv);

    if(af_script_file_name != NULL)
    {
        run_script(af_script_file_name);
        if(af_exit_after_script) exit(0);
    }

    setvbuf( stdin, 0, _IONBF, 0 );
    //setvbuf( stdout, 0, _IONBF, 0 );

    char buf[1024];

    for(;;) {

        printf("> ");

        getline(buf, sizeof(buf));
        if(strlen(buf) > 0) {
            parse_string(buf);
        }
        buf[0] = '\0';
    }

    return 0;
}
コード例 #4
0
ファイル: app.cpp プロジェクト: jj4jj/dcpots
int App::init(int argc, const char * argv[]){
    int ret = on_create(argc, argv);
    if (ret){
        GLOG_ERR("app check start error:%d !", ret);
        return -1;
    }
    ret = init_arguments(argc, argv, impl_, *this);
    if (ret){
        GLOG_ERR("init argumets error :%d !", ret);
        return -1;
    }
    _app_reload_env(impl_);
    //////////////////////////////////////////////////////////////
    const char * pidfile = cmdopt().getoptstr("pid-file");
    //1.control command
    ret = init_command(*this, pidfile);
    if (ret){
        if (ret < 0){
            GLOG_ERR("control command init error:%d !", ret);
            return -1;
        }
        else {
            exit(0);
        }
    }
    //"start:n:S:start process normal mode;"
    if (!cmdopt().hasopt("start")){
        exit(-1);
    }
    //2.daemonlization and pid running checking
    if (cmdopt().hasopt("daemon")){
        daemonlize(1, 0, pidfile);
    }
    if (pidfile && getpid() != dcs::lockpidfile(pidfile)){
        fprintf(stderr, "process should be unique running ...");
        return -2;
    }
    init_signal();
    //////////////////////////////////////////////////////////////
    ret = init_facilities(*this, impl_);
    if (ret){
        GLOG_ERR("init facilities error:%d !", ret);
        return -1;
    }
    GLOG_IFO("app framework init success !");
    //////////////////////////////////////////////////////////////////////////////////
    return on_init();
}
コード例 #5
0
ファイル: main.c プロジェクト: matwey/logfanoutd
int main(int argc, char** argv) {
	struct arguments* pargs;
	struct logfanoutd_state* plf_state;
	struct vpath_pair** aliases;
	size_t aliases_size;
	int ret = 1;

	signal(SIGINT, &handle_signal);
	signal(SIGTERM, &handle_signal);

	pargs = init_arguments();
	if (pargs == NULL) {
		goto fail_init_args;
	}
	if (parse_args(argc, argv, pargs)) {
		goto fail_parse_args;
	}

	aliases = init_aliases(pargs->alias_list, &aliases_size);
	if (aliases == NULL) {
		goto fail_alloc_aliases;
	}

	plf_state = logfanoutd_start(&(pargs->listen), pargs->verbose, pargs->log, aliases, aliases_size);
	if (plf_state == NULL) {
		goto fail_logfanoutd_start;
	}

	pause();

	logfanoutd_stop(plf_state);
	ret = 0;

fail_logfanoutd_start:
	free(aliases);
fail_alloc_aliases:
fail_parse_args:
	free_arguments(pargs);
fail_init_args:
	return ret;
}
コード例 #6
0
static HRESULT create_var_disp(FunctionInstance *function, LCID lcid, DISPPARAMS *dp, jsexcept_t *ei,
                               IServiceProvider *caller, DispatchEx **ret)
{
    DispatchEx *var_disp, *arg_disp;
    HRESULT hres;

    static const WCHAR argumentsW[] = {'a','r','g','u','m','e','n','t','s',0};

    hres = create_dispex(function->dispex.ctx, NULL, NULL, &var_disp);
    if(FAILED(hres))
        return hres;

    hres = create_dispex(function->dispex.ctx, NULL, NULL, &arg_disp);
    if(SUCCEEDED(hres)) {
        hres = init_arguments(arg_disp, function, lcid, dp, ei, caller);
        if(SUCCEEDED(hres)) {
            VARIANT var;

            V_VT(&var) = VT_DISPATCH;
            V_DISPATCH(&var) = (IDispatch*)_IDispatchEx_(arg_disp);
            hres = jsdisp_propput_name(var_disp, argumentsW, lcid, &var, ei, caller);
        }

        jsdisp_release(arg_disp);
    }

    if(SUCCEEDED(hres))
        hres = init_parameters(var_disp, function, lcid, dp, ei, caller);
    if(FAILED(hres)) {
        jsdisp_release(var_disp);
        return hres;
    }

    *ret = var_disp;
    return S_OK;
}
コード例 #7
0
int
main(int argc, char *argv[]) 
{    
    char *pshost = NULL;
    char *request_buffer = NULL;
    int requestlen;
    int return_value = 1;

    myproxy_socket_attrs_t *socket_attrs;
    myproxy_request_t      *client_request;
    myproxy_response_t     *server_response;
    
    /* check library version */
    if (myproxy_check_version()) {
	fprintf(stderr, "MyProxy library version mismatch.\n"
		"Expecting %s.  Found %s.\n",
		MYPROXY_VERSION_DATE, myproxy_version(0,0,0));
	exit(1);
    }

    myproxy_log_use_stream (stderr);

    socket_attrs = malloc(sizeof(*socket_attrs));
    memset(socket_attrs, 0, sizeof(*socket_attrs));

    client_request = malloc(sizeof(*client_request));
    memset(client_request, 0, sizeof(*client_request));

    server_response = malloc(sizeof(*server_response));
    memset(server_response, 0, sizeof(*server_response));

    /* setup defaults */
    client_request->version = malloc(strlen(MYPROXY_VERSION) + 1);
    strcpy(client_request->version, MYPROXY_VERSION);
    client_request->command_type = MYPROXY_DESTROY_PROXY;

    pshost = getenv("MYPROXY_SERVER");
    if (pshost != NULL) {
        socket_attrs->pshost = strdup(pshost);
    }

    client_request->proxy_lifetime = 0;
    
    if (getenv("MYPROXY_SERVER_PORT")) {
	socket_attrs->psport = atoi(getenv("MYPROXY_SERVER_PORT"));
    } else {
	socket_attrs->psport = MYPROXY_SERVER_PORT;
    }

    /* Initialize client arguments and create client request object */
    init_arguments(argc, argv, socket_attrs, client_request);

    /*
     * We don't need to send the real pass phrase to the server as it
     * will just use our identity to authenticate and authorize us.
     * But we need to send over a dummy pass phrase at least
     * MIN_PASS_PHASE_LEN (currently 6) characters long.
     */
    strncpy(client_request->passphrase, "DUMMY-PASSPHRASE",
	    sizeof(client_request->passphrase));
    
    /* Set up client socket attributes */
    if (myproxy_init_client(socket_attrs) < 0) {
	verror_print_error(stderr);
        goto cleanup;
    }

    /* Authenticate client to server */
    if (myproxy_authenticate_init(socket_attrs, NULL /* Default proxy */) < 0) {
	verror_print_error(stderr);
	goto cleanup;
    }

    if (client_request->username == NULL) { /* set default username */
	if (dn_as_username) {
	    if (ssl_get_base_subject_file(NULL,
					  &client_request->username)) {
		fprintf(stderr,
			"Cannot get subject name from your certificate\n");
		goto cleanup;
	    }
	} else {
	    char *username = NULL;
	    if (!(username = getenv("LOGNAME"))) {
		fprintf(stderr, "Please specify a username.\n");
		goto cleanup;
	    }
	    client_request->username = strdup(username);
	}
    }

    /* Serialize client request object */
    requestlen = myproxy_serialize_request_ex(client_request, 
					      &request_buffer);
    
    if (requestlen < 0) {
	verror_print_error(stderr);
        goto cleanup;
    }

    /* Send request to the myproxy-server */
    if (myproxy_send(socket_attrs, request_buffer, requestlen) < 0) {
	verror_print_error(stderr);
        goto cleanup;
    }
    free(request_buffer);
    request_buffer = NULL;

    /* Receive a response from the server */
    if (myproxy_recv_response_ex(socket_attrs, server_response,
				 client_request) < 0) {
	verror_print_error(stderr);
        goto cleanup;
    }

    /* Check response */
    switch(server_response->response_type) {
    case MYPROXY_ERROR_RESPONSE:
        fprintf(stderr, "Received error from server: %s\n",
		server_response->error_string);
	goto cleanup;
    case MYPROXY_OK_RESPONSE:
	if (client_request->credname) {
	    printf("MyProxy credential '%s' for user %s was successfully removed.\n",
		   client_request->credname, client_request->username); 
	} else {
	    printf("Default MyProxy credential for user %s was successfully removed.\n",
		   client_request->username); 
	}
        break;
    default:
        fprintf(stderr, "Invalid response type received.\n");
	goto cleanup;
    }
    
    return_value = 0;

 cleanup:
    /* free memory allocated */
    myproxy_free(socket_attrs, client_request, server_response);

    return return_value;
}
コード例 #8
0
int main(int argc, char *argv[])
{
    SSL_CREDENTIALS *creds;
    myproxy_creds_t my_creds = {0};
    char proxyfile[64] = "";
    int rval=1;

    /* check library version */
    if (myproxy_check_version()) {
	fprintf(stderr, "MyProxy library version mismatch.\n"
		"Expecting %s.  Found %s.\n",
		MYPROXY_VERSION_DATE, myproxy_version(0,0,0));
	exit(1);
    }

    myproxy_log_use_stream (stderr);

    creds = ssl_credentials_new();
    init_arguments (argc, argv, &my_creds);

    if (certfile == NULL) {
	fprintf (stderr, "Specify certificate file with -c option\n");
	fprintf(stderr, "%s", usage);
	goto cleanup;
    }

    if (keyfile == NULL) {
	fprintf (stderr, "Specify key file with -y option\n");
	fprintf(stderr, "%s", usage);
	goto cleanup;
    }

    sprintf(proxyfile, "%s.%u.%u", MYPROXY_DEFAULT_PROXY,
	    (unsigned)getuid(), (unsigned)getpid());
    /* Remove proxyfile if it already exists. */
    ssl_proxy_file_destroy(proxyfile);
    verror_clear();

    if (makeproxy(certfile, keyfile, proxyfile) < 0) {
	fprintf(stderr, "Failed to create temporary credentials file.\n");
	goto cleanup;
    }
		
    if (my_creds.username == NULL) { /* set default username */
	if (dn_as_username) {
	    if (ssl_get_base_subject_file(proxyfile,
					  &my_creds.username)) {
		fprintf(stderr,
			"Cannot get subject name from your certificate\n");
		goto cleanup;
	    }
	} else {
	    char *username = NULL;
	    if (!(username = getenv("LOGNAME"))) {
		fprintf(stderr, "Please specify a username.\n");
		goto cleanup;
	    }
	    my_creds.username = strdup(username);
	}
    }

    if (ssl_get_base_subject_file(proxyfile,
				  &my_creds.owner_name)) {
	fprintf(stderr,
		"Cannot get subject name from certificate.\n");
	goto cleanup;
    }
    my_creds.location = strdup(proxyfile);

    if (myproxy_creds_store(&my_creds) < 0) {
	myproxy_log_verror();
	fprintf (stderr, "Unable to store credentials. %s\n",
		 verror_get_string()); 
    goto cleanup;
    } else {
	fprintf (stdout, "Credential stored successfully\n");
    }

    rval = 0;
 cleanup:
    if (proxyfile[0]) ssl_proxy_file_destroy(proxyfile);
    return rval;
}