[GRASS-dev] Re: PNG/Display driver issue?

Markus Neteler neteler at itc.it
Tue Aug 1 17:31:17 EDT 2006


(cc'ing list for the sake of documenting the new gislib internals,
hope that's ok)


[@list: the problem was that d.rast recently started to segfault
  in a Apache-PHP environment.
]

On Tue, Aug 01, 2006 at 10:13:13PM +0100, Glynn Clements wrote:
> 
> Markus Neteler wrote:

[ how to debug a process launched by Apache ]

> > > Another possible option is to add a sleep() at the beginning of
> > > d.rast, then attach to the running process. Debugging a running
> > > process is often more reliable than using a core file.
> > 
> > Cool. this works:
> > 
> > ps -aef | grep d.rast
> > apache   25804 25650  0 16:03 ?        00:00:00 d.rast BMNG_May.rgb
> > 
> > [neteler at krokus d.rast]$ sudo gdb --pid=25804
> > GNU gdb Red Hat Linux (6.3.0.0-1.96rh)
> > This GDB was configured as "x86_64-redhat-linux-gnu".
> > Attaching to process 25804
> > Reading symbols from /hardmnt/krokus0/local/grass-6.1.cvs/bin/d.rast...done.
> > Using host libthread_db library "/lib64/tls/libthread_db.so.1".
> > ...
> > Loaded symbols for /lib64/ld-linux-x86-64.so.2
> > 0x0000003ae848f172 in __nanosleep_nocancel () from /lib64/tls/libc.so.6
> > (gdb) c
> > Continuing.
> > 
> > Program received signal SIGSEGV, Segmentation fault.
> > 0x0000002a95ab1f0e in G__read_row_ptrs (fd=29) at format.c:154
> > 154             fcb->row_ptr[row] = v;
> > (gdb) bt full
> > #0  0x0000002a95ab1f0e in G__read_row_ptrs (fd=29) at format.c:154
> >         v = 4325
> >         fcb = (struct fileinfo *) 0x550f50
> >         nrows = 1080
> >         nbytes = 4 '\004'
> >         buf = (unsigned char *) 0x550ee0 ""
> >         b = (unsigned char *) 0x550ee4 ""
> >         n = 4
> >         row = 0
> 
> I'm pretty certain that this is down to this recent change to lib/gis/G.h:
> 
> 	revision 2.2
> 	date: 2006/07/23 01:32:16;  author: glynn;  state: Exp;  lines: +42 -41
> 	Eliminate use of FCB macro
> 	Dynamically resize G__.fileinfo as required
> 
> The code which resizes the fileinfo array does:
> 
> 	static struct fileinfo *new_fileinfo(int fd)
> 	{
> 	    int oldsize = G__.fileinfo_count;
> 	    int newsize = oldsize;
> 	    int i;
> 	
> 	    if (fd < oldsize)
> 		return &G__.fileinfo[fd];
> 	
> 	    if (!newsize)
> 		newsize = 20;
> 	    else
> 		newsize *= 2;
> 
> The first time it's called, it allocates 20 slots, doubling
> thereafter. But note that fd == 29; d.rast appears to be inheriting a
> lot of descriptors from Apache, resulting in the initial array size of
> 20 slots being too small.
> 
> That explains why it doesn't happen when run from the command line,
> where it will normally only inherit 3 descriptors (std{in,out,err}).
> 
> The "newsize = 20" should be something like "newsize = fd + 20"
> instead.
> 
> [The "fd"s returned by G_open_cell() etc and passed to G_get_*_row()
> etc are the actual Unix file descriptors for the [f]cell files, and
> are used as indices into the fileinfo array, so you need one fileinfo
> slot for every descriptor, regardless of whether those descriptors
> correspond to raster maps or something else.]
> 
> -- 
> Glynn Clements <glynn at gclements.plus.com>

Great job, Glynn.

http://grass.itc.it/spearfish/php_grass_earthquakes.php
works again...

thanks,
Markus




More information about the grass-dev mailing list