static void test_load_file(const char *filename) { QofSession *session; QofBook *book; Account *root; gboolean ignore_lock; gchar *logdomain = "GConf"; guint loglevel = G_LOG_LEVEL_WARNING; TestErrorStruct check = { loglevel, logdomain, NULL }; g_log_set_handler (logdomain, loglevel, (GLogFunc)test_checked_handler, &check); session = qof_session_new(); remove_locks(filename); ignore_lock = (safe_strcmp(g_getenv("SRCDIR"), ".") != 0); qof_session_begin(session, filename, ignore_lock, FALSE, TRUE); qof_session_load(session, NULL); book = qof_session_get_book (session); root = gnc_book_get_root_account(book); do_test (gnc_account_get_book (root) == book, "book and root account don't match"); do_test_args(qof_session_get_error(session) == ERR_BACKEND_NO_ERR, "session load xml2", __FILE__, __LINE__, "qof error=%d for file [%s]", qof_session_get_error(session), filename); /* Uncomment the line below to generate corrected files */ qof_session_save( session, NULL ); qof_session_end(session); }
static int iterate_over_clients(struct config *conf, strlist_t **grouplist, int gcount, const char *ext, unsigned int maxlinks) { int ret=0; DIR *dirp=NULL; struct dirent *dirinfo=NULL; signal(SIGABRT, &sighandler); signal(SIGTERM, &sighandler); signal(SIGINT, &sighandler); if(!(dirp=opendir(conf->clientconfdir))) { logp("Could not opendir '%s': %s\n", conf->clientconfdir, strerror(errno)); return 0; } while((dirinfo=readdir(dirp))) { char *lockfile=NULL; char *lockfilebase=NULL; if(!strcmp(dirinfo->d_name, ".") || !strcmp(dirinfo->d_name, "..") || looks_like_vim_tmpfile(dirinfo->d_name) || !is_regular_file(conf->clientconfdir, dirinfo->d_name)) continue; if(gcount) { int ig=0; if((ig=in_group(conf->clientconfdir, dirinfo->d_name, grouplist, gcount, conf))<0) { ret=-1; break; } if(!ig) continue; } if(!(lockfilebase=prepend(conf->client_lockdir, dirinfo->d_name, "/")) || !(lockfile=prepend(lockfilebase, BEDUP_LOCKFILE_NAME, "/"))) { if(lockfilebase) free(lockfilebase); if(lockfile) free(lockfile); ret=-1; break; } free(lockfilebase); if(get_lock(lockfile)) { logp("Could not get %s\n", lockfile); free(lockfile); continue; } // Remember that we got that lock. if(strlist_add(&locklist, &lockcount, lockfile, 1)) { free(lockfile); lockcount=0; break; } logp("Got %s\n", lockfile); if(process_dir(conf->directory, dirinfo->d_name, ext, maxlinks, 1 /* burp mode */, 0 /* level */)) { ret=-1; break; } ccount++; } closedir(dirp); remove_locks(); return ret; }
static void sighandler(int signum) { remove_locks(); exit(1); }
static void remove_locks_on_signal(int signo) { remove_locks(); sigchain_pop(signo); raise(signo); }