[haiku-3rdparty-dev] Re: Can Haiku emulate Amiga CLI/GUI startup?

  • From: Ingo Weinhold <ingo_weinhold@xxxxxx>
  • To: haiku-3rdparty-dev@xxxxxxxxxxxxx
  • Date: Sun, 22 Feb 2015 13:28:18 +0100

On 02/22/2015 01:09 PM, Ingo Weinhold wrote:
4. You can determine whether your parent process is a shell or Tracker:

     team_id parent = getppid();
     image_info info;
     int32 cookie = 0;
     bool parentFound = false;

     while (get_next_image_info(parent, &cookie, &info) == B_OK) {
         if (info.type == B_APP_IMAGE) {
             parentFound = true;
             break;
         }
     }

     if (parentFound) {
         if (strcmp(info.name, "sh") == 0
             || strcmp(info.name, "bash") == 0
             || strcmp(info.name, "ksh") == 0
             || strcmp(info.name, "zsh") == 0
             || ...) {
             // parent is a shell
         }

// alternatively:
//        if (strcmp(info.name, "Tracker") == 0) {
//            // parent is Tracker
//        }
     }

Forgot to mention that this method isn't sure-fire either. If you want to know whether the program has been started from Tracker, it should be fairly good, unless Tracker has been terminated in the meantime (unlikely).

If you determine that your program has been started from a shell, it could, however, have been started via system() from a GUI application (not Tracker, which uses load_image()).

Terminal sets the environment variables TERM and TTY (the former should also be set on remote logins), so you could take those as another indicator. However, since the environment is inherited, starting Tracker from Terminal and then your program from that Tracker, you'll get a false positive.

CU, Ingo


Other related posts: