void reset(void) { /* Note on the nodeMCU, pin D0 (aka GPIO16) may or may not already be * connected to the RST pin. If it's not connected, connect via a 10K * resistor. Do no connect directly. * The reason it's connected is in order to be able to wake up from deep sleep. * When the esp8266 is put into deep sleep everything but the RTC is powered off. * You can set a timer in the RTC that toggles GPIO16 when it expires and that * resets the esp8266 causing it to power up again. This is the only way the * esp8266 can wake itself up from deep sleep, so it's quite a useful function * to have. On the esp-03 module there is a tiny jumper to connect GPIO16 to reset * so one can connect/disconnect it. On the esp-12, since everything is under a * shield that jumper is evidently not available, so they had to decide one way * or the other... */ /* Write a low to the pin that is physically connected to the RST pin. * This will force the hardware to reset. */ reset_config(); Serial.println("Rebooting ... this may take 15 seconds or more."); pinMode(PIN_SOFTRESET, OUTPUT); for (int a = 0; a < 10; a++) { digitalWrite(PIN_SOFTRESET, LOW); delay(1000); // CONSIDER using an optimistic_yield(1000000) instead so background tasks can still run digitalWrite(PIN_SOFTRESET, HIGH); delay(1000);// CONSIDER using an optimistic_yield(1000000) instead so background tasks can still run } }
short create_input_box_dialog(int argc, char **argv, int start) { if(argc - (start+3) < 1) return -1; char *msg = argv[start+1]; int width = atoi(argv[start+2]); int height = atoi(argv[start+3]); char *init = NULL; if(argc - (start+4) >= 1) init = argv[start+4]; //Create stuff GtkWidget *win = gtk_window_new(GTK_WINDOW_TOPLEVEL); if(width > 0 && height > 0) gtk_window_resize(GTK_WINDOW(win), width, height); gtk_window_set_title(GTK_WINDOW(win), "INPUT box"); gtk_container_set_border_width(GTK_CONTAINER(win), 18); g_signal_connect(G_OBJECT(win), "destroy", G_CALLBACK(destroy), NULL); apply_dialog_config(GTK_WINDOW(win)); //Create BOX + Message label GtkWidget *box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 18); GtkWidget *label = gtk_label_new(msg); //Create Input Box input = gtk_entry_new(); if(init != NULL) gtk_entry_set_text(GTK_ENTRY(input), init); //Create OK/CANCEL Buttons GtkWidget *buttonbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 12); GtkWidget *button_ok = gtk_button_new_with_label("OK"); g_signal_connect(G_OBJECT(button_ok), "clicked", G_CALLBACK(ok), win); GtkWidget *button_cancel = gtk_button_new_with_label("Cancel"); g_signal_connect(G_OBJECT(button_cancel) , "clicked", G_CALLBACK(cancel) , win); gtk_box_pack_end(GTK_BOX(buttonbox), button_cancel, FALSE, FALSE, 0); gtk_box_pack_end(GTK_BOX(buttonbox), button_ok , FALSE, FALSE, 0); gtk_container_add(GTK_CONTAINER(box), label); gtk_box_pack_end(GTK_BOX(box), buttonbox, FALSE, TRUE, 0); gtk_box_pack_end(GTK_BOX(box), input, FALSE, TRUE, 0); gtk_container_add(GTK_CONTAINER(win), box); gtk_widget_show_all(win); gtk_main(); reset_config(); return 0; }
void setup_config(int argc, char **argv, config *cfg) { int i = 1; char configFilePath[MAX_PATH_CHAR_SIZE]; int interval = 0; char iterations[MAX_STR_LEN] = "infinite"; reset_config(cfg); for (; i < argc; i++) { // Attached PID if (!strcmp(argv[i], "-a")) { cfg->attach = true; cfg->pid = atoi(argv[i+1]); } else // Configuration file if (!strcmp(argv[i], "-c")) { strcpy(configFilePath, argv[i+1]); fprintf(stderr, "Using config file: %s\n", configFilePath); readEventNames(configFilePath, cfg); } else if (!strcmp(argv[i], "-i")) { interval = atoi(argv[i+1]); fprintf(stderr, "Using interval: %d usec\n", interval); cfg->interval = interval; } else if (!strcmp(argv[i], "-n")) { if (atoi(argv[i]) > -1) strcpy(iterations, argv[i+1]); fprintf(stderr, "Monitoring for %s iterations\n", iterations); cfg->iterations = atoi(iterations); } else // Run new process if (!strcmp(argv[i], "-r")) { cfg->run = true; } else { if (i == 0){ // The first argument must be an option fprintf(stderr, "The first argument must be an option! (E.g. -a, -r).\n"); exit(1); } } } }
void wsh_panel_vars::load_config(stream_reader * reader, t_size size, abort_callback & abort) { reset_config(); if (size > sizeof(unsigned)) { bool have_read_config = false; unsigned ver = 0; try { // Read version reader->read_object_t(ver, abort); // fall-thru switch (ver) { case VERSION_0x81: reader->read_object_t(m_delay_load, abort); case VERSION_0x80: // Due to default value of delay load had been changed, skip if (ver < VERSION_0x81) { reader->skip_object(sizeof(m_delay_load), abort); } case VERSION_0x79: reader->read_object_t(m_config_guid, abort); case VERSION_0x78: reader->read_object(&m_edge_style, sizeof(m_edge_style), abort); case VERSION_0x77: m_config_prop.load(reader, abort); case VERSION_0x76: reader->read_object_t(m_disabled_before, abort); case VERSION_0x75: reader->read_object_t(m_grab_focus, abort); case VERSION_0x74: reader->read_object(&m_wndpl, sizeof(m_wndpl), abort); case VERSION_0x73: reader->read_string(m_script_engine_str, abort); reader->read_string(m_script_code, abort); reader->read_object_t(m_pseudo_transparent, abort); have_read_config = true; break; } } catch (std::exception &) { have_read_config = false; reset_config(); } if (!have_read_config) { // Configuration corruputed or config version dismatch. console::complain(WSPM_NAME, "Error: Configuration needs a newer component or is corrupted"); } } }
int main(int argc, char *argv[]) { struct sigaction act; int rc, rc1, rc2, readonly, clobbercfg; clobbercfg = readonly = 0; openlog("flatfsd", LOG_PERROR, LOG_DAEMON); while ((rc = getopt(argc, argv, "vcnribwH123hs?")) != EOF) { switch (rc) { case 'w': clobbercfg++; readonly++; break; case 'r': readonly++; break; case 'n': nowrite = 1; break; case 'c': #if !defined(USING_FLASH_FILESYSTEM) rc = flat_check(); if (rc < 0) { #ifdef LOGGING char ecmd[64]; sprintf(ecmd, "/bin/logd chksum-bad %d", -rc); system(ecmd); #endif printf("Flash filesystem is invalid %d - check syslog\n", rc); } else { printf("Flash filesystem is valid\n"); #ifdef LOGGING system("/bin/logd chksum-good"); #endif } exit(rc); #else exit(0); #endif break; case 'v': version(); exit(0); break; case 's': log_caller("/bin/logd flatfsd-s"); exit(saveconfig()); break; case 'b': log_caller("/bin/logd flatfsd-b"); exit(reboot_system()); break; case 'H': log_caller("/bin/logd flatfsd-h"); exit(halt_system()); break; case 'i': log_caller("/bin/logd flatfsd-i"); exit(reset_config()); break; case '1': fsver = 1; break; case '2': fsver = 2; break; case '3': fsver = 3; break; case 'h': case '?': usage(0); break; default: usage(1); break; } } if (readonly) { rc1 = rc2 = 0; if (clobbercfg || #if !defined(USING_FLASH_FILESYSTEM) ((rc = flat_restorefs()) < 0) || #endif (rc1 = flat_filecount()) <= 0 || (rc2 = flat_needinit()) ) { #ifdef LOGGING char ecmd[64]; /* log the reason we have for killing the flatfs */ if (clobbercfg) sprintf(ecmd, "/bin/logd newflatfs clobbered"); else if (rc < 0) sprintf(ecmd, "/bin/logd newflatfs recreate=%d", rc); else if (rc1 <= 0) sprintf(ecmd, "/bin/logd newflatfs filecount=%d", rc1); else if (rc2) sprintf(ecmd, "/bin/logd newflatfs needinit"); else sprintf(ecmd, "/bin/logd newflatfs unknown"); system(ecmd); #endif syslog(LOG_ERR, "Nonexistent or bad flatfs (%d), creating new one...", rc); flat_clean(1); if ((rc = flat_new(DEFAULTDIR)) < 0) { syslog(LOG_ERR, "Failed to create new flatfs, err=%d errno=%d", rc, errno); exit(1); } save_config_to_flash(); } syslog(LOG_INFO, "Created %d configuration files (%d bytes)", numfiles, numbytes); exit(0); } creatpidfile(); act.sa_handler = sighup; memset(&act.sa_mask, 0, sizeof(act.sa_mask)); act.sa_flags = SA_RESTART; act.sa_restorer = 0; sigaction(SIGHUP, &act, NULL); act.sa_handler = sigusr1; memset(&act.sa_mask, 0, sizeof(act.sa_mask)); act.sa_flags = SA_RESTART; act.sa_restorer = 0; sigaction(SIGUSR1, &act, NULL); act.sa_handler = sigusr2; memset(&act.sa_mask, 0, sizeof(act.sa_mask)); act.sa_flags = SA_RESTART; act.sa_restorer = 0; sigaction(SIGUSR2, &act, NULL); act.sa_handler = sigpwr; memset(&act.sa_mask, 0, sizeof(act.sa_mask)); act.sa_flags = SA_RESTART; act.sa_restorer = 0; sigaction(SIGPWR, &act, NULL); /* Make sure we don't suddenly exit while we are writing */ act.sa_handler = sigexit; memset(&act.sa_mask, 0, sizeof(act.sa_mask)); act.sa_flags = SA_RESTART; act.sa_restorer = 0; sigaction(SIGINT, &act, NULL); sigaction(SIGTERM, &act, NULL); sigaction(SIGQUIT, &act, NULL); register_resetpid(); /* * Spin forever, waiting for a signal to write... */ for (;;) { if (recv_usr1) { struct stat st_buf; recv_usr1 = 0; /* Don't write out config if temp file exists. */ if (stat(IGNORE_FLASH_WRITE_FILE, &st_buf) == 0) { syslog(LOG_INFO, "Not writing to flash " "because %s exists", IGNORE_FLASH_WRITE_FILE); continue; } save_config_to_flash(); continue; } if (recv_hup) { /* * Make sure we do the check above first so that we * commit to flash before rebooting. */ recv_hup = 0; reboot_now(); /*notreached*/ exit(1); } if (recv_pwr) { /* * Ditto for halt */ recv_pwr = 0; halt_now(); /*notreached*/ exit(1); } if (recv_usr2) { #ifdef LOGGING system("/bin/logd button"); #endif recv_usr2 = 0; current_cmd++; if (cmd_list[current_cmd].action == NULL) /* wrap */ current_cmd = 0; } if (exit_flatfsd) break; if (current_cmd) led_pause(); else if (!recv_hup && !recv_usr1 && !recv_usr2 && !recv_pwr) pause(); } return 0; }
/*ARGSUSED*/ int schedinit(int argc, char *argv[]) { char *id = "schedinit"; struct utsname name; struct sigaction act, oact; char *ptr, canon[PBS_MAXHOSTNAME + 1]; DBPRT(("\n%s\n", schd_VersionString)); log_record(PBSEVENT_SYSTEM, PBS_EVENTCLASS_SERVER, id, schd_VersionString); /* * If this is the initial startup configuration, then schd_TimeNow will * be 0. Initialize it to the current time, so it can be tested against * various times when initializing. */ if (schd_TimeNow == 0) { schd_TimeNow = time(NULL); DBPRT(("%s: initialize/startup at %s", id, ctime(&schd_TimeNow))); } /* * Determine location of configuration file. Check for the presence of * the PBSSCHED_CONFIG environment variable. If not defined, fall back * to the compiled default CONFIGFILE. * * Since neither the environment variables nor the compiled-in default * can be changed (with the exception of someone wreaking havoc with * a debugger or something), this only needs to be done once. */ if (schd_CfgFilename == NULL) { ptr = getenv("PBSSCHED_CONFIG"); if (ptr == NULL) ptr = CONFIGFILE; schd_CfgFilename = schd_strdup(ptr); if (schd_CfgFilename == NULL) { (void)sprintf(log_buffer, "schd_strdup() failed for configfile"); log_record(PBSEVENT_SYSTEM, PBS_EVENTCLASS_SERVER, id, log_buffer); DBPRT(("%s: %s\n", id, log_buffer)); return (-1); } } /* * From this point on, goto cleanup_and_error: to clean up any allocated * storage for filenames. */ DBPRT(("SCHEDINIT: Reading configuration from '%s'\n", schd_CfgFilename)); /* Reset the configuration to a "known" state. */ reset_config(); /* Determine on what host this scheduler running. */ uname(&name); if (get_fullhostname(name.nodename, canon, PBS_MAXHOSTNAME) == 0) { strncpy(schd_ThisHost, canon, PBS_MAXHOSTNAME); } else { (void)sprintf(log_buffer, "Failed to canonicalize uname %s (using it anyway)", name.nodename); log_record(PBSEVENT_SYSTEM, PBS_EVENTCLASS_SERVER, id, log_buffer); DBPRT(("%s: %s\n", id, log_buffer)); strncpy(schd_ThisHost, name.nodename, PBS_MAXHOSTNAME); } schd_lowercase(schd_ThisHost); DBPRT(("%s: This host is '%s'\n", id, schd_ThisHost)); /* * Register the state of the config file. The call to reset_config() * above will have cleared all file watches. */ if (schd_register_file(schd_CfgFilename)) { (void)sprintf(log_buffer, "cannot watch %s", schd_CfgFilename); log_record(PBSEVENT_SYSTEM, PBS_EVENTCLASS_SERVER, id, log_buffer); DBPRT(("%s: %s\n", id, log_buffer)); goto cleanup_and_error; } /* Read the configuration file. */ if (schd_get_config(schd_CfgFilename)) return (-1); /* if we are NOT making a distinction between Prime and Non-Prime Time, * then simply empty the holidays array; otherwise, try to read and load * the holidays file. */ if (!schd_ENFORCE_PRIME_TIME) init_holidays(); else { /* * Register the state of the holidays file. This allows schd_req() to * reload it if it is changed. */ if (schd_register_file(HOLIDAYS_FILE)) { (void)sprintf(log_buffer, "cannot watch %s", HOLIDAYS_FILE); log_record(PBSEVENT_SYSTEM, PBS_EVENTCLASS_SERVER, id, log_buffer); DBPRT(("%s: %s\n", id, log_buffer)); goto cleanup_and_error; } /* Get a list of prime/non-prime times from the holidays file */ if (schd_read_holidays() < 0) return (-1); } /* * Set up a signal handler for SIGHUP. catch_HUP() will re-read the * configuration file. */ act.sa_flags = 0; act.sa_handler = catch_HUP; sigemptyset(&act.sa_mask); if (sigaction(SIGHUP, &act, &oact)) { (void)sprintf(log_buffer, "Failed to setup SIGHUP handler."); log_record(PBSEVENT_SYSTEM, PBS_EVENTCLASS_SERVER, id, log_buffer); DBPRT(("%s: %s\n", id, log_buffer)); } DBPRT(("SCHEDINIT: configuration complete.\n")); return (0); cleanup_and_error: /* * Some error occurred. Remove watches and free the storage allocated * for the filenames. */ if (schd_CfgFilename) { schd_forget_file(schd_CfgFilename); free(schd_CfgFilename); } schd_CfgFilename = NULL; return (-1); }