コード例 #1
0
ファイル: plugins.c プロジェクト: dmilith/ekg2-bsd
static void *ekg2_dlopen(const char *name) {
#ifdef NO_POSIX_SYSTEM
	void *tmp = LoadLibraryA(name);
#else
	/* RTLD_LAZY is bad flag, because code can SEGV on executing undefined symbols...
	 *	it's better to fail earlier than later with SIGSEGV
	 *
	 * RTLD_GLOBAL is bad flag also, because we have no need to export symbols to another plugns
	 *	we should do it by queries... Yeah, I know it was used for example in perl && irc plugin.
	 *	But we cannot do it. Because if we load irc before sim plugin. Than we'll have unresolved symbols
	 *	even if we load sim plugin later.
	 */
	/*
	 * RTLD_GLOBAL is required by perl and python plugins...
	 *	need investigation. [XXX]
	 */
	void *tmp = dlopen(name, RTLD_NOW | RTLD_GLOBAL);
#endif
	if (!tmp) {
		debug_warn("[plugin] could not be loaded: %s %s\n", name, dlerror());
	} else {
		debug_ok("[plugin] loaded: %s\n", name);
	}
	return tmp;
}
コード例 #2
0
ファイル: um.c プロジェクト: KHATEEBNSIT/lsdk_ar9531
/*
* copy/change from netifd
*/
static void
setup_signals(void)
{
	struct sigaction s;

	memset(&s, 0, sizeof(s));
	s.sa_handler = handle_signal;
	s.sa_flags = 0;
	sigaction(SIGINT, &s, NULL);
	sigaction(SIGTERM, &s, NULL);
	sigaction(SIGUSR1, &s, NULL);
	sigaction(SIGUSR2, &s, NULL);

	s.sa_handler = SIG_IGN;
	sigaction(SIGPIPE, &s, NULL);

    os_sigaction_callstack();
    
	debug_ok("setup signal");
}
コード例 #3
0
static GModule *ekg2_dlopen(const char *name) {
	/* RTLD_LAZY is bad flag, because code can SEGV on executing undefined symbols...
	 *	it's better to fail earlier than later with SIGSEGV
	 *
	 * RTLD_GLOBAL is bad flag also, because we have no need to export symbols to another plugns
	 *	we should do it by queries... Yeah, I know it was used for example in perl && irc plugin.
	 *	But we cannot do it. Because if we load irc before sim plugin. Than we'll have unresolved symbols
	 *	even if we load sim plugin later.
	 */
	/*
	 * RTLD_GLOBAL is required by perl and python plugins...
	 *	need investigation. [XXX]
	 */
	GModule *tmp = g_module_open(name, 0);

	if (!tmp) {
		char *errstr = ekg_recode_from_locale(g_module_error());
		debug_warn("[plugin] could not be loaded: %s %s\n", name, errstr);
		g_free(errstr);
	} else {
		debug_ok("[plugin] loaded: %s\n", name);
	}
	return tmp;
}
コード例 #4
0
/*
 * plugin_load()
 *
 * ³aduje wtyczkê o podanej nazwie.
 * 
 * 0/-1
 */
int plugin_load(const char *name, int prio, int quiet)
{
#ifdef SHARED_LIBS
	const gchar *env_ekg_plugins_path = NULL;
	char *init = NULL;
	gchar *lib;
	gchar *libname;
	GModule *plugin = NULL;
#endif

	plugin_t *pl;
	int (*plugin_init)() = NULL;

	g_assert(name);
	if (plugin_find(name)) {
		printq("plugin_already_loaded", name); 
		return -1;
	}

#ifdef SHARED_LIBS
	libname = g_strdup_printf("%s.la", name);
	if ((env_ekg_plugins_path = g_getenv("EKG_PLUGINS_PATH"))) {
		lib = g_build_filename(env_ekg_plugins_path, libname, NULL);
		plugin = ekg2_dlopen(lib);
		g_free(lib);

		if (!plugin) {
			lib = g_build_filename(env_ekg_plugins_path, name, libname, NULL);
			plugin = ekg2_dlopen(lib);
			g_free(lib);
		}
	}

	/* The following lets ekg2 load plugins when it is run directly from
	 * the source tree, without installation. This can be beneficial when
	 * developing the program, or for less knowlegeable users, who don't
	 * know how to or cannot for some other reason use installation prefix
	 * to install in their home directory. It might be also useful
	 * for win32-style installs.
	 */
	if (!plugin && rel_plugin_dir) {
		lib = g_build_filename(rel_plugin_dir, "plugins", name, libname, NULL);
		plugin = ekg2_dlopen(lib);
		g_free(lib);
	}

	if (!plugin) {
		lib = g_build_filename(PLUGINDIR, libname, NULL);
		plugin = ekg2_dlopen(lib);
		g_free(lib);
	}

	g_free(libname);
	/* prefer shared plugins */
	if (plugin) {
		init = g_strdup_printf("%s_plugin_init", name);
		plugin_init = ekg2_dlsym(plugin, init);
		g_free(init);
	}
#endif /* SHARED_LIBS */

#ifdef STATIC_LIBS
	/* if no shared plugin, fallback to the static one */
	if (!plugin_init) {
		STATIC_PLUGIN_DECLS
		STATIC_PLUGIN_CALLS

		if (plugin_init)
			debug_ok("[plugin] statically compiled in: %s\n", name);
	}
コード例 #5
0
ファイル: www_server.c プロジェクト: slashdev/slashnet
void handle_request(uint8_t *data, uint16_t length) {
  debug_string_p(PSTR("HTTP: "));

  uint8_t type = 0;
  uint8_t path_start = 0;
  switch(data[0]) {
    case 'H': type = HTTP_METHOD_HEAD;   path_start = 5; break;
    case 'G': type = HTTP_METHOD_GET;    path_start = 4; break;
    case 'D': type = HTTP_METHOD_DELETE; path_start = 7; break;
    case 'P':
      switch(data[1]) {
        case 'O': type = HTTP_METHOD_POST; path_start = 5; break;
        case 'U': type = HTTP_METHOD_PUT;  path_start = 4; break;
        default:  type = 0;
      }
      break;
  }

  // Fetch path only if we have a type
  if (type) {
    uint8_t path_length = 0;
    uint8_t *path = &data[path_start];
    while (*path++ > 0x20) {
      path_length++;
    }
    // Make space after path 0x00 (for path matching)
    data[path_start + path_length] = 0x00;
    // Debug path
    debug_string_n((char *)data, path_start + path_length);
  }

  // Get callback for type/path combination
  // path_services_get(&data[path_start]);
  uint8_t i;
  void (*callback)(uint8_t, uint8_t *);

  for (i = 0, callback = 0; i < EXT_WWW_SERVER_SERVICES_LIST_SIZE; i++) {
    if (path_services[i].path && path_matches(&data[path_start], path_services[i].path)) {
      callback = path_services[i].callback;
      break;
    }
  }

  // Prepare tcp reply
  rbuffer = tcp_prepare_reply();
  rlength = 0;
  // Increase ack with length
  add_value_to_buffer(length, &buffer_out[TCP_PTR_ACK_NR], 4);
  // Set ACK flag
  tcp_add_flags(TCP_FLAG_ACK | TCP_FLAG_PUSH | TCP_FLAG_FIN);

  // Check if we can handle the request
  if (callback) {
    callback(type, data);
  } else {
    // Return 404, not found
    www_server_reply_header(HTTP_STATUS_404, HTTP_CONTENT_TYPE_PLAIN);
    www_server_reply_add_p(not_found);
    www_server_reply_send();
  }

  debug_ok();
}