comparison libinterp/corefcn/gl2ps-print.cc @ 21527:ab8760b1245d

Raise an error if writes to pipe fail (bug #47381). * gl2ps-print.cc: Re-order #includes. * gl2ps-print.cc (gl2ps_renderer::draw): When copying temporary file to pipe, check that write succeeds by comparing bytes read to bytes written. If an error has occured, clear the SIGPIPE signal by calling octave_signal_handler and then raise an error. letting SIGPIPE interrupt handler eventually deal with the problem.
author Rik <rik@octave.org>
date Tue, 22 Mar 2016 15:17:18 -0700
parents 13b6be3cb217
children 212bafe8413a
comparison
equal deleted inserted replaced
21526:b76d1de20f9a 21527:ab8760b1245d
23 #ifdef HAVE_CONFIG_H 23 #ifdef HAVE_CONFIG_H
24 # include "config.h" 24 # include "config.h"
25 #endif 25 #endif
26 26
27 #include "errwarn.h" 27 #include "errwarn.h"
28 #include "gl2ps-print.h"
29 28
30 #ifdef HAVE_GL2PS_H 29 #ifdef HAVE_GL2PS_H
31 30
32 #include <cstdio> 31 #include <cstdio>
33
34 #include <limits> 32 #include <limits>
35
36 #include <unistd.h> 33 #include <unistd.h>
37 34
38 #include <gl2ps.h> 35 #include <gl2ps.h>
39 36
40 #include "lo-mappers.h" 37 #include "lo-mappers.h"
41 #include "oct-locbuf.h" 38 #include "oct-locbuf.h"
42 #include "unwind-prot.h" 39 #include "unwind-prot.h"
43 40
41 #include "gl2ps-print.h"
44 #include "gl-render.h" 42 #include "gl-render.h"
45 #include "oct-opengl.h" 43 #include "oct-opengl.h"
44 #include "sighandlers.h"
46 #include "sysdep.h" 45 #include "sysdep.h"
47 #include "text-renderer.h" 46 #include "text-renderer.h"
48 47
49 class 48 class
50 OCTINTERP_API 49 OCTINTERP_API
267 } 266 }
268 267
269 // Copy temporary file to pipe 268 // Copy temporary file to pipe
270 gnulib::fseek (tmpf, 0, SEEK_SET); 269 gnulib::fseek (tmpf, 0, SEEK_SET);
271 char str[256]; 270 char str[256];
272 int nread = 1; 271 size_t nread, nwrite;
272 nread = 1;
273 while (! feof (tmpf) && nread) 273 while (! feof (tmpf) && nread)
274 { 274 {
275 nread = gnulib::fread (str, 1, 256, tmpf); 275 nread = gnulib::fread (str, 1, 256, tmpf);
276 if (nread) 276 if (nread)
277 gnulib::fwrite (str, 1, nread, fp); 277 {
278 nwrite = gnulib::fwrite (str, 1, nread, fp);
279 if (nwrite != nread)
280 {
281 octave_signal_handler (); // Clear SIGPIPE signal
282 error ("gl2ps_renderer::draw: internal pipe error");
283 }
284 }
278 } 285 }
279 } 286 }
280 else 287 else
281 opengl_renderer::draw (go); 288 opengl_renderer::draw (go);
282 } 289 }