[haiku-development] Re: VIm episodes: I. How to guess the name of parent process ...

  • From: Ingo Weinhold <ingo_weinhold@xxxxxx>
  • To: haiku-development@xxxxxxxxxxxxx
  • Date: Thu, 02 Apr 2009 01:16:49 +0200

On 2009-04-01 at 23:44:50 [+0200], Siarzhuk Zharski <zharik@xxxxxx> wrote:
> 
> I have build Vim 7.2 with BeOS GUI on Haiku. Current version of BeOS GUI
> code in Vim 6.4 use following trick to determine if Vim was started from
> the Tracker:
> ---------
>     /*
>      * XXX Try to determine whether we were started from
>      * the Tracker or the terminal.
>      * It would be nice to have this work, because the Tracker
>      * follows symlinks, so even if you double-click on gvim,
>      * when it is a link to vim it will still pass a command name
>      * of vim...
>      * We try here to see if stdin comes from /dev/null. If so,
>      * (or if there is an error, which should never happen) start the GUI.
>      * This does the wrong thing for vim - </dev/null, and we're
>      * too early to see the command line parsing. Tough.
>      * On the other hand, it starts the gui for vim file & which is nice.
>      */
>     if (!isatty(0)) {
>     struct stat stat_stdin, stat_dev_null;
> 
>     if (fstat(0, &stat_stdin) == -1 ||
>         stat("/dev/null", &stat_dev_null) == -1 ||
>         (stat_stdin.st_dev == stat_dev_null.st_dev &&
>          stat_stdin.st_ino == stat_dev_null.st_ino))
>         gui.starting = TRUE;
>     }
> ---------
> 
> But this doesn't work with Haiku.

Interesting. Have you found out why?

> Note that contents of argv[0] in case starting from Tracker is equal to
> "vim" both for "gvim" and "evim" links to vim binary.
>
> I have found that call
> 
> ---------
> team_info teamInfo;
> get_team_info(getppid(), &teamInfo);
> ---------
> 
> fill the  teamInfo.args  with "/boot/beos/system/Tracker" in case of
> call from Tracker and "/bin/sh --login" for call from Terminal. This
> code snippet can help me to resolve the "Tracker run question" by
> searching for "Tracker" sub-string. Is it correct enough?

I guess it is -- you would check for the login shell parent though, so that 
this also works when starting from Deskbar or LaunchBox.

> Are there better ways to handle this situation?

Alternatively you could try to open "/dev/tty". This will only succeed, if 
the process has a controlling terminal, which every process started 
directly or indirectly from the Terminal has (unless it starts a new 
session). So this might be a bit too lax.

> Is this correct at all, always start GUI Vim from Tracker?

I guess so.

> The only correct way I see now is installing the set of shell scripts
> (gvim, evim, rvim ...) with corresponding command line parameters. Are
> there any objections against it?

Sound fine to me.

CU, Ingo

Other related posts: