daily memorandum 2.3.0

CBUG | FreeBSD | Hiki | Knoppix | Mac | Ruby | W-ZERO3 | Windows | ad | amd64 | ks | linux | momonga | net | print | security | tdiary | unix | www | 会社 | 鯖缶 | 全学ゼミ |


2005-02-22 (Tue)

_ [FreeBSD][amd64] kterm が立ち上がらネ (2)

kterm が立ち上がらネ 話の続き。

追っかけてみたところ、main.c の spawn() の中の

   if(ioctl(tty, TIOCGETP, (char *)&sg) == -1)
       sg = d_sg;

とか

   if (ioctl (tty, TIOCSETP, (char *)&sg) == -1)
       HsSysError (cp_pipe[1], ERROR_TIOCSETP);

のあたりでしくってるっぽい。 tty とか sg とかいった変数の値は特に変じゃなさそうなので、 TIOCGETP とか TIOCSETP とかいった request を ioctl がサバけてない気がしてきた。 この辺のマクロって /usr/include/sys/ioctl_compat.h とかで 定義されてるし、man にも載ってないので、 obsolete なのかもしれない (だから amd64 のような新しい arch ではサポートされてない、と)。

xterm はちゃんと立ち上がるので、この辺どうしてるのかと見てみたら、

   #elif defined(USE_POSIX_TERMIOS)
	    if (tcgetattr(ttyfd, &tio) == -1)
		tio = d_tio;

とか

   #else /* USE_POSIX_TERMIOS */
	    if (tcsetattr(ttyfd, TCSANOW, &tio) == -1)
		HsSysError(cp_pipe[1], ERROR_TIOCSETP);
   #endif /* USE_POSIX_TERMIOS */

といった感じで、tc{s,g}etattr(3) 使ってるな。 この辺移植すると何とかなるんだろうか。 めんどくさいといえばめんどくさいけど、 main.c の中だけの話だし、1日あれば何とかなる、かな。

それにしても、{k,x}term って #ifdef が多くて読みづらいなぁ。。。

termios の source を見ると。。。

tcgetattr は

   int
   tcgetattr(fd, t)
           int fd;
           struct termios *t;
   {
           return (_ioctl(fd, TIOCGETA, t));
   }

って定義されてますた。ふむ。TIOCGETA なのね。 tty(4) の man によると、

   TIOCGETA struct termios *term
               Place the current value of the termios state associated with
               the device in the termios structure pointed to by term.  This
               is the underlying call that implements the termios(4)
               tcgetattr() call.

なんだそうだ。 まぁ、イマドキは ioctl(2) ではなく tc{g,s}etattr(3) 使うのが正しいみたいだけど。

[]