/* firstpass() reads the input assembly file and calls the parser to tokenize and analyze each record separetely. */ void firstpass(FILE* fp){ char instring[LINE_LEN]; //Initializing Globals flag_end_of_program = FALSE; // Used to end assembly when END is encountered flag_max_lc = FALSE; line_number = 1; // Numbers in this case = Readable errors = 0; fprintf(fout,"\n-------------- Input Records --------------\n"); while((fgets(instring, LINE_LEN, fp) != NULL) && flag_end_of_program == FALSE){ /* Truncate lines too long */ instring[LINE_LEN-1] = NUL; #ifdef debug printf("\n------Record %d------: %s", line_number, instring); #endif fprintf(fout, "\n------Record %d------: %s", line_number, instring); /* Completely skip record if it starts with a comment or it's a blank */ if((instring[0] != '\r') && (instring[0] != ';') && (instring[0] != '\n')){ parse_record(instring); } line_number++; // Line number is incremented regardless of blank or not } }
static int denydb_foreach_cb(void *rock, const char *key, size_t keylen, const char *data, size_t datalen) { struct denydb_rock *dr = (struct denydb_rock *)rock; struct buf user = BUF_INITIALIZER; struct buf buf = BUF_INITIALIZER; char *wild = NULL; const char *msg = NULL; int r; /* ensure we have a nul-terminated user string */ buf_appendmap(&user, key, keylen); buf_cstring(&user); /* get fields from the record */ buf_init_ro(&buf, data, datalen); r = parse_record(&buf, &wild, &msg); if (r) { syslog(LOG_WARNING, "DENYDB_ERROR: invalid entry for '%s'", user.s); r = 0; /* whatever, keep going */ goto out; } r = dr->proc(user.s, wild, msg, dr->rock); out: buf_free(&user); buf_free(&buf); return r; }
bool FileRecord::Remove(const std::string& id, const std::string& owner) { if(!valid_) return false; Glib::Mutex::Lock lock(lock_); Dbt key; Dbt data; make_key(id,owner,key); void* pkey = key.get_data(); if(dberr("",db_locked_->get(NULL,&key,&data,0))) { ::free(pkey); error_str_ = "Record has active locks"; return false; // have locks }; if(!dberr("Failed to retrieve record from database",db_rec_->get(NULL,&key,&data,0))) { ::free(pkey); return false; // No such record? }; std::string uid; std::string id_tmp; std::string owner_tmp; std::list<std::string> meta; parse_record(uid,id_tmp,owner_tmp,meta,key,data); if(!uid.empty()) { ::unlink(uid_to_path(uid).c_str()); // TODO: handle error }; if(!dberr("Failed to delete record from database",db_rec_->del(NULL,&key,0))) { // TODO: handle error ::free(pkey); return false; }; db_rec_->sync(0); ::free(pkey); return true; }
static LTSV *parse_ltsv(const char **string) { LTSV *ltsv = ltsv_init(); LTSV_Record *record; if (!ltsv) { fprintf(stderr, "couldn't allocate LTSV!\n"); return NULL; } while (**string != '\0') { record = parse_record(string); if (!record) { if (!is_newline(**string)) { goto bail; } fprintf(stderr, "string: %c\n", **string); return ltsv; } ltsv_add(ltsv, record); if (**string == 0x0d) { skip_char(string); } if (**string == 0x0a) { skip_char(string); } } return ltsv; bail: ltsv_free(ltsv); return NULL; }
bool FileRecord::Modify(const std::string& id, const std::string& owner, const std::list<std::string>& meta) { if(!valid_) return false; Glib::Mutex::Lock lock(lock_); Dbt key; Dbt data; make_key(id,owner,key); void* pkey = key.get_data(); if(!dberr("Failed to retrieve record from database",db_rec_->get(NULL,&key,&data,0))) { ::free(pkey); return false; }; std::string uid; std::string id_tmp; std::string owner_tmp; std::list<std::string> meta_tmp; parse_record(uid,id_tmp,owner_tmp,meta_tmp,key,data); ::free(pkey); make_record(uid,id,owner,meta,key,data); if(!dberr("Failed to store record to database",db_rec_->put(NULL,&key,&data,0))) { ::free(key.get_data()); ::free(data.get_data()); return false; }; db_rec_->sync(0); ::free(key.get_data()); ::free(data.get_data()); return true; }
/* * Parse the UsnJrnl block buffer. * * Recover the record size from the header. * * If the record does not fit in the entire buffer, returns to the callee * its offset for alignment. * * If the buffer is big enough, parses the USN record. * * Returns -1 on error, 0 in case the action callback decided to stop, * a number greater than 0 if the buffer is not big enough. */ static int parse_buffer(const unsigned char *buf, ssize_t bufsize, TSK_ENDIAN_ENUM endian, TSK_FS_USNJENTRY_WALK_CB action, void *ptr) { TSK_OFF_T offset = 0; TSK_WALK_RET_ENUM ret = 0; TSK_USN_RECORD_HEADER header; while ((offset = search_record(buf, offset, bufsize)) < bufsize) { parse_record_header(&buf[offset], &header, endian); /* The buffer does not contain the entire record */ if (offset + header.length > bufsize) return bufsize - offset; ret = parse_record(&buf[offset], &header, endian, action, ptr); if (ret == TSK_WALK_ERROR) return -1; else if (ret == TSK_WALK_STOP) return 0; offset += header.length; } return offset; }
// ./ovh domain domain.ext record toto add www type CNAME // TODO: ttl (optionnal) static command_status_t record_add(COMMAND_ARGS) { bool request_success; json_document_t *doc; domain_record_argument_t *args; USED(mainopts); args = (domain_record_argument_t *) arg; assert(NULL != args->domain); assert(NULL != args->record); { json_document_t *reqdoc; // data { json_value_t root; reqdoc = json_document_new(); root = json_object(); json_object_set_property(root, "target", json_string(args->value)); json_object_set_property(root, "fieldType", json_string(domain_record_types[args->type])); // if ('\0' != *subdomain) json_object_set_property(root, "subDomain", json_string(args->record)); json_document_set_root(reqdoc, root); } // request { request_t *req; req = request_new(REQUEST_FLAG_SIGN | REQUEST_FLAG_JSON, HTTP_POST, reqdoc, error, API_BASE_URL "/domain/zone/%s/record", args->domain); request_success = request_execute(req, RESPONSE_JSON, (void **) &doc, error); request_destroy(req); json_document_destroy(reqdoc); } } // result if (request_success) { domain_t *d; ht_hash_t h; domain_set_t *ds; d = NULL; ds = NULL; account_current_get_data(MODULE_NAME, (void **) &ds); assert(NULL != ds); h = hashtable_hash(ds->domains, args->domain); if (!hashtable_quick_get(ds->domains, h, args->domain, &d)) { d = domain_new(); hashtable_quick_put(ds->domains, 0, h, args->domain, d, NULL); } parse_record(d->records, doc); ask_for_refresh(RELAY_COMMAND_ARGS); } return request_success ? COMMAND_SUCCESS : COMMAND_FAILURE; }
FileRecord::Iterator& FileRecord::Iterator::operator--(void) { if(!cur_) return *this; Glib::Mutex::Lock lock(frec_.lock_); Dbt key; Dbt data; if(!frec_.dberr("Iterator:first",cur_->get(&key,&data,DB_PREV))) { cur_->close(); cur_=NULL; return *this; }; parse_record(uid_,id_,owner_,meta_,key,data); return *this; }
FileRecord::Iterator::Iterator(FileRecord& frec):frec_(frec),cur_(NULL) { Glib::Mutex::Lock lock(frec_.lock_); if(!frec_.dberr("Iterator:cursor",frec_.db_rec_->cursor(NULL,&cur_,0))) { if(cur_) { cur_->close(); cur_=NULL; }; return; }; Dbt key; Dbt data; if(!frec_.dberr("Iterator:first",cur_->get(&key,&data,DB_FIRST))) { cur_->close(); cur_=NULL; return; }; parse_record(uid_,id_,owner_,meta_,key,data); }
static bool get_domain_records(const char *domain, domain_t **d, bool force, error_t **error) { domain_set_t *ds; bool request_success; *d = NULL; FETCH_ACCOUNT_DOMAINS(ds); request_success = TRUE; // TODO: hashtable_clear((*d)->records) if force if (!hashtable_get(ds->domains, domain, d) || !(*d)->uptodate || force) { request_t *req; json_document_t *doc; if (NULL == *d) { *d = domain_new(); hashtable_put(ds->domains, 0, domain, *d, NULL); } req = request_new(REQUEST_FLAG_SIGN, HTTP_GET, NULL, error, API_BASE_URL "/domain/zone/%s/record", domain); request_success = request_execute(req, RESPONSE_JSON, (void **) &doc, error); request_destroy(req); // result if (request_success) { Iterator it; json_value_t root; root = json_document_get_root(doc); json_array_to_iterator(&it, root); for (iterator_first(&it); request_success && iterator_is_valid(&it); iterator_next(&it)) { json_value_t v; json_document_t *doc; v = (json_value_t) iterator_current(&it, NULL); req = request_new(REQUEST_FLAG_SIGN, HTTP_GET, NULL, error, API_BASE_URL "/domain/zone/%s/record/%u", domain, json_get_integer(v)); request_success = request_execute(req, RESPONSE_JSON, (void **) &doc, error); request_destroy(req); // result parse_record((*d)->records, doc); } iterator_close(&it); json_document_destroy(doc); (*d)->uptodate = TRUE; } } return request_success ? COMMAND_SUCCESS : COMMAND_FAILURE; }
std::string FileRecord::Find(const std::string& id, const std::string& owner, std::list<std::string>& meta) { if(!valid_) return ""; Glib::Mutex::Lock lock(lock_); Dbt key; Dbt data; make_key(id,owner,key); void* pkey = key.get_data(); if(!dberr("Failed to retrieve record from database",db_rec_->get(NULL,&key,&data,0))) { ::free(pkey); return ""; }; std::string uid; std::string id_tmp; std::string owner_tmp; parse_record(uid,id_tmp,owner_tmp,meta,key,data); ::free(pkey); return uid_to_path(uid); }
int main() { char ch; list_t *t, *h = NULL; scanf("%*d"); while(ch = getc(stdin), ch != EOF) { if(ch == '\n') { scanf("%[^\n]", dbuf), getchar(); } else { ungetc(ch, stdin); scanf("%[^\n]", buf), getchar(); t = parse_record(dbuf, buf); h = insert_record(h, t); buf[0] = NULL; } } t = h; while(t) { printf("----------------------------------------\n"); printf("%s %s %s\n", t->rec->title, t->rec->fname, t->rec->lname); printf("%s\n", t->rec->adrs); printf("Department: %s\n", t->rec->dept); printf("Home Phone: %s\n", t->rec->hphone); printf("Work Phone: %s\n", t->rec->wphone); printf("Campus Box: %s\n", t->rec->cambox); t = t->next; } return 0; }
int main(int argc, char **argv) { int i, recnum; char *p, buffer[1024]; char outheader[256]; char bcpfile[256]; char outdefconst[3][256]; FILE *in, *out[NUM_HEADERS], *fopen(); char errname[szErrname+1]; char outerrname[szErrname+1]; char errvalue[szErrvalue+1]; int errmodule; char errtext[szErrtext+1]; int parse_result; if(argc != 3) { usage(argv[0]); exit(-1); } strcpy(bcpfile, argv[2]); if(access(bcpfile, R_OK)) { fprintf(stderr, "Unable to access bcp file: %s\n",bcpfile); exit(-1); } for (i = 0; i < NUM_HEADERS; i++) { strcpy(outheader, argv[1]); strcat(outheader, outheaders[i].hdr_extension); if((out[i] = fopen(outheader, "w")) == NULL) { fprintf(stderr, "Unable to open output header file for write: %s\n", outheader); exit(-1); } fprintf(out[i], "/*%s\n", COMMENT_DELIMETER); fprintf(out[i], " * Filename: %s\n", outheader); fprintf(out[i], " *\n"); fprintf(out[i], " * Description: GENERATED FILE -- DO NOT EDIT!\n"); fprintf(out[i], " * Header file for error message information.\n"); fprintf(out[i], " * The macro value corresponds to GUI_MESSAGES.number\n"); fprintf(out[i], " *\n"); fprintf(out[i], " * %s\n", COPYRIGHT_STRING); fprintf(out[i], " *%s*/\n\n", COMMENT_DELIMETER); upcase_string_no_special(outdefconst[i], outheader); fprintf(out[i], "#ifndef %s\n", outdefconst[i]); fprintf(out[i], "#define %s\n\n", outdefconst[i]); } if((in = fopen(bcpfile, "r")) == NULL) { fprintf(stderr,"Unable to open input bcp file for read: %s\n",bcpfile); exit(-1); } recnum = 0; /* read each line in file */ while(fgets(buffer, 1024, in) != NULL) { if(strlen(buffer) < 2) { /* empty line, could be just extra blank line at end of file */ continue; } recnum++; memset(errname, '\0', szErrname); memset(errvalue, '\0', szErrvalue); memset(errtext, '\0', szErrtext); /* 2. read line by line; fields separator = tab, record separator = '\n' */ while ((parse_result = parse_record(buffer, errname, errvalue, &errmodule, errtext)) == 1) ; if (parse_result < 0) { /* error parsing record, corrupted data */ fprintf(stderr,"Unable to parse record %d in file %s\n",recnum,bcpfile); exit(-1); } /* 3. write data to out file */ for (i = 0; i < NUM_HEADERS; i++) { if (errmodule == outheaders[i].msg_type) { sprintf(outerrname, "%s_%s_ERROR", outheaders[i].define_prefix, errname); fprintf(out[i], "#define %-*s (%s)\n", MAX_ERROR_WIDTH, outerrname, errvalue); fprintf(out[i], "/* Text: %s */\n\n", errtext); break; } } if (i == NUM_HEADERS) { fprintf(stderr,"Unable to match msg_type for record %d in file %s\n", recnum,bcpfile); exit(-1); } } if(!feof(in)) { /* read loop ended due to non-eof error */ fprintf(stderr,"Error reading input bcp file: %s\n",bcpfile); exit(-1); } fclose(in); for (i = 0; i < NUM_HEADERS; i++) { fprintf(out[i], "#endif /* %s */\n", outdefconst[i]); fclose(out[i]); } fprintf(stderr,"Done: %s\n", outheader); return 0; }
// 讀取棋譜記錄檔 int load_game(const char *filename, int piece_type[PIECE_TYPE], int chsbrd[BOARD_SIZE], int *turn, int *time_limit) { int ret; int i, j, k; int piece_limit[15] = {1, 2, 2, 2, 2, 2, 5, 1, 2, 2, 2, 2, 2, 5}; int piece_check[15]; int src, dest; int time_str[500]; int first; int result; int ply = 0; char str1[500], str2[500], str3[500], str4[500]; char player1[500], player2[500]; FILE *fp; fp = fopen(filename, "rt"); if(fp == NULL) return 0; fgets(str1, 500, fp); str1[strlen(str1) - 1] = '\0'; strcpy(time_str, &str1[2]); fscanf(fp, "%s %s %s %s", str1, player2, str2, player2); fscanf(fp, "%s", str1); for(i = 0; i < 14; i++){ fscanf(fp, "%d", &j); if(j < 0 || j > piece_limit[i]) return -1; piece_type[i] = j; piece_check[i] = j; } for(i = 28; i >= 0; i -= 4){ fscanf(fp, "%s", str1); for(j = i; j < i + 4; j++){ fscanf(fp, "%s", str1); k = piece2int(str1[0]); if(k != EMPTY && k != DARK && k < 1 && k > 14) return -1; if(k != DARK && piece_check[k] == 0) return -1; chsbrd[j] = k; piece_check[k]--; } } fscanf(fp, "%s %s %d", str1, str2, &first); fscanf(fp, "%s %s %d", str1, str2, time_limit); *turn = first; n_ply = 0; while(1){ if(feof(fp)) break; str1[0] = '\0'; i = fscanf(fp, "%s %s %s %s", str1, str2, str3, str4); if(str1[0] != '*') break; if(strcmp(str3, "wins") == 0){ if(strcmp(str2, player1) == 0) result = 1; else if(strcmp(str2, player2) == 0) result = 2; break; } else if(strcmp(str2, "Draws") == 0){ result = 3; break; } ret = parse_record(str3, &src, &dest); if(ret == -1) return -1; if(src >= 100) chsbrd[src - 100] = dest; else{ if(chsbrd[dest] != EMPTY) piece_type[chsbrd[dest] - 1]--; chsbrd[dest] = chsbrd[src]; chsbrd[src] = EMPTY; } *turn = 1 - *turn; ply++; if(i == 4){ ret = parse_record(str4, &src, &dest); if(ret == -1) return -1; if(src >= 100) chsbrd[src - 100] = dest; else{ if(chsbrd[dest] != EMPTY) piece_type[chsbrd[dest] - 1]--; chsbrd[dest] = chsbrd[src]; chsbrd[src] = EMPTY; } *turn = 1 - *turn; ply++; } if(str4[0] == '*'){ fscanf(fp, "%s %s", str1, str2); if(strcmp(str2, "wins") == 0){ if(strcmp(str1, player1) == 0) result = 1; else if(strcmp(str1, player2) == 0) result = 2; break; } else if(strcmp(str2, "Draws") == 0){ result = 3; break; } } } fclose(fp); //*turn = (ply % 2 == 0) ? first : 1 - first; }
void process_record(char *inseed, char *match, char *netcode, int rec_size) { /* Define some structures to pass to parse_record() */ static struct s_dev_id *dev_id = NULL; static struct s_blk_1000 *blk_1000 = NULL; char type; char prtnet[4], prtsta[7]; char prtloc[4], prtchan[5]; char *seedsta, *spcptr, *encoding; char order[4], sourcename[50]; int parsed = 0; int seedreclen; int i,p; /* Simple verification of a data record */ type = inseed[6]; if ( type != 'D' && type != 'R' && type != 'Q' ) { lprintf(1, "Record header/quality indicator unrecognized!"); return; } /* Make sure there is room for these structs */ dev_id = (struct s_dev_id *) realloc(dev_id, sizeof(struct s_dev_id)); blk_1000 = (struct s_blk_1000 *) realloc(blk_1000, sizeof(struct s_blk_1000)); parsed = parse_record( (struct s_dev_id *) dev_id, (struct s_blk_1000 *) blk_1000, (char *) inseed, rec_size); if ( !parsed ) { lprintf(1, "1000 blockette was NOT found!"); return; } /* Most of this monkey business is so the data stream naming convention will be consistent even with oddly filled fields */ strncpy(prtnet, dev_id->network_code, 2); prtnet[2] = '\0'; strncpy(prtsta, dev_id->station_code, 5); prtsta[5] = '\0'; strncpy(prtloc, dev_id->location_id, 2); prtloc[2] = '\0'; strncpy(prtchan, dev_id->channel_id, 3); prtchan[3] = '\0'; /* Cut trailing spaces. Assumes left justified fields */ if ( (spcptr = strstr(prtnet, " ")) != NULL ) *spcptr = '\0'; if ( (spcptr = strstr(prtsta, " ")) != NULL ) *spcptr = '\0'; if ( (spcptr = strstr(prtloc, " ")) != NULL ) *spcptr = '\0'; if ( (spcptr = strstr(prtchan, " ")) != NULL ) *spcptr = '\0'; seedsta = strdup(prtsta); if (prtnet[0] != '\0') strcat(prtnet, "_"); if (prtsta[0] != '\0') strcat(prtsta, "_"); if (prtloc[0] != '\0') strcat(prtloc, "_"); /* Build the source name string */ sprintf( sourcename, "%.3s%.6s%.3s%.3s", prtnet, prtsta, prtloc, prtchan); /* Calculate record size in bytes as 2^(blk_1000->rec_len) */ for (p=1, i=1; i <= blk_1000->rec_len; i++) p *= 2; seedreclen = p; if (seedreclen != rec_size) { lprintf(1, "Record was not expected size: %d, dropping", rec_size); p = 0; /* temporarily used, notifies the if/else below */ } /* Big or little endian reported by the 1000 blockette? */ if (blk_1000->word_swap == 0) strcpy(order, "LE"); else if (blk_1000->word_swap == 1) strcpy(order, "BE"); else strcpy(order, "??"); /* Get a description of the encoding format */ encoding = (char *) encoding_hash(blk_1000->encoding); /* Force network code if supplied */ if ( netcode ) { strncpy( inseed+18, netcode, 2); } if ( matches(sourcename, match) && p ) { /* send it off to the daemon */ if ( send_mseed(seedsta, (void *) inseed, rec_size) < 0 ) { lprintf(0, "Error sending data to seedlink: %s", strerror(errno)); exit(1); } if ( netcode ) { lprintf(2, "%s (Forced net: '%s'): %s, %d bytes, %s", sourcename, netcode, order, seedreclen, encoding); } else { lprintf(2, "%s: %s, %d bytes, %s", sourcename, order, seedreclen, encoding); } } else { lprintf(2, "DROPPED %s: %s, %d bytes, %s", sourcename, order, seedreclen, encoding); } free (seedsta); return; }
Parse_stat MCAnswer::parse(MCScriptPoint &sp) { Parse_errors t_error = PE_UNDEFINED; Symbol_type t_type; const LT *t_literal; initpoint(sp); getit(sp, it); if (sp . skip_token(SP_ASK, TT_UNDEFINED, AT_PAGE) == PS_NORMAL) { if (sp . skip_token(SP_ASK, TT_UNDEFINED, AT_SETUP) == PS_NORMAL) mode = AT_PAGESETUP; else t_error = PE_ANSWER_BADQUESTION; } else if (sp . next(t_type) == PS_NORMAL) { if (sp . lookup(SP_ASK, t_literal) == PS_NORMAL) mode = (Ask_type)t_literal -> which; else sp . backup(); } if (t_error == PE_UNDEFINED) switch(mode) { case AT_PAGESETUP: // MJ: adding support for "answer pagesetup" syntax, following existing code t_error = parse_pagesetup(sp); break; case AT_PRINTER: t_error = parse_printer(sp); break; case AT_EFFECT: t_error = parse_effect(sp); break; case AT_RECORD: t_error = parse_record(sp); break; case AT_COLOR: t_error = parse_colour(sp); break; case AT_FILE: case AT_FILES: t_error = parse_file(sp); break; case AT_FOLDER: case AT_FOLDERS: t_error = parse_folder(sp); break; default: t_error = parse_notify(sp); break; } if (t_error == PE_UNDEFINED && sp . skip_token(SP_ASK, TT_UNDEFINED, AT_TITLED) == PS_NORMAL) if (sp . parseexp(False, True, &title) != PS_NORMAL) t_error = PE_ANSWER_BADTITLE; if (t_error == PE_UNDEFINED && sp . skip_token(SP_FACTOR, TT_PREP, PT_AS) == PS_NORMAL) if (sp . skip_token(SP_ASK, TT_UNDEFINED, AT_SHEET) == PS_NORMAL) sheet = True; else t_error = PE_ANSWER_BADRESPONSE; if (t_error != PE_UNDEFINED) { MCperror -> add(t_error, sp); return PS_ERROR; } return PS_NORMAL; }
int mcs_file::load(const char* name) { FILE *f; int rc = -1; char line[256]; struct stat st; int len, type, addr; unsigned char buff[64]; int addr_offs = 0; u32 max_length; if (data || length) // Call clear() first return -1; if (stat(name, &st) < 0) { msgf(STR_UNABLE_TO_OPEN_FILE); return -1; } f = fopen(name, "rt"); if (f == NULL) { msgf(STR_UNABLE_TO_OPEN_FILE); return -1; } // This size must be enough! max_length = st.st_size / 2; data = (u8*)malloc(max_length); if (data == NULL) goto cleanup; memset(data, 0xFF, max_length); length = 0; // Read lines while(!feof(f)) { if (fgets(line, sizeof(line), f) == NULL) break; strip_whitespaces(line); if (parse_record(line, &len, &addr, &type, buff, sizeof(buff))) { msgf(STR_INVALID_FILE_FORMAT); goto cleanup; } if (type == RECORD_DATA) { if ((u32)(addr_offs + addr + len) > max_length) { msgf(STR_INVALID_FILE_FORMAT); goto cleanup; } memcpy(data + addr_offs + addr, buff, len); if ((u32)(addr_offs + addr + len) > length) length = (u32)(addr_offs + addr + len); } else if (type == RECORD_ADDRESS) addr_offs = (buff[0] << 24) + (buff[1] << 16); else if (type == RECORD_EOF) // EOF break; } rc = 0; cleanup: if (rc) clear(); if (f) fclose(f); return rc; }
int dns_resolver(void *log_fp) { DNODEPTR h_entries; DNODEPTR l_list = NULL; int i; int save_verbose=verbose; u_long listEntries = 0; struct sigaction sigPipeAction; struct stat dbStat; struct tms mytms; /* aligned dnsRecord to prevent Solaris from doing a dump */ /* (not found in debugger, as it can dereference it :( */ struct dnsRecord alignedRecord; struct flock tmp_flock; tmp_flock.l_whence=SEEK_SET; /* default flock fields */ tmp_flock.l_start=0; tmp_flock.l_len=0; tmp_flock.l_pid=0; time(&runtime); start_time = times(&mytms); /* get start time */ /* minimal sanity check on it */ if(stat(dns_cache, &dbStat) < 0) { if(errno != ENOENT) { dns_cache=NULL; dns_db=NULL; return 0; /* disable cache */ } } else { if(!dbStat.st_size) /* bogus file, probably from a crash */ { unlink(dns_cache); /* remove it so we can recreate... */ } } /* open cache file */ if(!(dns_db = dbopen(dns_cache, O_RDWR|O_CREAT, 0664, DB_HASH, NULL))) { /* Error: Unable to open DNS cache file <filename> */ if (verbose) fprintf(stderr,"%s %s\n",msg_dns_nodb,dns_cache); dns_cache=NULL; dns_db=NULL; return 0; /* disable cache */ } /* get file descriptor */ dns_fd = dns_db->fd(dns_db); tmp_flock.l_type=F_WRLCK; /* set read/write lock type */ if (fcntl(dns_fd,F_SETLK,&tmp_flock) < 0) /* and barf if we cant lock */ { /* Error: Unable to lock DNS cache file <filename> */ if (verbose) fprintf(stderr,"%s %s\n",msg_dns_nolk,dns_cache); dns_db->close(dns_db); dns_cache=NULL; dns_db=NULL; return 0; /* disable cache */ } /* Setup signal handlers */ sigPipeAction.sa_handler = SIG_IGN; sigPipeAction.sa_flags = SA_RESTART; sigemptyset(&sigPipeAction.sa_mask); sigaction(SIGPIPE, &sigPipeAction, NULL); /* disable warnings/errors for this run... */ verbose=0; /* Main loop to read log records (either regular or zipped) */ while ( (gz_log)?(our_gzgets((gzFile)log_fp,buffer,BUFSIZE) != Z_NULL): (fgets(buffer,BUFSIZE,log_fname?(FILE *)log_fp:stdin) != NULL)) { if (strlen(buffer) == (BUFSIZE-1)) { /* get the rest of the record */ while ( (gz_log)?(our_gzgets((gzFile)log_fp,buffer,BUFSIZE)!=Z_NULL): (fgets(buffer,BUFSIZE,log_fname?(FILE *)log_fp:stdin)!=NULL)) { if (strlen(buffer) < BUFSIZE-1) break; } continue; /* go get next record if any */ } memset(tmp_buf, 0, sizeof(tmp_buf)); strncpy(tmp_buf, buffer, sizeof(tmp_buf)-1); /* save buffer in case of error */ if(parse_record(buffer)) /* parse the record */ { if((log_rec.addr.s_addr = inet_addr(log_rec.hostname)) != INADDR_NONE) { DBT q, r; q.data = log_rec.hostname; q.size = strlen(log_rec.hostname); switch((dns_db->get)(dns_db, &q, &r, 0)) { case -1: break; /* Error while retrieving .. just ignore */ case 1: /* No record on file, queue up for resolving */ { put_dnode(log_rec.hostname, &log_rec.addr, host_table); break; } case 0: /* We have a record for this address */ { memcpy(&alignedRecord, r.data, sizeof(struct dnsRecord)); if((runtime - alignedRecord.timeStamp ) < DNS_CACHE_TTL) { if(!alignedRecord.numeric) /* It is a name. Do nothing */ break; /* otherise, it a number.. fall through */ } else { /* queue up stale entry for retrieval */ put_dnode(log_rec.hostname, &log_rec.addr, host_table); break; } } } } } } verbose = save_verbose; /* restore verbosity level... */ listEntries = 0; /* build our linked list l_list */ for(i=0;i < MAXHASH; i++) { for(h_entries=host_table[i]; h_entries ; h_entries = h_entries->next) { h_entries->llist = l_list; l_list = h_entries; listEntries++; } } if(!l_list) { /* No valid addresses found... */ if (verbose>1) printf("%s\n",msg_dns_none); tmp_flock.l_type=F_UNLCK; fcntl(dns_fd, F_SETLK, &tmp_flock); dns_db->close(dns_db); return 0; } /* process our list now... */ process_list(l_list); /* display timing totals ? */ end_time = times(&mytms); /* display timing totals? */ if (time_me || (verbose>1)) { if (verbose<2 && time_me) printf("DNS: "); printf("%lu %s ",listEntries, msg_addresses); /* get processing time (end-start) */ temp_time = (float)(end_time-start_time)/CLK_TCK; printf("%s %.2f %s", msg_in, temp_time, msg_seconds); /* calculate records per second */ if (temp_time) i=( (int)((float)listEntries/temp_time) ); else i=0; if ( (i>0) && (i<=listEntries) ) printf(", %d/sec\n", i); else printf("\n"); } /* processing done, exit */ tmp_flock.l_type=F_UNLCK; fcntl(dns_fd, F_SETLK, &tmp_flock); dns_db->close(dns_db); return 0; }
/* * userdeny() checks to see if 'user' is denied access to 'service' * Returns 1 if a matching deny entry exists in DB, otherwise returns 0. */ EXPORTED int userdeny(const char *user, const char *service, char *msgbuf, size_t bufsiz) { int r, ret = 0; /* allow access by default */ const char *data = NULL; size_t datalen; struct buf buf = BUF_INITIALIZER; char *wild = NULL; const char *msg = NULL; tok_t tok; char *pat; int not; if (!denydb) denydb_open(/*create*/0); if (!denydb) return 0; memset(&tok, 0, sizeof(tok)); /* fetch entry for user */ syslog(LOG_DEBUG, "fetching user_deny.db entry for '%s'", user); do { r = cyrusdb_fetch(denydb, user, strlen(user), &data, &datalen, NULL); } while (r == CYRUSDB_AGAIN); /* XXX Should we try to reopen the DB if we get IOERROR? This might be necessary when using SQL backend and we lose the connection. */ if (r || !data || !datalen) { /* ignore non-existent/empty entry, report all other errors */ if (r != CYRUSDB_NOTFOUND) { syslog(LOG_WARNING, "DENYDB_ERROR: error reading entry '%s': %s", user, cyrusdb_strerror(r)); } goto out; } buf_init_ro(&buf, data, datalen); /* parse the data */ r = parse_record(&buf, &wild, &msg); if (r) { syslog(LOG_WARNING, "DENYDB_ERROR: invalid entry for '%s'", user); goto out; } /* scan wildmat right to left for a match against our service */ syslog(LOG_DEBUG, "wild: '%s' service: '%s'", wild, service); tok_initm(&tok, wild, ",", 0); while ((pat = tok_next(&tok))) { /* XXX trim leading & trailing whitespace? */ /* is it a negated pattern? */ not = (*pat == '!'); if (not) ++pat; syslog(LOG_DEBUG, "pat %d:'%s'", not, pat); /* see if pattern matches our service */ if (wildmat(service, pat)) { /* match ==> we're done */ ret = !not; if (msgbuf) strlcpy(msgbuf, msg, bufsiz); break; } } out: tok_fini(&tok); buf_free(&buf); return ret; }
int work_rr ( struct error_data *errors, struct name_context *context, u_int8_t **rr, char **non_rr) { char first_token[MAXTOKENLENGTH]; int ret_code; int i; struct scratch scratch; /* Memory management clean up */ if (*rr) { FREE (*rr); *rr = NULL; } if (*non_rr) { FREE (*non_rr); *non_rr = NULL; } if ((scratch.s_field = (u_int8_t *) MALLOC(RR_SCRATCH_LENGTH)) == NULL) { errors->ed_error_value = ERR_OUTOFMEMORY; return -1; } scratch.s_length = RR_SCRATCH_LENGTH; /* Source of data is hidden, just use GETWORD() to work my way through it */ /* Initialize errors to 'nothing set' */ errors->ed_error_value = ERR_UNSET; do { GETWORDorEOLN (ret_code, errors, first_token, sizeof(first_token), *non_rr, "First word", FREE_SCRATCH_UPDATE_ERRORS_AND_RETURN_NEG1); if (ret_code == GW_EOLN) { errors->ed_curr_line++; decrement_current_line(); } } while (ret_code == GW_EOLN); /* ret_code must be GW_WORD and first_token is the first word in line */ /* If the beginning of the first word is in special_chars, then get words until GW_EOLN is returned problem - storing the words until we MALLOC non_rr assemble them into *non_rr return ERR_OKBUTNOTRR in error structure, other ancillarys else take the first word as the name and parse the envelope depending on the type value, parse the remainder of the record no matter what happens, read tokens up through GW_EOLN */ /* This takes care of all the specially registered characters, processing and returning anything that is not an RR. */ for (i =0; i < special_count; i++) if (first_token[0]==special_chars[i]) { /* return with all of the upcoming line in *non_rr, *rr = NULL (already is), errors stating OKBUTNOTRR and update its line count. */ *non_rr = collect_words (first_token); errors->ed_curr_line=errors->ed_curr_line+current_line(); if (*non_rr) errors->ed_error_value = ERR_OKBUTNOTRR; else errors->ed_error_value = ERR_OUTOFMEMORY; FREE (scratch.s_field); return -1; } /* Now we can set about the business of parsing RR's */ /* Two parts, the envelope, the rdata */ ret_code = parse_record (&scratch, first_token, errors, context, non_rr); /* Final clean up */ if (ret_code==0) { if ((*rr = (u_int8_t*) MALLOC (scratch.s_index))==NULL) { errors->ed_error_value = ERR_OUTOFMEMORY; return -1; } memcpy (*rr, scratch.s_field, scratch.s_index); } errors->ed_curr_line=errors->ed_curr_line+current_line(); FREE (scratch.s_field); return ret_code; }
void Restore::restore_next(Signal* signal, FilePtr file_ptr) { Uint32 *data, len= 0; Uint32 status = file_ptr.p->m_status; Uint32 page_count = file_ptr.p->m_pages.getSize(); do { Uint32 left= file_ptr.p->m_bytes_left; if (left < 8) { jam(); /** * Not enough bytes to read header */ break; } Ptr<GlobalPage> page_ptr(0,0), next_page_ptr(0,0); m_global_page_pool.getPtr(page_ptr, file_ptr.p->m_current_page_ptr_i); List::Iterator it; Uint32 pos= file_ptr.p->m_current_page_pos; if(status & File::READING_RECORDS) { jam(); /** * We are reading records */ len= ntohl(* (page_ptr.p->data + pos)) + 1; ndbrequire(len < GLOBAL_PAGE_SIZE_WORDS); } else { jam(); /** * Section length is in 2 word */ if(pos + 1 == GLOBAL_PAGE_SIZE_WORDS) { jam(); /** * But that's stored on next page... * and since we have atleast 8 bytes left in buffer * we can be sure that that's in buffer */ LocalDataBuffer<15> pages(m_databuffer_pool, file_ptr.p->m_pages); Uint32 next_page = file_ptr.p->m_current_page_index + 1; pages.position(it, next_page % page_count); m_global_page_pool.getPtr(next_page_ptr, * it.data); len= ntohl(* next_page_ptr.p->data); } else { jam(); len= ntohl(* (page_ptr.p->data + pos + 1)); } } if (file_ptr.p->m_status & File::FIRST_READ) { jam(); len= 3; file_ptr.p->m_status &= ~(Uint32)File::FIRST_READ; } if (4 * len > left) { jam(); /** * Not enought bytes to read "record" */ if (unlikely((status & File:: FILE_THREAD_RUNNING) == 0)) { crash_during_restore(file_ptr, __LINE__, 0); } len= 0; break; } /** * Entire record is in buffer */ if(pos + len >= GLOBAL_PAGE_SIZE_WORDS) { jam(); /** * But it's split over pages */ if(next_page_ptr.p == 0) { LocalDataBuffer<15> pages(m_databuffer_pool, file_ptr.p->m_pages); Uint32 next_page = file_ptr.p->m_current_page_index + 1; pages.position(it, next_page % page_count); m_global_page_pool.getPtr(next_page_ptr, * it.data); } file_ptr.p->m_current_page_ptr_i = next_page_ptr.i; file_ptr.p->m_current_page_pos = (pos + len) - GLOBAL_PAGE_SIZE_WORDS; file_ptr.p->m_current_page_index = (file_ptr.p->m_current_page_index + 1) % page_count; if (len <= GLOBAL_PAGE_SIZE_WORDS) { jam(); Uint32 first = (GLOBAL_PAGE_SIZE_WORDS - pos); // wl4391_todo removing valgrind overlap warning for now memmove(page_ptr.p, page_ptr.p->data+pos, 4 * first); memcpy(page_ptr.p->data+first, next_page_ptr.p, 4 * (len - first)); data= page_ptr.p->data; } else { jam(); /** * A table definition can be larger than one page... * when that happens copy it out to side buffer * * First copy part belonging to page_ptr * Then copy full middle pages (moving forward in page-list) * Last copy last part */ Uint32 save = len; assert(len <= NDB_ARRAY_SIZE(m_table_buf)); Uint32 * dst = m_table_buf; /** * First */ Uint32 first = (GLOBAL_PAGE_SIZE_WORDS - pos); memcpy(dst, page_ptr.p->data+pos, 4 * first); len -= first; dst += first; /** * Middle */ while (len > GLOBAL_PAGE_SIZE_WORDS) { jam(); memcpy(dst, next_page_ptr.p, 4 * GLOBAL_PAGE_SIZE_WORDS); len -= GLOBAL_PAGE_SIZE_WORDS; dst += GLOBAL_PAGE_SIZE_WORDS; { LocalDataBuffer<15> pages(m_databuffer_pool, file_ptr.p->m_pages); Uint32 next_page = (file_ptr.p->m_current_page_index + 1) % page_count; pages.position(it, next_page % page_count); m_global_page_pool.getPtr(next_page_ptr, * it.data); file_ptr.p->m_current_page_ptr_i = next_page_ptr.i; file_ptr.p->m_current_page_index = next_page; } } /** * last */ memcpy(dst, next_page_ptr.p, 4 * len); file_ptr.p->m_current_page_pos = len; /** * Set pointer and len */ len = save; data = m_table_buf; } } else { file_ptr.p->m_current_page_pos = pos + len; data= page_ptr.p->data+pos; } file_ptr.p->m_bytes_left -= 4*len; if(status & File::READING_RECORDS) { if(len == 1) { file_ptr.p->m_status = status & ~(Uint32)File::READING_RECORDS; } else { parse_record(signal, file_ptr, data, len); } } else { switch(ntohl(* data)){ case BackupFormat::FILE_HEADER: parse_file_header(signal, file_ptr, data-3, len+3); break; case BackupFormat::FRAGMENT_HEADER: file_ptr.p->m_status = status | File::READING_RECORDS; parse_fragment_header(signal, file_ptr, data, len); break; case BackupFormat::FRAGMENT_FOOTER: parse_fragment_footer(signal, file_ptr, data, len); break; case BackupFormat::TABLE_LIST: parse_table_list(signal, file_ptr, data, len); break; case BackupFormat::TABLE_DESCRIPTION: parse_table_description(signal, file_ptr, data, len); break; case BackupFormat::GCP_ENTRY: parse_gcp_entry(signal, file_ptr, data, len); break; case BackupFormat::EMPTY_ENTRY: // skip break; case 0x4e444242: // 'NDBB' if (check_file_version(signal, ntohl(* (data+2))) == 0) { break; } default: parse_error(signal, file_ptr, __LINE__, ntohl(* data)); } } } while(0); if(file_ptr.p->m_bytes_left == 0 && status & File::FILE_EOF) { file_ptr.p->m_status &= ~(Uint32)File::RESTORE_THREAD_RUNNING; /** * File is finished... */ close_file(signal, file_ptr); return; } /** * We send an immediate signal to continue the restore, at times this * could lead to burning some extra CPU since we might still wait for * input from the disk reading. This code is however only executed * as part of restarts, so it should be ok to spend some extra CPU * to ensure that restarts are quick. */ signal->theData[0] = RestoreContinueB::RESTORE_NEXT; signal->theData[1] = file_ptr.i; sendSignal(reference(), GSN_CONTINUEB, signal, 2, JBB); }
int main() { int flag; int ret; fd_set rfds; struct timeval tv; char tmp[NAME_LEN]; char kbd_path[NAME_LEN]; char cmd_buf[BUF_LEN]; char type_buf[BUF_LEN]; char exec_buf[READ_LINE]; double rtt; struct timeval tvpressed; struct timeval tvreleased; struct input_event myinput; atexit( close_fd ); //signal(SIGCHLD, SIG_IGN); //init_deamon(); memset(keys, 0, KEY_LEN * sizeof(int)); memset(cmd_buf, 0, BUF_LEN); memset(type_buf, 0, BUF_LEN); memset(exec_buf, 0, READ_LINE); get_dev_path(kbd_path); sys_says("kbd_path : %s\n", kbd_path); sprintf(tmp, "gksudo chmod 777 %s", kbd_path); sys_says("gksudo : %s\n", tmp); system(tmp); fd = open(kbd_path, O_RDONLY); if ( fd == -1 ) { sys_says("open keyboard err : %s\n", strerror(errno) ); return -1; } //pthread_t recd_start; //init_deamon(); while (1) { memset(&myinput, 0, sizeof(myinput)); FD_ZERO(&rfds); FD_SET(fd, &rfds); tv.tv_sec = 5; tv.tv_usec = 0; ret = select( fd + 1, &rfds, NULL, NULL, &tv ); if ( ret == -1 ) { sys_says( "select err : %s\n", strerror(errno) ); } else if ( ret == 0 ) { continue; } else { //if ( FD_ISSET(fd, &rfds) ) { flag = read(fd, &myinput, sizeof(myinput)); if ( flag == -1 ) { sys_says("read keyboard err : %s\n", strerror(errno)); } else if (flag == sizeof(myinput)) { if (myinput.code == KEY_ESC) { //close(fd); //fd = -1; break; } if ( (myinput.code == KEY_LEFTCTRL || myinput.code == KEY_RIGHTCTRL) ) { if ( myinput.value == 1 ) { //按下 memset(&tvpressed, 0, sizeof(struct timeval)); gettimeofday( &tvpressed, NULL ); sys_says("KEY_CTRL Pressed\n"); first_record = 1; record_abort = 1; /*if ( pthread_create(&recd_start, 0, record_start, 0) != 0 ) { sys_says("create thrd err...\n"); return -1; }*/ } else if ( myinput.value == 0 ) { //松开 memset(&tvreleased, 0, sizeof(struct timeval)); gettimeofday( &tvreleased, NULL ); sys_says("KEY_CTRL Released\n"); record_abort = 0; //pthread_join(recd_start, NULL); tv_sub(&tvpressed, &tvreleased); rtt = tvreleased.tv_sec * 1000 + tvreleased.tv_usec / 1000; sys_says("rtt : %0.1f\n\n", rtt); if ( (((int)rtt) / 1000) < 2 ) { //按下时间小于2s,不是录音操作,放弃 continue; } parse_record(cmd_buf); if ( cmd_buf[0] == '\0' ) { continue; } if ( !is_config_set() ) { fprintf(stderr, "!is_config_set\n"); no_set_config(cmd_buf, exec_buf, type_buf); } else { fprintf(stderr, "is_config_set\n"); has_set_config(cmd_buf, exec_buf, type_buf); } } } if ( (myinput.code == KEY_LEFTALT) || (myinput.code == KEY_RIGHTALT) ) { if ( myinput.value == 1 ) { //按下 read_xsel(); } } } //} } } /* if ( fd != -1 ) { close(fd); } */ return 0; }
int dns_resolver(void *log_fp) { DNODEPTR h_entries; DNODEPTR l_list = NULL; int i; int save_verbose=verbose; u_int64_t listEntries = 0; struct sigaction sigPipeAction; struct stat dbStat; /* aligned dnsRecord to prevent Solaris from doing a dump */ /* (not found in debugger, as it can dereference it :( */ struct dnsRecord alignedRecord; struct flock tmp_flock; tmp_flock.l_whence=SEEK_SET; /* default flock fields */ tmp_flock.l_start=0; tmp_flock.l_len=0; tmp_flock.l_pid=0; time(&runtime); /* get processing start time */ start_time = time(NULL); /* minimal sanity check on it */ if(stat(dns_cache, &dbStat) < 0) { if(errno != ENOENT) { dns_cache=NULL; dns_db=NULL; return 0; /* disable cache */ } } else { if(!dbStat.st_size) /* bogus file, probably from a crash */ { unlink(dns_cache); /* remove it so we can recreate... */ } } /* open cache file */ if ( (db_create(&dns_db, NULL, 0) != 0) || (dns_db->open(dns_db, NULL, dns_cache, NULL, DB_HASH, DB_CREATE, 0644) != 0) ) { /* Error: Unable to open DNS cache file <filename> */ if (verbose) fprintf(stderr,"%s %s\n",msg_dns_nodb,dns_cache); dns_cache=NULL; dns_db=NULL; return 0; /* disable cache */ } /* get file descriptor */ dns_db->fd(dns_db, &dns_fd); tmp_flock.l_type=F_WRLCK; /* set read/write lock type */ if (fcntl(dns_fd,F_SETLK,&tmp_flock) < 0) /* and barf if we cant lock */ { /* Error: Unable to lock DNS cache file <filename> */ if (verbose) fprintf(stderr,"%s %s\n",msg_dns_nolk,dns_cache); dns_db->close(dns_db, 0); dns_cache=NULL; dns_db=NULL; return 0; /* disable cache */ } /* Setup signal handlers */ sigPipeAction.sa_handler = SIG_IGN; sigPipeAction.sa_flags = SA_RESTART; sigemptyset(&sigPipeAction.sa_mask); sigaction(SIGPIPE, &sigPipeAction, NULL); /* disable warnings/errors for this run... */ verbose=0; /* Main loop to read log records (either regular or zipped) */ while ( ourget(buffer,BUFSIZE,our_fp) != NULL) { int len = strlen(buffer); if (len == (BUFSIZE-1)) { /* get the rest of the record */ while ( ourget(buffer,BUFSIZE,our_fp) != NULL) { len = strlen(buffer); if (len < BUFSIZE-1) break; } continue; /* go get next record if any */ } strcpy(tmp_buf, buffer); /* save buffer in case of error */ if(parse_record(buffer, len)) /* parse the record */ { struct addrinfo hints, *ares; memset(&hints, 0, sizeof(hints)); hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; hints.ai_flags = AI_NUMERICHOST; if (0 == getaddrinfo(log_rec.hostname, "0", &hints, &ares)) { DBT q, r; memset(&q, 0, sizeof(q)); memset(&r, 0, sizeof(r)); q.data = log_rec.hostname; q.size = log_rec.hnamelen; /* Check if we have it in DB */ if ( (i=dns_db->get(dns_db, NULL, &q, &r, 0)) == 0 ) { /* have a record for this address */ memcpy(&alignedRecord, r.data, sizeof(struct dnsRecord)); if (alignedRecord.timeStamp != 0) /* If it's not permanent, check if it's TTL has expired */ if ( (runtime-alignedRecord.timeStamp ) > (86400*cache_ttl) ) put_dnode(log_rec.hostname, log_rec.hnamelen, ares->ai_addr, ares->ai_addrlen, host_table); } else { if (i==DB_NOTFOUND) put_dnode(log_rec.hostname, log_rec.hnamelen, ares->ai_addr, ares->ai_addrlen, host_table); } freeaddrinfo(ares); } } } verbose = save_verbose; /* restore verbosity level... */ listEntries = 0; /* build our linked list l_list */ for(i=0;i < MAXHASH; i++) { for(h_entries=host_table[i]; h_entries ; h_entries = h_entries->next) { h_entries->llist = l_list; l_list = h_entries; listEntries++; } } if(!l_list) { /* No valid addresses found... */ if (verbose>1) printf("%s\n",msg_dns_none); tmp_flock.l_type=F_UNLCK; fcntl(dns_fd, F_SETLK, &tmp_flock); dns_db->close(dns_db, 0); return 0; } /* process our list now... */ process_list(l_list); /* get processing end time */ end_time = time(NULL); /* display DNS processing statistics */ if (time_me || (verbose>1)) { if (verbose<2 && time_me) printf("DNS: "); printf("%llu %s ",listEntries, msg_addresses); /* total processing time in seconds */ temp_time = difftime(end_time,start_time); if (temp_time==0) temp_time=1; printf("%s %.0f %s", msg_in, temp_time, msg_seconds); /* calculate records per second */ if (temp_time) i=( (int)((float)listEntries/temp_time) ); else i=0; if ( (i>0) && (i<=listEntries) ) printf(", %d/sec\n", i); else printf("\n"); } /* processing done, exit */ tmp_flock.l_type=F_UNLCK; fcntl(dns_fd, F_SETLK, &tmp_flock); dns_db->close(dns_db, 0); return 0; }