void error_update(void) { unsigned short temp_read_idx, temp_write_idx; //Read in the normal-preemption level error codes: temp_read_idx = error_in_buf_read_idx; temp_write_idx = error_in_buf_write_idx; while (temp_read_idx != temp_write_idx) { error_push(error_in_buf[temp_read_idx]); if (++temp_read_idx >= error_in_buf_size) {temp_read_idx = 0;} } error_in_buf_read_idx = temp_read_idx; //Read in the IRQ preemption level error codes: temp_read_idx = error_in_buf_read_idx_irq; temp_write_idx = error_in_buf_write_idx_irq; while (temp_read_idx != temp_write_idx) { error_push(error_in_buf_irq[temp_read_idx]); if (++temp_read_idx >= error_in_buf_size) {temp_read_idx = 0;} } error_in_buf_read_idx_irq = temp_read_idx; //Read in the FIQ preemption level error codes: temp_read_idx = error_in_buf_read_idx_fiq; temp_write_idx = error_in_buf_write_idx_fiq; while (temp_read_idx != temp_write_idx) { error_push(error_in_buf_fiq[temp_read_idx]); if (++temp_read_idx >= error_in_buf_size) {temp_read_idx = 0;} } error_in_buf_read_idx_fiq = temp_read_idx; }
void load_config(void) { struct stat sfile; int load_context; char *rcpath; load_context = error_new_context(_("Error loading configfile"), NULL); rcpath = filename_config(load_context); if(!rcpath) { error_flush(load_context); return; } /* no config file is fine */ if(stat(rcpath, &sfile) == -1 || !sfile.st_size) { error_flush(load_context); /* If there is no configuration file, we start with the current configuration file version */ config->config_version = CURRENT_CONFIG_VERSION; config->asked_version = CURRENT_CONFIG_VERSION; g_free(rcpath); return; } /* refuse to read config file if world readable (bind passwords) */ if( ((sfile.st_mode & ~S_IFMT) & (S_IRWXG|S_IRWXO)) != 0 ) { error_push(load_context, _("%s is group and/or world readable or writeable.\n" "This file can contain passwords in cleartext,\n" "and is recommended to have mode 0600.\n\n" "Continuing with default settings...\n"), rcpath); error_flush(load_context); g_free(rcpath); return; } config = process_rcfile_XML(load_context, rcpath); /* printf("config = %08lx\n", config); */ /* process_rcfile(rcfile) */ g_free(rcpath); if (config == NULL) { error_push(load_context, _("No valid configuration found. Using default (empty) configuration")); config = new_config(); } error_flush(load_context); }
void XMLmessageHandler(struct parser_context *ctx, int severity, const char *type, const char *format, va_list ap) { struct parser_comm *comm = ctx->user_data; if (comm) { int len = 1024, pos = 0, i; char *buf = g_malloc(len); g_snprintf(buf, len, "%s: ", type); i = strlen(buf); pos += i; /* OK for UTF-8 */ g_vsnprintf(buf + pos, len - pos, format, ap); error_push(comm->error_context, buf); fprintf(stderr, "%s\n", buf); g_free(buf); if (severity > comm->severity) { comm->severity = severity; } } }
void error_popup(char *title, char *message, GtkWidget *transient_for) { int context; context = error_new_context(title, transient_for); error_push(context, message); error_flush(context); }
/* * Check LDAP connection for additional error information and append * it to the error context if such information is available. */ void push_ldap_addl_error(LDAP *ld, int context) { char *error_msg; ldap_get_option(ld, LDAP_OPT_ERROR_STRING, &error_msg); if (error_msg != NULL && *error_msg != 0) { error_push(context, _("Additional error: %s"), error_msg); } }
/** This function iterates through and updates the list of errors that have occurred, putting the error data into @ref ERROR_INFO structs. @note @c error_update should be called with every tick of the scheduler. */ void error_update(void){ int chunk, bit; int index; int found = 0; ERROR_ID error_code; volatile ERROR_BUFFER* buf; volatile ERROR_INFO new_error; if (er_is_init){ //make sure error module has been initialized first for (chunk = 0; chunk < er_length; chunk++){ if (er_flags[chunk]){ for (bit = 0; bit < 32; bit++){ if (er_flags[chunk] & (1<<bit)){ error_code = (ERROR_ID)(bit + (32 * chunk)); buf = &er_buffer; // ********* CHECK IF ERROR ALREADY OCCURRED *********** if (!(buf->empty)){ //only traverse if the buffer has stuff in it index = buf->first; while (index != buf->next) { //traverse the buf of errors to see if this error has already been generated if (buf->errors[index].error_id == error_code) { //we've had this error before since the last time we sent info buf->errors[index].frequency++; //if it has, increase the frequency found = 1; break; } if (index + 1 >= ERR_BUF_SIZE){ index = 0; } else { index++; } } } // ********** ADD NEW ERROR TO BUFFER ********* if (!found) { //we haven't seen this error before, add it to the ring buffer new_error.error_id = error_code; new_error.frequency = 1; new_error.time_occurred = er_get_timestamp(); //will hold actual value when sent out; this is just the initial time error_push(buf, new_error); //will new_error be out of scope here and be meaningless? TOMMY HELP!! } } } er_flags[chunk] = 0; } } } }
/* filename_config returns the name of the config file. The returned pointer must g_free'd. */ gchar *filename_config(int context) { gchar *rcpath = NULL; char *home; char *env = getenv("GQRC"); if (env) { return g_strdup(env); } else { home = homedir(); if(home == NULL) { error_push(context, _("You have no home directory!")); return(NULL); } /* need add'l "/", thus add some extra chars */ rcpath = g_malloc(strlen(home) + strlen(RCFILE) + 3); sprintf(rcpath, "%s/%s", home, RCFILE); g_free(home); return(rcpath); } }
static int dot_gq_upgrade_hack(int error_context, const char *filename) { FILE *fp = fopen(filename, "r"); int changed = 0; if (fp) { /* nasty heuristics to find out if .gq is "old" (written with a gq that does not yet use libxml) or "new". The way this is done is by checking for an "encoding" in the first line of .gq (should be: in the xml declaration, actually). This works because the encoding is only there in "new" versions of .gq. The situation does not allow to do it differently: We cannot just check for the config-version, because for this to work the parser would need to run. A better way would be to check the encoding when the parser sees the xml decl. But libxml seems not to allow for this. */ char firstline[255]; fgets(firstline, sizeof(firstline) - 1, fp); rewind(fp); if (strstr(firstline, "encoding=") != NULL ) { /* NEW version - everything is OK */ fclose(fp); return 0; } else { char *cfgbuf; GString *newbuf; int i; struct stat sfile; /* OLD version */ /* more nastiness... since this config file was written by a pre-UTF-8 version of GQ, it's not going to have <>&'" escaped properly... fudge this now: silently rewrite the config file on disk, then reopen it for the XML parser */ changed = 0; stat(filename, &sfile); cfgbuf = g_malloc(sfile.st_size + 1); fread(cfgbuf, 1, sfile.st_size, fp); cfgbuf[sfile.st_size] = 0; newbuf = g_string_sized_new(sfile.st_size + 128); /* take care of the XML declaration in the first line... */ g_string_sprintf(newbuf, "<?xml version=\"1.0\" encoding=\"%s\" standalone=\"yes\"?>", gq_codeset); /* skip line 1 in the input buffer */ for(i = 0 ; cfgbuf[i] && cfgbuf[i] != '\n' ; i++) ; for( ; cfgbuf[i] ; i++) { switch(cfgbuf[i]) { case '\\': /* < and > used to be escaped with a \ */ if(cfgbuf[i + 1] == '<') { g_string_append(newbuf, "<"); changed++; i++; } else if(cfgbuf[i + 1] == '>') { g_string_append(newbuf, ">"); changed++; i++; } else g_string_append_c(newbuf, cfgbuf[i]); break; case '&': g_string_append(newbuf, "&"); changed++; break; default: g_string_append_c(newbuf, cfgbuf[i]); } } fclose(fp); if(changed) { int fd; int rc; int wrote; int l = strlen(filename) + 20; char *tmp = g_malloc(l); g_snprintf(tmp, l, "%s.tmp", filename); unlink(tmp); /* provide very minor security */ fd = open(tmp, O_CREAT | O_WRONLY, sfile.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO) ); if (fd < 0) { error_push(error_context, _("Could not open temporary configuration file '%1$s': %2$s"), tmp, strerror(errno)); return -1; } wrote = write(fd, newbuf->str, newbuf->len); if (wrote == (int) newbuf->len) { close(fd); rename(tmp, filename); return 1; } close(fd); error_push(error_context, _("Could not write silently upgraded configuration file")); return -1; /* fwrite error */ } g_free(cfgbuf); g_string_free(newbuf, TRUE); } return 1; /* silent upgrade done */ } if (errno != ENOENT) { error_push(error_context, _("Could not open configuration file '%1$s': %2$s"), filename, strerror(errno)); } return -1; /* failed (fopen) */ }
static gboolean save_config_internal(int write_context, struct gq_config *cfg, const char *rcpath) { GList *templatelist, *oclist, *filterlist; GqServer *server; struct gq_template *template; struct gq_filter *filter; struct writeconfig *wc; char *tmprcpath; struct stat sfile; int mode = S_IRUSR|S_IWUSR; GList *I; gboolean ok = FALSE; gpointer wc_and_cfg[2] = { NULL, cfg }; if (cfg->config_version > CURRENT_CONFIG_VERSION) { error_push(write_context, _("Configuration file version too high - saving the configuration is not possible")); return FALSE; } wc = new_writeconfig(); wc_and_cfg[0] = wc; /* write to temp file... */ tmprcpath = g_malloc(strlen(rcpath) + 10); strcpy(tmprcpath, rcpath); strcat(tmprcpath, ".new"); /* check mode of original file. Do not overwrite without write permission. */ if(stat(rcpath, &sfile) == 0) { mode = sfile.st_mode & (S_IRUSR|S_IWUSR); } wc->outfile = fopen(tmprcpath, "w"); if(!wc->outfile) { error_push(write_context, _("Unable to open %1$s for writing:\n%2$s\n"), rcpath, strerror(errno)); g_free(tmprcpath); return FALSE; } fchmod(fileno(wc->outfile), mode); config_write(wc, "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"); config_write(wc, "<gq-config>\n\n"); /* global settings */ wc->indent++; if (cfg->config_version > 0) { config_write_int(wc, cfg->config_version, "config-version", NULL); config_write_int(wc, cfg->config_version, "asked-config-version", NULL); config_write_int(wc, cfg->config_version, "last-asked", NULL); } config_write_bool(wc, cfg->confirm_mod, "confirm-mod", NULL); config_write_string(wc, detokenize(token_searchargument, cfg->search_argument), "search-argument", NULL); config_write_bool(wc, cfg->showdn, "show-dn", NULL); config_write_bool(wc, cfg->showoc, "show-oc", NULL); config_write_bool(wc, cfg->show_rdn_only, "show-rdn-only", NULL); config_write_bool(wc, cfg->sort_search, "sort-search-mode", NULL); config_write_bool(wc, cfg->sort_browse, "sort-browse-mode", NULL); config_write_bool(wc, cfg->browse_use_user_friendly, "browse-use-user-friendly", NULL); config_write_bool(wc, cfg->restore_window_sizes, "restore-window-sizes", NULL); config_write_bool(wc, cfg->restore_window_positions, "restore-window-positions", NULL); config_write_bool(wc, cfg->restore_search_history, "restore-search-history", NULL); config_write_bool(wc, cfg->restore_tabs, "restore-tabs", NULL); config_write_bool(wc, cfg->never_leak_credentials, "never-leak-credentials", NULL); config_write_bool(wc, cfg->do_not_use_ldap_conf, "do-not-use-ldap-conf", NULL); config_write_string(wc, detokenize(token_ldifformat, cfg->ldifformat), "ldif-format", NULL); if(strlen(cfg->schemaserver)) config_write_string(wc, cfg->schemaserver, "schema-server", NULL); config_write(wc, "\n"); /* ldapservers */ gq_server_list_foreach(gq_server_list_get(), write_server, wc_and_cfg); /* templates */ templatelist = cfg->templates; while(templatelist) {