static void cstat_free_content(struct cstat *c) { if(!c) return; bu_list_free(&c->bu); bu_list_free(&c->bu_current); free_w(&c->name); free_w(&c->conffile); free_w(&c->running_detail); sdirs_free_content(c->sdirs); c->clientdir_mtime=0; c->lockfile_mtime=0; }
int timestamp_get_new(struct sdirs *sdirs, char *buf, size_t s, char *bufforfile, size_t bs, struct conf **cconfs) { time_t t=0; unsigned long index=0; struct bu *bu=NULL; struct bu *bu_list=NULL; const struct tm *ctm=NULL; // Want to prefix the timestamp with an index that increases by // one each time. This makes it far more obvious which backup depends // on which - even if the system clock moved around. Take that, // bacula! // This function orders the array with the highest index number last. if(bu_get_list(sdirs, &bu_list)) return -1; for(bu=bu_list; bu; bu=bu->next) if(!bu->next) index=bu->bno; bu_list_free(&bu_list); time(&t); ctm=localtime(&t); // Windows does not like the %T strftime format option - you get // complaints under gdb. index++; write_to_buf(buf, s, index, NULL, ctm); write_to_buf(bufforfile, bs, index, get_string(cconfs[OPT_TIMESTAMP_FORMAT]), ctm); return 0; }
int timestamp_get_new(struct sdirs *sdirs, char *buf, size_t s, struct conf *cconf) { time_t t=0; char tmpbuf[32]=""; unsigned long index=0; struct bu *bu=NULL; struct bu *bu_list=NULL; const struct tm *ctm=NULL; // Want to prefix the timestamp with an index that increases by // one each time. This makes it far more obvious which backup depends // on which - even if the system clock moved around. Take that, // bacula! // This function orders the array with the highest index number last. if(bu_list_get(sdirs, &bu_list)) return -1; for(bu=bu_list; bu; bu=bu->next) if(!bu->next) index=bu->bno; bu_list_free(&bu_list); time(&t); ctm=localtime(&t); // Windows does not like the %T strftime format option - you get // complaints under gdb. strftime(tmpbuf, sizeof(tmpbuf), cconf->timestamp_format, ctm); snprintf(buf, s, "%07lu %s", ++index, tmpbuf); return 0; }
int do_delete_server(struct asfd *asfd, struct sdirs *sdirs, struct cntr *cntr, const char *cname, const char *backup, const char *manual_delete) { int ret=-1; int found=0; unsigned long bno=0; struct bu *bu=NULL; struct bu *bu_list=NULL; logp("in do_delete\n"); if(bu_get_list(sdirs, &bu_list) || write_status(CNTR_STATUS_DELETING, NULL, cntr)) goto end; if(backup && *backup) bno=strtoul(backup, NULL, 10); for(bu=bu_list; bu; bu=bu->next) { if(!backup || !*backup) continue; if(!found && (!strcmp(bu->timestamp, backup) || bu->bno==bno)) { if(bu->flags & BU_DELETABLE) { found=1; if(asfd->write_str(asfd, CMD_GEN, "ok") || delete_backup(sdirs, cname, bu, manual_delete)) goto end; } else { asfd->write_str(asfd, CMD_ERROR, "backup not deletable"); goto end; } break; } } if(backup && *backup && !found) { asfd->write_str(asfd, CMD_ERROR, "backup not found"); goto end; } ret=0; end: bu_list_free(&bu_list); return ret; }
static void cstat_free_content(struct cstat *c) { if(!c) return; bu_list_free(&c->bu); free_w(&c->name); free_w(&c->conffile); cntr_free(&c->cntr); if(c->sdirs) logp("%s() called without freeing sdirs\n", __func__); c->clientdir_mtime=0; c->lockfile_mtime=0; }
static #endif int reload_from_clientdir(struct cstat **clist) { int reloaded=0; struct cstat *c; for(c=*clist; c; c=c->next) { time_t ltime=0; struct stat statp; struct stat lstatp; struct sdirs *sdirs; if(!c->permitted) continue; sdirs=(struct sdirs *)c->sdirs; if(!sdirs || !sdirs->client) continue; if(stat(sdirs->client, &statp)) { // No clientdir. if(!c->run_status) cstat_set_run_status(c); continue; } if(!lstat(sdirs->lock->path, &lstatp)) ltime=lstatp.st_mtime; if(statp.st_mtime==c->clientdir_mtime && ltime==c->lockfile_mtime && c->run_status!=RUN_STATUS_SERVER_CRASHED) //&& !c->cntr) { // clientdir has not changed - no need to do anything. continue; } c->clientdir_mtime=statp.st_mtime; c->lockfile_mtime=ltime; cstat_set_run_status(c); bu_list_free(&c->bu); // FIX THIS: should probably not load everything each time. // if(bu_get_current(sdirs, &c->bu)) // goto error; if(bu_get_list_with_working(sdirs, &c->bu, c)) goto error; reloaded++; } return reloaded; error: return -1; }
int delete_backups(struct sdirs *sdirs, const char *cname, struct strlist *keep, const char *manual_delete) { int ret=-1; struct bu *bu_list=NULL; // Deleting a backup might mean that more become available to delete. // Keep trying to delete until we cannot delete any more. while(1) { if(bu_get_list(sdirs, &bu_list)) goto end; switch(do_delete_backups(sdirs, cname, keep, bu_list, manual_delete)) { case 0: ret=0; goto end; case -1: ret=-1; goto end; default: break; } bu_list_free(&bu_list); } end: bu_list_free(&bu_list); return ret; }
static #endif int do_list_server_work( int list_server_callback(const char *fullpath)) { int ret=-1; int found=0; //logp("in do_list_server\n"); if(write_status(CNTR_STATUS_LISTING, NULL, cntr)) goto end; switch(list_mode) { case LIST_MODE_BACKUPS: if((found=list_all_backups())<0) goto end; break; case LIST_MODE_CONTENTS_ONE: if((found=list_contents_one(list_server_callback))<0) goto end; break; case LIST_MODE_CONTENTS_MANY: if((found=list_contents_many(list_server_callback))<0) goto end; break; } if(!found) { if(list_mode==LIST_MODE_BACKUPS) { asfd_write_wrapper_str(asfd, CMD_MESSAGE, "no backups"); // Success. } else { asfd_write_wrapper_str(asfd, CMD_MESSAGE, "backup not found"); goto end; } } ret=0; end: bu_list_free(&bu_list); return ret; }
static int do_delete_backups(struct sdirs *sdirs, struct conf *cconf) { int ret=-1; int deleted=0; unsigned long m=1; struct bu *bu=NULL; struct bu *last=NULL; struct bu *bu_list=NULL; struct strlist *keep=NULL; if(bu_list_get(sdirs, &bu_list)) goto end; // Find the last entry in the list. for(bu=bu_list; bu; bu=bu->next) last=bu; // For each of the 'keep' values, generate ranges in which to keep // one backup. for(keep=cconf->keep; keep; keep=keep->next) { unsigned long rmin=0; rmin=m * keep->flag; if(keep->next && range_loop(sdirs, cconf, keep, rmin, bu_list, last, &deleted)) goto end; m=rmin; } // Remove the very oldest backups. for(bu=bu_list; bu; bu=bu->next) if(bu->trbno>m) break; for(; bu; bu=bu->prev) { if(delete_backup(sdirs, cconf, bu)) goto end; deleted++; } ret=deleted; end: bu_list_free(&bu_list); return ret; }
int cstat_set_backup_list(struct cstat *cstat) { struct bu *bu=NULL; // Free any previous list. bu_list_free(&cstat->bu); if(bu_list_get(cstat->sdirs, &bu)) { //logp("error when looking up current backups\n"); return 0; } // Find the end of the list just loaded, so we can traverse // it backwards later. while(bu && bu->next) bu=bu->next; cstat->bu=bu; return 0; }
static int reload_from_clientdir(struct cstat **clist, struct conf *conf) { struct cstat *c; for(c=*clist; c; c=c->next) { time_t ltime=0; struct stat statp; struct stat lstatp; if(!c->sdirs->client) continue; if(stat(c->sdirs->client, &statp)) { // No clientdir. if(!c->status && cstat_set_status(c)) goto error; continue; } if(!lstat(c->sdirs->lock->path, &lstatp)) ltime=lstatp.st_mtime; if(statp.st_mtime==c->clientdir_mtime && ltime==c->lockfile_mtime && c->status!=STATUS_SERVER_CRASHED && !c->running_detail) { // clientdir has not changed - no need to do anything. continue; } c->clientdir_mtime=statp.st_mtime; c->lockfile_mtime=ltime; if(cstat_set_status(c)) goto error; bu_list_free(&c->bu_current); if(bu_current_get(c->sdirs, &c->bu_current)) goto error; } return 0; error: return -1; }
int do_list_server(struct asfd *asfd, struct sdirs *sdirs, struct conf *conf, const char *backup, const char *listregex, const char *browsedir) { int ret=-1; uint8_t found=0; unsigned long bno=0; regex_t *regex=NULL; struct bu *bu=NULL; struct bu *bu_list=NULL; printf("in do_list_server\n"); if(compile_regex(®ex, listregex) || bu_list_get(sdirs, &bu_list) || write_status(STATUS_LISTING, NULL, conf)) goto end; if(backup && *backup) bno=strtoul(backup, NULL, 10); for(bu=bu_list; bu; bu=bu->next) { // Search all backups for things matching the regex. if(listregex && backup && *backup=='a') { found=1; if(write_wrapper_str(asfd, CMD_TIMESTAMP, bu->timestamp) || list_manifest(asfd, bu->path, regex, browsedir, conf)) goto end; } // Search or list a particular backup. else if(backup && *backup) { if(!found && (!strcmp(bu->timestamp, backup) || bu->bno==bno)) { found=1; if(send_backup_name_to_client(asfd, bu, conf) || list_manifest(asfd, bu->path, regex, browsedir, conf)) goto end; } } // List the backups. else { found=1; if(send_backup_name_to_client(asfd, bu, conf)) goto end; } } if(backup && *backup && !found) { write_wrapper_str(asfd, CMD_ERROR, "backup not found"); goto end; } if(flush_asio(asfd)) goto end; ret=0; end: if(regex) { regfree(regex); free(regex); } bu_list_free(&bu); return ret; }
/* * F _ N I R T * * Invoke nirt with the current view & stuff */ int dgo_nirt_cmd(struct dg_obj *dgop, struct view_obj *vop, int argc, const char **argv) { const char **vp; FILE *fp_in; FILE *fp_out, *fp_err; #ifndef _WIN32 int ret; size_t sret; int pid, rpid; int retcode; int pipe_in[2]; int pipe_out[2]; int pipe_err[2]; #else HANDLE pipe_in[2], pipe_inDup; HANDLE pipe_out[2], pipe_outDup; HANDLE pipe_err[2], pipe_errDup; STARTUPINFO si; PROCESS_INFORMATION pi; SECURITY_ATTRIBUTES sa; char name[1024]; char line1[2048]; int rem = 2048; #endif int use_input_orig = 0; vect_t center_model; vect_t dir; vect_t cml; int i; struct solid *sp; char line[RT_MAXLINE]; char *val; struct bu_vls vls = BU_VLS_INIT_ZERO; struct bu_vls o_vls = BU_VLS_INIT_ZERO; struct bu_vls p_vls = BU_VLS_INIT_ZERO; struct bu_vls t_vls = BU_VLS_INIT_ZERO; struct bn_vlblock *vbp; struct dg_qray_dataList *ndlp; struct dg_qray_dataList HeadQRayData; int args; args = argc + 20 + 2 + dgo_count_tops((struct solid *)&dgop->dgo_headSolid); dgop->dgo_rt_cmd = (char **)bu_calloc(args, sizeof(char *), "alloc dgo_rt_cmd"); vp = (const char **)&dgop->dgo_rt_cmd[0]; *vp++ = "nirt"; /* swipe x, y, z off the end if present */ if (argc > 3) { double scan[3]; if (sscanf(argv[argc-3], "%lf", &scan[X]) == 1 && sscanf(argv[argc-2], "%lf", &scan[Y]) == 1 && sscanf(argv[argc-1], "%lf", &scan[Z]) == 1) { VMOVE(center_model, scan); use_input_orig = 1; argc -= 3; VSCALE(center_model, center_model, dgop->dgo_wdbp->dbip->dbi_local2base); } } /* Calculate point from which to fire ray */ if (!use_input_orig) { VSET(center_model, -vop->vo_center[MDX], -vop->vo_center[MDY], -vop->vo_center[MDZ]); } VSCALE(cml, center_model, dgop->dgo_wdbp->dbip->dbi_base2local); VMOVEN(dir, vop->vo_rotation + 8, 3); VSCALE(dir, dir, -1.0); bu_vls_printf(&p_vls, "xyz %lf %lf %lf;", cml[X], cml[Y], cml[Z]); bu_vls_printf(&p_vls, "dir %lf %lf %lf; s", dir[X], dir[Y], dir[Z]); i = 0; if (DG_QRAY_GRAPHICS(dgop)) { *vp++ = "-e"; *vp++ = DG_QRAY_FORMAT_NULL; /* first ray ---- returns partitions */ *vp++ = "-e"; *vp++ = DG_QRAY_FORMAT_P; /* ray start, direction, and 's' command */ *vp++ = "-e"; *vp++ = bu_vls_addr(&p_vls); /* second ray ---- returns overlaps */ *vp++ = "-e"; *vp++ = DG_QRAY_FORMAT_O; /* ray start, direction, and 's' command */ *vp++ = "-e"; *vp++ = bu_vls_addr(&p_vls); if (DG_QRAY_TEXT(dgop)) { char *cp; int count = 0; /* get 'r' format now; prepend its' format string with a newline */ val = bu_vls_addr(&dgop->dgo_qray_fmts[0].fmt); /* find first '"' */ while (*val != '"' && *val != '\0') ++val; if (*val == '\0') goto done; else ++val; /* skip first '"' */ /* find last '"' */ cp = (char *)strrchr(val, '"'); if (cp != (char *)NULL) /* found it */ count = cp - val; done: if (*val == '\0') bu_vls_printf(&o_vls, " fmt r \"\\n\" "); else { struct bu_vls tmp = BU_VLS_INIT_ZERO; bu_vls_strncpy(&tmp, val, count); bu_vls_printf(&o_vls, " fmt r \"\\n%V\" ", &tmp); bu_vls_free(&tmp); if (count) val += count + 1; bu_vls_printf(&o_vls, "%s", val); } i = 1; *vp++ = "-e"; *vp++ = bu_vls_addr(&o_vls); } } if (DG_QRAY_TEXT(dgop)) { /* load vp with formats for printing */ for (; dgop->dgo_qray_fmts[i].type != (char)0; ++i) bu_vls_printf(&t_vls, "fmt %c %s; ", dgop->dgo_qray_fmts[i].type, bu_vls_addr(&dgop->dgo_qray_fmts[i].fmt)); *vp++ = "-e"; *vp++ = bu_vls_addr(&t_vls); /* nirt does not like the trailing ';' */ bu_vls_trunc(&t_vls, -2); } /* include nirt script string */ if (bu_vls_strlen(&dgop->dgo_qray_script)) { *vp++ = "-e"; *vp++ = bu_vls_addr(&dgop->dgo_qray_script); } *vp++ = "-e"; *vp++ = bu_vls_addr(&p_vls); for (i = 1; i < argc; i++) *vp++ = argv[i]; *vp++ = dgop->dgo_wdbp->dbip->dbi_filename; dgop->dgo_rt_cmd_len = (char **)vp - (char **)dgop->dgo_rt_cmd; /* Note - dgo_build_tops sets the last vp to (char *)0 */ dgop->dgo_rt_cmd_len += dgo_build_tops((struct solid *)&dgop->dgo_headSolid, vp, (const char **)&dgop->dgo_rt_cmd[args]); if (dgop->dgo_qray_cmd_echo) { /* Print out the command we are about to run */ vp = (const char **)&dgop->dgo_rt_cmd[0]; while (*vp) Tcl_AppendResult(dgop->interp, *vp++, " ", (char *)NULL); Tcl_AppendResult(dgop->interp, "\n", (char *)NULL); } if (use_input_orig) { bu_vls_printf(&vls, "\nFiring from (%lf, %lf, %lf)...\n", center_model[X], center_model[Y], center_model[Z]); Tcl_AppendResult(dgop->interp, bu_vls_addr(&vls), (char *)NULL); bu_vls_free(&vls); } else Tcl_AppendResult(dgop->interp, "\nFiring from view center...\n", (char *)NULL); #ifndef _WIN32 ret = pipe(pipe_in); if (ret < 0) perror("pipe"); ret = pipe(pipe_out); if (ret < 0) perror("pipe"); ret = pipe(pipe_err); if (ret < 0) perror("pipe"); (void)signal(SIGINT, SIG_IGN); if ((pid = fork()) == 0) { /* Redirect stdin, stdout, stderr */ (void)close(0); ret = dup(pipe_in[0]); if (ret < 0) perror("dup"); (void)close(1); ret = dup(pipe_out[1]); if (ret < 0) perror("dup"); (void)close(2); ret = dup(pipe_err[1]); if (ret < 0) perror("dup"); /* close pipes */ (void)close(pipe_in[0]); (void)close(pipe_in[1]); (void)close(pipe_out[0]); (void)close(pipe_out[1]); (void)close(pipe_err[0]); (void)close(pipe_err[1]); for (i = 3; i < 20; i++) (void)close(i); (void)signal(SIGINT, SIG_DFL); (void)execvp(dgop->dgo_rt_cmd[0], dgop->dgo_rt_cmd); perror (dgop->dgo_rt_cmd[0]); exit(16); } /* use fp_in to feed view info to nirt */ (void)close(pipe_in[0]); fp_in = fdopen(pipe_in[1], "w"); /* use fp_out to read back the result */ (void)close(pipe_out[1]); fp_out = fdopen(pipe_out[0], "r"); /* use fp_err to read any error messages */ (void)close(pipe_err[1]); fp_err = fdopen(pipe_err[0], "r"); /* send quit command to nirt */ sret = fwrite("q\n", 1, 2, fp_in); if (sret != 2) bu_log("fwrite failure\n"); (void)fclose(fp_in); #else memset((void *)&si, 0, sizeof(STARTUPINFO)); memset((void *)&pi, 0, sizeof(PROCESS_INFORMATION)); memset((void *)&sa, 0, sizeof(SECURITY_ATTRIBUTES)); sa.nLength = sizeof(sa); sa.bInheritHandle = TRUE; sa.lpSecurityDescriptor = NULL; /* Create a pipe for the child process's STDOUT. */ CreatePipe(&pipe_out[0], &pipe_out[1], &sa, 0); /* Create noninheritable read handle and close the inheritable read handle. */ DuplicateHandle(GetCurrentProcess(), pipe_out[0], GetCurrentProcess(), &pipe_outDup , 0, FALSE, DUPLICATE_SAME_ACCESS); CloseHandle(pipe_out[0]); /* Create a pipe for the child process's STDERR. */ CreatePipe(&pipe_err[0], &pipe_err[1], &sa, 0); /* Create noninheritable read handle and close the inheritable read handle. */ DuplicateHandle(GetCurrentProcess(), pipe_err[0], GetCurrentProcess(), &pipe_errDup , 0, FALSE, DUPLICATE_SAME_ACCESS); CloseHandle(pipe_err[0]); /* The steps for redirecting child process's STDIN: * 1. Save current STDIN, to be restored later. * 2. Create anonymous pipe to be STDIN for child process. * 3. Set STDIN of the parent to be the read handle to the * pipe, so it is inherited by the child process. * 4. Create a noninheritable duplicate of the write handle, * and close the inheritable write handle. */ /* Create a pipe for the child process's STDIN. */ CreatePipe(&pipe_in[0], &pipe_in[1], &sa, 0); /* Duplicate the write handle to the pipe so it is not inherited. */ DuplicateHandle(GetCurrentProcess(), pipe_in[1], GetCurrentProcess(), &pipe_inDup, 0, FALSE, /* not inherited */ DUPLICATE_SAME_ACCESS); CloseHandle(pipe_in[1]); si.cb = sizeof(STARTUPINFO); si.lpReserved = NULL; si.lpReserved2 = NULL; si.cbReserved2 = 0; si.lpDesktop = NULL; si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW; si.hStdInput = pipe_in[0]; si.hStdOutput = pipe_out[1]; si.hStdError = pipe_err[1]; si.wShowWindow = SW_HIDE; snprintf(line1, rem, "%s ", dgop->dgo_rt_cmd[0]); rem -= (int)strlen(line1) - 1; for (i = 1; i < dgop->dgo_rt_cmd_len; i++) { /* skip commands */ if (strstr(dgop->dgo_rt_cmd[i], "-e") != NULL) ++i; else { /* append other arguments (i.e. options, file and obj(s)) */ snprintf(name, 1024, "\"%s\" ", dgop->dgo_rt_cmd[i]); if (rem - strlen(name) < 1) { bu_log("Ran out of buffer space!"); bu_free(dgop->dgo_rt_cmd, "free dgo_rt_cmd"); dgop->dgo_rt_cmd = NULL; return TCL_ERROR; } bu_strlcat(line1, name, sizeof(line1)); rem -= (int)strlen(name); } } CreateProcess(NULL, line1, NULL, NULL, TRUE, DETACHED_PROCESS, NULL, NULL, &si, &pi); /* use fp_in to feed view info to nirt */ CloseHandle(pipe_in[0]); fp_in = _fdopen(_open_osfhandle((intptr_t)pipe_inDup, _O_TEXT), "wb"); setmode(fileno(fp_in), O_BINARY); /* send commands down the pipe */ for (i = 1; i < dgop->dgo_rt_cmd_len-2; i++) if (strstr(dgop->dgo_rt_cmd[i], "-e") != NULL) fprintf(fp_in, "%s\n", dgop->dgo_rt_cmd[++i]); /* use fp_out to read back the result */ CloseHandle(pipe_out[1]); fp_out = _fdopen(_open_osfhandle((intptr_t)pipe_outDup, _O_TEXT), "rb"); setmode(fileno(fp_out), O_BINARY); /* use fp_err to read any error messages */ CloseHandle(pipe_err[1]); fp_err = _fdopen(_open_osfhandle((intptr_t)pipe_errDup, _O_TEXT), "rb"); setmode(fileno(fp_err), O_BINARY); /* send quit command to nirt */ fwrite("q\n", 1, 2, fp_in); (void)fclose(fp_in); #endif bu_vls_free(&p_vls); /* use to form "partition" part of nirt command above */ if (DG_QRAY_GRAPHICS(dgop)) { double scan[4]; if (DG_QRAY_TEXT(dgop)) bu_vls_free(&o_vls); /* used to form "overlap" part of nirt command above */ BU_LIST_INIT(&HeadQRayData.l); /* handle partitions */ while (bu_fgets(line, RT_MAXLINE, fp_out) != (char *)NULL) { if (line[0] == '\n') { Tcl_AppendResult(dgop->interp, line+1, (char *)NULL); break; } BU_ALLOC(ndlp, struct dg_qray_dataList); BU_LIST_APPEND(HeadQRayData.l.back, &ndlp->l); if (sscanf(line, "%le %le %le %le", &scan[0], &scan[1], &scan[2], &scan[3]) != 4) break; ndlp->x_in = scan[0]; ndlp->y_in = scan[1]; ndlp->z_in = scan[2]; ndlp->los = scan[3]; } vbp = rt_vlblock_init(); dgo_qray_data_to_vlist(dgop, vbp, &HeadQRayData, dir, 0); bu_list_free(&HeadQRayData.l); dgo_cvt_vlblock_to_solids(dgop, vbp, bu_vls_addr(&dgop->dgo_qray_basename), 0); rt_vlblock_free(vbp); /* handle overlaps */ while (bu_fgets(line, RT_MAXLINE, fp_out) != (char *)NULL) { if (line[0] == '\n') { Tcl_AppendResult(dgop->interp, line+1, (char *)NULL); break; } BU_ALLOC(ndlp, struct dg_qray_dataList); BU_LIST_APPEND(HeadQRayData.l.back, &ndlp->l); if (sscanf(line, "%le %le %le %le", &scan[0], &scan[1], &scan[2], &scan[3]) != 4) break; ndlp->x_in = scan[0]; ndlp->y_in = scan[1]; ndlp->z_in = scan[2]; ndlp->los = scan[3]; } vbp = rt_vlblock_init(); dgo_qray_data_to_vlist(dgop, vbp, &HeadQRayData, dir, 1); bu_list_free(&HeadQRayData.l); dgo_cvt_vlblock_to_solids(dgop, vbp, bu_vls_addr(&dgop->dgo_qray_basename), 0); rt_vlblock_free(vbp); } /* * Notify observers, if any, before generating textual output since * such an act (observer notification) wipes out whatever gets stuffed * into the result. */ dgo_notify(dgop); if (DG_QRAY_TEXT(dgop)) { bu_vls_free(&t_vls); while (bu_fgets(line, RT_MAXLINE, fp_out) != (char *)NULL) Tcl_AppendResult(dgop->interp, line, (char *)NULL); } (void)fclose(fp_out); while (bu_fgets(line, RT_MAXLINE, fp_err) != (char *)NULL) Tcl_AppendResult(dgop->interp, line, (char *)NULL); (void)fclose(fp_err); #ifndef _WIN32 /* Wait for program to finish */ while ((rpid = wait(&retcode)) != pid && rpid != -1) ; /* NULL */ if (retcode != 0) pr_wait_status(dgop->interp, retcode); #else /* Wait for program to finish */ WaitForSingleObject(pi.hProcess, INFINITE); #endif FOR_ALL_SOLIDS(sp, &dgop->dgo_headSolid) sp->s_wflag = DOWN; bu_free(dgop->dgo_rt_cmd, "free dgo_rt_cmd"); dgop->dgo_rt_cmd = NULL; return TCL_OK; }
static int put_tree_into_comb(struct ged *gedp, struct rt_comb_internal *comb, struct directory *dp, const char *old_name, const char *new_name, const char *imstr) { int i; int done; char *line; char *ptr; char relation; char *name; struct rt_tree_array *rt_tree_array; struct line_list *llp; int node_count = 0; int tree_index = 0; union tree *tp; matp_t matrix; struct bu_vls vls = BU_VLS_INIT_ZERO; char *str; if (imstr == (char *)NULL) return GED_ERROR; BU_LIST_INIT(&HeadLines.l); /* duplicate the immutable str (from argv) for strtok style mutation */ str = bu_strdup(imstr); /* break str into lines */ line = str; ptr = strchr(str, '\n'); if (ptr != NULL) *ptr = '\0'; while (line != (char *)NULL) { int n; bu_vls_strcpy(&vls, line); if ((n = count_nodes(gedp, bu_vls_addr(&vls))) < 0) { bu_vls_free(&vls); bu_list_free(&HeadLines.l); bu_free(str, "dealloc bu_strdup str"); return GED_ERROR; } else if (n > 0) { BU_ALLOC(llp, struct line_list); BU_LIST_INSERT(&HeadLines.l, &llp->l); llp->line = line; node_count += n; } /* else blank line */ if (ptr != NULL && *(ptr+1) != '\0') { /* leap frog past EOS */ line = ptr + 1; ptr = strchr(line, '\n'); if (ptr != NULL) *ptr = '\0'; } else { line = NULL; } } bu_vls_free(&vls); /* build tree list */ if (node_count) rt_tree_array = (struct rt_tree_array *)bu_calloc(node_count, sizeof(struct rt_tree_array), "tree list"); else rt_tree_array = (struct rt_tree_array *)NULL; for (BU_LIST_FOR (llp, line_list, &HeadLines.l)) { done = 0; ptr = strtok(llp->line, _delims); while (!done) { if (!ptr) break; /* First non-white is the relation operator */ relation = (*ptr); if (relation == '\0') break; /* Next must be the member name */ ptr = strtok((char *)NULL, _delims); if (ptr == (char *)NULL) { bu_list_free(&HeadLines.l); if (rt_tree_array) bu_free((char *)rt_tree_array, "red: tree list"); bu_log("no name specified\n"); bu_free(str, "dealloc bu_strdup str"); return GED_ERROR; } name = ptr; /* Eliminate trailing white space from name */ i = (int)strlen(ptr); while (isspace((int)name[--i])) name[i] = '\0'; /* Check for existence of member */ if ((db_lookup(gedp->ged_wdbp->dbip, name, LOOKUP_QUIET)) == RT_DIR_NULL) bu_log("\tWARNING: ' %s ' does not exist\n", name); /* get matrix */ ptr = strtok((char *)NULL, _delims); if (ptr == (char *)NULL) { matrix = (matp_t)NULL; done = 1; } else if (*ptr == 'u' || (*ptr == '-' && *(ptr+1) == '\0') || (*ptr == '+' && *(ptr+1) == '\0')) { /* assume another relational operator */ matrix = (matp_t)NULL; } else { int k; matrix = (matp_t)bu_calloc(16, sizeof(fastf_t), "red: matrix"); matrix[0] = atof(ptr); for (k = 1; k < 16; k++) { ptr = strtok((char *)NULL, _delims); if (!ptr) { bu_log("incomplete matrix for member %s - No changes made\n", name); bu_free((char *)matrix, "red: matrix"); if (rt_tree_array) bu_free((char *)rt_tree_array, "red: tree list"); bu_list_free(&HeadLines.l); bu_free(str, "dealloc bu_strdup str"); return GED_ERROR; } matrix[k] = atof(ptr); } if (bn_mat_is_identity(matrix)) { bu_free((char *)matrix, "red: matrix"); matrix = (matp_t)NULL; } ptr = strtok((char *)NULL, _delims); if (ptr == (char *)NULL) done = 1; } /* Add it to the combination */ switch (relation) { case '+': rt_tree_array[tree_index].tl_op = OP_INTERSECT; break; case '-': rt_tree_array[tree_index].tl_op = OP_SUBTRACT; break; default: if (relation != 'u') { bu_log("unrecognized relation (assume UNION)\n"); } rt_tree_array[tree_index].tl_op = OP_UNION; break; } BU_ALLOC(tp, union tree); RT_TREE_INIT(tp); rt_tree_array[tree_index].tl_tree = tp; tp->tr_l.tl_op = OP_DB_LEAF; tp->tr_l.tl_name = bu_strdup(name); tp->tr_l.tl_mat = matrix; tree_index++; } } bu_list_free(&HeadLines.l); i = make_tree(gedp, comb, dp, node_count, old_name, new_name, rt_tree_array, tree_index); bu_free(str, "dealloc bu_strdup str"); return i; }
void list_server_free(void) { bu_list_free(&bu_list); regex_free(®ex); }
int do_restore_server(struct asfd *asfd, struct sdirs *sdirs, enum action act, int srestore, char **dir_for_notify, struct conf **confs) { int ret=0; uint8_t found=0; struct bu *bu=NULL; struct bu *bu_list=NULL; unsigned long bno=0; regex_t *regex=NULL; const char *backup=get_string(confs[OPT_BACKUP]); logp("in do_restore\n"); if(compile_regex(®ex, get_string(confs[OPT_REGEX]))) return -1; if(bu_get_list(sdirs, &bu_list)) { if(regex) { regfree(regex); free(regex); } return -1; } if((!backup || !*backup || !(bno=strtoul(backup, NULL, 10))) && bu_list) { found=1; // No backup specified, do the most recent. for(bu=bu_list; bu && bu->next; bu=bu->next) { } ret=restore_manifest(asfd, bu, regex, srestore, act, sdirs, dir_for_notify, confs); } if(!found) for(bu=bu_list; bu; bu=bu->next) { if(!strcmp(bu->timestamp, backup) || bu->bno==bno) { found=1; //logp("got: %s\n", bu->path); ret|=restore_manifest(asfd, bu, regex, srestore, act, sdirs, dir_for_notify, confs); break; } } bu_list_free(&bu_list); if(!found) { logp("backup not found\n"); asfd->write_str(asfd, CMD_ERROR, "backup not found"); ret=-1; } if(regex) { regfree(regex); free(regex); } return ret; }