]> granicus.if.org Git - graphviz/commitdiff
Fix code not to call exit if it can't open a file for writing. This is not
authorerg <devnull@localhost>
Mon, 21 Feb 2011 23:20:51 +0000 (23:20 +0000)
committererg <devnull@localhost>
Mon, 21 Feb 2011 23:20:51 +0000 (23:20 +0000)
library-friendly. In general, all of the calls to exit() should be reviewed
with an eye to this.

I believe I have altered things correctly in gvRenderJobs so that cleanup is done
correctly and finalizers are called as needed for good jobs. It would be good for
John to review the changes.

lib/common/emit.c
lib/gvc/gvcproc.h
lib/gvc/gvdevice.c
lib/gvc/gvrender.c

index e3239974795908637d093b91927650bdc7ced6bc..33a473db67db57b800e77b1615d8b7abb0e9c55e 100644 (file)
@@ -3580,8 +3580,9 @@ int gvRenderJobs (GVC_t * gvc, graph_t * g)
            job->output_file = prevjob->output_file;  /* FIXME - this is dumb ! */
        }
        else {
+           if (gvrender_begin_job(job))
+               continue;
            gvc->active_jobs = job;   /* first job of new list */
-           gvrender_begin_job(job);
        }
        job->next_active = NULL;      /* terminate active list */
        job->callbacks = &gvdevice_callbacks;
index ca4b8af2323dc72533b543179e7a701e35bd577c..53d6c63c477b9273943f9bd1018cd883223ce0b5 100644 (file)
@@ -65,7 +65,7 @@
     extern usershape_t *gvusershape_find(char *name);
 
 /* device */
-    extern void gvdevice_initialize(GVJ_t * job);
+    extern int gvdevice_initialize(GVJ_t * job);
     extern void gvdevice_format(GVJ_t * job);
     extern void gvdevice_finalize(GVJ_t * job);
 
@@ -74,7 +74,7 @@
     extern pointf gvrender_ptf(GVJ_t *job, pointf p);
     extern pointf* gvrender_ptf_A(GVJ_t *job, pointf *af, pointf *AF, int n);
 
-    extern void gvrender_begin_job(GVJ_t * job);
+    extern int gvrender_begin_job(GVJ_t * job);
     extern void gvrender_end_job(GVJ_t * job);
     extern int gvrender_select(GVJ_t * job, const char *lang);
     extern int gvrender_features(GVJ_t * job);
index 9caab3458b1e1f9f351f53cec60737e57f33be97..0c910fd009819101a8db0351f1e09bc4018dc71d 100644 (file)
@@ -23,6 +23,9 @@
 #include <stdlib.h>
 #include <string.h>
 
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
 #endif
@@ -120,7 +123,10 @@ static void auto_output_filename(GVJ_t *job)
     job->output_filename = buf;
 }
 
-void gvdevice_initialize(GVJ_t * job)
+/* gvdevice_initialize:
+ * Return 0 on success, non-zero on failure
+ */
+int gvdevice_initialize(GVJ_t * job)
 {
     gvdevice_engine_t *gvde = job->device.engine;
     GVC_t *gvc = job->gvc;
@@ -137,8 +143,10 @@ void gvdevice_initialize(GVJ_t * job)
         if (job->output_filename) {
             job->output_file = fopen(job->output_filename, "w");
             if (job->output_file == NULL) {
-                perror(job->output_filename);
-                exit(1);
+               (job->common->errorfn) ("Could not open \"%s\" for writing : %s\n", 
+                   job->output_filename, strerror(errno));
+                /* perror(job->output_filename); */
+                return(1);
             }
         }
         else
@@ -171,14 +179,15 @@ void gvdevice_initialize(GVJ_t * job)
 
        if (deflateInit2(z, Z_DEFAULT_COMPRESSION, Z_DEFLATED, -MAX_WBITS, MAX_MEM_LEVEL, Z_DEFAULT_STRATEGY) != Z_OK) {
            (job->common->errorfn) ("Error initializing for deflation\n");
-           exit(1);
+           return(1);
        }
        gvwrite_no_z(job, z_file_header, sizeof(z_file_header));
 #else
        (job->common->errorfn) ("No libz support.\n");
-       exit(1);
+       return(1);
 #endif
     }
+    return 0;
 }
 
 size_t gvwrite (GVJ_t * job, const char *s, size_t len)
index 24708193a61603fd532562b9f722fd46adfa5040..d585fa0b5aef543449d48866803f1c24f69e6fb0 100644 (file)
@@ -111,15 +111,20 @@ int gvrender_features(GVJ_t * job)
     return features;
 }
 
-void gvrender_begin_job(GVJ_t * job)
+/* gvrender_begin_job:
+ * Return 0 on success
+ */
+int gvrender_begin_job(GVJ_t * job)
 {
     gvrender_engine_t *gvre = job->render.engine;
 
-    gvdevice_initialize(job);
+    if (gvdevice_initialize(job))
+       return 1;
     if (gvre) {
         if (gvre->begin_job)
            gvre->begin_job(job);
     }
+    return 0;
 }
 
 void gvrender_end_job(GVJ_t * job)