void remove_entry(const char *nameId, const char *fileName) { //This removes the entry and then puts it back into the file. productList temp[150]; int count, i, type; get_from_db(temp, &count, fileName); type = IS_NUM(nameId[0]); for(i = 0; i < count; i++) { if(type == 0) { if(strcmp(temp[i].name, nameId) == 0) { strcpy(temp[i].name, ""); strcpy(temp[i].id, ""); temp[i].qty = 0; temp[i].price = 0; break; } } else { if(strcmp(temp[i].id, nameId) == 0) { strcpy(temp[i].name, ""); strcpy(temp[i].id, ""); temp[i].qty = 0; temp[i].price = 0; break; } } } db_write(temp, count, fileName); }
/***************************************************************** Function Name: main Description: This is a main function Parameter: @argc: argument count @argv: argument vector Author: SA12226114(Xin Zhu), SA12226139(Dan Shu) Date: 2012-11-27 ******************************************************************/ int main(int argc, char *argv[]) { void *db = NULL; char cmdline[CMDLINE_LEN], cmd[CMD_LEN], key[KEY_LEN], value[VALUE_LEN]; /* display menu */ util_menu(); while(1) { /* format command line */ util_format(cmdline, cmd, key, value); if(strncmp(cmd, "open", sizeof("open")) == 0) /* create database */ { db_create(&db, key); } else if(strncmp(cmd, "set", sizeof("set")) == 0) /* store records */ { db_write(db, key, value); } else if(strncmp(cmd, "get", sizeof("get")) == 0) /* retrieve records */ { db_read(db, key); } else if(strncmp(cmd, "remove", sizeof("remove")) == 0) /* remove a record */ { db_remove(db, key); } else if(strncmp(cmd, "ls", sizeof("ls")) == 0) /* dump all records in database */ { db_queryallrecords(db); } else if(strncmp(cmd, "close", sizeof("close")) == 0) /* close the database */ { db_close(&db); } else if(strncmp(cmd, "delete", sizeof("delete")) == 0) /* delete the object */ { db_delete(&db); } else if(strncmp(cmd, "help", sizeof("help")) == 0) /* display menu info */ { util_menu(); } else if(strncmp(cmd, "quit", sizeof("quit")) == 0) /* quit system */ { return; } } return 0; }
cgi_status cgi_cs_user_account_set( cs_uint8 *usr, cs_uint8 *pwd) { db_ctc_user_t user; CGI_ASSERT_RET((NULL != usr &&(NULL != pwd)), CGI_ERROR_PARAM); memset(&user,0x00,sizeof(user)); strncpy(user.usr, usr, DB_CTC_MAX_USR_LEN); strncpy(user.pwd, pwd, DB_CTC_MAX_PWD_LEN); db_write(DB_CTC_USER_INFO_ID,(cs_uint8*) &user,sizeof(user)); return CGI_OK; }
cgi_status cgi_cs_admin_account_set( cs_uint8 *usr, cs_uint8 *pwd) { db_ctc_user_t admin; CGI_ASSERT_RET((NULL != usr &&(NULL != pwd)), CGI_ERROR_PARAM); memset(&admin,0x00,sizeof(admin)); strncpy(admin.usr, usr, DB_CTC_MAX_USR_LEN); strncpy(admin.pwd, pwd, DB_CTC_MAX_PWD_LEN); db_write(DB_CTC_ADMIN_INFO_ID,(cs_uint8*) &admin,sizeof(admin)); return CGI_OK; }
void mod_entry(productList newDetails, const char *replaceNameId, const char *fileName, int changeId) { //Here the product name may have changed. So we open up the old one with the id or name and delete it. Then we write it anew where ever we need. But with the same id int count, i, type; char tFileName[11]; //We delete the old one. strcpy(tFileName, ""); if(IS_NUM(replaceNameId[0])) { sprintf(tFileName, "%c%c%c", replaceNameId[0],replaceNameId[1],replaceNameId[2]); sprintf(tFileName, "%c_db.txt", atoi(tFileName)-4); remove_entry(replaceNameId, tFileName); } else { sprintf(tFileName, "%c_db.txt", replaceNameId[0]); remove_entry(replaceNameId, tFileName); } //Now that the old one is gone. We add a new one if(strcmp(fileName, tFileName) != 0) { gInit.fileItemCount[tolower(tFileName[0])-97]--; gInit.fileItemCount[tolower(fileName[0])-97]++; } db_write(&newDetails, -1, fileName); }
cgi_status cgi_cs_port_config_set(cgi_handler_param_t * p) { cs_uint8 port, admin,auto_neg,mode, pause,loopback,isolation; cs_uint32 mac; cs_status ret = CS_E_OK; cs_callback_context_t context; db_ctc_port_t port_info; if(CS_E_OK != cgi_get_int8_by_key(p,"port",&port) || CS_E_OK != cgi_get_int8_by_key(p,"phy",&admin) || CS_E_OK != cgi_get_int8_by_key(p,"mode",&mode) || CS_E_OK != cgi_get_int8_by_key(p, "isolation", &isolation) || CS_E_OK != cgi_get_int32_by_key(p, "mac", &mac) || CS_E_OK != cgi_get_int8_by_key(p,"pause",&pause) || CS_E_OK != cgi_get_int8_by_key(p, "loopback", &loopback)){ CGI_LOG("get parameters failed from URL"); cgi_send_int(p,CGI_ERROR_PARAM); return CS_E_ERROR; } CGI_DEBUG("port = %d ,admin = %d ,mode = %d ,isolation = %d ,mac = %d ,pause = %d ,loopback = %d\n", port,admin,mode,isolation,mac,pause,loopback); ret = epon_request_onu_port_admin_set(context, ONU_DEVICEID_FOR_API, ONU_LLIDPORT_FOR_API, port, admin); if(ret != CS_E_OK){ CGI_LOG("set port admin status failed ,ret = %d \n",ret); cgi_send_int(p,CGI_SDL_FAILED); return CS_E_ERROR; } if(mode == 0) { auto_neg = 1; } else { auto_neg = 0; } ret = cgi_cs_port_auto_set(port,auto_neg); if(ret != CS_E_OK){ CGI_LOG("set port auto status failed ,ret = %d \n",ret); cgi_send_int(p,CGI_SDL_FAILED); return CS_E_ERROR; } ret = cgi_cs_port_work_mode_set(port,mode); if(ret != CS_E_OK){ CGI_LOG("set port working mode failed ,ret = %d \n",ret); cgi_send_int(p,CGI_SDL_FAILED); return CS_E_ERROR; } ret = epon_request_onu_port_isolation_set(context, ONU_DEVICEID_FOR_API, ONU_LLIDPORT_FOR_API,isolation); if(ret != CS_E_OK){ CGI_LOG("set port isolation failed, ret =%d \n", ret); cgi_send_int(p, CGI_SDL_FAILED); return CS_E_ERROR; } ret = epon_request_onu_port_mac_learn_set(context, ONU_DEVICEID_FOR_API, ONU_LLIDPORT_FOR_API, port, mac); if(ret != CS_E_OK){ CGI_LOG("set port max mac learning failed, ret=%d \n", ret); cgi_send_int(p, CGI_SDL_FAILED); return CS_E_ERROR; } ret = epon_request_onu_port_flow_ctrl_set(context, ONU_DEVICEID_FOR_API, ONU_LLIDPORT_FOR_API, port, pause); if(ret != CS_E_OK){ CGI_LOG("set port pause failed ,ret = %d \n",ret); cgi_send_int(p,CGI_SDL_FAILED); return CS_E_ERROR; } ret = epon_request_onu_port_lpbk_set(context, ONU_DEVICEID_FOR_API, ONU_LLIDPORT_FOR_API, port, loopback); if(ret != CS_E_OK){ CGI_LOG("set port loopback failed, ret = %d \n",ret); cgi_send_int(p,CGI_SDL_FAILED); return CS_E_ERROR; } memset(&port_info,0x00,sizeof(port_info)); db_read(DB_CTC_PORT_INFO_ID,(cs_uint8 *) &port_info, sizeof(port_info)); port_info.port[port - 1].admin= admin; port_info.port[port - 1].auto_neg = auto_neg; switch (mode) { case CGI_CTC_PORT_MODE_AUTO: port_info.port[port - 1].work_mode = SDL_PORT_AUTO_10_100_1000; break; case CGI_CTC_PORT_MODE_10M_HALF: port_info.port[port - 1].work_mode = SDL_PORT_10_HALF; break; case CGI_CTC_PORT_MODE_10M_FULL: port_info.port[port - 1].work_mode = SDL_PORT_10_FULL; break; case CGI_CTC_PORT_MODE_100M_HALF: port_info.port[port - 1].work_mode = SDL_PORT_100_HALF; break; case CGI_CTC_PORT_MODE_100M_FULL: port_info.port[port - 1].work_mode = SDL_PORT_100_FULL; break; case CGI_CTC_PORT_MODE_1000M_FULL: port_info.port[port - 1].work_mode = SDL_PORT_1000_FULL; break; default: return CS_E_PARAM; } port_info.port[port - 1].pause = pause; db_write(DB_CTC_PORT_INFO_ID,(cs_uint8 *) &port_info, sizeof(port_info)); cs_thread_delay(2000); cgi_send_int(p,CGI_OK); return CS_E_OK; }
void panic(const char *message) { char panicfile[2048]; FILE *f; log_status("PANIC: %s", message); fprintf(stderr, "PANIC: %s\n", message); /* shut down interface */ if (!forked_dump_process_flag) { emergency_shutdown(); } /* dump panic file */ snprintf(panicfile, sizeof(panicfile), "%s.PANIC", dumpfile); if ((f = fopen(panicfile, "wb")) == NULL) { perror("CANNOT OPEN PANIC FILE, YOU LOSE"); sync(); #ifdef NOCOREDUMP exit(135); #else /* !NOCOREDUMP */ # ifdef SIGIOT signal(SIGIOT, SIG_DFL); # endif abort(); #endif /* NOCOREDUMP */ } else { log_status("DUMPING: %s", panicfile); fprintf(stderr, "DUMPING: %s\n", panicfile); db_write(f); fclose(f); log_status("DUMPING: %s (done)", panicfile); fprintf(stderr, "DUMPING: %s (done)\n", panicfile); } /* Write out the macros */ snprintf(panicfile, sizeof(panicfile), "%s.PANIC", MACRO_FILE); if ((f = fopen(panicfile, "wb")) != NULL) { macrodump(macrotop, f); fclose(f); } else { perror("CANNOT OPEN MACRO PANIC FILE, YOU LOSE"); sync(); #ifdef NOCOREDUMP exit(135); #else /* !NOCOREDUMP */ #ifdef SIGIOT signal(SIGIOT, SIG_DFL); #endif abort(); #endif /* NOCOREDUMP */ } sync(); #ifdef NOCOREDUMP exit(136); #else /* !NOCOREDUMP */ #ifdef SIGIOT signal(SIGIOT, SIG_DFL); #endif abort(); #endif /* NOCOREDUMP */ }
static void dump_database_internal(void) { char tmpfile[2048]; FILE *f; snprintf(tmpfile, sizeof(tmpfile), "%s.#%d#", dumpfile, epoch - 1); (void) unlink(tmpfile); /* nuke our predecessor */ snprintf(tmpfile, sizeof(tmpfile), "%s.#%d#", dumpfile, epoch); if ((f = fopen(tmpfile, "wb")) != NULL) { db_write(f); fclose(f); #ifdef DISKBASE fclose(input_file); #endif #ifdef WIN32 (void) unlink(dumpfile); /* Delete old file before rename */ #endif if (rename(tmpfile, dumpfile) < 0) perror(tmpfile); #ifdef DISKBASE free((void *) in_filename); in_filename = string_dup(dumpfile); if ((input_file = fopen(in_filename, "rb")) == NULL) perror(dumpfile); #endif } else { perror(tmpfile); } /* Write out the macros */ snprintf(tmpfile, sizeof(tmpfile), "%s.#%d#", MACRO_FILE, epoch - 1); (void) unlink(tmpfile); snprintf(tmpfile, sizeof(tmpfile), "%s.#%d#", MACRO_FILE, epoch); if ((f = fopen(tmpfile, "wb")) != NULL) { macrodump(macrotop, f); fclose(f); #ifdef WIN32 unlink(MACRO_FILE); #endif if (rename(tmpfile, MACRO_FILE) < 0) perror(tmpfile); } else { perror(tmpfile); } sync(); #ifdef DISKBASE /* Only show dumpdone mesg if not doing background saves. */ if (tp_dbdump_warning && tp_dumpdone_warning) wall_and_flush(tp_dumpdone_mesg); propcache_hits = 0L; propcache_misses = 1L; #endif }
int ag_db_write(unsigned dbh) { return db_write(h2p(dbh)); }
int mod_ircinput(char *fullline, char *part2, char *part3, char *part4, char *part5, struct global_t * g2) { unsigned int j = 1; context(); if (!strcasecmp(part2, "NICK") && part3) { char *newnick, *oldnick;; oldnick = (char *) mycalloc(TEXTLENGTH_STD); while (fullline[j] != '!' && j < strlen(fullline) && (j < (TEXTLENGTH_STD - 1))) { oldnick[j - 1] = fullline[j]; j++; } oldnick[j - 1] = '\0'; newnick = part3; if (newnick[0] == ':') newnick++; if (!strcasecmp(oldnick, g2->user_nick)) { free(g2->user_nick); g2->user_nick = (char *)calloc(1,TEXTLENGTH_STD); //allocated by libconfig strncpy(g2->user_nick, newnick, TEXTLENGTH_STD); } else { /* someone else changed nicks */ if (db_write("UPDATE %s.%s SET user='******' WHERE user='******'", g2->mysql_db, g2->mysql_table_irc_users, newnick, oldnick)) ioutput(OUTPUT_DEST_LOG | OUTPUT_TYPE_WARN, "nick.so: user missed %s -> %s", oldnick, newnick); } mydelete(oldnick); return (T_OK); } else if (!strcasecmp(part2, "MODE") && part3 && part4 && part5) { //mode change // WARNING: mode change (:[email protected] MODE #ANTHALIA.COM +oo Heimy ifsnopALS ) (MODE) (#ANTHALIA.COM) (+oo) int channelid = -1; context(); for (j = 0; j < g2->irc_channel_count; j++) { if (!strcasecmp(g2->irc_channel[j], part3)) { channelid = j; break; } } if (channelid > -1) { if (strlen(part4) >= 2) { char *ptr; int k = 1, umode = USER_MODE_HAS_0; struct db_row_t row; while (part4[k] != '\0') { ptr = getpart(fullline, k + 4); if (part4[k] == 'l' || part4[k] == 'b') goto next; if (part4[k] == 'o') umode = USER_MODE_HAS_OP; if (part4[k] == 'v') umode = USER_MODE_HAS_V; row = db_read("SELECT mode FROM %s.%s WHERE channelid = '%d' AND user = '******'", g2->mysql_db, g2->mysql_table_irc_users, channelid, ptr); if ( row.num_fields >= 1 ) { if (part4[0] == '+') { umode |= atoi(row.r[0]); } else { if (part4[0] == '-') umode ^= atoi(row.r[0]); } if (db_write("UPDATE %s.%s SET mode = '%d' WHERE channelid = '%d' AND user = '******'", g2->mysql_db, g2->mysql_table_irc_users, umode, channelid, ptr)) ioutput(OUTPUT_DEST_LOG | OUTPUT_TYPE_WARN, "nick.so: problem changing user mode %s %c", ptr, umode); } else { ioutput(OUTPUT_DEST_LOG | OUTPUT_TYPE_WARN, "nick.so: problem finding user %s", ptr); } db_row_clean(row); next: mydelete(ptr); k++; } } } else ioutput(OUTPUT_DEST_LOG | OUTPUT_TYPE_WARN, "nick.so: problem changing user mode, channel not found %s", part5); return (T_OK); } else if (!strcmp(part2, "PART") && part3) { char *nick; int channelid = -1; context(); nick = (char *) mycalloc(TEXTLENGTH_STD); while ( (fullline[j] != '!') && (j < strlen(fullline)) && (j < (TEXTLENGTH_STD -1)) ) { nick[j - 1] = fullline[j]; j++; } nick[j - 1] = '\0'; if ( !strcasecmp(nick, g2->user_nick) ) { // we left, funny, why? } else { char *t3; t3 = part3; if (t3[0] == ':') t3++; for (j = 0; j < g2->irc_channel_count; j++) { if (!strcasecmp(g2->irc_channel[j], t3)) { channelid = j; break; } } if (channelid > -1) { if ( db_write("DELETE FROM %s.%s WHERE channelid = '%d' AND user = '******'", g2->mysql_db, g2->mysql_table_irc_users, channelid, nick) ) ioutput(OUTPUT_DEST_LOG | OUTPUT_TYPE_WARN, "nick.so: error deleting (%s) from (%d)(%s)", nick, channelid, t3); } else ioutput(OUTPUT_DEST_LOG | OUTPUT_TYPE_WARN, "nick.so: someone (%s) leave a not known channel (%s)", nick, t3); } mydelete(nick); return (T_OK); } else if (!strcasecmp(part2, "JOIN") && part3) { int channelid = -1; char *nick; context(); nick = (char *) mycalloc(TEXTLENGTH_STD); while ( (fullline[j] != '!') && (j < strlen(fullline)) && (j < (TEXTLENGTH_STD - 1)) ) { nick[j - 1] = fullline[j]; j++; } nick[j - 1] = '\0'; if (part3[0] == ':') { for (j = 1; j <= strlen(part3); j++) part3[j - 1] = part3[j]; part3[j] = '\0'; // lets ensure that part3 aka channel is #channelname, and not :#channel or whatever. } if ( !strcasecmp(nick, g2->user_nick) ) { // we joined for (j = 0; j < g2->irc_channel_count; j++) { if (!strcasecmp(g2->irc_channel[j], part3)) { g2->irc_channel_joined[j] = 'Y'; channelid = j; break; } } if (channelid == -1) ioutput(OUTPUT_DEST_LOG | OUTPUT_TYPE_WARN, "nick.so: joined (%s) which is not a known channel", part3); /* else { if ( db_write("DELETE FROM irc_users WHERE channelid = '%d'", channelid) ) ioutput(OUTPUT_DEST_LOG | OUTPUT_TYPE_WARN, "nick.so: can't delete userlist from (%d)(%s)", channelid, part3); }*/ //redundante, al hacer un join ya se ha hecho un delete previo } else { //someone else joined for (j = 0; j < g2->irc_channel_count; j++) { if (!strcasecmp(g2->irc_channel[j], part3)) { channelid = j; break; } } if (channelid > -1) { if (db_write("INSERT INTO %s.%s (channelid, user, mode) VALUES ('%d', '%s', '%d')", g2->mysql_db, g2->mysql_table_irc_users, channelid, nick, 0)) { ioutput(OUTPUT_DEST_LOG | OUTPUT_TYPE_WARN, "nick.so: error adding (%s) to (%s) ", nick, part3); } } else { ioutput(OUTPUT_DEST_LOG | OUTPUT_TYPE_WARN, "nick.so: someone (%s) joined (%s) which is not a known channel", nick, part3); } } mydelete(nick); return (T_OK); } else if (!strcmp(part2, "QUIT")) { char *nick; context(); nick = (char *) mycalloc(TEXTLENGTH_STD); while ( (fullline[j] != '!') && ( j < strlen(fullline)) && (j < (TEXTLENGTH_STD - 1)) ) { nick[j - 1] = fullline[j]; j++; } nick[j - 1] = '\0'; if (!strcasecmp(nick, g2->user_nick)) { // we leave? funny ioutput(OUTPUT_DEST_LOG | OUTPUT_TYPE_INFO, "nick.so: we leave"); } else { if ( db_write("DELETE FROM %s.%s WHERE user = '******'", g2->mysql_db, g2->mysql_table_irc_users, nick) ) ioutput(OUTPUT_DEST_LOG | OUTPUT_TYPE_WARN, "nick.so: error deleting (%s)", nick); } mydelete(nick); } else if (!strcmp(part2, "KICK") && part3 && part4) { int channelid = -1; context(); for (j = 0; j < g2->irc_channel_count; j++) { if (!strcasecmp(g2->irc_channel[j], part3)) { channelid = j; break; } } if (channelid > -1) { if (!strcasecmp(part4, g2->user_nick)) { ioutput(OUTPUT_DEST_LOG | OUTPUT_TYPE_INFO, "nick.so: kicked from %s, rejoining", part3); g2->irc_channel_joined[channelid] = 'N'; } else { if ( db_write("DELETE FROM %s.%s WHERE user = '******' AND channelid = '%d'", g2->mysql_db, g2->mysql_table_irc_users, part4, channelid) ) ioutput(OUTPUT_DEST_LOG | OUTPUT_TYPE_WARN, "nick.so: error deleting kicked (%s) from (%d)(%s)", part4, channelid, part3); } } else ioutput(OUTPUT_DEST_LOG | OUTPUT_TYPE_WARN, "nick.so: kick to (%s) on a not known channel (%s)", part4, part3); return (T_OK); } else if (!strcmp(part2, "353") && part3 && part4 && part5) { /* names list for a channel */ /* :server 353 our_nick = #channel :nick @nick +nick nick */ char *t, *t2; int i; int channelid = -1; context(); for (j = 0; j < g2->irc_channel_count; j++) { if (!strcasecmp(g2->irc_channel[j], part5)) { channelid = j; break; } } if (channelid > -1) { for (i = 0; (t2 = t = getpart(fullline, 6 + i)) ; i++) { int umode = USER_MODE_HAS_0; if (t[0] == ':') { umode |= USER_MODE_HAS_0; t++; } if (t[0] == '@') { umode |= USER_MODE_HAS_OP; t++; } if (t[0] == '+') { umode |= USER_MODE_HAS_V; t++; } if (t[0] == '@') { umode |= USER_MODE_HAS_OP; t++; } if (db_write("INSERT INTO %s.%s (channelid, user, mode) VALUES ('%d', '%s', '%d')", g2->mysql_db, g2->mysql_table_irc_users, channelid, t, umode)) ioutput(OUTPUT_DEST_LOG | OUTPUT_TYPE_WARN, "nick.so: problem inserting user (%s)", t); mydelete(t2); } } else { ioutput(OUTPUT_DEST_LOG | OUTPUT_TYPE_WARN, "nick.so: userlist from unknown channel (%s)", part5); } return (T_OK); } else { return (T_IGNORE); } return (T_IGNORE); }
int main(int argc, char *argv[]) { int setflags, clrflags, ver, nochk; int db_ver, db_format, db_flags, do_check, do_write; char *fp; FILE *f_ptr; char s_filename[120]; f_ptr = NULL; nochk = 0; if (argc == 3) { for (fp = argv[2]; *fp; fp++) { if (*fp == 'x') { nochk = 1; break; } } } if (!nochk) { sprintf(s_filename, "%.115s.db", argv[1]); if ( (f_ptr = fopen(s_filename, "r")) != NULL ) { fprintf(stderr, "GDBM file(s) already exist for %s\n", s_filename); fclose(f_ptr); exit(1); } sprintf(s_filename, "%.115s.dir", argv[1]); if ( (f_ptr = fopen(s_filename, "r")) != NULL ) { fprintf(stderr, "GDBM file(s) already exist for %s\n", s_filename); fclose(f_ptr); exit(1); } sprintf(s_filename, "%.115s.pag", argv[1]); if ( (f_ptr = fopen(s_filename, "r")) != NULL ) { fprintf(stderr, "GDBM file(s) already exist for %s\n", s_filename); fclose(f_ptr); exit(1); } } debugmem = (Debugmem *)malloc(sizeof(Debugmem)); if( !debugmem ) abort(); INITDEBUG(debugmem); if ((argc < 2) || (argc > 3)) { usage(argv[0]); exit(1); } dddb_var_init(); cache_var_init(); cf_init(); /* Decide what conversions to do and how to format the output file */ setflags = clrflags = ver = do_check = 0; do_write = 1; if (argc == 3) { for (fp = argv[2]; *fp; fp++) { switch (*fp) { case 'C': do_check = 1; break; case 'G': setflags |= V_GDBM; break; case 'g': clrflags |= V_GDBM; break; case 'Z': setflags |= V_ZONE; break; case 'z': clrflags |= V_ZONE; break; case 'L': setflags |= V_LINK; break; case 'l': clrflags |= V_LINK; break; case 'N': setflags |= V_ATRNAME; break; case 'n': clrflags |= V_ATRNAME; break; case 'K': setflags |= V_ATRKEY; break; case 'k': clrflags |= V_ATRKEY; break; case 'P': setflags |= V_PARENT; break; case 'p': clrflags |= V_PARENT; break; case 'W': do_write = 1; break; case 'w': do_write = 0; break; case 'X': clrflags = 0xffffffff; setflags = OUTPUT_FLAGS; ver = OUTPUT_VERSION; break; case 'x': clrflags = 0xffffffff; setflags = UNLOAD_OUTFLAGS; ver = UNLOAD_VERSION; break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': ver = ver * 10 + (*fp - '0'); break; default: fprintf(stderr, "Unknown flag: '%c'\n", *fp); usage(argv[0]); exit(1); } } } /* Open the gdbm file */ if (init_gdbm_db(argv[1]) < 0) { fprintf(stderr, "Can't open GDBM file\n"); exit(1); } /* Go do it */ db_read(stdin, &db_format, &db_ver, &db_flags); fprintf(stderr, "Input: "); info(db_format, db_flags, db_ver); val_count(); if (do_check) do_dbck(NOTHING, NOTHING, DBCK_FULL); if (do_write) { db_flags = (db_flags & ~clrflags) | setflags; if (db_format != F_MUSH) db_ver = 3; if (ver != 0) db_ver = ver; fprintf(stderr, "Output: "); info(F_MUSH, db_flags, db_ver); db_write(stdout, F_MUSH, db_ver | db_flags); } CLOSE; return(0); }
void panic(const char *message) { char panicfile[2048]; FILE *f; log_status("PANIC: %s\n", message); fprintf(stderr, "PANIC: %s\n", message); /* shut down interface */ emergency_shutdown(); /* dump panic file */ sprintf(panicfile, "%s.PANIC", dumpfile); if ((f = fopen(panicfile, "w")) == NULL) { perror("CANNOT OPEN PANIC FILE, YOU LOSE"); #if defined(NOCOREDUMP) || defined(WINNT) _exit(135); #else /* !NOCOREDUMP */ # ifdef SIGIOT signal(SIGIOT, SIG_DFL); # endif abort(); #endif /* NOCOREDUMP */ } else { log_status("DUMP: %s\n", panicfile); fprintf(stderr, "DUMP: %s\n", panicfile); db_write(f); fclose(f); log_status("DUMP: %s (done)\n", panicfile); fprintf(stderr, "DUMP: %s (done)\n", panicfile); (void) unlink(DELTAFILE_NAME); } /* Write out the macros */ sprintf(panicfile, "%s.PANIC", MACRO_FILE); if ((f = fopen(panicfile, "w")) != NULL) { macrodump(macrotop, f); fclose(f); } else { perror("CANNOT OPEN MACRO PANIC FILE, YOU LOSE"); #if defined(NOCOREDUMP) || defined(WINNT) _exit(135); #else /* !NOCOREDUMP */ # ifdef SIGIOT signal(SIGIOT, SIG_DFL); # endif abort(); #endif /* NOCOREDUMP */ } #if defined(NOCOREDUMP) || defined(WINNT) _exit(136); #else /* !NOCOREDUMP */ # ifdef SIGIOT signal(SIGIOT, SIG_DFL); # endif abort(); #endif /* NOCOREDUMP */ }
static void dump_database_internal(void) { char tmpfile[2048]; char timestring[1024]; struct tm *timestamp; time_t curtime; FILE *f; curtime = time((time_t *)NULL); timestamp = localtime(&curtime); tune_save_parmsfile(); format_time(timestring, 1024, "%Y.%m.%d", timestamp); if (tp_dbdump_warning) wall_and_flush(tp_dumping_mesg); #ifndef KEEPDUMPS sprintf(tmpfile, "%s.#%d#", dumpfile, epoch - 1); (void) unlink(tmpfile); /* nuke our predecessor */ #else /* sprintf(tmpfile, "backup/%s.%s.#%d#", dumpfile, timestring, epoch - 1); */ sprintf(tmpfile, "backup/%s.#%d#", dumpfile, epoch - 1); (void) rename(dumpfile, tmpfile); sprintf(tmpfile, "backup/%s.#%d#", dumpfile, epoch - 10); (void) unlink(tmpfile); #endif sprintf(tmpfile, "%s.#%d#", dumpfile, epoch); if ((f = fopen(tmpfile, "w")) != NULL) { db_write(f); fclose(f); #ifdef WIN32 if (unlink(dumpfile)) perror(dumpfile); #endif if (rename(tmpfile, dumpfile) < 0) perror(tmpfile); #ifdef DISKBASE #ifdef FLUSHCHANGED fclose(input_file); free((void *)in_filename); in_filename = string_dup(dumpfile); if ((input_file = fopen(in_filename, "r")) == NULL) perror(dumpfile); #ifdef DELTADUMPS fclose(delta_outfile); if ((delta_outfile = fopen(DELTAFILE_NAME, "w")) == NULL) perror(DELTAFILE_NAME); fclose(delta_infile); if ((delta_infile = fopen(DELTAFILE_NAME, "r")) == NULL) perror(DELTAFILE_NAME); #endif #endif #endif } else { perror(tmpfile); } /* Write out the macros */ sprintf(tmpfile, "%s.#%d#", MACRO_FILE, epoch - 1); (void) unlink(tmpfile); sprintf(tmpfile, "%s.#%d#", MACRO_FILE, epoch); if ((f = fopen(tmpfile, "w")) != NULL) { macrodump(macrotop, f); fclose(f); #ifdef WIN32 if (unlink(MACRO_FILE)) perror(MACRO_FILE); #endif if (rename(tmpfile, MACRO_FILE) < 0) perror(tmpfile); } else { perror(tmpfile); } if (tp_dbdump_warning) wall_and_flush(tp_dumpdone_mesg); #ifdef DISKBASE propcache_hits = 0L; propcache_misses = 1L; #endif if (tp_periodic_program_purge) free_unused_programs(); #ifdef DISKBASE dispose_all_oldprops(); #endif }