Ejemplo n.º 1
0
void
ovh(int argc, char *argv[]) {

	struct arguments args = { NULL, NULL, NULL };
	struct ip_addresses ip;
	struct error_s err_s;
	int s = 0;

	(void)memset(&ip, 0, sizeof(ip));
	init_error(&err_s, LOG_USER, argv[0], EMAIL);

	if(get_flags_ovh(&args, argc, argv)) {
		(void)fprintf(stderr, USAGE,  argv[0]);
		exit(EXIT_FAILURE);
	}

	if(check_ovh(args.interface, &ip)) {
		if((s = get_connection(DYNDNSHOST_IP, PORT)) < 0)
		    print_error_ovh(LOG_ERR, EXIT, STANDARD, "get_connection() failed");
		update_ovh(s, &ip, &args);
		if(check_server_msg_ovh(s))
		    print_error_ovh(LOG_ERR, EXIT, STANDARD, "unknown server message");
		else update_cache_ovh(&ip);
		(void)close(s);
	} else print_error_ovh(LOG_INFO, CONTINUE, STANDARD, "update is not necessary");

	return;

}
Ejemplo n.º 2
0
//////////////////////////////////////////////////////////////////////////////
/// Inizialization. This function is called once before entering 
/// main loop. 
///
//////////////////////////////////////////////////////////////////////////////
void init() {
	VMC_INT_16 motorID;

	init_aisc167b();
    init_asccom();    
    init_cycletime_counter();
	i2c_init();
	init_bioport();
	if (can_init(CAN_BAUD, 0)) while(1){led_swap_green();}

    led_set_green(0);
    led_set_red(0);
	ledseq_init();

    ais_system_init();


	//init_Thermic();
	init_error();
	init_calculatestate();
	init_motorcontrol();
	init_controller();
	init_current_limiter();
	mpwr_init();

	set_default_configuration();

	for (motorID = 0; motorID < 3; motorID++) {
	//	init_Limiter(i, 100);
		init_encoder(motorID);
	}
   


}
Ejemplo n.º 3
0
/*!
  \brief Open database (OGR datasource)

  \param handle pointer to dbHandle (db name and schema)

  \return DB_OK on success
  \return DB_FAILED on failure
*/
int db__driver_open_database(dbHandle * handle)
{
    const char *name;
    dbConnection connection;

    init_error();
    db_get_connection(&connection);
    name = db_get_handle_dbname(handle);

    /* if name is empty use connection.databaseName */
    if (strlen(name) == 0)
	name = connection.databaseName;

    G_debug(3, "db_driver_open_database() name = '%s'", name);

    OGRRegisterAll();

    hDs = OGROpen(name, TRUE, NULL);

    if (hDs == NULL) {
	append_error(_("Unable to open OGR data source"));
	report_error();
	return DB_FAILED;
    }

    G_debug(3, "Datasource opened");

    return DB_OK;
}
Ejemplo n.º 4
0
void error_add_message(char *msg)
{
	if (!error_wnd) init_error();
	if (error_wnd)
	{
		struct error_node *enode = (struct error_node*)malloc(sizeof(struct error_node));
		if (enode)
		{
			if ((enode->text = mystrdup(msg)))
			{
				static char error_label[32];

				set(text_list, MUIA_NList_Quiet, TRUE);
				DoMethod(text_list, MUIM_NList_Clear);
				DoMethod(text_list, MUIM_NList_InsertSingleWrap, (ULONG)enode->text, MUIV_NList_Insert_Bottom, WRAPCOL0, ALIGN_LEFT);
				set(text_list, MUIA_NList_Quiet, FALSE);

				list_insert_tail(&error_list, &enode->node);

				sprintf(error_label, "Error %%ld/%d",list_length(&error_list));

				SetAttrs(error_numeric,
						MUIA_Numeric_Min, 1,
						MUIA_Numeric_Max, list_length(&error_list),
						MUIA_Numeric_Value, list_length(&error_list),
						MUIA_Numeric_Format, error_label,
						TAG_DONE);
			} else free(enode);
		}

		set(error_wnd, MUIA_Window_Open, TRUE);
	}
}
Ejemplo n.º 5
0
t_wolf	*init_map(char *av)
{
  t_wolf	*wolf;
  t_bunny_ini_scope	*scope;
  t_bunny_ini	*ini;

  if ((wolf = bunny_malloc(sizeof(t_wolf))) == NULL)
    return ((t_wolf *)-1);
  if ((ini = bunny_load_ini(av)) == NULL)
    return ((t_wolf *)-1);
  scope = bunny_ini_first(ini);
  scope = bunny_ini_next(ini, scope);
  wolf->s_name = bunny_ini_scope_name(ini, scope);
  wolf->width = 0;
  wolf->height = 0;
  wolf = get_dim(wolf, ini);
  if (check_air(wolf, ini) == -1)
    return ((t_wolf *)-1);
  wolf = get_map(wolf, ini);
  wolf = get_player(wolf, ini);
  if (init_error(wolf) == -1)
    return ((t_wolf *)-1);
  bunny_delete_ini(ini);
  return (wolf);
}
Ejemplo n.º 6
0
void x86Machine::rebootPulseResetLine() {
	if(reqport(PORT_KB_DATA) < 0)
		throw init_error("Unable to request keyboard data-port");
	if(reqport(PORT_KB_CTRL) < 0)
		throw init_error("Unable to request keyboard-control-port");

	// wait until in-buffer empty
	while((inbyte(PORT_KB_CTRL) & 0x2) != 0)
		;
	// command 0xD1 to write the outputport
	outbyte(PORT_KB_CTRL,0xD1);
	// wait again until in-buffer empty
	while((inbyte(PORT_KB_CTRL) & 0x2) != 0)
		;
	// now set the new output-port for reset
	outbyte(PORT_KB_DATA,0xFE);
}
Ejemplo n.º 7
0
		SDL(Uint32 flags = SDL_INIT_VIDEO)
		{
			if (SDL_Init(flags) < 0) {
				std::stringstream ss;
				ss << "Unable to initialize SDL: " << SDL_GetError() << std::endl;
				throw init_error(ss.str());
			}
		}
Ejemplo n.º 8
0
void tool_parse(int argc, char *argv[], cpili_task_t *task) {
    if (1 == argc) {
        // wrong param, show usage
        init_error(CPILI_ERROR_WRONG_PARAM, &(task->error));
        tool_route(CPILI_OPT_USAGE, task);
    } else {
        cpili_task_operation_t opt = CPILI_OPT_USAGE;
        
        int i = 1;
        while (i < argc) {
            cpili_option_t option = get_option(argv[i]);
            if (NULL == option.letter) {
                init_error(CPILI_ERROR_WRONG_PARAM, &(task->error));
                break;
            } else if (!strcmp("h", option.letter)) {
                // help
                opt = CPILI_OPT_USAGE;
            } else if (!strcmp("v", option.letter)) {
                // version
                opt = CPILI_OPT_VERSION;
            } else {
                // streaming
                opt = CPILI_OPT_STREAMING;
            }
            
            if (option.extra_param) {
                if (i + 1 < argc) {
                    const char *value = argv[++i];
                    if (!option.setter(task, value)) {
                        init_error(CPILI_ERROR_WRONG_PARAM, &(task->error));
                        break;
                    }
                } else {
                    init_error(CPILI_ERROR_WRONG_PARAM, &(task->error));
                    break;
                }
            }
            ++i;
        }
        
        tool_route(opt, task);
    }
}
Ejemplo n.º 9
0
/*!
  \brief Close open database

  \return DB_OK on success
  \return DB_FAILED on failure
*/
int db__driver_close_database()
{
    G_debug(3, "db_driver_close_database()");

    init_error();
    OGR_DS_Destroy(hDs);

    G_debug(3, "Database closed");

    return DB_OK;
}
Ejemplo n.º 10
0
int rbac_adm_perm_init( void )
{ struct event_handler_s *eh;
    struct event_names_s *event;

    if( (eh=malloc(6*sizeof(struct event_handler_s)))==NULL )
    {	init_error(Out_of_memory);
        return(-1);
    }
    /* create_role */
    event=event_type_find_name("create_role");
    strncpy(eh[0].op_name,"rbac_h_create_role",MEDUSA_OPNAME_MAX);
    eh[0].handler=rbac_h_create_role;
    eh[0].local_vars=NULL;
    if( register_event_handler(&(eh[0]),event,&(event->handlers_hash[EHH_VS_ALLOW]),ALL_OBJ,ALL_OBJ)<0 )
        return(init_error("rbac: Can't register handler for create_role"));
    /* delete_role */
    event=event_type_find_name("delete_role");
    strncpy(eh[1].op_name,"rbac_h_delete_role",MEDUSA_OPNAME_MAX);
    eh[1].handler=rbac_h_delete_role;
    eh[1].local_vars=NULL;
    if( register_event_handler(&(eh[1]),event,&(event->handlers_hash[EHH_VS_ALLOW]),ALL_OBJ,ALL_OBJ)<0 )
        return(init_error("rbac: Can't register handler for delete_role"));
    /* role_hierarchy */
    event=event_type_find_name("role_hierarchy");
    strncpy(eh[2].op_name,"rbac_h_role_hierarchy",MEDUSA_OPNAME_MAX);
    eh[2].handler=rbac_h_role_hierarchy;
    eh[2].local_vars=NULL;
    if( register_event_handler(&(eh[2]),event,&(event->handlers_hash[EHH_VS_ALLOW]),ALL_OBJ,ALL_OBJ)<0 )
        return(init_error("rbac: Can't register handler for role_hierarchy"));
    /* uses_assign */
    event=event_type_find_name("uses_assign");
    strncpy(eh[3].op_name,"rbac_h_user_assign",MEDUSA_OPNAME_MAX);
    eh[3].handler=rbac_h_user_assign;
    eh[3].local_vars=NULL;
    if( register_event_handler(&(eh[3]),event,&(event->handlers_hash[EHH_VS_ALLOW]),ALL_OBJ,ALL_OBJ)<0 )
        return(init_error("rbac: Can't register handler for uses_assign"));
    /* role_assign */
    event=event_type_find_name("role_assign");
    strncpy(eh[4].op_name,"rbac_h_role_assign",MEDUSA_OPNAME_MAX);
    eh[4].handler=rbac_h_role_assign;
    eh[4].local_vars=NULL;
    if( register_event_handler(&(eh[4]),event,&(event->handlers_hash[EHH_VS_ALLOW]),ALL_OBJ,ALL_OBJ)<0 )
        return(init_error("rbac: Can't register handler for role_assign"));
    /* permission_assign */
    event=event_type_find_name("permission_assign");
    strncpy(eh[5].op_name,"rbac_h_perm_assign",MEDUSA_OPNAME_MAX);
    eh[5].handler=rbac_h_perm_assign;
    eh[5].local_vars=NULL;
    if( register_event_handler(&(eh[5]),event,&(event->handlers_hash[EHH_VS_ALLOW]),ALL_OBJ,ALL_OBJ)<0 )
        return(init_error("rbac: Can't register handler for permission_assign"));
    return(0);
}
Ejemplo n.º 11
0
int db__driver_begin_transaction(void)
{
    G_debug(2, "mysql: START TRANSACTION");

    init_error();

    if (mysql_query(connection, "START TRANSACTION") != 0) {
	append_error("Cannot start transaction: \n");
	append_error(mysql_error(connection));
	report_error();
	return DB_FAILED;
    }

    return DB_OK;
}
Ejemplo n.º 12
0
int db__driver_commit_transaction(void)
{
    G_debug(2, "mysql: COMMIT");

    init_error();

    if (mysql_query(connection, "COMMIT") != 0) {
	append_error("Cannot commit transaction: \n");
	append_error(mysql_error(connection));
	report_error();
	return DB_FAILED;
    }

    return DB_OK;
}
Ejemplo n.º 13
0
int db__driver_close_cursor(dbCursor * dbc)
{
    cursor *c;

    init_error();

    /* get my cursor via the dbc token */
    c = (cursor *) db_find_token(db_get_cursor_token(dbc));
    if (c == NULL)
	return DB_FAILED;

    /* free_cursor(cursor) */
    free_cursor(c);

    return DB_OK;
}
Ejemplo n.º 14
0
/* Initialize the C++ front end.  This function is very sensitive to
   the exact order that things are done here.  It would be nice if the
   initialization done by this routine were moved to its subroutines,
   and the ordering dependencies clarified and reduced.  */
bool
cxx_init (void)
{
  location_t saved_loc;
  unsigned int i;
  static const enum tree_code stmt_codes[] = {
   CTOR_INITIALIZER,	TRY_BLOCK,	HANDLER,
   EH_SPEC_BLOCK,	USING_STMT,	TAG_DEFN,
   IF_STMT,		CLEANUP_STMT,	FOR_STMT,
   RANGE_FOR_STMT,	WHILE_STMT,	DO_STMT,
   BREAK_STMT,		CONTINUE_STMT,	SWITCH_STMT,
   EXPR_STMT
  };

  memset (&statement_code_p, 0, sizeof (statement_code_p));
  for (i = 0; i < ARRAY_SIZE (stmt_codes); i++)
    statement_code_p[stmt_codes[i]] = true;

  saved_loc = input_location;
  input_location = BUILTINS_LOCATION;

  init_reswords ();
  init_tree ();
  init_cp_semantics ();
  init_operators ();
  init_method ();
  init_error ();

  current_function_decl = NULL;

  class_type_node = ridpointers[(int) RID_CLASS];

  cxx_init_decl_processing ();

  if (c_common_init () == false)
    {
      input_location = saved_loc;
      return false;
    }

  init_cp_pragma ();

  init_repo ();

  input_location = saved_loc;
  return true;
}
Ejemplo n.º 15
0
int init_transducer (int argc, char **argv, int edit, int *usize, char **fname)
	{ FILE *input;

	  /* primary initialization */
	  init_error ();
	  init_options ();

	  /* command line parsing */
	  input = scanargs (argc, argv, fname);

	  /* initialize data structures */
	  init_textstorage (strstore_size);
	  init_ds (tstack_size, qstack_size);
	  init_textparsing (pbuffer_size, max_nr_parses);
	  *usize = ubuffer_size;

	  if (edit && (input == stdin)) return (0);
	  copy_file_into_parsebuffer (input);
	  return (1);
	};
Ejemplo n.º 16
0
/*!
  \brief Open select cursor

  \param sel select statement (given as dbString)
  \param[out] dbc pointer to dbCursor
  \param mode open mode

  \return DB_OK on success
  \return DB_FAILED on failure
*/
int db__driver_open_select_cursor(dbString * sel, dbCursor * dbc, int mode)
{
    cursor *c;
    dbTable *table;

    init_error();

    /* allocate cursor */
    c = alloc_cursor();
    if (c == NULL)
	return DB_FAILED;

    db_set_cursor_mode(dbc, mode);
    db_set_cursor_type_readonly(dbc);

    G_debug(3, "SQL: '%s'", db_get_string(sel));
    c->hLayer = OGR_DS_ExecuteSQL(hDs, db_get_string(sel), NULL, NULL);

    if (c->hLayer == NULL) {
	append_error(_("Unable to select: \n"));
	append_error(db_get_string(sel));
	append_error("\n");
	report_error();
	return DB_FAILED;
    }

    if (describe_table(c->hLayer, &table, c) == DB_FAILED) {
	append_error(_("Unable to describe table\n"));
	report_error();
	OGR_DS_ReleaseResultSet(hDs, c->hLayer);
	return DB_FAILED;
    }

    /* record table with dbCursor */
    db_set_cursor_table(dbc, table);

    /* set dbCursor's token for my cursor */
    db_set_cursor_token(dbc, c->token);

    return DB_OK;
}
Ejemplo n.º 17
0
int db__driver_execute_immediate(dbString * sql)
{
    char *str;

    init_error();

    /* In addition to standard escape character ' (apostrophe) 
     * MySQL supports also \ (backslash). Because this is not SQL
     * standard, GRASS modules cannot escape all \ in the text
     * because other drivers do not support this feature. 
     * For example, if a text contains string \' GRASS modules 
     * escape ' by another ' and the string passed to the driver is \''
     * MySQL converts \' to ' but second ' remains not escaped and 
     * result is error. 
     * Because of this, all occurencies of \ in sql must be 
     * escaped by \ */
    str = G_str_replace(db_get_string(sql), "\\", "\\\\");

    G_debug(3, "Escaped SQL: %s", str);

    if (mysql_query(connection, str) != 0) {
	append_error("Cannot execute: \n");
	append_error(str);
	append_error("\n");
	append_error(mysql_error(connection));
	report_error();
	if (str)
	    G_free(str);
	return DB_FAILED;
    }

    if (str)
	G_free(str);

    return DB_OK;
}
Ejemplo n.º 18
0
int init_tls_stream(int fd)
{
    const SSL_METHOD* method;

    printf("Starting TLS connection...");

    SSL_library_init();
    SSL_load_error_strings();
    OpenSSL_add_all_algorithms();

    if ((method = TLSv1_method()) == NULL)
        return init_error();

    if ((ctx = SSL_CTX_new(method)) == NULL)
        return init_error();

    SSL_CTX_set_verify(ctx, SSL_VERIFY_NONE, NULL);

    if ((ssl = SSL_new(ctx)) == NULL)
        return init_error();

    if (SSL_set_fd(ssl, fd) != 1)
        return init_error();

    if (SSL_connect(ssl) != 1)
        return init_error();

    if (SSL_do_handshake(ssl) != 1)
        return init_error();

    _recv_proc = _tls_recv;
    _send_proc = _tls_send;
    _perror_proc = _tls_perror;

    printf("done.\n");

    return 0;
}
Ejemplo n.º 19
0
Archivo: pyuv.c Proyecto: benoitc/pyuv
/* Module */
PyObject*
init_pyuv(void)
{
    /* Modules */
    PyObject *pyuv;
    PyObject *errno_module;
    PyObject *error_module;
    PyObject *fs_module;
    PyObject *util_module;

    /* Initialize GIL */
    PyEval_InitThreads();

#ifdef PYUV_WINDOWS
    if (pyuv_setmaxstdio()) {
        return NULL;
    }
#endif

    /* Main module */
#ifdef PYUV_PYTHON3
    pyuv = PyModule_Create(&pyuv_module);
#else
    pyuv = Py_InitModule("pyuv", NULL);
#endif

    /* Errno module */
    errno_module = init_errno();
    if (errno_module == NULL) {
        goto fail;
    }
    PyUVModule_AddObject(pyuv, "errno", errno_module);
#ifdef PYUV_PYTHON3
    PyDict_SetItemString(PyImport_GetModuleDict(), pyuv_errno_module.m_name, errno_module);
    Py_DECREF(errno_module);
#endif

    /* Error module */
    error_module = init_error();
    if (error_module == NULL) {
        goto fail;
    }
    PyUVModule_AddObject(pyuv, "error", error_module);
#ifdef PYUV_PYTHON3
    PyDict_SetItemString(PyImport_GetModuleDict(), pyuv_error_module.m_name, error_module);
    Py_DECREF(error_module);
#endif

    /* FS module */
    fs_module = init_fs();
    if (fs_module == NULL) {
        goto fail;
    }
    PyUVModule_AddObject(pyuv, "fs", fs_module);
#ifdef PYUV_PYTHON3
    PyDict_SetItemString(PyImport_GetModuleDict(), pyuv_fs_module.m_name, fs_module);
    Py_DECREF(fs_module);
#endif

    /* Util module */
    util_module = init_util();
    if (util_module == NULL) {
        goto fail;
    }
    PyUVModule_AddObject(pyuv, "util", util_module);
#ifdef PYUV_PYTHON3
    PyDict_SetItemString(PyImport_GetModuleDict(), pyuv_util_module.m_name, util_module);
    Py_DECREF(util_module);
#endif

    /* Types */
    AsyncType.tp_base = &HandleType;
    TimerType.tp_base = &HandleType;
    PrepareType.tp_base = &HandleType;
    IdleType.tp_base = &HandleType;
    CheckType.tp_base = &HandleType;
    SignalType.tp_base = &HandleType;
    UDPType.tp_base = &HandleType;
    PollType.tp_base = &HandleType;
    ProcessType.tp_base = &HandleType;

    StreamType.tp_base = &HandleType;
    TCPType.tp_base = &StreamType;
    PipeType.tp_base = &StreamType;
    TTYType.tp_base = &StreamType;

    PyUVModule_AddType(pyuv, "Loop", &LoopType);
    PyUVModule_AddType(pyuv, "Async", &AsyncType);
    PyUVModule_AddType(pyuv, "Timer", &TimerType);
    PyUVModule_AddType(pyuv, "Prepare", &PrepareType);
    PyUVModule_AddType(pyuv, "Idle", &IdleType);
    PyUVModule_AddType(pyuv, "Check", &CheckType);
    PyUVModule_AddType(pyuv, "Signal", &SignalType);
    PyUVModule_AddType(pyuv, "TCP", &TCPType);
    PyUVModule_AddType(pyuv, "Pipe", &PipeType);
    PyUVModule_AddType(pyuv, "TTY", &TTYType);
    PyUVModule_AddType(pyuv, "UDP", &UDPType);
    PyUVModule_AddType(pyuv, "Poll", &PollType);
    PyUVModule_AddType(pyuv, "StdIO", &StdIOType);
    PyUVModule_AddType(pyuv, "Process", &ProcessType);
    PyUVModule_AddType(pyuv, "ThreadPool", &ThreadPoolType);
    PyUVModule_AddType(pyuv, "SignalChecker", &SignalCheckerType);

    /* UDP constants */
    PyModule_AddIntMacro(pyuv, UV_JOIN_GROUP);
    PyModule_AddIntMacro(pyuv, UV_LEAVE_GROUP);

    /* Process constants */
    PyModule_AddIntMacro(pyuv, UV_PROCESS_SETUID);
    PyModule_AddIntMacro(pyuv, UV_PROCESS_SETGID);
    PyModule_AddIntMacro(pyuv, UV_PROCESS_WINDOWS_VERBATIM_ARGUMENTS);
    PyModule_AddIntMacro(pyuv, UV_PROCESS_DETACHED);
    PyModule_AddIntMacro(pyuv, UV_IGNORE);
    PyModule_AddIntMacro(pyuv, UV_CREATE_PIPE);
    PyModule_AddIntMacro(pyuv, UV_READABLE_PIPE);
    PyModule_AddIntMacro(pyuv, UV_WRITABLE_PIPE);
    PyModule_AddIntMacro(pyuv, UV_INHERIT_FD);
    PyModule_AddIntMacro(pyuv, UV_INHERIT_STREAM);

    /* Poll constants */
    PyModule_AddIntMacro(pyuv, UV_READABLE);
    PyModule_AddIntMacro(pyuv, UV_WRITABLE);

    /* Handle types */
    PyModule_AddIntMacro(pyuv, UV_UNKNOWN_HANDLE);
#define XX(uc, lc) PyModule_AddIntMacro(pyuv, UV_##uc);
    UV_HANDLE_TYPE_MAP(XX)
#undef XX

    /* Module version (the MODULE_VERSION macro is defined by setup.py) */
    PyModule_AddStringConstant(pyuv, "__version__", __MSTR(MODULE_VERSION));

    /* libuv version */
    PyModule_AddStringConstant(pyuv, "LIBUV_VERSION", __MSTR(LIBUV_VERSION));

    return pyuv;

fail:
#ifdef PYUV_PYTHON3
    Py_DECREF(pyuv);
#endif
    return NULL;

}
Ejemplo n.º 20
0
/*-------------------------------------------------------------------------
 * Function:	main
 *
 * Purpose:	Test error API.
 *
 * Programmer:	Raymond Lu
 *		July 10, 2003
 *
 *-------------------------------------------------------------------------
 */
int
main(void)
{
    hid_t		file, fapl;
    hid_t               estack_id;
    char		filename[1024];
    const char          *FUNC_main = "main";

    HDfprintf(stderr, "   This program tests the Error API.  There're supposed to be some error messages\n");

    /* Initialize errors */
    if(init_error() < 0)
        TEST_ERROR;

    fapl = h5_fileaccess();

    h5_fixname(FILENAME[0], fapl, filename, sizeof filename);
    if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
	TEST_ERROR;

    /* Test error stack */
    if(error_stack() < 0) {
        /* Push an error onto error stack */
        if(H5Epush(ERR_STACK, __FILE__, FUNC_main, __LINE__, ERR_CLS, ERR_MAJ_TEST, ERR_MIN_ERRSTACK,
                "Error stack test failed") < 0) TEST_ERROR;

        /* Delete an error from the top of error stack */
        H5Epop(ERR_STACK, 1);

        /* Make sure we can use other class's major or minor errors. */
        H5Epush(ERR_STACK, __FILE__, FUNC_main, __LINE__, ERR_CLS2, ERR_MAJ_TEST, ERR_MIN_ERRSTACK,
                "Error stack test failed");

        /* Print out the errors on stack */
        dump_error(ERR_STACK);

        /* Empty error stack */
        H5Eclear2(ERR_STACK);

        /* Close error stack */
        H5Eclose_stack(ERR_STACK);
    } /* end if */

    /* Test error API */
    if(test_error(file) < 0) {
        H5Epush(H5E_DEFAULT, __FILE__, FUNC_main, __LINE__, ERR_CLS, ERR_MAJ_TEST, ERR_MIN_SUBROUTINE,
                "Error test failed, %s", "it's wrong");
        estack_id = H5Eget_current_stack();
        H5Eprint2(estack_id, stderr);
        H5Eclose_stack(estack_id);
    } /* end if */

    /* Test pushing a very long error description */
    if(test_long_desc() < 0) TEST_ERROR;

    /* Test creating a new error stack */
    if(test_create() < 0) TEST_ERROR;

    /* Test copying a new error stack */
    if(test_copy() < 0) TEST_ERROR;

    if(H5Fclose(file) < 0) TEST_ERROR;

    /* Close error information */
    if(close_error() < 0)
        TEST_ERROR;

    /* Test error message during data reading when filter isn't registered 
     * Use default FAPL to avoid some VFD drivers by the check-vfd test because
     * the test file was pre-generated. */
    h5_fixname(DATAFILE, H5P_DEFAULT, filename, sizeof filename);
    if(test_filter_error(filename) < 0)
        TEST_ERROR;

    h5_clean_files(FILENAME, fapl);

    HDfprintf(stderr, "\nAll error API tests passed.\n");
    return 0;

error:
    HDfprintf(stderr, "\n***** ERROR TEST FAILED (real problem)! *****\n");
    return 1;
}
Ejemplo n.º 21
0
int db__driver_create_table(dbTable * table)
{
    int col, ncols;
    dbColumn *column;
    const char *colname;
    int sqltype;
    char buf[500];
    PGresult *res;
    dbString sql;
    dbConnection connection;

    G_debug(3, "db__driver_create_table()");

    init_error();

    db_init_string(&sql);

    /* db_table_to_sql ( table, &sql ); */

    db_set_string(&sql, "create table ");
    db_append_string(&sql, db_get_table_name(table));
    db_append_string(&sql, " ( ");

    ncols = db_get_table_number_of_columns(table);

    for (col = 0; col < ncols; col++) {
	column = db_get_table_column(table, col);
	colname = db_get_column_name(column);
	sqltype = db_get_column_sqltype(column);

	G_debug(3, "%s (%s)", colname, db_sqltype_name(sqltype));

	if (col > 0)
	    db_append_string(&sql, ", ");
	db_append_string(&sql, colname);
	db_append_string(&sql, " ");
	switch (sqltype) {
	case DB_SQL_TYPE_CHARACTER:
	    sprintf(buf, "varchar(%d)", db_get_column_length(column));
	    db_append_string(&sql, buf);
	    break;
	case DB_SQL_TYPE_TEXT:
	    db_append_string(&sql, "text");
	    break;

	case DB_SQL_TYPE_SMALLINT:
	    db_append_string(&sql, "smallint");
	    break;
	case DB_SQL_TYPE_INTEGER:
	    db_append_string(&sql, "integer");
	    break;

	case DB_SQL_TYPE_REAL:
	    db_append_string(&sql, "real");
	    break;

	    /* TODO: better numeric types */
	case DB_SQL_TYPE_DOUBLE_PRECISION:
	case DB_SQL_TYPE_DECIMAL:
	case DB_SQL_TYPE_NUMERIC:
	case DB_SQL_TYPE_INTERVAL:
	    db_append_string(&sql, "double precision");
	    break;

	case DB_SQL_TYPE_DATE:
	    db_append_string(&sql, "date");
	    break;
	case DB_SQL_TYPE_TIME:
	    db_append_string(&sql, "time");
	    break;
	case DB_SQL_TYPE_TIMESTAMP:
	    db_append_string(&sql, "timestamp");
	    break;

	default:
	    G_warning("Unknown column type (%s)", colname);
	    return DB_FAILED;
	}
    }
    db_append_string(&sql, " )");


    G_debug(3, " SQL: %s", db_get_string(&sql));

    res = PQexec(pg_conn, db_get_string(&sql));

    if (!res || PQresultStatus(res) != PGRES_COMMAND_OK) {
	append_error("Cannot create table:\n");
	append_error(db_get_string(&sql));
	append_error("\n");
	append_error(PQerrorMessage(pg_conn));
	report_error();
	PQclear(res);
	db_free_string(&sql);
	return DB_FAILED;
    }

    PQclear(res);

    /* Grant privileges */
    db_get_connection(&connection);

    db_set_string(&sql, "grant select on ");
    db_append_string(&sql, db_get_table_name(table));
    db_append_string(&sql, " to public");

    if (connection.group) {
	db_append_string(&sql, ", group ");
	db_append_string(&sql, connection.group);
    }

    G_debug(3, " SQL: %s", db_get_string(&sql));

    res = PQexec(pg_conn, db_get_string(&sql));

    if (!res || PQresultStatus(res) != PGRES_COMMAND_OK) {
	append_error("Cannot grant select on table:\n");
	append_error(db_get_string(&sql));
	append_error("\n");
	append_error(PQerrorMessage(pg_conn));
	report_error();
	PQclear(res);
	db_free_string(&sql);
	return DB_FAILED;
    }

    PQclear(res);
    db_free_string(&sql);

    return DB_OK;
}
Ejemplo n.º 22
0
int main (int argc, char **argv)
{

    apoint      source, goal;
    aobj        *astar;
    int         i, x, y;
    char        *output = "astar.bmp";
    
    if (argc != 8)
    {
        init_error();
        return 0;
    }
    
    source.x = atoi(argv[1]);
    source.y = atoi(argv[2]);

    goal.x = atoi(argv[3]);
    goal.y = atoi(argv[4]);

    debug = atoi(argv[7]);
    
    astar = malloc(sizeof(aobj));
    if(astar == NULL)
        return 0;
    astar->path.size = 0;
    astar->path.path = NULL;
    astar->output = malloc(20*sizeof(char));
    sprintf(astar->output, "%s", argv[6]);
    //printf("Archivo de salida: %s\n", argv[6]);

    if(!read_map(argv[5]))
    {
        printf("Error al cargar %s. Debe ser una imagen ", argv[5]);
        printf("BMP sin compresión de 24 bits.\n");
        return 0;
    }
    //maps_init(map1);

    astar->cache = malloc(x_tildes *  sizeof(anode *));
    if(!(astar->cache))
        return 0;
    for(i=0; i < x_tildes; i++)
    {
        astar->cache[i] = malloc(y_tildes * sizeof(anode));
        if(!(astar->cache[i]))
            return 0;
    }
    for(x=0; x<x_tildes; x++)
        for(y=0; y<y_tildes; y++)
            astar->cache[x][y].pointer = NULL;

    astar->open_empty = 0;
    astar->closed_empty = 0;

    if(!ai_shortes_path(astar, 0, source, goal))
    {
        printf("We couldn't find any path to the goal!\n");
    }

    if( astar->path.size == 0)
    {
        printf("Error: Couldnt find a path!\n");
        clean_gmaps();
        return 0;
    }

    data_store(astar);
    
    ai_free_aobj(astar);
    clean_gmaps();

    return 0;
}
Ejemplo n.º 23
0
int db__driver_open_select_cursor(dbString * sel, dbCursor * dbc, int mode)
{
    PGresult *res;
    cursor *c;
    dbTable *table;
    char *str;

    init_error();

    /* Set datetime style */
    res = PQexec(pg_conn, "SET DATESTYLE TO ISO");

    if (!res || PQresultStatus(res) != PGRES_COMMAND_OK) {
	append_error("Cannot set DATESTYLE\n");
	report_error();
	PQclear(res);
	return DB_FAILED;
    }

    PQclear(res);

    /* allocate cursor */
    c = alloc_cursor();
    if (c == NULL)
	return DB_FAILED;

    db_set_cursor_mode(dbc, mode);
    db_set_cursor_type_readonly(dbc);

    /* \ must be escaped, see explanation in db_driver_execute_immediate() */
    str = G_str_replace(db_get_string(sel), "\\", "\\\\");
    G_debug(3, "Escaped SQL: %s", str);

    c->res = PQexec(pg_conn, str);

    if (!c->res || PQresultStatus(c->res) != PGRES_TUPLES_OK) {
	append_error("Cannot select: \n");
	append_error(db_get_string(sel));
	append_error("\n");
	append_error(PQerrorMessage(pg_conn));
	report_error();
	PQclear(c->res);
	if (str)
	    G_free(str);
	return DB_FAILED;
    }

    if (str)
	G_free(str);

    if (describe_table(c->res, &table, c) == DB_FAILED) {
	append_error("Cannot describe table\n");
	report_error();
	PQclear(res);
	return DB_FAILED;
    }

    c->nrows = PQntuples(c->res);
    c->row = -1;

    /* record table with dbCursor */
    db_set_cursor_table(dbc, table);

    /* set dbCursor's token for my cursor */
    db_set_cursor_token(dbc, c->token);

    return DB_OK;
}
Ejemplo n.º 24
0
int main ( int argc, char * argv [] )
{
	
	cmd_defaults(&cmd,argv[0]);
	
	init_error();
		
	if(!is_path_absolute(argv[0])) {
		wrn_print("Require execution with absolute path(%s)",argv[0]);
		terminate();
	}		
	
	cmd_process(argc,argv,&cmd);	
	
	if(!cmd.no_dump_config)
		dump_cmd(&cmd);
//	if( check_creds(&cmd.creds) == -1 )
//		wrn_print("check_creds failed, program execution compromised");
		
	if( cmd.kill_running || cmd.rexec_running) {
		// dbg_print("Sending %s signal",strsignal(cmd.rexec_running ? SIGHUP : cmd.kill_running ? SIGTERM : 0));
		KILL_FROM_PID_ERRORS(kill_from_pid_file(cmd.pid_file, cmd.rexec_running ? SIGHUP : SIGTERM));
		exit(EXIT_SUCCESS);
	}

	
	if(cmd.logs_enable)
		if(reopen_files() == -1) {
			wrn_print("reopen_files failed");
			terminate();
		}
		
	dbg_print("%s started executinon", argv[0]);
	dbg_print("Running as uid:%ld gid:%ld", (long)getuid(), (long)getgid());
	
	if(cmd.need_daemon) {
		dbg_print("Demonizing..");
		if(become_daemon()) {
			wrn_print("Can't demonize because of error");
			terminate();
		}
	} 
	if(cmd.pid_file) {	
		switch (create_pid_file(cmd.pid_file)) {
	        case -1: 
			wrn_print("creat_pid_file failed");
			terminate();
		case -2:
			wrn_print("An instance of %s is already running",cmd.path);
			exit(EXIT_SUCCESS);		

		}
	}	
	
	if(cmd.exit_after_dump) 
		exit(EXIT_SUCCESS);
		
	block_all_sigs();
	
	main_loop();
	
	wrn_print("suspicious main_loop return...");
	exit(EXIT_FAILURE);
}
Ejemplo n.º 25
0
int db__driver_create_table(dbTable * table)
{
    int col, ncols;
    dbColumn *column;
    const char *colname;
    int sqltype;
    char buf[500];
    dbString sql;

    /* dbConnection conn_par; */

    G_debug(3, "db__driver_create_table()");

    init_error();

    db_init_string(&sql);

    db_set_string(&sql, "CREATE TABLE ");
    db_append_string(&sql, db_get_table_name(table));
    db_append_string(&sql, " ( ");

    ncols = db_get_table_number_of_columns(table);

    for (col = 0; col < ncols; col++) {
	column = db_get_table_column(table, col);
	colname = db_get_column_name(column);
	sqltype = db_get_column_sqltype(column);

	G_debug(3, "%s (%s)", colname, db_sqltype_name(sqltype));

	if (col > 0)
	    db_append_string(&sql, ", ");
	db_append_string(&sql, colname);
	db_append_string(&sql, " ");
	switch (sqltype) {
	case DB_SQL_TYPE_SMALLINT:
	    db_append_string(&sql, "SMALLINT");
	    break;
	case DB_SQL_TYPE_INTEGER:
	    db_append_string(&sql, "INT");
	    break;

	case DB_SQL_TYPE_REAL:
	    db_append_string(&sql, "FLOAT");
	    break;

	    /* TODO: better numeric types */
	case DB_SQL_TYPE_DOUBLE_PRECISION:
	case DB_SQL_TYPE_DECIMAL:
	case DB_SQL_TYPE_NUMERIC:
	case DB_SQL_TYPE_INTERVAL:
	    db_append_string(&sql, "DOUBLE");
	    break;

	    /* GRASS does not distinguish TIMESTAMP and DATETIME */
	    /*
	       case DB_SQL_TYPE_DATETIME|DB_DATETIME_MASK:
	       db_append_string ( &sql, "DATETIME");
	       break;
	     */
	case DB_SQL_TYPE_TIMESTAMP:
	    /* db_append_string ( &sql, "TIMESTAMP"); */
	    db_append_string(&sql, "DATETIME");
	    break;

	case DB_SQL_TYPE_DATE:
	    db_append_string(&sql, "DATE");
	    break;
	case DB_SQL_TYPE_TIME:
	    db_append_string(&sql, "TIME");
	    break;

	case DB_SQL_TYPE_CHARACTER:
	    sprintf(buf, "VARCHAR(%d)", db_get_column_length(column));
	    db_append_string(&sql, buf);
	    break;
	case DB_SQL_TYPE_TEXT:
	    db_append_string(&sql, "TEXT");
	    break;

	default:
	    G_warning("Unknown column type (%s)", colname);
	    return DB_FAILED;
	}
    }
    db_append_string(&sql, " )");

    G_debug(3, " SQL: %s", db_get_string(&sql));

    if (mysql_query(connection, db_get_string(&sql)) != 0) {
	append_error("Cannot create table:\n");
	append_error(db_get_string(&sql));
	append_error("\n");
	append_error(mysql_error(connection));
	report_error();
	db_free_string(&sql);
	return DB_FAILED;
    }

    /* Grant privileges */

    /*
     * 1) MySQL does not support user groups but it is possible 
     *    to specify list of users. 
     * 2) Only root can grant privileges.
     */
    /*
       db_get_connection(&conn_par);

       if ( conn_par.group ) 
       {
       db_set_string ( &sql, "GRANT SELECT ON on " );
       db_append_string ( &sql, db_get_table_name ( table ) );
       db_append_string ( &sql, " TO " );
       db_append_string ( &sql, conn_par.group );

       G_debug (3, " SQL: %s", db_get_string(&sql) );

       if ( mysql_query ( connection, db_get_string(&sql) ) != 0 )
       {
       G_warning ( "Cannot grant select on table: \n%s\n%s",
       db_get_string(&sql), mysql_error(connection) );
       }
       }
     */

    db_free_string(&sql);

    return DB_OK;
}
Ejemplo n.º 26
0
tsd_t *ReginaInitializeProcess(void)
{
   int OK;

   if (__regina_tsd_initialized)
      return(&__regina_tsd);
   __regina_tsd_initialized = 1;

                                        /* Set up the current (single) tsd_t:*/
                                        /* Default all values to zero        */
   memset(&__regina_tsd,0,sizeof(__regina_tsd));
   __regina_tsd.MTMalloc = MTMalloc;
   __regina_tsd.MTFree = MTFree;
   __regina_tsd.MTExit = MTExit;

   /* Since the local data structure contains a memory chain for the memory
    * management we initialize it first.
    */
   if ((__regina_tsd.mt_tsd = malloc(sizeof(mt_tsd_t))) == NULL)
      return(NULL);                     /* This is a catastrophy             */
   memset(__regina_tsd.mt_tsd,0,sizeof(mt_tsd_t));

   OK = init_memory(&__regina_tsd);     /* Initialize the memory module FIRST*/

   /* Without the initial memory we don't have ANY chance! */
   if (!OK)
      return(NULL);

   /*
    * Some systems with an own MT file don't compile in MT mode. But they
    * still are systems of that kind.
    */
#if defined(WIN32) || defined(__WIN32__)
   {
      extern OS_Dep_funcs __regina_OS_Win;
      __regina_tsd.OS = &__regina_OS_Win;
   }
#elif defined(OS2) && !defined(DOS)
   {
      extern OS_Dep_funcs __regina_OS_Os2;
      __regina_tsd.OS = &__regina_OS_Os2;
   }
#elif defined(GO32)
   {
      extern OS_Dep_funcs __regina_OS_Other;
      __regina_tsd.OS = &__regina_OS_Other;
   }
#elif defined(unix) || defined(__unix__) || defined(__unix) || defined(__QNX__) || defined(__BEOS__) || defined(SKYOS) || ( defined( __APPLE_CC__ ) && defined( __MACH__ ) )
   {
      extern OS_Dep_funcs __regina_OS_Unx;
      __regina_tsd.OS = &__regina_OS_Unx;
   }
#else
   {
      extern OS_Dep_funcs __regina_OS_Other;
      __regina_tsd.OS = &__regina_OS_Other;
   }
#endif
   __regina_tsd.OS->init();
   OK |= init_vars(&__regina_tsd);      /* Initialize the variable module    */
   OK |= init_stacks(&__regina_tsd);    /* Initialize the stack module       */
   OK |= init_filetable(&__regina_tsd); /* Initialize the files module       */
   OK |= init_math(&__regina_tsd);      /* Initialize the math module        */
   OK |= init_spec_vars(&__regina_tsd); /* Initialize the interprt module    */
   OK |= init_tracing(&__regina_tsd);   /* Initialize the tracing module     */
   OK |= init_builtin(&__regina_tsd);   /* Initialize the builtin module     */
   OK |= init_client(&__regina_tsd);    /* Initialize the client module      */
   OK |= init_library(&__regina_tsd);   /* Initialize the library module     */
   OK |= init_rexxsaa(&__regina_tsd);   /* Initialize the rexxsaa module     */
   OK |= init_shell(&__regina_tsd);     /* Initialize the shell module       */
   OK |= init_envir(&__regina_tsd);     /* Initialize the envir module       */
   OK |= init_expr(&__regina_tsd);      /* Initialize the expr module        */
   OK |= init_error(&__regina_tsd);     /* Initialize the error module       */
#ifdef VMS
   OK |= init_vms(&__regina_tsd);       /* Initialize the vmscmd module      */
   OK |= init_vmf(&__regina_tsd);       /* Initialize the vmsfuncs module    */
#endif
   OK |= init_arexxf(&__regina_tsd);    /* Initialize the arxfuncs modules */
   __regina_tsd.loopcnt = 1;            /* stupid r2perl-module              */
   __regina_tsd.traceparse = -1;
   __regina_tsd.thread_id = 1;

   if (!OK)
      exiterror( ERR_STORAGE_EXHAUSTED, 0 ) ;

   return(&__regina_tsd);
}
Ejemplo n.º 27
0
int main(int argc, char **argv)
{
    int timer_tick_rate;
    char *addr;

    /* world is a global now */
    world = &World;

    if (sock_startup() < 0) {
    	warn("Error initializing sockets\n");
	return 1;
    }

    if (World_init() < 0) {
	warn("Error initializing world\n");
	return 1;
    }

    /*
     * Make output always linebuffered.  By default pipes
     * and remote shells cause stdout to be fully buffered.
     */
    setvbuf(stdout, NULL, _IOLBF, BUFSIZ);
    setvbuf(stderr, NULL, _IOLBF, BUFSIZ);

    /*
     * --- Output copyright notice ---
     */

    xpprintf("  " COPYRIGHT ".\n"
	   "  " TITLE " comes with ABSOLUTELY NO WARRANTY; "
	      "for details see the\n"
	   "  provided COPYING file.\n\n");

    init_error(argv[0]);

    /*seedMT((unsigned)time(NULL) * Get_process_id());*/
    /* Removed seeding random number generator because of server recordings. */

    Groups_init();

    /* Make trigonometric tables */
    Make_table();

    if (!Parser(argc, argv))
	exit(1);

    Init_recording();
    /* Lock the server into memory */
    plock_server(options.pLockServer);

    Asteroid_line_init();
    Wormhole_line_init();
    Walls_init();

    /* Allocate memory for players, shots and messages */
    Alloc_players(Num_bases() + MAX_PSEUDO_PLAYERS + MAX_SPECTATORS);
    spectatorStart = Num_bases() + MAX_PSEUDO_PLAYERS;
    Alloc_shots(MAX_TOTAL_SHOTS);
    Alloc_cells();

    Move_init();
    Robot_init();
    Treasure_init();
    Hitmasks_init();

    Rank_init_saved_scores();

    /*
     * Get server's official name.
     */
    if (options.serverHost) {
	addr = sock_get_addr_by_name(options.serverHost);
	if (addr == NULL) {
	    warn("Failed name lookup on: %s", options.serverHost);
	    exit(1);
	}
	serverAddr = xp_strdup(addr);
	strlcpy(Server.host, options.serverHost, sizeof(Server.host));
    } else
	sock_get_local_hostname(Server.host, sizeof Server.host,
				(options.reportToMetaServer != 0 &&
				 options.searchDomainForXPilot != 0));

    Get_login_name(Server.owner, sizeof Server.owner);

    /* Log, if enabled. */
    Log_game("START");

    if (!Contact_init())
	End_game();

    Meta_init();

    Timing_setup();
    Check_playerlimit();

    if (Setup_net_server() == -1)
	End_game();

#ifndef _WINDOWS
    if (options.NoQuit)
	signal(SIGHUP, SIG_IGN);
    else
	signal(SIGHUP, Handle_signal);
    signal(SIGTERM, Handle_signal);
    signal(SIGINT, Handle_signal);
    signal(SIGPIPE, SIG_IGN);
#ifdef IGNORE_FPE
    signal(SIGFPE, SIG_IGN);
#endif
#endif	/* _WINDOWS */

    /*
     * Set the time the server started
     */
    serverStartTime = time(NULL);

    xpprintf("%s Server runs at %d frames per second\n",
	     showtime(), options.framesPerSecond);

    teamcup_init();

#ifdef SELECT_SCHED
    install_timer_tick(Main_loop, FPS);
#else
    if (options.timerResolution > 0)
	timer_tick_rate = options.timerResolution;
    else
	timer_tick_rate = FPS;

# ifdef _WINDOWS
    /* Windows returns here, we let the worker thread call sched() */
    install_timer_tick(ServerThreadTimerProc, timer_tick_rate);
# else
    install_timer_tick(Main_loop, timer_tick_rate);

# endif
#endif

    sched();
    End_game();

    /* NOT REACHED */
    abort();
}
Ejemplo n.º 28
0
/* Initialize the C++ front end.  This function is very sensitive to
   the exact order that things are done here.  It would be nice if the
   initialization done by this routine were moved to its subroutines,
   and the ordering dependencies clarified and reduced.  */
bool
cxx_init (void)
{
  unsigned int i;
  static const enum tree_code stmt_codes[] = {
   CTOR_INITIALIZER,	TRY_BLOCK,	HANDLER,
   EH_SPEC_BLOCK,	USING_STMT,	TAG_DEFN,
   IF_STMT,		CLEANUP_STMT,	FOR_STMT,
   WHILE_STMT,		DO_STMT,	BREAK_STMT,
   CONTINUE_STMT,	SWITCH_STMT,	EXPR_STMT
  };

  memset (&statement_code_p, 0, sizeof (statement_code_p));
  for (i = 0; i < ARRAY_SIZE (stmt_codes); i++)
    statement_code_p[stmt_codes[i]] = true;

  /* We cannot just assign to input_filename because it has already
     been initialized and will be used later as an N_BINCL for stabs+
     debugging.  */
#ifdef USE_MAPPED_LOCATION
  push_srcloc (BUILTINS_LOCATION);
#else
  push_srcloc ("<built-in>", 0);
#endif

  init_reswords ();
  init_tree ();
  init_cp_semantics ();
  init_operators ();
  init_method ();
  init_error ();

  current_function_decl = NULL;

  class_type_node = ridpointers[(int) RID_CLASS];

  cxx_init_decl_processing ();

  /* The fact that G++ uses COMDAT for many entities (inline
     functions, template instantiations, virtual tables, etc.) mean
     that it is fundamentally unreliable to try to make decisions
     about whether or not to output a particular entity until the end
     of the compilation.  However, the inliner requires that functions
     be provided to the back end if they are to be inlined.
     Therefore, we always use unit-at-a-time mode; in that mode, we
     can provide entities to the back end and it will decide what to
     emit based on what is actually needed.  */
  flag_unit_at_a_time = 1;

  if (c_common_init () == false)
    {
      pop_srcloc();
      return false;
    }

  init_cp_pragma ();

  init_repo ();

  pop_srcloc();
  return true;
}