This is the mail archive of the cygwin-developers mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: tcgetpgrp


2009/10/8 Corinna Vinschen <corinna-cygwin@cygwin.com>:
> On Oct Â8 07:34, Andy Koppe wrote:
>> I'm having trouble with this change:
>>
>> Â Â Â Â * fhandler_termios.cc (fhandler_termios::tcgetpgrp): Only return
>> Â Â Â Â valid pgid if tty is controlling tty. ÂSet errno to ENOTTY and
>> Â Â Â Â return -1 otherwise.
>>
>> Mintty uses the following call to create its pty:
>>
>> Â openpty (&parent_fd, &child_fd, 0, 0, winp)
>>
>> It then forks a child process which calls login_tty(child_fd) and
>> execs the shell or other command. Meanwhile, the parent mintty process
>> retains the child_fd, so that it can find out what the current
>> foreground process of the pty is, using tcgetpgrp(child_fd).
>> /proc/<id>/cwd then allows it to find the current working directory of
>> the foreground process.
>>
>> This is used for a new feature in mintty-0.5: Ctrl+clicking on a file
>> to open it via cygstart, whereby the current working directory of the
>> foreground process is needed for relative paths. This worked fine up
>> to 1.7.0-62, but due to the change above it no longer works on
>> cygwin-cvs.
>>
>> Is it really necessary to restrict tcgetpgrp() in that way? Is there
>> any other way to find the current foreground process of a terminal?
>
> STC?

Here you go. Prints a process ID on 1.7.0-62, but -1 on the latest snapshot.

#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <pty.h>

int main(void) {
  int parent_fd, child_fd;
  openpty(&parent_fd, &child_fd, 0, 0, 0);
  if (!fork()) {
    // child process
    close(parent_fd);
    login_tty(child_fd);
    sleep(2);
    exit(0);
  }

  // parent process
  sleep(1);
  printf("%i\n", tcgetpgrp(child_fd));
  wait();
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]