f02bb3ce9489bb2c922188ebf94f52a0e80dd757 braney Mon Jul 5 10:45:34 2021 -0700 change system() calls to pipeline() calls. diff --git src/lib/dnaMotif.c src/lib/dnaMotif.c index 0e2f3f7..817a241 100644 --- src/lib/dnaMotif.c +++ src/lib/dnaMotif.c @@ -1,28 +1,29 @@ /* dnaMotif.c was originally generated by the autoSql program, which also * generated dnaMotif.h and dnaMotif.sql. This module links the database and * the RAM representation of objects. */ /* Copyright (C) 2011 The Regents of the University of California * See README in this or parent directory for licensing information. */ #include "common.h" #include "linefile.h" #include "sqlList.h" #include "dystring.h" #include "dnaMotif.h" #include "portable.h" +#include "pipeline.h" struct dnaMotif *dnaMotifCommaIn(char **pS, struct dnaMotif *ret) /* Create a dnaMotif out of a comma separated string. * This will fill in ret if non-null, otherwise will * return a new dnaMotif */ { char *s = *pS; int i; if (ret == NULL) AllocVar(ret); ret->name = sqlStringComma(&s); ret->columnCount = sqlSignedComma(&s); s = sqlEatChar(s, '{'); @@ -521,55 +522,46 @@ /* Write logo corresponding to motif to postScript file. */ { dnaMotifToLogoPs2(motif, widthPerBase, height, 0.0, fileName); } void dnaMotifToLogoPng( struct dnaMotif *motif, /* Motif to draw. */ double widthPerBase, /* Width of each base. */ double height, /* Max height. */ char *gsExe, /* ghostscript executable, NULL for default */ char *tempDir, /* temp dir , NULL for default */ char *fileName) /* output png file name. */ /* Write logo corresponding to motif to png file. */ { char *psName = rTempName(tempDir, "dnaMotif", ".ps"); -struct dyString *dy = dyStringNew(0); int w, h; int sysRet; if (gsExe == NULL) gsExe = "gs"; if (tempDir == NULL) tempDir = "/tmp"; dnaMotifToLogoPs(motif, widthPerBase, height, psName); dnaMotifDims(motif, widthPerBase, height, &w, &h); -dyStringAppend(dy, gsExe); -dyStringAppend(dy, " -sDEVICE=png16m -sOutputFile="); -dyStringAppend(dy, fileName); -dyStringAppend(dy, " -dBATCH -dNOPAUSE -q "); -dyStringPrintf(dy, "-g%dx%d ", w, h); -dyStringAppend(dy, psName); -sysRet = system(dy->string); +char geoBuf[1024]; +safef(geoBuf, sizeof geoBuf, "-g%dx%d", w, h); +char outputBuf[1024]; +safef(outputBuf, sizeof outputBuf, "-sOutputFile=%s", fileName); +char *pipeCmd[] = {gsExe, "-sDEVICE=png16m", outputBuf, "-dBATCH","-dNOPAUSE","-q", geoBuf, psName, NULL}; +struct pipeline *pl = pipelineOpen1(pipeCmd, pipelineWrite | pipelineNoAbort, "/dev/null", NULL); +sysRet = pipelineWait(pl); if (sysRet != 0) - errAbort("System call returned %d for:\n %s", sysRet, dy->string); - -/* Clean up. */ -dyStringFree(&dy); - -/* change permisssions so the webserver can access the file */ -dy = newDyString(0); -dyStringPrintf(dy, "chmod 666 %s ", fileName); -sysRet = system(dy->string); + errAbort("System call returned %d for:\n %s", sysRet, pipelineDesc(pl)); remove(psName); } void dnaMotifToLogoPsW(struct dnaMotif *motif, double widthPerBase, double width, double height, char *fileName) /* Write logo corresponding to motif to postScript file. */ { FILE *f = mustOpen(fileName, "w"); int i; int xStart = 0; int w, h; char *s = #include "dnaMotif.pss" ; @@ -589,43 +581,35 @@ fprintf(f, "showpage\n"); carefulClose(&f); } void dnaMotifToLogoPGM( struct dnaMotif *motif, /* Motif to draw. */ double widthPerBase, /* Width of each base. */ double width, /* Max width. */ double height, /* Max height. */ char *gsExe, /* ghostscript executable, NULL for default */ char *tempDir, /* temp dir , NULL for default */ char *fileName) /* output png file name. */ /* Write logo corresponding to motif to pgm file. */ { char *psName = rTempName(tempDir, "dnaMotif", ".ps"); -struct dyString *dy = dyStringNew(0); int w, h; int sysRet; if (gsExe == NULL) gsExe = "gs"; if (tempDir == NULL) tempDir = "/tmp"; dnaMotifToLogoPsW(motif, widthPerBase, width, height, psName); dnaMotifDims(motif, widthPerBase, height, &w, &h); -dyStringAppend(dy, gsExe); -dyStringAppend(dy, " -sDEVICE=pgmraw -sOutputFile="); -dyStringAppend(dy, fileName); -dyStringAppend(dy, " -dBATCH -dNOPAUSE -q "); -dyStringPrintf(dy, "-g%dx%d ", (int) ceil(width), h); -dyStringAppend(dy, psName); -sysRet = system(dy->string); -if (sysRet != 0) - errAbort("System call returned %d for:\n %s", sysRet, dy->string); +char geoBuf[1024]; +safef(geoBuf, sizeof geoBuf, "-g%dx%d ", (int) ceil(width), h); +char outputBuf[1024]; +safef(outputBuf, sizeof outputBuf, "-sOutputFile=%s", fileName); +char *pipeCmd[] = {gsExe, "-sDEVICE=pgmraw", outputBuf, "-dBATCH","-dNOPAUSE","-q", geoBuf, psName, NULL}; +struct pipeline *pl = pipelineOpen1(pipeCmd, pipelineWrite | pipelineNoAbort, "/dev/null", NULL); +sysRet = pipelineWait(pl); -/* Clean up. */ -dyStringFree(&dy); - -/* change permisssions so the webserver can access the file */ -dy = newDyString(0); -dyStringPrintf(dy, "chmod 666 %s ", fileName); -sysRet = system(dy->string); +if (sysRet != 0) + errAbort("System call returned %d for:\n %s", sysRet, pipelineDesc(pl)); remove(psName); }