Subject:
Re: X11 works well
From:
Daniel R Risacher ####@####.####
Date:
3 Dec 1999 13:30:57 -0000
Message-Id: <m2u2m0qhuc.fsf@alum.mit.edu>
>>>>> "Dave" == Dave Creelman ####@####.#### writes:
Dave> I haven't been able to get the mterm demo to work properly,
Dave> is that being worked on or is there a problem with it ?
You may have the same problem I had, which is that the pseudo terminal
isn't opened properly. I'm not sure of the most portable way to do
this, but if you have glibc, then the following patch may work.
Question: does whatever passes for libc on ELKS (and/or other OS's
that we're currently targeting) support the getpt(), grantpt(),
unlockpt(), and ptsname_r() calls?
--- demos/microwin/mterm.c.old Fri Dec 3 07:03:39 1999
+++ demos/microwin/mterm.c Fri Dec 3 07:16:23 1999
@@ -248,15 +248,16 @@
char * argv[2];
again:
- sprintf(pty_name, "/dev/ptyp%d", n);
- if ((tfd = open(pty_name, O_RDWR | O_NONBLOCK)) < 0) {
- if ((errno == EBUSY) && (n < 3)) {
- ++n;
- goto again;
- }
- fprintf(stderr, "Can't create pty %s\n", pty_name);
+ if ((tfd = getpt())<0) {
+ fprintf(stderr, "Can't create master pty\n");
return -1;
}
+
+ if (grantpt(tfd))
+ perror("failure");
+ if (unlockpt(tfd))
+ perror("failure");
+
signal(SIGCHLD, ptysignaled);
signal(SIGINT, ptysignaled);
if ((pid = fork()) == -1) {
@@ -264,13 +265,13 @@
return -1;
}
if (!pid) {
+ ptsname_r(tfd, pty_name, 12);
close(STDIN_FILENO);
close(STDOUT_FILENO);
close(STDERR_FILENO);
close(tfd);
setsid();
- pty_name[5] = 't';
if ((tfd = open(pty_name, O_RDWR)) < 0) {
fprintf(stderr, "Child: Can't open pty %s\n", pty_name);
exit(1);
--- demos/nanox/nterm.c.old Fri Dec 3 07:03:39 1999
+++ demos/nanox/nterm.c Fri Dec 3 07:16:20 1999
@@ -162,15 +162,16 @@
pid_t pid;
again:
- sprintf(pty_name, "/dev/ptyp%d", n);
- if ((tfd = open(pty_name, O_RDWR | O_NONBLOCK)) < 0) {
- if ((errno == EBUSY || errno == EIO) && n < 10) {
- n++;
- goto again;
- }
- fprintf(stderr, "Can't create pty %s\n", pty_name);
+ if ((tfd = getpt())<0) {
+ fprintf(stderr, "Can't create master pty\n");
return -1;
}
+
+ if (grantpt(tfd))
+ perror("failure");
+ if (unlockpt(tfd))
+ perror("failure");
+
signal(SIGCHLD, sigchild);
signal(SIGINT, sigchild);
if ((pid = fork()) == -1) {
@@ -178,13 +179,13 @@
return -1;
}
if (!pid) {
+ ptsname_r(tfd, pty_name, 12);
close(STDIN_FILENO);
close(STDOUT_FILENO);
close(STDERR_FILENO);
close(tfd);
setsid();
- pty_name[5] = 't';
if ((tfd = open(pty_name, O_RDWR)) < 0) {
fprintf(stderr, "Child: Can't open pty %s\n", pty_name);
exit(1);
--
"So, shall we go act innocent now?"
Daniel Risacher ####@####.####