int backup_talker(void) { char fname[6][FNAME_LEN]; int i; set_crash(); switch (double_fork()) { case -1 : sprintf(text,"~OLSYSTEM: backup_talker(): Failed to fork backup process...\n"); write_level(ARCH, 1, text, NULL); write_syslog(ERRLOG, 1, "backup_talker(): Failed to fork process...\n"); return 0; /* double_fork() failed */ case 0 : /* Start Backup Of Files */ sprintf(fname[0], "%s/%s.tgz", BACKUPDIR, BACKUPFILE); sprintf(fname[1], "%s/%s.log1", LOGFILES, BACKUPFILE); sprintf(fname[2], "%s/%s.log2", LOGFILES, BACKUPFILE); sprintf(fname[3], "%s/%s.tgz", TEMPFILES, BACKUPFILE); sprintf(fname[4], "%s/%s.log1", TEMPFILES, BACKUPFILE); sprintf(fname[5], "%s/%s.log2", TEMPFILES, BACKUPFILE); for (i=0; i<6; i++) unlink(fname[i]); write_syslog(SYSLOG, 1, "Backing Up Talker Files To : %s/%s.tgz\n",BACKUPDIR,BACKUPFILE); write_syslog(SYSLOG, 1, "For Zip Progress, Read File: %s/%s.log\n",LOGFILES,BACKUPFILE); // sprintf(text,"zip -v -9 -r %s/%s.zip * > %s/%s/%s.log", BACKUPDIR, BACKUPFILE, ROOTDIR, LOGFILES, BACKUPFILE); sprintf(text, "tar -zcfp '%s' '%s' 1> '%s' 2> '%s'", fname[3], ROOTDIR, fname[4], fname[5]); system(text); for (i=0; i<3; i++) rename(fname[i+3], fname[i]); _exit(1); return 1; } return 0; }
void server_log(char level, char nexit, char *format, ...) { va_list ap; char *str; char date[128]; int fd; va_start(ap, format); vasprintf(&str, format, ap); if (!str) { perror("Error on malloc"); exit(1); } va_end(ap); get_date(date); fd = open("server.log", O_WRONLY | O_APPEND); if (fd != -1) { xwrite(fd, date, strlen(date)); write_level(fd, level); xwrite(fd, str, strlen(str)); close(fd); } write_log(str, level); if (nexit) exit(1); }
int sdrlevel(void) { int delay[DFII_PIX_DATA_SIZE/2]; int high_skew[DFII_PIX_DATA_SIZE/2]; if(!write_level(delay, high_skew)) return 0; read_bitslip(delay, high_skew); read_delays(); return 1; }
static void write_log(char *str, char level) { if (level == 1) printf("\033[36m"); else if (level == 2) printf("\033[33m"); else if (level > 2) printf("\033[31m"); else printf("\033[0m"); fflush(stdout); write_level(1, level); printf("%s", str); printf("\033[0m"); fflush(stdout); if (str) free(str); }
int cola_insert(cola_t c, cola_key_t key) { cola_key_t newcnt = c->c_nelem + 1; struct buf level; unsigned int i; dprintf("Insert key %"PRIu64"\n", key); if ( !buf_alloc(c, 1, &level) ) return 0; level.ptr[0].key = key; /* make sure the level we're about to write to is allocated and, * if required, mapped */ if ( newcnt == (1ULL << c->c_nxtlvl) ) { cola_key_t nr_ent, ofs; size_t sz; nr_ent = (1ULL << c->c_nxtlvl); ofs = nr_ent - 1; ofs *= sizeof(struct cola_elem); ofs += sizeof(struct cola_hdr); sz = nr_ent * sizeof(struct cola_elem); dprintf("fallocate level %u\n", c->c_nxtlvl); if ( posix_fallocate(c->c_fd, ofs, ofs + sz) ) fprintf(stderr, "%s: fallocate: %s\n", cmd, os_err()); if ( c->c_nxtlvl <= MAP_LEVELS && (1U << c->c_nxtlvl) > c->c_nelem ) { if ( !remap(c, c->c_nxtlvl) ) return 0; } c->c_nxtlvl++; } for(i = 0; newcnt >= (1U << i); i++) { if ( c->c_nelem & (1U << i) ) { struct buf level2, merged; int ret; dprintf(" - level %u full\n", i); if ( !read_level(c, i, &level2) ) { buf_finish(&level); return 0; } if ( (c->c_nelem & (1U << (i + 1))) || i + 1 >= c->c_maplvls ) { ret = buf_alloc(c, (1U << (i + 1)), &merged); }else{ /* landing in next level so write to map */ ret = write_prep(c, i + 1, &merged); } if ( !ret ) { buf_finish(&level2); buf_finish(&level); return 0; } level_merge(&level2, &level, &merged); if ( !write_level(c, i, &level2) ) { buf_finish(&level2); buf_finish(&level); buf_finish(&merged); return 0; } buf_finish(&level2); buf_finish(&level); memcpy(&level, &merged, sizeof(level)); }else{ dprintf(" - level %u empty\n", i); if ( !fractional_cascade(c, i, level.ptr) || !write_level(c, i, &level) ) { buf_finish(&level); return 0; } buf_finish(&level); break; } } c->c_nelem++; dprintf("\n"); #if DEBUG cola_dump(c); dprintf("\n"); #endif return 1; }