static int 
proc_auth(tc_sess_t *s, tc_iph_t *ip, tc_tcph_t *tcp)
{
    uint16_t          size_tcp;
    unsigned char    *p, *payload, pack_number;
    tc_mysql_session *mysql_sess;

    if (!s->sm.rcv_rep_greet) {
        return PACK_STOP;
    }

    mysql_sess = s->data;

    if (!s->sm.fake_syn) {
        
        if (!mysql_sess->req_begin) {
            size_tcp    = tcp->doff << 2;
            payload = (unsigned char *) ((char *) tcp + size_tcp);
            /* skip packet length */
            payload     = payload + 3; 
            pack_number = payload[0];

            if (pack_number == 0) { 
                mysql_sess->req_begin = 1; 
                mysql_sess->old_ps_cleaned = 1;
                tc_log_debug0(LOG_NOTICE, 0, "it has no sec auth packet");
                release_resources(s->hash_key);

            } else if (pack_number == (unsigned char) SEC_AUTH_PACKET_NUM) { 
                /* if it is the second authenticate_user, skip it */
                tc_log_debug0(LOG_NOTICE, 0, "omit sec validation for mysql");
                mysql_sess->req_begin = 1; 
                mysql_sess->seq_diff = s->cur_pack.cont_len;
                mysql_sess->old_ps_cleaned = 1;
                release_resources(s->hash_key);

                return PACK_NEXT;
            }    
        }    

        if (!mysql_sess->req_begin) {
            if (!ctx.fir_auth_pack) {
                p = cp_fr_ip_pack(ctx.pool, ip); 
                ctx.fir_auth_pack = (tc_iph_t *) (p + ETHERNET_HDR_LEN);
                ctx.fir_auth_cont_len = s->cur_pack.cont_len;
                tc_log_info(LOG_NOTICE, 0, "fir auth is set");
            }
        }
    } else {
        if (!mysql_sess->old_ps_cleaned) {
            mysql_sess->old_ps_cleaned = 1;
            release_resources(s->hash_key);
        }
    }
    
    return PACK_CONTINUE;
}
SoundOutput_DirectSound::~SoundOutput_DirectSound()
{
	stop_mixer_thread();
	if (soundbuffer)
		soundbuffer->Stop();
	release_resources();
}
SoundOutput_DirectSound::SoundOutput_DirectSound(int mixing_frequency, int mixing_latency)
: SoundOutput_Impl(mixing_frequency, mixing_latency), directsound(0), soundbuffer(0),
  frag_size(0), sleep_event(0), hwnd(0), notify(0), has_sound(true), last_write_pos(-1)
{
	try
	{
		create_directsound_object();
		set_cooperative_level();
		set_fragment_size();
		create_sound_buffer();
		verify_sound_buffer_capabilities();
		clear_sound_buffer();
		create_notify_event();
		retrieve_notify_interface();
		set_notify_positions();
		play_sound_buffer();
	}
	catch (const Exception &e)
	{
		release_resources();
		log_event("mixer", e.message);
		frag_size = mixing_frequency/2;
		has_sound = false;
	}
}
Beispiel #4
0
void statement_imp::prepare (std::string const& query, bool bRepeatable)
{
  m_query = query;
  m_session.log_query(query);
  m_last_insert_rowid = 0;

  release_resources();

  char const* tail = 0;
  int result = sqlite3_prepare_v2(
    m_session.get_connection(),
    query.c_str(),
    static_cast<int>(query.size()),
    &m_stmt,
    &tail );

  if (result == SQLITE_OK)
  {
    m_bReady = true;
  }
  else
  {
    Throw (detail::sqliteError (__FILE__, __LINE__, result));
  }
}
Beispiel #5
0
void clean(){
    int i;
    int flag = FALSE;
lock_repo();
    for (i=0; i<REPO_SIZE; ++i) {
        if (SHM_SERVER_IDS_ADRESS[i] == MSG_RECEIVER) {
            SHM_SERVER_IDS_ADRESS[i] = -1;
        } else if (SHM_SERVER_IDS_ADRESS[i] != -1) {
            flag = TRUE;
        }
    }
    unlock_repo();
    for(i=0; i<MAX_USERS_NUMBER; ++i) {
        if (LOCAL_REPO[i].client_id != -1){
            MSG_LOGIN user;
            user.ipc_num = LOCAL_REPO[i].client_id;
            strcpy(user.username, LOCAL_REPO[i].user_name);
            unregister_user(user);
        }
    }

    log_data("DEAD");
    
    //we are last server so we clean whole repo
    if(!flag){
        log_data("CLEANING REPOSITORY");
        clean_repo();
    }

    release_resources();

    signal(SIGINT, SIG_DFL);
    exit(EXIT_SUCCESS);
}
Beispiel #6
0
/* 
 * Log & Quit
 */
void
quit_route6d(char *s, int ret_code)
{
	if (s)
		syslog(LOG_ERR, "%s: %m", s);
	release_resources();
	exit(ret_code);
}
Beispiel #7
0
int			main(int argc, char **argv)
{
	t_core		c;

	if (!init(&c))
		return (0);
	loop(&c);
	release_resources(&c);
	release_levels(&c);
	free(c.rdf);
	(void)argc;
	(void)argv;
	return (1);
}
Beispiel #8
0
int openib_initialize()
{

    // Use the previously cached info
    me = l_state.rank;
    nprocs = l_state.size;
    assert(l_state.world_comm);

    // initialize the envs
    openib_init_envs();

    //Initialize the registration cache

    reg_cache_init(nprocs, 0);

    init_params();

    if(open_hca()) {
        release_resources();
        exit(1);
    }

    if(create_cq()) {
        release_resources();
        exit(1);
    }

    if(get_lid()) {
        release_resources();
        exit(1);
    }

    if(create_qp()) {
        release_resources();
        exit(1);
    }

    if(exch_addr()) {
        release_resources();
        exit(1);
    }

    if(connect_qp()) {
        release_resources();
        exit(1);
    }

    // Create network locks
    openib_create_locks();

    // Allocate buffers for one sided operations
    openib_alloc_buf();

    MPI_Barrier(l_state.world_comm);

    return 0;
}
Beispiel #9
0
static void
signal_handler(int sig)
{
    tc_log_info(LOG_ERR, 0, "set signal handler:%d", sig);
    printf("set signal handler:%d\n", sig);

    if (sig == SIGSEGV) {
        tc_log_info(LOG_ERR, 0, "SIGSEGV error");
        release_resources();
        /* avoid dead loop*/
        signal(SIGSEGV, SIG_DFL);
        kill(getpid(), sig);
    } else {
        exit(EXIT_SUCCESS);
    }
}
static void 
remove_obsolete_resources(int is_full) 
{
    time_t      thresh_access_tme;
    uint32_t    i, cnt = 0;
    link_list  *l;
    hash_node  *hn;
    p_link_node ln, next_ln;

    if (ctx.table == NULL || ctx.table->total == 0) {
        return;
    }

    if (is_full) {
        thresh_access_tme = tc_time() + 1;
    } else {
        thresh_access_tme = tc_time() - MAX_IDLE_TIME;
    }

    for (i = 0; i < ctx.table->size; i ++) {
        l  = get_link_list(ctx.table, i);
        if (l->size > 0) {
            ln = link_list_first(l);
            while (ln) {
                hn = (hash_node *) ln->data;
                next_ln = link_list_get_next(l, ln);
                if (hn->access_time < thresh_access_tme) {
                    release_resources(hn->key);
                }
                ln = next_ln;
            }
            
            cnt += l->size;

            if (ctx.table->total == cnt) {
                break;
            }
        }
    }
}
void *thread_create(void *cno)
{
	int ii,j,request[NUMBER_OF_RESOURCES],request_flag=0;
	int cust_no = (int)cno;
	//Create a random request
	for(ii=0;ii<NUMBER_OF_RESOURCES;ii++)
	{
		//this will be always less than the max that can be requested
		request[ii] = rand() % available[ii];
	}

	//Resource allocated depending on safety and this customer waits on request
		if(request_resources(cust_no,request)<0)
		{
			printf("\n Customer %d ", cust_no);
			for(j=0;j<NUMBER_OF_RESOURCES;j++)
				printf("%d ", request[j]);
			printf(":Request Denied\n");
		}
		else
		{
			request_flag = 1;
			printf("\n Customer %d ", cust_no);
			for(j=0;j<NUMBER_OF_RESOURCES;j++)
				printf("%d ", request[j]);
			printf(":Request Accepted\n");
		}	
	//sleep for a random amount of time
	sleep(rand() % 10);

	//Release the resource if allocated
	if(request_flag==1)
	{
		release_resources(cust_no, request);
		printf("\n Customer %d released resouces", cust_no);
	}

}
Beispiel #12
0
void
parse_file(PARROT_INTERP, int flexdebug, ARGIN(FILE *infile),
           ARGIN(char * const filename), int flags,
           int thr_id, unsigned macro_size,
           ARGMOD_NULLOK(char * const outputfile))
{
    ASSERT_ARGS(parse_file)
    yyscan_t     yyscanner;
    lexer_state *lexer     = NULL;

    /* create a yyscan_t object */
    yypirlex_init(&yyscanner);
    /* set debug flag */
    yypirset_debug(flexdebug, yyscanner);
    /* set the input file */
    yypirset_in(infile, yyscanner);
    /* set the extra parameter in the yyscan_t structure */
    lexer = new_lexer(interp, filename, flags);
    lexer->macro_size = macro_size;

    /* initialize the scanner state */
    init_scanner_state(yyscanner);

    if (strstr(filename, ".pasm")) { /* PASM mode */
        SET_FLAG(lexer->flags, LEXER_FLAG_PASMFILE);
    }

    yypirset_extra(lexer, yyscanner);
    /* and store the yyscanner in the lexer, so they're close buddies */
    lexer->yyscanner = yyscanner;
    /* go parse */
    yypirparse(yyscanner, lexer);


    if (lexer->parse_errors == 0) {
        char outfile[20];
        sprintf(outfile, "output_thr_%d", thr_id);
        lexer->outfile = open_file(outfile, "w");
        if (lexer->outfile == NULL) {
            fprintf(stderr, "Failed to open file %s\n", outfile);
            lexer->outfile = stdout;
        }

        if (TEST_FLAG(lexer->flags, LEXER_FLAG_NOOUTPUT)) /* handy for testing the compiler */
            fprintf(stdout, "ok\n");
        else if (TEST_FLAG(lexer->flags, LEXER_FLAG_PREPROCESS))
            emit_pir_subs(lexer, outputfile);
        else if (TEST_FLAG(lexer->flags, LEXER_FLAG_OUTPUTPBC))
            emit_pbc(lexer, outputfile);
        else
            /*
            fprintf(stderr, "Parse successful!\n");
            */
            print_subs(lexer);


        fclose(lexer->outfile);

        if (TEST_FLAG(lexer->flags, LEXER_FLAG_WARNINGS))
            check_unused_symbols(lexer);

    }

    /* there may have been errors during the instruction generation, check again here. */
    if (lexer->parse_errors > 0)
        fprintf(stderr, "There were %d errors\n", lexer->parse_errors);

    fclose(infile);


    /* XXX just want to make sure pirc doesn't segfault when doing bytecode stuff. */
/*
    if (TEST_FLAG(lexer->flags, LEXER_FLAG_OUTPUTPBC))
        fprintf(stderr, "pirc ok\n");
*/

    /* clean up after playing */
    release_resources(lexer);
    yypirlex_destroy(yyscanner);

}
Beispiel #13
0
/*

=item C<void parse_string(PARROT_INTERP, char *pirstring, int flags, int
pasminput, unsigned macro_size)>

Parse a PIR string.

=cut

*/
void
parse_string(PARROT_INTERP, ARGIN(char *pirstring), int flags, int pasminput,
    unsigned macro_size)
{
    ASSERT_ARGS(parse_string)
    yyscan_t            yyscanner;
    lexer_state        *lexer = NULL;
    char                name[64];
    PackFile_ByteCode  *old_cs, *new_cs;
    INTVAL              eval_number;


    if (eval_nr == 0)
        MUTEX_INIT(eval_nr_lock);

    LOCK(eval_nr_lock);
    eval_number = ++eval_nr;
    UNLOCK(eval_nr_lock);

    snprintf(name, sizeof (name), "EVAL_" INTVAL_FMT, eval_number);

    new_cs = PF_create_default_segs(interp, Parrot_str_new(interp, name, strlen(name)), 0);
    old_cs = Parrot_switch_to_cs(interp, new_cs, 0);

    /* create a yyscan_t object */
    yypirlex_init(&yyscanner);

    yypirset_debug(0, yyscanner);


    /* set the extra parameter in the yyscan_t structure */
    lexer = new_lexer(interp, name, flags);
    lexer->macro_size = macro_size;
    yypirset_extra(lexer, yyscanner);
    lexer->yyscanner = yyscanner;

    /* initialize the scanner state */
    init_scanner_state(yyscanner);

    /* set the scanner to a string buffer and go parse */
    yypir_scan_string(pirstring, yyscanner);

    if (pasminput) { /* PASM mode */
        SET_FLAG(lexer->flags, LEXER_FLAG_PASMFILE);
    }


    yypirparse(yyscanner, lexer);

    if (lexer->parse_errors == 0) {

        print_subs(lexer);

        if (TEST_FLAG(lexer->flags, LEXER_FLAG_WARNINGS))
            check_unused_symbols(lexer);
    }

    /* there may have been errors during the instruction generation, check again here. */
    if (lexer->parse_errors > 0)
        fprintf(stderr, "There were %d errors\n", lexer->parse_errors);

    /* XXX just want to make sure pirc doesn't segfault when doing bytecode stuff. */
    if (TEST_FLAG(lexer->flags, LEXER_FLAG_OUTPUTPBC)) {
        emit_pbc(lexer, NULL);
    }

/*
    fprintf(stderr, "ok\n");
*/

    /* clean up after playing */
    release_resources(lexer);

    /* clean up after playing */
    yypirlex_destroy(yyscanner);


}
Beispiel #14
0
void statement_imp::clean_up()
{
  erase_bindings();
  release_resources();
}
Beispiel #15
0
int openib_finalize()
{
    release_resources();
}
file_system_watcher::path_watcher::~path_watcher()
{ try { release_resources(); } catch( const std::exception& exception ) { assert(false); } }
Beispiel #17
0
 void term() {
   release_resources();
   if(device) { device->Release(); device = 0; }
   if(lpd3d) { lpd3d->Release(); lpd3d = 0; }
 }
static int 
proc_when_sess_destroyed(tc_sess_t *s)
{
    release_resources(s->hash_key);
    return TC_OK;
}