예제 #1
0
파일: socket.c 프로젝트: dpw/molerat
static struct client_socket *client_socket_create(
					      struct addrinfo *addrinfos,
					      void (*fai)(struct addrinfo *))
{
	struct connector *c = xalloc(sizeof *c);
	struct client_socket *s = xalloc(sizeof *s);

	c->socket = s;

	tasklet_init(&c->tasklet, &s->base.mutex, c);
	wait_list_init(&c->connecting, 0);
	c->fd = -1;
	c->connected = 0;
	c->next_addrinfo = c->addrinfos = addrinfos;
	c->fai = fai;
	error_init(&c->err);

	simple_socket_init(&s->base, &client_socket_ops, -1);
	s->connector = c;

	/* Start connecting */
	mutex_lock(&s->base.mutex);
	start_connecting(c);
	tasklet_later(&c->tasklet, finish_connecting);
	mutex_unlock(&s->base.mutex);

	return s;
}
예제 #2
0
atf_error_t
atf_error_new(const char *type, void *data, size_t datalen,
              void (*format)(const atf_error_t, char *, size_t))
{
    atf_error_t err;

    PRE(!error_on_flight);
    PRE(data != NULL || datalen == 0);
    PRE(datalen != 0 || data == NULL);

    err = malloc(sizeof(*err));
    if (err == NULL)
        err = atf_no_memory_error();
    else {
        if (!error_init(err, type, data, datalen, format)) {
            free(err);
            err = atf_no_memory_error();
        } else {
            err->m_free = true;
            error_on_flight = true;
        }
    }

    INV(err != NULL);
    POST(error_on_flight);
    return err;
}
예제 #3
0
파일: socket.c 프로젝트: dpw/molerat
static struct server_socket *bound_server_socket(struct socket_factory *gf,
						 const char *host,
						 const char *service,
						 struct error *err_out)
{
	struct addrinfo *ai, *addrinfos, hints;
	int n_addrs = 0, n_sockets = 0;
	int *fds;
	int res;
	struct simple_server_socket *s;
	struct error err;

	assert(gf->ops == &simple_socket_factory_ops);

	/* See RFC4038, section 6.3.1. */

	memset(&hints, 0, sizeof hints);
	hints.ai_family = AF_UNSPEC;
	hints.ai_socktype = SOCK_STREAM;
	hints.ai_flags = AI_PASSIVE;

	res = getaddrinfo(host, service, &hints, &addrinfos);
	if (res) {
		error_set(err_out, ERROR_OS, "resolving network address: %s",
			  gai_strerror(res));
		return NULL;
	}

	/* Should have at least one addrinfo */
	assert(addrinfos);

	/* Count how many addresses we have */
	for (ai = addrinfos; ai; ai = ai->ai_next)
		n_addrs++;

	/* Allocate space for the fds */
	fds = xalloc(n_addrs * sizeof *fds);

	/* Create sockets */
	error_init(&err);
	for (ai = addrinfos; ai; ai = ai->ai_next) {
		int fd = make_bound_socket(ai, &err);
		if (fd >= 0)
			fds[n_sockets++] = fd;
	}

	freeaddrinfo(addrinfos);

	/* If no sockets were successfully bound, report an error. */
	if (n_sockets == 0) {
		error_propogate(&err, err_out);
		free(fds);
		return NULL;
	}

	s = simple_server_socket_create(fds, n_sockets);
	error_fini(&err);
	free(fds);
	return &s->base;
}
예제 #4
0
static MonoArray*
create_names_array_idx_dynamic (const guint16 *names, int ml, MonoError *error)
{
	MonoArray *ret;
	MonoDomain *domain;
	int i, len = 0;

	error_init (error);

	if (names == NULL)
		return NULL;

	domain = mono_domain_get ();

	for (i = 0; i < ml; i++) {
		if (names [i] == 0)
			break;
		len++;
	}

	ret = mono_array_new_cached (mono_domain_get (), mono_get_string_class (), len, error);
	return_val_if_nok (error, NULL);

	for(i = 0; i < len; i++)
		mono_array_setref (ret, i, mono_string_new (domain, pattern2string (names [i])));

	return ret;
}
예제 #5
0
gpointer
ves_icall_System_Threading_Mutex_CreateMutex_internal (MonoBoolean owned, MonoStringHandle name, MonoBoolean *created, MonoError *error)
{
	gpointer mutex;

	error_init (error);
	*created = TRUE;

	/* Need to blow away any old errors here, because code tests
	 * for ERROR_ALREADY_EXISTS on success (!) to see if a mutex
	 * was freshly created */
	mono_w32error_set_last (ERROR_SUCCESS);

	if (MONO_HANDLE_IS_NULL (name)) {
		mutex = mutex_create (owned);
	} else {
		gchar *utf8_name = mono_string_handle_to_utf8 (name, error);
		return_val_if_nok (error, NULL);

		mutex = namedmutex_create (owned, utf8_name);

		if (mono_w32error_get_last () == ERROR_ALREADY_EXISTS)
			*created = FALSE;
		g_free (utf8_name);
	}

	return mutex;
}
예제 #6
0
static MonoBoolean
construct_culture (MonoCultureInfo *this_obj, const CultureInfoEntry *ci, MonoError *error)
{
	MonoDomain *domain = mono_domain_get ();

	error_init (error);

	this_obj->lcid = ci->lcid;
	MONO_OBJECT_SETREF (this_obj, name, mono_string_new (domain, idx2string (ci->name)));
	MONO_OBJECT_SETREF (this_obj, englishname, mono_string_new (domain, idx2string (ci->englishname)));
	MONO_OBJECT_SETREF (this_obj, nativename, mono_string_new (domain, idx2string (ci->nativename)));
	MONO_OBJECT_SETREF (this_obj, win3lang, mono_string_new (domain, idx2string (ci->win3lang)));
	MONO_OBJECT_SETREF (this_obj, iso3lang, mono_string_new (domain, idx2string (ci->iso3lang)));
	MONO_OBJECT_SETREF (this_obj, iso2lang, mono_string_new (domain, idx2string (ci->iso2lang)));

	// It's null for neutral cultures
	if (ci->territory > 0)
		MONO_OBJECT_SETREF (this_obj, territory, mono_string_new (domain, idx2string (ci->territory)));

	MonoArray *native_calendar_names = create_names_array_idx (ci->native_calendar_names, NUM_CALENDARS, error);
	return_val_if_nok (error, FALSE);
	MONO_OBJECT_SETREF (this_obj, native_calendar_names, native_calendar_names);
	this_obj->parent_lcid = ci->parent_lcid;
	this_obj->datetime_index = ci->datetime_format_index;
	this_obj->number_index = ci->number_format_index;
	this_obj->calendar_type = ci->calendar_type;
	this_obj->text_info_data = &ci->text_info;
	
	return TRUE;
}
예제 #7
0
파일: watchdog.c 프로젝트: gpg/oftpd
int watchdog_init(watchdog_t *w, int inactivity_timeout, error_t *err)
{
    pthread_t thread_id;
    int error_code;

    daemon_assert(w != NULL);
    daemon_assert(inactivity_timeout > 0);
    daemon_assert(err != NULL);

    pthread_mutex_init(&w->mutex, NULL);
    w->inactivity_timeout = inactivity_timeout;
    w->oldest = NULL;
    w->newest = NULL;

    error_code = pthread_create(&thread_id, NULL, watcher, w);
    if (error_code != 0) {
	error_init(err, error_code, "error %d from pthread_create()", 
	  error_code);
        return 0;
    }
    pthread_detach(thread_id);

    daemon_assert(invariant(w));

    return 1;
}
예제 #8
0
gboolean
mono_rand_try_get_bytes (gpointer *handle, guchar *buffer, gint buffer_size, MonoError *error)
{
	gint count = 0;

	error_init (error);
	
	do {
		if (buffer_size - count >= sizeof (gint32) && RAND_MAX >= 0xFFFFFFFF) {
			*(gint32*) buffer = rand();
			count += sizeof (gint32);
			buffer += sizeof (gint32) / sizeof (guchar);
		} else if (buffer_size - count >= sizeof (gint16) && RAND_MAX >= 0xFFFF) {
			*(gint16*) buffer = rand();
			count += sizeof (gint16);
			buffer += sizeof (gint16) / sizeof (guchar);
		} else if (buffer_size - count >= sizeof (gint8) && RAND_MAX >= 0xFF) {
			*(gint8*) buffer = rand();
			count += sizeof (gint8);
			buffer += sizeof (gint8) / sizeof (guchar);
		}
	} while (count < buffer_size);

	return TRUE;
}
예제 #9
0
static void receiver_init(struct receiver *r, struct async_transport *t)
{
	mutex_init(&r->mutex);
	error_init(&r->err);
	r->received = 0;
	r->server = async_transport_serve(t, handler, r, &r->err);
	if (!r->server)
		die("%s", error_message(&r->err));
}
예제 #10
0
파일: module.c 프로젝트: B-Rich/smart
PyMODINIT_FUNC
initheimdal(void)
{
	PyObject *module, *self;
	module = Py_InitModule("heimdal", module_methods);
	self = PyModule_GetDict(module);

	error_init(self);
}
예제 #11
0
gpointer
ves_icall_System_Threading_Mutex_OpenMutex_internal (MonoStringHandle name, gint32 rights G_GNUC_UNUSED, gint32 *err, MonoError *error)
{
	error_init (error);
	gchar *utf8_name = mono_string_handle_to_utf8 (name, error);
	return_val_if_nok (error, NULL);
	gpointer handle = mono_w32mutex_open (utf8_name, rights, err);
	g_free (utf8_name);
	return handle;
}
예제 #12
0
void ftdi_device_init(ftdi_device_t* dev, struct ftdi_context* libftdi_context,
    struct usb_bus* libusb_bus, struct usb_device* libusb_device) {
  dev->libftdi_context = libftdi_context;
  dev->libusb_device = libusb_device;

  dev->bus = libusb_bus->location;
  string_scanf(libusb_device->filename, "%d", &dev->address);

  dev->product_id = libusb_device->descriptor.idProduct;
  
  switch (libusb_device->descriptor.bcdDevice) {
    case 0x0400:
      dev->chip = ftdi_chip_bm;
      break;
    case 0x0200:
      if (!libusb_device->descriptor.iSerialNumber)
        dev->chip = ftdi_chip_bm;
      else
        dev->chip = ftdi_chip_am;
      break;
    case 0x0500:
      dev->chip = ftdi_chip_2232c;
      break;
    case 0x0600:
      dev->chip = ftdi_chip_r;
      break;
    case 0x0700:
      dev->chip = ftdi_chip_2232h;
      break;
    case 0x0800:
      dev->chip = ftdi_chip_4232h;
      break;
    case 0x0900:
      dev->chip = ftdi_chip_232h;
      break;
    default:
      dev->chip = ftdi_chip_unkown;
  }
  dev->interface = ftdi_interface_any;
  
  dev->baud_rate = 0;
  dev->data_bits = 0;
  dev->stop_bits = 0;
  dev->parity= ftdi_parity_none;
  dev->flow_ctrl = ftdi_flow_ctrl_off;
  dev->break_type = ftdi_break_off;

  dev->timeout = 0.0;
  dev->latency = 0.0;
  
  dev->num_read = 0;
  dev->num_written = 0;
  
  error_init(&dev->error, ftdi_errors);
}
예제 #13
0
atf_error_t
atf_no_memory_error(void)
{
    PRE(!error_on_flight);

    error_init(&no_memory_error, "no_memory", NULL, 0,
               no_memory_format);

    error_on_flight = true;
    return &no_memory_error;
}
예제 #14
0
static json_t *parse_json(lex_t *lex, json_error_t *error)
{
    error_init(error);

    lex_scan(lex, error);
    if(lex->token != '[' && lex->token != '{') {
        error_set(error, lex, "'[' or '{' expected");
        return NULL;
    }

    return parse_value(lex, error);
}
예제 #15
0
/*
 * Returns TRUE if there is "something" where the Authenticode signature is 
 * normally located. Returns FALSE is data directory is empty.
 *
 * Note: Neither the structure nor the signature is verified by this function.
 */
MonoBoolean
ves_icall_System_Security_Policy_Evidence_IsAuthenticodePresent (MonoReflectionAssemblyHandle refass, MonoError *error)
{
	error_init (error);
	if (MONO_HANDLE_IS_NULL (refass))
		return FALSE;
	MonoAssembly *assembly = MONO_HANDLE_GETVAL (refass, assembly);
	if (assembly && assembly->image) {
		return (MonoBoolean)mono_image_has_authenticode_entry (assembly->image);
	}
	return FALSE;
}
예제 #16
0
void system_init(void)
{
    error_init();

    sms_init();
    pio_init();
    vdp_init();
    render_init();
    sound_init();

    sms.save = 0;
}
예제 #17
0
int main(int argc, char *argv[])
{
	mem_init();
#ifdef __linux__
#if DXX_WORDS_NEED_ALIGNMENT
	prctl(PR_SET_UNALIGN, PR_UNALIGN_NOPRINT, 0, 0, 0);
#endif
#else
	error_init(msgbox_error);
	set_warn_func(msgbox_warning);
#endif
	return dsx::main(argc, argv);
}
예제 #18
0
static void handler(struct stream *input, void *v_r)
{
	struct incoming *i = xalloc(sizeof *i);

	i->receiver = v_r;
	i->input = input;
	mutex_init(&i->mutex);
	tasklet_init(&i->tasklet, &i->mutex, i);
	growbuf_init(&i->buf, 10);
	error_init(&i->err);

	tasklet_later(&i->tasklet, read_message);
}
예제 #19
0
guint32
mono_dynstream_insert_mstring (MonoDynamicStream *sh, MonoString *str, MonoError *error)
{
	MONO_REQ_GC_UNSAFE_MODE;

	error_init (error);
	char *name = mono_string_to_utf8_checked_internal (str, error);
	return_val_if_nok (error, -1);
	guint32 idx;
	idx = mono_dynstream_insert_string (sh, name);
	g_free (name);
	return idx;
}
예제 #20
0
파일: conf.c 프로젝트: shangyanjin/mydns-ng
/**************************************************************************************************
	CONF_SET_LOGGING
	Sets the logging type and opens the syslog connection if necessary.
**************************************************************************************************/
void
conf_set_logging(void) {
    char *logtype;

    /* logtype is preset to LOG_DAEMON unless overridden */
    logtype = STRDUP(conf_get(&Conf, "log", NULL));
    strtolower(logtype);

    if (err_file) {
        if (err_file != stderr && err_file != stdout)
            fclose(err_file);
        err_file = NULL;
    } else {
        closelog();
    }

    if (!strcasecmp(logtype, "stderr")) {
        err_file = stderr;
        closelog();
    }
    else if (!strcasecmp(logtype, "stdout")) {
        err_file = stdout;
        closelog();
    }
    else if (!strcasecmp(logtype, "log_daemon")) error_init(NULL, LOG_DAEMON);
    else if (!strcasecmp(logtype, "log_local0")) error_init(NULL, LOG_LOCAL0);
    else if (!strcasecmp(logtype, "log_local1")) error_init(NULL, LOG_LOCAL1);
    else if (!strcasecmp(logtype, "log_local2")) error_init(NULL, LOG_LOCAL2);
    else if (!strcasecmp(logtype, "log_local3")) error_init(NULL, LOG_LOCAL3);
    else if (!strcasecmp(logtype, "log_local4")) error_init(NULL, LOG_LOCAL4);
    else if (!strcasecmp(logtype, "log_local5")) error_init(NULL, LOG_LOCAL5);
    else if (!strcasecmp(logtype, "log_local6")) error_init(NULL, LOG_LOCAL6);
    else if (!strcasecmp(logtype, "log_local7")) error_init(NULL, LOG_LOCAL7);
    else {
        FILE *fp;

        if (!(fp = fopen(logtype, "a")))
            Warn("%s: %s: %s", opt_conf, logtype, _("Error opening log file"));
        err_file = fp;
        closelog();
    }
    RELEASE(logtype);
}
예제 #21
0
파일: exception.c 프로젝트: vargaz/mono
/**
 * mono_exception_from_name_two_strings_checked:
 * \param image the Mono image where to look for the class
 * \param name_space the namespace for the class
 * \param name class name
 * \param a1 first string argument to pass
 * \param a2 second string argument to pass
 * \param error set on error
 *
 * Creates an exception from a constructor that takes two string
 * arguments.
 *
 * \returns the initialized exception instance. On failure returns
 * NULL and sets \p error.
 */
MonoExceptionHandle
mono_exception_from_name_two_strings_checked (MonoImage *image, const char *name_space,
					      const char *name, MonoStringHandle a1, MonoStringHandle a2,
					      MonoError *error)
{
	HANDLE_FUNCTION_ENTER ();

	MonoClass *klass;

	error_init (error);
	klass = mono_class_load_from_name (image, name_space, name);

	HANDLE_FUNCTION_RETURN_REF (MonoException, create_exception_two_strings (klass, a1, a2, error));
}
예제 #22
0
int ftdi_context_init(ftdi_context_t* context) {
  if (context != ftdi_default_context) {
    context->num_devices = 0;
    context->devices = 0;
      
    context->num_references = 1;    
  }
  else
    context->num_references++;          
  
  error_init(&context->error, ftdi_errors);
  
  return ftdi_context_refresh(context);
}
예제 #23
0
gpointer
ves_icall_System_Security_Principal_WindowsIdentity_GetUserToken (MonoStringHandle username, MonoError *error)
{
	gpointer token = (gpointer)-2;

	error_init (error);
#if defined (HAVE_PWD_H) && !defined (HOST_WASM)

#ifdef HAVE_GETPWNAM_R
	struct passwd pwd;
	size_t fbufsize;
	gchar *fbuf;
	gint32 retval;
#endif
	struct passwd *p;
	gchar *utf8_name;
	gboolean result;

	utf8_name = mono_string_handle_to_utf8 (username, error);
	return_val_if_nok (error, NULL);

#ifdef HAVE_GETPWNAM_R
#ifdef _SC_GETPW_R_SIZE_MAX
 	fbufsize = mono_sysconf (_SC_GETPW_R_SIZE_MAX);
#else
	fbufsize = MONO_SYSCONF_DEFAULT_SIZE;
#endif

	fbuf = (gchar *)g_malloc0 (fbufsize);
	retval = getpwnam_r (utf8_name, &pwd, fbuf, fbufsize, &p);
	result = ((retval == 0) && (p == &pwd));
#else
	/* default to non thread-safe but posix compliant function */
	p = getpwnam (utf8_name);
	result = (p != NULL);
#endif

	if (result) {
		token = GINT_TO_POINTER (p->pw_uid);
	}

#ifdef HAVE_GETPWNAM_R
	g_free (fbuf);
#endif
	g_free (utf8_name);

#endif /* HAVE_PWD_H */

	return token;
}
예제 #24
0
void do_repurldef(char* val)
{
  url_t* u=NULL;

  
  u=parse_url(val);
  /* FIXME Check the URL if you add support for databases that cannot be 
   * both input and output urls */
  if(u==NULL||u->type==url_unknown||u->type==url_stdin){
    error(0,_("Unsupported output URL-type:%s\n"),val);
  } else {
    error_init(u,0);
  }
  
}
예제 #25
0
파일: mudlle.c 프로젝트: MUME/mudlle
void mudlle_init(void)
{
  garbage_init();
  global_init();
  strbuf_init();
  print_init();
  stack_init();
  module_init();
  runtime_init();
  compile_init();
  mcompile_init();
  interpret_init();
  error_init();
  ports_init();
  context_init();
}
예제 #26
0
파일: exception.c 프로젝트: vargaz/mono
/**
 * mono_exception_from_token_two_strings_checked:
 *
 *   Same as mono_exception_from_name_two_strings, but lookup the exception class using
 * IMAGE and TOKEN.
 */
MonoExceptionHandle
mono_exception_from_token_two_strings_checked (MonoImage *image, guint32 token,
					       MonoStringHandle a1, MonoStringHandle a2,
					       MonoError *error)
{
	HANDLE_FUNCTION_ENTER ();

	MonoClass *klass;

	error_init (error);

	klass = mono_class_get_checked (image, token, error);
	mono_error_assert_ok (error); /* FIXME handle the error. */

	HANDLE_FUNCTION_RETURN_REF (MonoException, create_exception_two_strings (klass, a1, a2, error));
}
예제 #27
0
static void sender_init(struct sender *s, struct async_transport *t,
			struct address *addr)
{
	s->transport = t;
	s->address = addr;

	mutex_init(&s->mutex);
	tasklet_init(&s->tasklet, &s->mutex, s);
	error_init(&s->err);
	s->output = NULL;
	s->buf = c_string_bytes("Hello");

	mutex_lock(&s->mutex);
	tasklet_goto(&s->tasklet, send);
	mutex_unlock(&s->mutex);
}
예제 #28
0
파일: exception.c 프로젝트: vargaz/mono
MonoStringHandle
ves_icall_Mono_Runtime_GetNativeStackTrace (MonoExceptionHandle exc, MonoError *error)
{
	char *trace;
	MonoStringHandle res;
	error_init (error);

	if (MONO_HANDLE_IS_NULL (exc)) {
		mono_error_set_argument_null (error, "exception", "");
		return NULL_HANDLE_STRING;
	}

	trace = mono_exception_handle_get_native_backtrace (exc);
	res = mono_string_new_handle (mono_domain_get (), trace, error);
	g_free (trace);
	return res;
}
예제 #29
0
파일: exception.c 프로젝트: vargaz/mono
MonoExceptionHandle
mono_get_exception_type_initialization_handle (const gchar *type_name, MonoExceptionHandle inner, MonoError *error)
{
	HANDLE_FUNCTION_ENTER ();

	MonoClass *klass;
	MonoMethod *method;
	gpointer iter;

	error_init (error);

	klass = mono_class_load_from_name (mono_get_corlib (), "System", "TypeInitializationException");

	mono_class_init_internal (klass);

	iter = NULL;
	while ((method = mono_class_get_methods (klass, &iter))) {
		if (!strcmp (".ctor", mono_method_get_name (method))) {
			MonoMethodSignature *sig = mono_method_signature_internal (method);

			if (sig->param_count == 2 && sig->params [0]->type == MONO_TYPE_STRING && mono_class_from_mono_type_internal (sig->params [1]) == mono_defaults.exception_class)
				break;
		}
		method = NULL;
	}
	g_assert (method);

	MonoDomain * const domain = mono_domain_get ();
	MonoStringHandle type_name_str = mono_string_new_handle (domain, type_name, error);
	mono_error_assert_ok (error);
	gpointer args [ ] = { MONO_HANDLE_RAW (type_name_str), MONO_HANDLE_RAW (inner) };

	MonoObjectHandle exc = mono_object_new_handle (domain, klass, error);
	mono_error_assert_ok (error);

	mono_runtime_invoke_handle (method, exc, args, error);
	goto_if_nok (error, return_null);
	goto exit;
return_null:
	exc = mono_new_null ();
exit:
	HANDLE_FUNCTION_RETURN_REF (MonoException, MONO_HANDLE_CAST (MonoException, exc));
}
예제 #30
0
/* note: we better manipulate the string in managed code (easier and safer) */
MonoStringHandle
ves_icall_System_Environment_GetOSVersionString (MonoError *error)
{
	error_init (error);
#ifdef HOST_WIN32
	OSVERSIONINFOEX verinfo;

	verinfo.dwOSVersionInfoSize = sizeof (OSVERSIONINFOEX);
	if (GetVersionEx ((OSVERSIONINFO*)&verinfo)) {
		char version [128];
		/* maximum string length is 45 bytes
		   4 x 10 bytes per number, 1 byte for 0, 3 x 1 byte for dots, 1 for NULL */
		sprintf (version, "%ld.%ld.%ld.%d",
				 verinfo.dwMajorVersion,
				 verinfo.dwMinorVersion,
				 verinfo.dwBuildNumber,
				 verinfo.wServicePackMajor << 16);
		return mono_string_new_handle (mono_domain_get (), version, error);
	}
#elif defined(HAVE_SYS_UTSNAME_H) && defined(_AIX)
	/*
	 * AIX puts the major version number in .version and minor in .release; so make a
	 * version string based on that; other Unices seem to cram everything in .release
	 * and .version is for things like kernel variants.
	 */
	struct utsname name;
	char version [sizeof(name)];

	if (uname (&name) >= 0) {
		sprintf (version, "%s.%s", name.version, name.release);
		return mono_string_new_handle (mono_domain_get (), version, error);
	}
#elif defined(HAVE_SYS_UTSNAME_H)
	struct utsname name;

	memset (&name, 0, sizeof (name)); // WSL does not always nul terminate.

	if (uname (&name) >= 0) {
		return mono_string_new_handle (mono_domain_get (), name.release, error);
	}
#endif
	return mono_string_new_handle (mono_domain_get (), "0.0.0.0", error);
}