[uim-commit] r886 - in trunk: . fep

yamamoto at freedesktop.org yamamoto at freedesktop.org
Thu Jun 16 04:54:46 PDT 2005


Author: yamamoto
Date: 2005-06-16 04:54:44 -0700 (Thu, 16 Jun 2005)
New Revision: 886

Modified:
   trunk/configure.ac
   trunk/fep/str.c
   trunk/fep/uim-fep.c
Log:
 * configure.ac: add langinfo.h and utmp.h to AC_CHECK_HEADERS
 * fep/uim-fep.c (my_forkpty) : use login_tty instead of ioctl to compile on Cygwin


Modified: trunk/configure.ac
===================================================================
--- trunk/configure.ac	2005-06-16 11:43:45 UTC (rev 885)
+++ trunk/configure.ac	2005-06-16 11:54:44 UTC (rev 886)
@@ -167,9 +167,9 @@
 AC_FUNC_ALLOCA
 AC_HEADER_STDC
 AC_CHECK_HEADERS([fcntl.h locale.h stdlib.h unistd.h])
-AC_CHECK_HEADERS([locale.h stdlib.h string.h sys/ioctl.h sys/socket.h termios.h unistd.h wchar.h])
+AC_CHECK_HEADERS([langinfo.h stdlib.h string.h sys/ioctl.h sys/socket.h termios.h unistd.h wchar.h])
 AC_CHECK_HEADERS([sys/time.h sys/stat.h sys/un.h getopt.h assert.h signal.h term.h ncurses/term.h ctype.h pwd.h stdarg.h fcntl.h])
-AC_CHECK_HEADERS([pty.h util.h libutil.h])
+AC_CHECK_HEADERS([pty.h utmp.h util.h libutil.h])
 AC_CHECK_HEADERS([curses.h stropts.h])
 AC_CHECK_HEADERS([sys/param.h strings.h])
 

Modified: trunk/fep/str.c
===================================================================
--- trunk/fep/str.c	2005-06-16 11:43:45 UTC (rev 885)
+++ trunk/fep/str.c	2005-06-16 11:54:44 UTC (rev 886)
@@ -59,6 +59,9 @@
 #ifdef HAVE_STDLIB_H
 #include <stdlib.h>
 #endif
+#ifdef HAVE_LANGINFO_H
+#include <langinfo.h>
+#endif
 #include "uim-fep.h"
 #include "str.h"
 
@@ -84,16 +87,7 @@
 #ifdef __CYGWIN32__
   return "EUC-JP";
 #else
-  const char *locale = setlocale(LC_CTYPE, NULL);
-  assert(locale != NULL);
-
-  if (strcasecmp(locale, "ja") == 0) {
-    return "EUC-JP";
-  } else {
-    char *ptr = strstr(locale, ".");
-    return ptr != NULL ? ptr + 1 : "UTF-8";
-  }
-  return "UTF-8";
+  return nl_langinfo(CODESET);
 #endif
 }
 

Modified: trunk/fep/uim-fep.c
===================================================================
--- trunk/fep/uim-fep.c	2005-06-16 11:43:45 UTC (rev 885)
+++ trunk/fep/uim-fep.c	2005-06-16 11:54:44 UTC (rev 886)
@@ -99,6 +99,9 @@
 #ifdef HAVE_PTY_H
 #include <pty.h>
 #endif
+#ifdef HAVE_UTMP_H
+#include <utmp.h>
+#endif
 #ifdef HAVE_UTIL_H
 #include <util.h>
 #endif
@@ -220,6 +223,7 @@
     UNDEFINED, /* foreground */
     UNDEFINED  /* background */
   };
+  FILE *fp;
 
   int op;
 
@@ -360,7 +364,6 @@
     g_win_out = WIN_OUT_FILENO;
   }
 
-  /* exit if stdin is redirected */
   if (!isatty(g_win_in)) {
     g_win_in = open("/dev/tty", O_RDONLY);
   }
@@ -386,7 +389,8 @@
   snprintf(env_buf, 30, "UIM_FEP_PID=%d", getpid());
   putenv(env_buf);
 
-  if (fopen(s_path_getmode, "wt") != NULL) {
+  if ((fp = fopen(s_path_getmode, "wt")) != NULL) {
+    fclose(fp);
     unlink(s_path_getmode);
     env_buf = malloc(strlen("UIM_FEP_GETMODE=") + strlen(s_path_getmode) + 1);
     sprintf(env_buf, "UIM_FEP_GETMODE=%s", s_path_getmode);
@@ -415,6 +419,9 @@
     }
     if (child == 0) {
       /* »Ò¥×¥í¥»¥¹ */
+      if (g_win_in != STDIN_FILENO) {
+        close(g_win_in);
+      }
       execvp(command[0], (char *const *)command);
       perror(command[0]);
       done(EXIT_FAILURE);
@@ -567,17 +574,13 @@
   }
   if (pid == 0) {
     /* »Ò¥×¥í¥»¥¹ */
-    setsid();
-    /* man tty_ioctl */
-    ioctl(slave, TIOCSCTTY, 0);
-
+    int redirected_stdin = dup(STDIN_FILENO);
     close(*amaster);
-    if (g_win_in == STDIN_FILENO) {
-      dup2(slave, STDIN_FILENO);
+    login_tty(slave);
+    if (g_win_in != STDIN_FILENO) {
+      dup2(redirected_stdin, STDIN_FILENO);
     }
-    dup2(slave, STDOUT_FILENO);
-    dup2(slave, STDERR_FILENO);
-    close(slave);
+    close(redirected_stdin);
     return 0;
   } else {
     close(slave);



More information about the uim-commit mailing list