[GRASS5] [bug #1038] (grass) Tempfile cleanup problem revisited: G_tempfile()

this bug's URL: http://intevation.de/rt/webrt?serial_num=1038
-------------------------------------------------------------------------

Subject: Tempfile cleanup problem revisited: G_tempfile()

grass obtained from: CVS
grass binary for platform: Compiled from Sources
GRASS Version: latest CVS

Hi,

some of you may remember the thread about the GRASS tempfile problem:
http://grass.itc.it/pipermail/grass5/2002-April/002598.html

I have revisited the problem and done a draft check where G_tempfile() function
is used but the temp file not deleted later (using unlink()). This leads to left-over
files if GRASS is not left with "exit" (but simply the GRASS shell-window clicked
away) since $ETC/clean_temp won't be run in this case. In our networked GRASS
database I found 1GB leftover files.

My quick-and-dirty test has delivered:

find . -type f -name '*.c' -exec grep -l G_tempfile {} \;
find . -type f -name '*.c' -exec grep -l unlink {} \;

Diff'ed list of potential modules which call G_tempfile() but do not
use the unlink() function to delete the tempfile(s) later:

- example: r.drain

./src/mapdev/v.extract/inter/main.c
./src/mapdev/v.digit/digmain.c
./src/mapdev/v.digit/main.c
./src/mapdev/v.in.arc/main_cmd.c
./src/mapdev/v.in.arc/main_inter.c
./src/mapdev/v.in.mif/write_lines.c
./src/mapdev/v.in.shape/test/arctest1.c
./src/mapdev/v.out.arc/main.c
./src/mapdev/v.out.shape/main.c
./src/imagery/i.class/main.c
./src/imagery/i.pca/cmd/main.c
./src/imagery/i.points3/inter/list_group.c
./src/display/d.barscale/cmd/mouse.c
./src/display/d.display/histo.c
./src/display/d.label/cmd/label.c
./src/display/d.labels/do_label.c
./src/display/d.labels/proc_old.c
./src/display/d.profile/Range.c
./src/display/d.rast.edit/mk_tmp_file.c
./src/display/d.rast.edit/main.c
./src/display/d.rast.edit/mk_new_layer.c
./src/display/d.scale/cmd/draw_scale.c
./src/display/d.site.labels/do_labels.c
./src/display/d.text/cmd/main.c
./src/display/d.vect.labels/do_labels.c
./src/display/devices/CELL/Graph_Set.c
./src/display/devices/CELL/Graph_Clse.c
./src/display/devices/CELL/Panel.c
./src/display/devices/PNGdriver/Panel.c
./src/display/devices/XDRIVER/XDRIVER24/Panel.c
./src/display/devices/lib/connect_sock.c
./src/display/d.vect.area/d.vect.area.c
./src/display/d.vect.line/d.vect.line.c
./src/libes/display/popup.c
./src/general/init/clean_temp.c
./src/libes/g3d/g3dopen.c
./src/libes/g3d/g3dclose.c
./src/libes/g3d/g3drange.c
./src/libes/gis/closecell.c
./src/libes/gis/opencell.c
./src/libes/gis/put_title.c
./src/libes/gis/remove.c
./src/libes/lock/lock.c
./src/libes/lock/unlock.c
./src/libes/raster/Panel.c
./src/libes/raster/io.c
./src/libes/raster/new_io.c
./src/libes/vect32/Vlib/open1.c
./src/libes/vect32/bin_digit/bin_digit.c
./src/libes/vect32_64/Vlib/open1.c
./src/misc/m.dem.extract/getgrid.c
./src/misc/m.dem.extract/main.c
./src/misc/m.dem.extract/usgs_buf.c
./src/misc/m.dem.extract/usgs_num.c
./src/misc/m.svfit/hgnio.c
./src/misc/m.svfit/pltline.c
./src/paint/Programs/p.icons/edit.c
./src/misc/m.svfit/save.c
./src/paint/Drivers/shinko635/finish.c
./src/paint/Drivers/versatec/driver/finish.c
./src/paint/Drivers/versatec/driver/write.c
./src/paint/Interface/driverlib/interface.c
./src/paint/Programs/p.map/cmd/comment.c
./src/paint/Programs/p.map/cmd/label.c
./src/paint/Programs/p.map/cmd/main.c
./src/paint/Programs/p.map/cmd/plfile.c
./src/paint/Programs/p.map/cmd/session.c
./src/paint/Programs/p.map.new/cmd/barscale.c
./src/paint/Programs/p.map.new/cmd/colrtable.c
./src/paint/Programs/p.map.new/cmd/comment.c
./src/paint/Programs/p.map.new/cmd/do_barscale.c
./src/paint/Programs/p.map.new/cmd/do_legend.c
./src/paint/Programs/p.map.new/cmd/do_legendfin.c
./src/paint/Programs/p.map.new/cmd/label.c
./src/paint/Programs/p.map.new/cmd/legendtable.c
./src/paint/Programs/p.map.new/cmd/linefile.c
./src/paint/Programs/p.map.new/cmd/do_labels.c
./src/paint/Programs/p.map.new/cmd/main.c
./src/paint/Programs/p.map.new/cmd/plfile.c
./src/paint/Programs/p.map.new/cmd/pre_legend.c
./src/paint/Programs/p.map.new/cmd/regionfile.c
./src/paint/Programs/p.map.new/cmd/session.c
./src/ps.map/ps.map/cmd/comment.c
./src/ps.map/ps.map/cmd/label.c
./src/ps.map/ps.map/cmd/do_masking.c
./src/ps.map/ps.map/cmd/plfile.c
./src/ps.map/ps.map/cmd/session.c
./src/raster/r.agnps50/src_agnps_input_1/cell_num_id.c
./src/raster/r.agnps50/src_agnps_input_1/misc_routines.c
./src/raster/r.agnps50/src_agnps_input_2a/cell_num_id.c
./src/raster/r.agnps50/src_agnps_input_2a/misc_routines.c
./src/raster/r.binfer/reclass.c
./src/raster/r.drain/main.c
./src/raster/r.fill.dir/main.c
./src/raster/r.flow/io.13.c
./src/raster/r.mapcalc/mapcalc/main.c
./src/raster/r.out.mpeg/main.c
./src/raster/r.null/null.c
./src/raster/r.out.gridatb/check_ready.c
./src/raster/r.report/cmd/parse.c
./src/raster/r.support/inter/support.c
./src/raster/r.surf.contour/cmd/bseg_close.c
./src/raster/r.surf.contour/cmd/cseg_close.c
./src/raster/r.thin/cmd/thin_lines.c
./src/raster/r.topmodel/check_ready.c
./src/raster/r.watershed/seg/bseg_close.c
./src/raster/r.watershed/seg/cseg_close.c
./src/raster/r.watershed/seg/dseg_close.c
./src/raster/r.watershed/seg/seg_close.c
./src/raster/r.watershed/seg/sseg_close.c
./src/sites/s.sv/plthgpt.c
./src/sites/s.sv/save.c
./src/sites/s.probplt/save.c
./src/sites/s.to.rast/main.c
./src/sites/s.to.vect/cmd/main.c
./src/sites/s.to.rast/write_cell.c
./unused/display/d.vect.zoom/label.c
./unused/display/d.vect.zoom/what.c
./src.contrib/CERL/raster/r.water.fea/src/inter/shell.c
./unused/sites/s.menu/site_reports/run_report.c
./src.contrib/GMSL/g3d/src3d/raster/r3.mapcalc/mapcalc/main.c
./src.contrib/GMSL/xganim/main.c
./src.contrib/SCS/imp_exp/dig_dlg/v.exp_dlg.c
./src.contrib/SCS/imp_exp/dig_dlg/v.export_dlg.c
./src.contrib/SCS/imp_exp/dlg_dig/dlgcat.c
./src.contrib/SCS/imp_exp/gef_dig/imp_main.c
./src.contrib/SCS/imp_exp/tig_dig/imp_main.c
./src.contrib/SCS/mapdev/dlg_to_bdlg.scs/a_b_dlg.c
./src.contrib/SCS/misc/dotmaps/v.scale.random/main.c
./src.contrib/SCS/paint/Drivers/color.ps/text.c
./src.contrib/SCS/paint/Drivers/grey.ps/text.c
./src.contrib/SCS/paint/Drivers/grey.ps.n/text.c
./src.contrib/SCS/paint/Programs/color.map/cmd/comment.c
./src.contrib/SCS/paint/Programs/color.map/cmd/label.c
./src.contrib/GMSL/g3d/src3d/sites/s.vol.rst/user4.c
./src.contrib/SCS/paint/Drivers/driverlib/interface.c
./src.contrib/SCS/paint/Interface/driverlib/interface.c
./src.contrib/SCS/paint/Programs/color.map/cmd/main.c
./src.contrib/SCS/paint/Programs/color.map/cmd/plfile.c
./src.contrib/SCS/paint/Programs/color.map/cmd/session.c
./src.contrib/SCS/paint/Programs/grey.map/cmd/comment.c
./src.contrib/SCS/paint/Programs/grey.map/cmd/label.c
./src.contrib/SCS/paint/Programs/grey.map/cmd/main.c
./src.contrib/SCS/paint/Programs/grey.map/cmd/plfile.c
./src.contrib/SCS/paint/Programs/grey.map/cmd/session.c
./src.contrib/SCS/paint/Programs/newp.map/cmd/barscale.c
./src.contrib/SCS/paint/Programs/newp.map/cmd/colrtable.c
./src.contrib/SCS/paint/Programs/newp.map/cmd/comment.c
./src.contrib/SCS/paint/Programs/newp.map/cmd/do_barscale.c
./src.contrib/SCS/paint/Programs/newp.map/cmd/do_legend.c
./src.contrib/SCS/paint/Programs/newp.map/cmd/label.c
./src.contrib/SCS/paint/Programs/newp.map/cmd/legendtable.c
./src.contrib/SCS/paint/Programs/newp.map/cmd/linefile.c
./src.contrib/SCS/paint/Programs/newp.map/cmd/main.c
./src.contrib/SCS/paint/Programs/newp.map/cmd/plfile.c
./src.contrib/SCS/paint/Programs/newp.map/cmd/pre_legend.c
./src.contrib/SCS/paint/Programs/newp.map/cmd/regionfile.c
./src.contrib/SCS/paint/Programs/newp.map/cmd/session.c
./src.contrib/SCS/paint/Programs/ps.map/session.c
./src.contrib/SCS/paint/Programs/ps.map/main.c
./src.contrib/SCS/raster/r.in.miads/cmd/proces.c
./src.contrib/SCS/raster/r.reclass.scs/inter/main.c
./src.contrib/SCS/sites/s.dotmap.new/inter/main.c
./src.contrib/SCS/sites/s.dotmap.new/inter/sfactor.c
./src.contrib/SCS/vector/v.dump/cmd/edit_head.c
./src.contrib/SCS/vector/v.mk_stats/do_stats.c
./src.contrib/SCS/vector/v.proj/cmd/main.c
./src.contrib/SDTS/mapdev/v.in.sdts/wr_attrs.c
./src.garden/answers/src.answers/raster/r.direct/cmd/direct.c

(slightly cleaned up list)

These modules have to be checked if the G_tempfile is properly
deleted on G_fatal_error() or successful module termination.

Markus

-------------------------------------------- Managed by Request Tracker

A followup:

the same problem of left-over temp-files occurs when a
running GRASS module (which uses G_tempfile()) is terminated
with CTRL-C or the kill command.
Perhaps we could add some code to the signal handler (if present in
GRASS) to delete open temp files when SIGINT, SIGQUIT, SIGKILL, SIGTERM
occur. The temp file name is the PID of the running process.

Markus

On Sun, May 05, 2002 at 08:23:01PM +0200, Request Tracker wrote:

this bug's URL: http://intevation.de/rt/webrt?serial_num=1038
-------------------------------------------------------------------------

Subject: Tempfile cleanup problem revisited: G_tempfile()

[...]

Markus Neteler wrote:

the same problem of left-over temp-files occurs when a
running GRASS module (which uses G_tempfile()) is terminated
with CTRL-C or the kill command.
Perhaps we could add some code to the signal handler (if present in
GRASS) to delete open temp files when SIGINT, SIGQUIT, SIGKILL, SIGTERM
occur.

You *cannot* catch SIGKILL. Also, you can't realistically handle
SIGSEGV either; although you can catch it, the memory might be too
badly corrupted to actually do anything about it.

--
Glynn Clements <glynn.clements@virgin.net>