int main(void) { //Initialisieren der Komponenten led_init(); //LED Initialisieren td_init(); //Zeitbasis initialisieren script_init(); //Sriptengine initialisieren //Funkmodul initialisieren rf12_init(); rf12_setfreq(RF12FREQ(433.25)); // 433,92MHz rf12_setbandwidth(4, 1, 4); // 200kHz Bandbreite, -6dB Verstärkung, DRSSI threshold: -79dBm rf12_setbaud(19200); // 19200 baud rf12_setpower(0, 6); // 1mW Ausgangangsleistung, 120kHz Frequenzshift sei(); //Interrupts aktivieren uint8_t buf_temp[10]; //Mainloop while(23) { //Zustandsmaschinen aktualisieren script_tick(); rgb_fade_tick(); //Prüfen ob ein neues Datenframe empfangen wurde. if (rf12_getStatus() == rf12_data_status_ready) { rf12_getData(buf_temp); //Daten abholen rf_data_reset(); //Empfangspuffer zurücksetzen command(buf_temp); //Empfangenes Kommando ausführen } } }
int weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[]) { weechat_guile_plugin = plugin; guile_stdout = NULL; scm_init_guile (); guile_module_weechat = scm_c_define_module ("weechat", &weechat_guile_api_module_init, NULL); scm_c_use_module ("weechat"); weechat_guile_catch (scm_gc_protect_object, (void *)guile_module_weechat); guile_quiet = 1; script_init (weechat_guile_plugin, argc, argv, &weechat_guile_command_cb, &weechat_guile_completion_cb, &weechat_guile_infolist_cb, &weechat_guile_signal_debug_dump_cb, &weechat_guile_signal_buffer_closed_cb, &weechat_guile_signal_script_action_cb, &weechat_guile_load_cb); guile_quiet = 0; script_display_short_list (weechat_guile_plugin, guile_scripts); /* init ok */ return WEECHAT_RC_OK; }
std::string ModManager::uninstall(const char* modname) { std::string scriptpath = game_path + DIR_DELIM + "modmanager.lua"; std::string modpath = game_path + DIR_DELIM + "mods" + DIR_DELIM + modname + DIR_DELIM; lua_State *L = script_init(); if (luaL_loadfile(L, scriptpath.c_str()) || lua_pcall(L, 0, 0, 0)) { errorstream<<lua_tostring(L, -1)<<std::endl; return "error.lua"; } lua_getglobal(L, "modmanager_uninstall"); lua_pushstring(L, modpath.c_str()); if (lua_pcall(L, 1, 1, 0)) { errorstream<<lua_tostring(L, -1)<<std::endl; return "error.lua"; } if (!lua_isnil(L, 1)) { errorstream<<lua_tostring(L, 1)<<std::endl; return "error.uninstall"; } script_deinit(L); return ""; }
int main(int argc, char* argv[]) { script_init(); load_ini(); engine_init(); // includes ttf init too vid_init(); dump_lua(); game_loop(); engine_shutdown(); script_shutdown(); return 0; }
/* process function for help_state=0 */ static void help_send_escape(int fd, char c) { struct termios pts; /* termios settings on port */ in_escape = 0; help_state = 0; switch (c) { case 'x': /* restore termios settings and exit */ write(STDOUT_FILENO, "\n", 1); cleanup_termios(0); break; case 'q': /* quit help */ break; case 'l': /* log on/off */ if (flog == 0) { /* open log file */ open_logFile(log_file); } else { /* close log file */ close_logFile(); } break; case 's': /* script active/inactive */ script_init(scr_name); script = (script)? 0: 1; break; case 'b': /* send break */ /* send a break */ tcsendbreak(fd, 0); break; case 't': /* set terminal */ help_state = 1; help_terminal(); in_escape = 1; break; case '~': /* display it again */ help_escape(); break; default: /* pass the character through */ /* "C-\ C-\" sends "C-\" */ write(fd, &c, 1); break; } if (in_escape == 0) help_done(); return; }
static inline struct ia64_script * script_new (struct ia64_script_cache *cache, unw_word_t ip) { struct ia64_script *script, *prev, *tmp; unw_hash_index_t index; unsigned short head; head = cache->lru_head; script = cache->buckets + head; cache->lru_head = script->lru_chain; /* re-insert script at the tail of the LRU chain: */ cache->buckets[cache->lru_tail].lru_chain = head; cache->lru_tail = head; /* remove the old script from the hash table (if it's there): */ if (script->ip) { index = hash (script->ip); tmp = cache->buckets + cache->hash[index]; prev = 0; while (1) { if (tmp == script) { if (prev) prev->coll_chain = tmp->coll_chain; else cache->hash[index] = tmp->coll_chain; break; } else prev = tmp; if (tmp->coll_chain >= IA64_UNW_CACHE_SIZE) /* old script wasn't in the hash-table */ break; tmp = cache->buckets + tmp->coll_chain; } } /* enter new script in the hash table */ index = hash (ip); script->coll_chain = cache->hash[index]; cache->hash[index] = script - cache->buckets; script_init (script, ip); return script; }
static int server_loop(void) { script_init(script); mrdisc_init(interval); while (running) { if (reloading) { reload(); reloading = 0; } socket_poll(NULL); } return 0; }
int main(int argc, char *argv[]) { char buf[128], tmp[128]; script_init(argv[1]); for (int i = 0; i < 1000000; i++) { memset(buf, 0, sizeof(buf)); curr_title = tmp; curr_title_len = sprintf(tmp, "t%08d", i); perl_content(buf); printf("%s\n", buf); } return 0; }
void check_lua_script() { // calculate don't need script handler if (opts.is_calc_mode) return; if(!opts.script) { opts.script = "../scripts/example.lua"; } if(access(opts.script, R_OK) == -1) { logger(ERROR, "load lua script %s failed, as %s\n", opts.script, strerror(errno)); exit(0); } L = script_init(opts.script); // check callback function is exist. if(!script_check_func_exists(L, DEFAULT_CALLBACK)) { logger(ERROR, "function %s is required in lua script.\n", DEFAULT_CALLBACK); exit(0); } }
static int uncached_find_save_locs (struct cursor *c) { struct ia64_script script; int ret = 0; if ((ret = ia64_fetch_proc_info (c, c->ip, 1)) < 0) return ret; script_init (&script, c->ip); if ((ret = build_script (c, &script)) < 0) { if (ret != -UNW_ESTOPUNWIND) Dprintf ("%s: failed to build unwind script for ip %lx\n", __FUNCTION__, (long) c->ip); return ret; } return run_script (&script, c); }
int void_init( unsigned char flags ) { int status = 0; if ( flags&VOID_LOGGER ) status |= log_init()<<6; if ( flags&VOID_VIDEO ) status |= video_init(); if ( flags&VOID_AUDIO ) status |= audio_init()<<1; if ( flags&VOID_INPUT ) status |= input_init()<<2; if ( flags&VOID_NET ) status |= net_init()<<3; if ( flags&VOID_SCRIPT ) status |= script_init()<<4; if ( flags&VOID_PHYSICS ) status |= phys_init()<<5; return status; }
int script_run(const char* filename) { char scriptname[8192]; int result; strcpy(scriptname, filename); if (!io_fileexists(scriptname)) { strcat(scriptname, ".lua"); } if (!io_fileexists(scriptname)) { return 0; } currentScript = scriptname; if (!script_init()) return -1; result = lua_dofile(L, scriptname); return (result == 0) ? 1 : -1; }
ModManagerSpec ModManager::info(const char* modname) { ModManagerSpec spec; std::string scriptpath = game_path + DIR_DELIM + "modmanager.lua"; lua_State *L = script_init(); if (luaL_loadfile(L, scriptpath.c_str()) || lua_pcall(L, 0, 0, 0)) { errorstream<<lua_tostring(L, -1)<<std::endl; spec.name = "error.lua"; return spec; } lua_getglobal(L, "modmanager_info"); lua_pushstring(L, modname); lua_pushstring(L, (game_path + DIR_DELIM).c_str()); if (lua_pcall(L, 2, 4, 0)) { errorstream<<lua_tostring(L, -1)<<std::endl; spec.name = "error.lua"; return spec; } if (lua_isnil(L, 1)) { errorstream<<lua_tostring(L, 1)<<std::endl; spec.name = "error.info"; return spec; } spec.name = lua_tostring(L, 1); spec.url = lua_tostring(L, 2); spec.description = lua_tostring(L, 3); spec.version = lua_tonumber(L, 4); script_deinit(L); return spec; }
void warlock_init (void) { #ifdef DEBUG g_log_set_always_fatal (G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING); #endif preferences_init (); highlight_init (); preferences_dialog_init (); profile_dialog_init (); text_strings_dialog_init (); hand_init (warlock_get_widget ("left_hand_label"), warlock_get_widget ("right_hand_label")); status_init (warlock_get_widget ("status_table")); compass_init (warlock_get_widget ("compass_table")); warlock_entry_init (warlock_get_widget ("warlock_entry")); macro_init (); macro_dialog_init (); warlock_time_init (); warlock_views_init (); warlock_log_init (); script_init (); }
std::string *ModManager::refresh() { std::string *error = new std::string[1]; lua_State *L = script_init(); std::string scriptpath = game_path + DIR_DELIM + "modmanager.lua"; if (!fs::PathExists(scriptpath)) { error[0] = "error.oldgame"; return error; } if (luaL_loadfile(L, scriptpath.c_str()) || lua_pcall(L, 0, 0, 0)) { errorstream<<lua_tostring(L, -1)<<std::endl; error[0] = "error.lua"; return error; } lua_getglobal(L, "modmanager_refresh"); lua_pushstring(L, (game_path + DIR_DELIM).c_str()); if (lua_pcall(L, 1, 2, 0)) { errorstream<<lua_tostring(L, -1)<<std::endl; error[0] = "error.lua"; return error; } if (!lua_isnil(L, 2)) { errorstream<<lua_tostring(L, 2)<<std::endl; error[0] = "error.modlist"; return error; } std::string *modnames; modnames = read_modlist(L, 1); script_deinit(L); return modnames; }
int weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[]) { weechat_tcl_plugin = plugin; tcl_quiet = 1; script_init (weechat_tcl_plugin, argc, argv, &weechat_tcl_command_cb, &weechat_tcl_completion_cb, &weechat_tcl_infolist_cb, &weechat_tcl_signal_debug_dump_cb, &weechat_tcl_signal_buffer_closed_cb, &weechat_tcl_signal_script_action_cb, &weechat_tcl_load_cb); tcl_quiet = 0; script_display_short_list (weechat_tcl_plugin, tcl_scripts); /* init ok */ return WEECHAT_RC_OK; }
lua_State *script_cache_get_script(server *srv, connection *con, script_cache *cache, buffer *name) { size_t i; script *sc = NULL; stat_cache_entry *sce; for (i = 0; i < cache->used; i++) { sc = cache->ptr[i]; if (buffer_is_equal(name, sc->name)) { sc->last_used = time(NULL); /* oops, the script failed last time */ if (lua_gettop(sc->L) == 0) break; force_assert(lua_gettop(sc->L) == 1); if (HANDLER_ERROR == stat_cache_get_entry(srv, con, sc->name, &sce)) { lua_pop(sc->L, 1); /* pop the old function */ break; } if (!buffer_is_equal(sce->etag, sc->etag)) { /* the etag is outdated, reload the function */ lua_pop(sc->L, 1); break; } force_assert(lua_isfunction(sc->L, -1)); return sc->L; } sc = NULL; } /* if the script was script already loaded but either got changed or * failed to load last time */ if (sc == NULL) { sc = script_init(); if (cache->size == 0) { cache->size = 16; cache->ptr = malloc(cache->size * sizeof(*(cache->ptr))); } else if (cache->used == cache->size) { cache->size += 16; cache->ptr = realloc(cache->ptr, cache->size * sizeof(*(cache->ptr))); } cache->ptr[cache->used++] = sc; buffer_copy_buffer(sc->name, name); sc->L = luaL_newstate(); luaL_openlibs(sc->L); } sc->last_used = time(NULL); if (0 != luaL_loadfile(sc->L, name->ptr)) { /* oops, an error, return it */ return sc->L; } if (HANDLER_GO_ON == stat_cache_get_entry(srv, con, sc->name, &sce)) { buffer_copy_buffer(sc->etag, sce->etag); } force_assert(lua_isfunction(sc->L, -1)); return sc->L; }
int weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[]) { int ruby_error; char *weechat_ruby_code = { "$stdout = WeechatOutputs\n" "$stderr = WeechatOutputs\n" "\n" "class Module\n" " @load_eval_file_error = ''\n" "\n" " def load_eval_file (file)\n" " lines = ''\n" " begin\n" " f = File.open(file, 'r')\n" " lines = f.readlines.join\n" " rescue => e\n" " @load_eval_file_error = e\n" " return 1\n" " end\n" "\n" " begin\n" " module_eval(lines)\n" " rescue => e\n" " @load_eval_file_error = e\n" " return 2\n" " end\n" "\n" " has_init = false\n" "\n" " instance_methods.each do |meth|\n" " if meth == 'weechat_init'\n" " has_init = true\n" " end\n" " module_eval('module_function :' + meth)\n" " end\n" "\n" " unless has_init\n" " return 3\n" " end\n" "\n" " return 0\n" " end\n" "end\n" }; weechat_ruby_plugin = plugin; ruby_error = 0; /* init stdout/stderr buffer */ ruby_buffer_output[0] = '\0'; ruby_init (); ruby_init_loadpath (); ruby_script ("__weechat_plugin__"); ruby_mWeechat = rb_define_module("Weechat"); weechat_ruby_api_init (ruby_mWeechat); /* redirect stdin and stdout */ ruby_mWeechatOutputs = rb_define_module("WeechatOutputs"); rb_define_singleton_method(ruby_mWeechatOutputs, "write", weechat_ruby_output, 1); rb_define_singleton_method(ruby_mWeechatOutputs, "puts", weechat_ruby_output, 1); rb_define_singleton_method(ruby_mWeechatOutputs, "p", weechat_ruby_output, 1); rb_define_singleton_method(ruby_mWeechatOutputs, "flush", weechat_ruby_output_flush, 0); rb_eval_string_protect(weechat_ruby_code, &ruby_error); if (ruby_error) { VALUE ruby_error_info = rb_inspect(ruby_errinfo); weechat_printf (NULL, weechat_gettext ("%s%s: unable to eval WeeChat ruby " "internal code"), weechat_prefix ("error"), RUBY_PLUGIN_NAME); weechat_printf (NULL, weechat_gettext ("%s%s: error: %s"), weechat_prefix ("error"), RUBY_PLUGIN_NAME, STR2CSTR(ruby_error_info)); return WEECHAT_RC_ERROR; } ruby_quiet = 1; script_init (weechat_ruby_plugin, argc, argv, &ruby_scripts, &weechat_ruby_command_cb, &weechat_ruby_completion_cb, &weechat_ruby_infolist_cb, &weechat_ruby_signal_debug_dump_cb, &weechat_ruby_signal_buffer_closed_cb, &weechat_ruby_signal_script_action_cb, &weechat_ruby_load_cb, &weechat_ruby_api_buffer_input_data_cb, &weechat_ruby_api_buffer_close_cb); ruby_quiet = 0; script_display_short_list (weechat_ruby_plugin, ruby_scripts); /* init ok */ return WEECHAT_RC_OK; }
int main( int argc, char *argv[] ) { int screenMode = GFX_AUTODETECT_WINDOWED; BITMAP *backbuf; TitleScreen *mode_titlescreen; CityMode *mode_city; bool showConsole = false; //args for (int i=1; i < argc; i++) { if (!strcmp(argv[i],"-fullscreen") ) { screenMode = GFX_AUTODETECT_FULLSCREEN; } } // Init alleg allegro_init(); install_keyboard(); install_mouse(); set_color_depth( 16 ); // Turn on the screeny goodness if (set_gfx_mode(screenMode, 640,480, 0, 0) != 0) { set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message("Unable to set 640x480 graphic mode\n%s\n", allegro_error); return 1; } alfont_init(); //set_color_conversion(COLORCONV_TOTAL); //drawing_mode(DRAW_MODE_TRANS, NULL,0,0); // fonts font_console = alfont_load_font("Graphics/fonts/ProFontWindows.ttf"); alfont_set_font_size(font_console, 12); font_title = alfont_load_font("Graphics/fonts/AbductionIII.ttf"); alfont_set_font_size( font_title, 24 ); font_game = alfont_load_font("Graphics/fonts/archtura.ttf" ); alfont_set_font_size( font_game, 24 ); // screen backbuf = create_bitmap( 640, 480 ); rectfill( backbuf, 0,0, 640, 480, 0x0 ); SpriteGraphic *testgfx = new SpriteGraphic( "testship" ); Sprite *test = new Sprite( testgfx ); test->m_x = 10; test->m_y = 70; // game mode mode_titlescreen = new TitleScreen(); mode_city = new CityMode(); g_mode = mode_titlescreen; // init scripts script_init( font_console ); // The main loop while (1) { if (g_mode) { g_mode->update(); } g_mode->draw( backbuf ); #if 0 // draw the game if (Map::g_activeMap) { Map::g_activeMap->draw( backbuf ); // DBG: Map scrolling Map::g_activeMap->m_scroll = ((float)mouse_y / 480.0) * ((Map::g_activeMap->m_maphite-15)*32); } else { rectfill( backbuf, 0,0, 640, 480, 0x0 ); alfont_textout_centre( backbuf, font_game, "Infection", 320, 200, makecol(200, 0, 0) ); } // draw the sprites test->draw( backbuf ); char buff[200]; sprintf( buff, "testy %d m2s %d scroll %d", test->m_y, Map::mapYtoScreenY( test->m_y ), Map::getScroll() ); alfont_textout( backbuf, font_console, buff, 320, 200, makecol(255,255,255) ); #endif // draw the console if (showConsole) { draw_console( backbuf ); } // event handler if (keypressed()) { int k = readkey(); int kk = k >>8; // mode specific keypress g_mode->key_pressed( k ); // global keypress if (kk==KEY_TILDE) { showConsole = !showConsole; } else if (showConsole) { // send key to console console_key( k ); } else { switch(k>>8) { case KEY_DOWN: test->m_y += 10; break; case KEY_UP: test->m_y -= 10; break; } } } if (key[KEY_ESC]) { //exit(0); break; } // Blit the screen vsync(); acquire_screen(); blit( backbuf, screen, 0, 0, 0, 0, 640, 480 ); release_screen(); yield_timeslice(); } return 0; }
int main(_unused int argc, char* const argv[]) { openlog("odhcp6c", LOG_PERROR | LOG_PID, LOG_DAEMON); // Allocate ressources const char *pidfile = NULL; const char *script = "/usr/sbin/odhcp6c-update"; ssize_t l; uint8_t buf[134]; char *optpos; uint16_t opttype; enum odhcp6c_ia_mode ia_na_mode = IA_MODE_TRY; bool help = false, daemonize = false; int c, request_pd = 0; while ((c = getopt(argc, argv, "N:P:c:r:s:p:Sqdh")) != -1) { switch (c) { case 'S': allow_slaac_only = false; break; case 'N': if (!strcmp(optarg, "force")) ia_na_mode = IA_MODE_FORCE; else if (!strcmp(optarg, "none")) ia_na_mode = IA_MODE_NONE; else if (!strcmp(optarg, "try")) ia_na_mode = IA_MODE_TRY; else help = true; break; case 'P': allow_slaac_only = false; request_pd = strtoul(optarg, NULL, 10); if (request_pd == 0) request_pd = -1; break; case 'c': l = script_unhexlify(&buf[4], sizeof(buf) - 4, optarg); if (l > 0) { buf[0] = 0; buf[1] = DHCPV6_OPT_CLIENTID; buf[2] = 0; buf[4] = l; odhcp6c_add_state(STATE_CLIENT_ID, buf, l + 4); } else { help = true; } break; case 'q': log_quiet = true; break; case 'r': optpos = optarg; while (optpos[0]) { opttype = htons(strtoul(optarg, &optpos, 10)); if (optpos == optarg) break; else if (optpos[0]) optarg = &optpos[1]; odhcp6c_add_state(STATE_ORO, &opttype, 2); } break; case 's': script = optarg; break; case 'd': daemonize = true; break; case 'p': pidfile = optarg; break; default: help = true; break; } } const char *ifname = argv[optind]; if (help || !ifname) return usage(); if ((urandom_fd = open("/dev/urandom", O_CLOEXEC | O_RDONLY)) < 0 || init_dhcpv6(ifname, request_pd) || ra_init(ifname) || script_init(script, ifname)) { dhcpv6_syslog(LOG_ERR, "failed to initialize: %s", strerror(errno)); return 3; } signal(SIGIO, sighandler); signal(SIGHUP, sighandler); signal(SIGINT, sighandler); signal(SIGCHLD, sighandler); signal(SIGTERM, sighandler); signal(SIGUSR1, sighandler); signal(SIGUSR2, sighandler); if (daemonize) { openlog("odhcp6c", LOG_PID, LOG_DAEMON); // Disable LOG_PERROR if (daemon(0, 0)) { dhcpv6_syslog(LOG_ERR, "Failed to daemonize: %s", strerror(errno)); return 4; } char pidbuf[128]; if (!pidfile) { snprintf(pidbuf, sizeof(pidbuf), "/var/run/odhcp6c.%s.pid", ifname); pidfile = pidbuf; } int fd = open(pidfile, O_WRONLY | O_CREAT); if (fd >= 0) { char buf[8]; int len = snprintf(buf, sizeof(buf), "%i\n", getpid()); write(fd, buf, len); close(fd); } } script_call("started"); while (do_signal != SIGTERM) { // Main logic odhcp6c_clear_state(STATE_SERVER_ID); odhcp6c_clear_state(STATE_SERVER_CAND); odhcp6c_clear_state(STATE_IA_PD); odhcp6c_clear_state(STATE_SNTP_IP); odhcp6c_clear_state(STATE_SNTP_FQDN); odhcp6c_clear_state(STATE_SIP_IP); odhcp6c_clear_state(STATE_SIP_FQDN); dhcpv6_set_ia_na_mode(ia_na_mode); bound = false; dhcpv6_syslog(LOG_NOTICE, "(re)starting transaction on %s", ifname); do_signal = 0; int res = dhcpv6_request(DHCPV6_MSG_SOLICIT); odhcp6c_signal_process(); if (res < 0) { continue; // Might happen if we got a signal } else if (res == DHCPV6_STATELESS) { // Stateless mode while (do_signal == 0 || do_signal == SIGUSR1) { do_signal = 0; res = dhcpv6_request(DHCPV6_MSG_INFO_REQ); odhcp6c_signal_process(); if (do_signal == SIGUSR1) continue; else if (res < 0) break; else if (res > 0) script_call("informed"); bound = true; dhcpv6_syslog(LOG_NOTICE, "entering stateless-mode on %s", ifname); if (dhcpv6_poll_reconfigure() > 0) script_call("informed"); } continue; } // Stateful mode if (dhcpv6_request(DHCPV6_MSG_REQUEST) < 0) continue; odhcp6c_signal_process(); script_call("bound"); bound = true; dhcpv6_syslog(LOG_NOTICE, "entering stateful-mode on %s", ifname); while (do_signal == 0 || do_signal == SIGUSR1) { // Renew Cycle // Wait for T1 to expire or until we get a reconfigure int res = dhcpv6_poll_reconfigure(); odhcp6c_signal_process(); if (res >= 0) { if (res > 0) script_call("updated"); continue; } // Handle signal, if necessary if (do_signal == SIGUSR1) do_signal = 0; // Acknowledged else if (do_signal > 0) break; // Other signal type size_t ia_pd_len, ia_na_len, ia_pd_new, ia_na_new; odhcp6c_get_state(STATE_IA_PD, &ia_pd_len); odhcp6c_get_state(STATE_IA_NA, &ia_na_len); // If we have any IAs, send renew, otherwise request int r; if (ia_pd_len == 0 && ia_na_len == 0) r = dhcpv6_request(DHCPV6_MSG_REQUEST); else r = dhcpv6_request(DHCPV6_MSG_RENEW); odhcp6c_signal_process(); if (r > 0) // Publish updates script_call("updated"); if (r >= 0) continue; // Renew was successful odhcp6c_clear_state(STATE_SERVER_ID); // Remove binding // If we have IAs, try rebind otherwise restart res = dhcpv6_request(DHCPV6_MSG_REBIND); odhcp6c_signal_process(); odhcp6c_get_state(STATE_IA_PD, &ia_pd_new); odhcp6c_get_state(STATE_IA_NA, &ia_na_new); if (res < 0 || (ia_pd_new == 0 && ia_pd_len) || (ia_na_new == 0 && ia_na_len)) break; // We lost all our IAs, restart else if (res > 0) script_call("rebound"); } size_t ia_pd_len, ia_na_len, server_id_len; odhcp6c_get_state(STATE_IA_PD, &ia_pd_len); odhcp6c_get_state(STATE_IA_NA, &ia_na_len); odhcp6c_get_state(STATE_SERVER_ID, &server_id_len); // Add all prefixes to lost prefixes bound = false; script_call("unbound"); if (server_id_len > 0 && (ia_pd_len > 0 || ia_na_len > 0)) dhcpv6_request(DHCPV6_MSG_RELEASE); odhcp6c_clear_state(STATE_IA_NA); odhcp6c_clear_state(STATE_IA_PD); } script_call("stopped"); return 0; }
void lcd_load_driver(char *drivername) { /* Initialise the shared stuff (for dampcore.sh) */ script_init(); /* Add the LCD-specific stuff for the driver */ scAdd_External_Symbol("lcd_surround_symbol", &lcd_surround_symbol); scAdd_External_Symbol("lcd_play_symbol", &lcd_play_symbol); scAdd_External_Symbol("lcd_random_symbol", &lcd_random_symbol); scAdd_External_Symbol("lcd_rew_symbol", &lcd_rew_symbol); scAdd_External_Symbol("lcd_continuous_symbol", &lcd_continuous_symbol); scAdd_External_Symbol("lcd_driver_name", lcd_driver_name); scAdd_External_Symbol("lcd_driver_author", lcd_driver_author); scAdd_External_Symbol("lcd_driver_author_email", lcd_driver_author_email); scAdd_External_Symbol("lcd_driver_description", lcd_driver_description); scAdd_External_Symbol("lcd_driver_version", &lcd_driver_version); scAdd_External_Symbol("lcd_display_width", &lcd_display_width); scAdd_External_Symbol("lcd_display_lines", &lcd_display_lines); scAdd_External_Symbol("lcd_line", lcd_line); scAdd_External_Symbol("damp_vu", &damp_vu); scAdd_External_Symbol("damp_random_play", &damp_playlist_random); scAdd_External_Symbol("damp_surround", &audio_driver->surround); scAdd_External_Symbol("damp_paused", &track_paused); scAdd_External_Symbol("damp_volume", &damp_volume); scAdd_External_Symbol("damp_status", lcd_status); scAdd_External_Symbol("damp_filename", short_filename); scAdd_External_Symbol("damp_playlist_filename", damp_playlist_filename); scAdd_External_Symbol("damp_playlist_filename_short", damp_playlist_filename_short); scAdd_External_Symbol("damp_id3_title", damp_id3_tag.title); scAdd_External_Symbol("damp_id3_artist", damp_id3_tag.artist); scAdd_External_Symbol("damp_id3_album", damp_id3_tag.album); scAdd_External_Symbol("damp_id3_year", damp_id3_tag.year); scAdd_External_Symbol("damp_id3_comment", damp_id3_tag.comment); scAdd_External_Symbol("damp_id3_genre", damp_id3_genre); scAdd_External_Symbol("damp_time", timestr); scAdd_External_Symbol("damp_time_remaining", timeremainstr); scAdd_External_Symbol("damp_track_number", &damp_track_number); scAdd_External_Symbol("damp_selection_buffer", track_sel); scAdd_External_Symbol("damp_state", &damp_state); /* Compile the driver */ lcd_driver_script = scCompile_File(drivername); /* If that failed, give an error */ if(lcd_driver_script == NULL) { printf("Failed to load LCD driver: %s\n",drivername); printf("%s\n",scErrorMsg); exit(-1); } /* Create an instance of the driver */ lcd_driver_instance = scCreate_Instance(lcd_driver_script,NULL); /* If that failed, give an error */ if(!lcd_driver_instance) { printf("Failed to instance LCD driver: %s\n",drivername); printf("%s\n",scErrorMsg); exit(-1); } }
int weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[]) { int ruby_error; char *weechat_ruby_code = { "$stdout = WeechatOutputs\n" "$stderr = WeechatOutputs\n" "begin" " if RUBY_VERSION.split('.')[1] == '9'\n" " require 'enc/encdb.so'\n" " require 'enc/trans/transdb.so'\n" "\n" " require 'thread'\n" " class ::Mutex\n" " def synchronize(*args)\n" " yield\n" " end\n" " end\n" " require 'rubygems'\n" " else\n" " require 'rubygems'\n" " end\n" "rescue LoadError\n" "end\n" "\n" "class Module\n" "\n" " def load_eval_file (file)\n" " lines = ''\n" " begin\n" " lines = File.read(file)\n" " rescue => e\n" " return 1\n" " end\n" "\n" " begin\n" " module_eval(lines)\n" " rescue Exception => e\n" " @load_eval_file_error = e\n" " return 2\n" " end\n" "\n" " has_init = false\n" "\n" " instance_methods.each do |meth|\n" " if meth.to_s == 'weechat_init'\n" " has_init = true\n" " end\n" " module_eval('module_function :' + meth.to_s)\n" " end\n" "\n" " unless has_init\n" " return 3\n" " end\n" "\n" " return 0\n" " end\n" "end\n" }; weechat_ruby_plugin = plugin; ruby_error = 0; /* init stdout/stderr buffer */ ruby_buffer_output[0] = '\0'; #if defined(RUBY_VERSION) && RUBY_VERSION >= 19 RUBY_INIT_STACK; #endif ruby_hide_errors = 1; ruby_init (); ruby_init_loadpath (); ruby_script ("__weechat_plugin__"); ruby_mWeechat = rb_define_module("Weechat"); weechat_ruby_api_init (ruby_mWeechat); /* redirect stdin and stdout */ ruby_mWeechatOutputs = rb_define_module("WeechatOutputs"); rb_define_singleton_method(ruby_mWeechatOutputs, "write", weechat_ruby_output, 1); rb_define_singleton_method(ruby_mWeechatOutputs, "puts", weechat_ruby_output, 1); rb_define_singleton_method(ruby_mWeechatOutputs, "p", weechat_ruby_output, 1); rb_define_singleton_method(ruby_mWeechatOutputs, "flush", weechat_ruby_output_flush, 0); ruby_hide_errors = 0; rb_eval_string_protect(weechat_ruby_code, &ruby_error); if (ruby_error) { weechat_printf (NULL, weechat_gettext ("%s%s: unable to eval WeeChat ruby " "internal code"), weechat_prefix ("error"), RUBY_PLUGIN_NAME); VALUE err = rb_gv_get("$!"); weechat_ruby_print_exception(err); return WEECHAT_RC_ERROR; } ruby_quiet = 1; script_init (weechat_ruby_plugin, argc, argv, &weechat_ruby_command_cb, &weechat_ruby_completion_cb, &weechat_ruby_infolist_cb, &weechat_ruby_signal_debug_dump_cb, &weechat_ruby_signal_buffer_closed_cb, &weechat_ruby_signal_script_action_cb, &weechat_ruby_load_cb); ruby_quiet = 0; script_display_short_list (weechat_ruby_plugin, ruby_scripts); /* init ok */ return WEECHAT_RC_OK; }
/* main program loop */ void mux_loop(int pf) { fd_set ready; /* used for select */ int i = 0; /* used in the multiplex loop */ int done = 0; char buf[BUFSIZE]; struct timeval tv; tv.tv_sec = SCRIPT_DELAY; tv.tv_usec = 0; if (script) { script_init(scr_name); } do { /* forever */ FD_ZERO(&ready); FD_SET(STDIN_FILENO, &ready); FD_SET(pf, &ready); if (script) { if (!select(pf+1, &ready, NULL, NULL, &tv)) { i = script_process(S_TIMEOUT, buf, BUFSIZE); if (i > 0) { cook_buf(pf, buf, i); } /* restart timer */ tv.tv_sec = SCRIPT_DELAY; tv.tv_usec = 0; } } /* if */ else { select(pf+1, &ready, NULL, NULL, NULL); } if (FD_ISSET(pf, &ready)) { /* pf has characters for us */ i = read(pf, buf, BUFSIZE); if (i > 0) { if (options & OPTION_LOG_FILTER) { /* only printable characters */ size_t size = 0; char *printable = PrintableBuffer(buf,i,&size); DEBUG_MSG("received printable buffer = %s",printable); if (flog != NULL) { printable[size] = '\n'; printable[size+1] = '\0'; const size_t written = fwrite(printable, 1, size, flog); if (written != size) { const int error = errno; DEBUG_MSG("error writing log file, only %u characters written, errno = %d",written,error); } } } else { /* raw memory dump */ DEBUG_DUMP_MEMORY(buf,i); if (flog != 0) { fwrite(buf, 1, i, flog); } } write(STDOUT_FILENO, buf, i); if (script) { i = script_process(S_DCE, buf, i); if (i > 0) { cook_buf(pf, buf, i); } } } else { done = 1; } } /* if */ if (FD_ISSET(STDIN_FILENO, &ready)) { /* standard input has characters for us */ i = read(STDIN_FILENO, buf, BUFSIZE); if (i > 0) { cook_buf(pf, buf, i); } else { done = 1; } } /* if */ } while (!done); /* do */ }
int main(_unused int argc, char* const argv[]) { // Allocate ressources const char *pidfile = NULL; const char *script = "/usr/sbin/odhcp6c-update"; ssize_t l; uint8_t buf[134]; char *optpos; uint16_t opttype; uint16_t optlen; enum odhcp6c_ia_mode ia_na_mode = IA_MODE_TRY; enum odhcp6c_ia_mode ia_pd_mode = IA_MODE_NONE; int ia_pd_iaid_index = 0; static struct in6_addr ifid = IN6ADDR_ANY_INIT; int sol_timeout = DHCPV6_SOL_MAX_RT; #ifdef EXT_BFD_PING int bfd_interval = 0, bfd_loss = 3; #endif bool help = false, daemonize = false; int logopt = LOG_PID; int c; unsigned int client_options = DHCPV6_CLIENT_FQDN | DHCPV6_ACCEPT_RECONFIGURE; while ((c = getopt(argc, argv, "S::N:V:P:FB:c:i:r:Ru:s:kt:m:hedp:fa")) != -1) { switch (c) { case 'S': allow_slaac_only = (optarg) ? atoi(optarg) : -1; break; case 'N': if (!strcmp(optarg, "force")) { ia_na_mode = IA_MODE_FORCE; allow_slaac_only = -1; } else if (!strcmp(optarg, "none")) { ia_na_mode = IA_MODE_NONE; } else if (!strcmp(optarg, "try")) { ia_na_mode = IA_MODE_TRY; } else{ help = true; } break; case 'V': l = script_unhexlify(buf, sizeof(buf), optarg); if (!l) help=true; odhcp6c_add_state(STATE_VENDORCLASS, buf, l); break; case 'P': if (ia_pd_mode == IA_MODE_NONE) ia_pd_mode = IA_MODE_TRY; if (allow_slaac_only >= 0 && allow_slaac_only < 10) allow_slaac_only = 10; char *iaid_begin; int iaid_len = 0; int prefix_length = strtoul(optarg, &iaid_begin, 10); if (*iaid_begin != '\0' && *iaid_begin != ',' && *iaid_begin != ':') { syslog(LOG_ERR, "invalid argument: '%s'", optarg); return 1; } struct odhcp6c_request_prefix prefix = { 0, prefix_length }; if (*iaid_begin == ',' && (iaid_len = strlen(iaid_begin)) > 1) memcpy(&prefix.iaid, iaid_begin + 1, iaid_len > 4 ? 4 : iaid_len); else if (*iaid_begin == ':') prefix.iaid = htonl((uint32_t)strtoul(&iaid_begin[1], NULL, 16)); else prefix.iaid = htonl(++ia_pd_iaid_index); odhcp6c_add_state(STATE_IA_PD_INIT, &prefix, sizeof(prefix)); break; case 'F': allow_slaac_only = -1; ia_pd_mode = IA_MODE_FORCE; break; #ifdef EXT_BFD_PING case 'B': bfd_interval = atoi(optarg); break; #endif case 'c': l = script_unhexlify(&buf[4], sizeof(buf) - 4, optarg); if (l > 0) { buf[0] = 0; buf[1] = DHCPV6_OPT_CLIENTID; buf[2] = 0; buf[3] = l; odhcp6c_add_state(STATE_CLIENT_ID, buf, l + 4); } else { help = true; } break; case 'i': if (inet_pton(AF_INET6, optarg, &ifid) != 1) help = true; break; case 'r': optpos = optarg; while (optpos[0]) { opttype = htons(strtoul(optarg, &optpos, 10)); if (optpos == optarg) break; else if (optpos[0]) optarg = &optpos[1]; odhcp6c_add_state(STATE_ORO, &opttype, 2); } break; case 'R': client_options |= DHCPV6_STRICT_OPTIONS; break; case 'u': optlen = htons(strlen(optarg)); odhcp6c_add_state(STATE_USERCLASS, &optlen, 2); odhcp6c_add_state(STATE_USERCLASS, optarg, strlen(optarg)); break; case 's': script = optarg; break; case 'k': release = false; break; case 't': sol_timeout = atoi(optarg); break; case 'm': min_update_interval = atoi(optarg); break; case 'e': logopt |= LOG_PERROR; break; case 'd': daemonize = true; break; case 'p': pidfile = optarg; break; case 'f': client_options &= ~DHCPV6_CLIENT_FQDN; break; case 'a': client_options &= ~DHCPV6_ACCEPT_RECONFIGURE; break; default: help = true; break; } } openlog("odhcp6c", logopt, LOG_DAEMON); const char *ifname = argv[optind]; if (help || !ifname) return usage(); signal(SIGIO, sighandler); signal(SIGHUP, sighandler); signal(SIGINT, sighandler); signal(SIGCHLD, sighandler); signal(SIGTERM, sighandler); signal(SIGUSR1, sighandler); signal(SIGUSR2, sighandler); if ((urandom_fd = open("/dev/urandom", O_CLOEXEC | O_RDONLY)) < 0 || init_dhcpv6(ifname, client_options, sol_timeout) || ra_init(ifname, &ifid) || script_init(script, ifname)) { syslog(LOG_ERR, "failed to initialize: %s", strerror(errno)); return 3; } if (daemonize) { openlog("odhcp6c", LOG_PID, LOG_DAEMON); // Disable LOG_PERROR if (daemon(0, 0)) { syslog(LOG_ERR, "Failed to daemonize: %s", strerror(errno)); return 4; } char pidbuf[128]; if (!pidfile) { snprintf(pidbuf, sizeof(pidbuf), "/var/run/odhcp6c.%s.pid", ifname); pidfile = pidbuf; } int fd = open(pidfile, O_WRONLY | O_CREAT, 0644); if (fd >= 0) { char buf[8]; int len = snprintf(buf, sizeof(buf), "%i\n", getpid()); write(fd, buf, len); close(fd); } } script_call("started"); while (!signal_term) { // Main logic odhcp6c_clear_state(STATE_SERVER_ID); odhcp6c_clear_state(STATE_IA_NA); odhcp6c_clear_state(STATE_IA_PD); odhcp6c_clear_state(STATE_SNTP_IP); odhcp6c_clear_state(STATE_NTP_IP); odhcp6c_clear_state(STATE_NTP_FQDN); odhcp6c_clear_state(STATE_SIP_IP); odhcp6c_clear_state(STATE_SIP_FQDN); dhcpv6_set_ia_mode(ia_na_mode, ia_pd_mode); bound = false; syslog(LOG_NOTICE, "(re)starting transaction on %s", ifname); signal_usr1 = signal_usr2 = false; int mode = dhcpv6_request(DHCPV6_MSG_SOLICIT); odhcp6c_signal_process(); if (mode < 0) continue; do { int res = dhcpv6_request(mode == DHCPV6_STATELESS ? DHCPV6_MSG_INFO_REQ : DHCPV6_MSG_REQUEST); bool signalled = odhcp6c_signal_process(); if (res > 0) break; else if (signalled) { mode = -1; break; } mode = dhcpv6_promote_server_cand(); } while (mode > DHCPV6_UNKNOWN); if (mode < 0) continue; switch (mode) { case DHCPV6_STATELESS: bound = true; syslog(LOG_NOTICE, "entering stateless-mode on %s", ifname); while (!signal_usr2 && !signal_term) { signal_usr1 = false; script_call("informed"); int res = dhcpv6_poll_reconfigure(); odhcp6c_signal_process(); if (res > 0) continue; if (signal_usr1) { signal_usr1 = false; // Acknowledged continue; } if (signal_usr2 || signal_term) break; res = dhcpv6_request(DHCPV6_MSG_INFO_REQ); odhcp6c_signal_process(); if (signal_usr1) continue; else if (res < 0) break; } break; case DHCPV6_STATEFUL: script_call("bound"); bound = true; syslog(LOG_NOTICE, "entering stateful-mode on %s", ifname); #ifdef EXT_BFD_PING if (bfd_interval > 0) bfd_start(ifname, bfd_loss, bfd_interval); #endif while (!signal_usr2 && !signal_term) { // Renew Cycle // Wait for T1 to expire or until we get a reconfigure int res = dhcpv6_poll_reconfigure(); odhcp6c_signal_process(); if (res > 0) { script_call("updated"); continue; } // Handle signal, if necessary if (signal_usr1) signal_usr1 = false; // Acknowledged if (signal_usr2 || signal_term) break; // Other signal type // Send renew as T1 expired res = dhcpv6_request(DHCPV6_MSG_RENEW); odhcp6c_signal_process(); if (res > 0) { // Renew was succesfull // Publish updates script_call("updated"); continue; // Renew was successful } odhcp6c_clear_state(STATE_SERVER_ID); // Remove binding size_t ia_pd_len, ia_na_len; odhcp6c_get_state(STATE_IA_PD, &ia_pd_len); odhcp6c_get_state(STATE_IA_NA, &ia_na_len); if (ia_pd_len == 0 && ia_na_len == 0) break; // If we have IAs, try rebind otherwise restart res = dhcpv6_request(DHCPV6_MSG_REBIND); odhcp6c_signal_process(); if (res > 0) script_call("rebound"); else { #ifdef EXT_BFD_PING bfd_stop(); #endif break; } } break; default: break; } size_t ia_pd_len, ia_na_len, server_id_len; odhcp6c_get_state(STATE_IA_PD, &ia_pd_len); odhcp6c_get_state(STATE_IA_NA, &ia_na_len); odhcp6c_get_state(STATE_SERVER_ID, &server_id_len); // Add all prefixes to lost prefixes bound = false; script_call("unbound"); if (server_id_len > 0 && (ia_pd_len > 0 || ia_na_len > 0) && release) dhcpv6_request(DHCPV6_MSG_RELEASE); odhcp6c_clear_state(STATE_IA_NA); odhcp6c_clear_state(STATE_IA_PD); } script_call("stopped"); return 0; }