comparison main/database/inst/pq_lo_view.m @ 12097:b9544a96bc8d octave-forge

support viewing large objects with viewers needing a temporary file * inst/pq_lo_view.m: New function file. * src/__pq_internal_exit__.cc: New file. * src/Makefile.in: Include __pq_internal_exit__.cc. * NEWS, INDEX, DESCRIPTION: Respective changes.
author i7tiol
date Tue, 08 Oct 2013 13:54:46 +0000
parents
children 52ca082757c2
comparison
equal deleted inserted replaced
12096:3b98291666c7 12097:b9544a96bc8d
1 ## Copyright (C) 2013 Olaf Till <i7tiol@t-online.de>
2 ##
3 ## This program is free software; you can redistribute it and/or modify it under
4 ## the terms of the GNU General Public License as published by the Free Software
5 ## Foundation; either version 3 of the License, or (at your option) any later
6 ## version.
7 ##
8 ## This program is distributed in the hope that it will be useful, but WITHOUT
9 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
11 ## details.
12 ##
13 ## You should have received a copy of the GNU General Public License along with
14 ## this program; if not, see <http://www.gnu.org/licenses/>.
15
16 ## -*- texinfo -*-
17 ## @deftypefn {Function File} pq_lo_view (@var{connection}, @var{oid}, @var{viewer})
18 ##
19 ## Exports the large object of Oid @var{oid} in the database associated
20 ## with @var{connection} to a temporary file and starts the program
21 ## @var{viewer} in the background with the name of the temporary file as
22 ## argument.
23 ##
24 ## The temporary file will be removed after termination of the viewer.
25 ##
26 ## @end deftypefn
27
28 function pq_lo_view (conn, oid, viewer)
29
30 if (nargin () != 3 || ! ischar (viewer) || rows (viewer) != 1)
31 print_usage ();
32 endif
33
34 if (([opid, omsg] = fork ()) == 0)
35 ## outer child
36
37 unwind_protect
38
39 if (([vpid, vmsg] = fork ()) == 0)
40 ## child for viewer
41
42 unwind_protect
43
44 ## We don't rely on Octave to delete the tempfile since we
45 ## perform a "shortcut" exit from Octave in the child.
46 if (([~, tname, msg] = mkstemp ...
47 (fullfile (P_tmpdir (), "octave-pq_lo_view-XXXXXX"))) == -1)
48 error ("could not make temporary file: %s", msg);
49 endif
50
51 unwind_protect
52
53 ## throws an error for errors
54 pq_lo_export (conn, oid, tname);
55
56 if (system (sprintf ("%s %s", viewer, tname)) != 0)
57 error ("error in execution of viewer program or viewer terminated by a signal");
58 endif
59
60 unwind_protect_cleanup
61
62 unlink (tname);
63
64 end_unwind_protect
65
66 unwind_protect_cleanup
67
68 __pq_internal_exit__ ();
69
70 end_unwind_protect
71
72 elseif (vpid < 0)
73 ## fork for viewer went wrong
74 error ("error in fork for viewer process: %s", vmsg);
75 endif
76
77 unwind_protect_cleanup
78
79 __pq_internal_exit__ ();
80
81 end_unwind_protect
82
83 elseif (opid < 0)
84 ## fork for outer child went wrong
85 error ("error in fork for outer child: %s", omsg);
86 endif
87
88 ## parent
89 waitpid (opid);
90
91 endfunction