On Sun, Mar 23, 2008 at 09:34:31PM +0000, Samuel Thibault wrote:
> Grmbl, now I'm getting segfaults in aumix...  That is because aumix
> initializes ncurses first, then gpm, but it happens that patch
> 013_xterm_mouse_support_000 does this:

I see - InitScreen calls initscr, and this reinitializes the terminal.
But see below.
 
> +#ifdef HAVE_TERM_H
> +   if (setupterm((char *) 0, 1, &terror) == 0 && terror == 1
> +       && (mousecap=tigetstr("kmous")) && mousecap != (char *)-1
> +       && mousecap[0]) {
> +     del_curterm(cur_term);
> +#else /* ! HAVE_TERM_H */
>     if ((term=(char *)getenv("TERM")) && !strncmp(term,"xterm",5)) {
> +#endif
>        if(gpm_tried) return gpm_fd; /* no stack */
>        gpm_fd=-2;
>        GPM_XTERM_ON;
>        gpm_flag=1;
>        return gpm_fd;
>     }
> +#ifdef HAVE_TERM_H
> +   if (cur_term)
> +     del_curterm(cur_term);
> +#endif /* HAVE_TERM_H */
> 
> and that destroys the initialization of ncurses, thus leading to a
> segfault later.  Initializing gpm first is not so great in the way aumix
> is written because it looks like this:
> 
> main() {
>       ...
>       InitScreen();
>       StartMouse();
>       ...
> }
> 
> StartMouse() {
>       Gpm_Open();
>       mousemask();
> }
> 
> moving the call to StartMouse before InitScreen would make the
> mousemask() call have no effect since ncurses is then not initialized...
> 
> libgpm calling del_curterm seems a bit odd to me: will there be side
> effects if it leaves cur_term initialized?  Won't another call to
> setupterm just override what was initialized by libgpm? (from reading
> the ncurses source, it looks like it will)

I believe that's generally correct.  curses would only save the result
if something like newterm were used.  However, ncurses does check to
try to reuse the data - see these items in NEWS (for some other program
than aumix):

20041127
        + amend change to setupterm() in 20030405 which would reuse the value
          of cur_term if the same output was selected.  This now reuses it only
          when setupterm() is called from tgetent(), which has no notion of
          separate SCREENs.  Note that tgetent() must be called after initscr()
          or newterm() to use this feature (Redhat Bugzilla #140326).  

20030405
        + modify setupterm() to check if the terminfo and terminal-modes have
          already been read.  This ensures that it does not reinvoke
          def_prog_mode() when an application calls more than one function,
          such as tgetent() and initscr() (report by Olaf Buddenhagen).

From what I'm reading, it sounds as if one could fix this by omitting the
del_curterm and making some other tweaks to make it use this feature in
ncurses.

-- 
Thomas E. Dickey
http://invisible-island.net
ftp://invisible-island.net

Attachment: pgpPxLHsN6A9e.pgp
Description: PGP signature

Reply via email to