Author: yamakenz
Date: Mon Jan 14 09:54:15 2008
New Revision: 5129

Modified:
  trunk/uim/Makefile.am
  trunk/uim/uim-error.c
  trunk/uim/uim-helper-server.c
  trunk/uim/uim-helper.c
  trunk/uim/uim-internal.h
  trunk/uim/uim-notify.c
  trunk/uim/uim-notify.h
  trunk/uim/uim-util.c
  trunk/uim/uim.c

Log:
* uim/uim-util.c
 - Exclude uim-notify.h
 - (dlfunc): Removed
 - (uim_scm_notify_get_plugins, uim_scm_notify_load,
   uim_scm_notify_info, uim_scm_notify_fatal): Move to uim-notify.c
 - (uim_init_util_subrs): Move uim-notify procedures initialization
   to uim_init_notify_subrs()
* uim/uim-notify.h
 - (uim_notify_stderr_get_desc): Move to uim-notify.c
* uim/uim-internal.h
 - (uim_init_notify_subrs): New function decl
* uim/uim-notify.c
 - (uim_notify_stderr_get_desc):
   * Moved decl from uim-notify.h
   * Make static
 - (uim_scm_notify_get_plugins, uim_scm_notify_load,
   uim_scm_notify_info, uim_scm_notify_fatal): Moved from uim-util.c
 - (uim_init_notify_subrs): New function
* uim/uim.c
 - (uim_init_internal): Add uim_init_notify_subrs() invocation

* uim/uim-helper.c
 - (USE_UIM_NOTIFY): New macro
 - (uim_helper_check_connection_fd): Disable uim_notify

* uim/uim-helper-server.c
 - Exclude uim-notify.h
 - (write_message): Revert uim_notify_fatal() to keep
   uim-helper-server independent of libuim
* uim/Makefile.am
 - (uim_helper_server_SOURCES): Remove uim-notify.c


Modified: trunk/uim/Makefile.am
==============================================================================
--- trunk/uim/Makefile.am       (original)
+++ trunk/uim/Makefile.am       Mon Jan 14 09:54:15 2008
@@ -199,7 +199,7 @@
uim_helper_server_LIBS =
uim_helper_server_CPPFLAGS = $(uim_defs) -I$(top_srcdir)
uim_helper_server_CFLAGS =
-uim_helper_server_SOURCES = uim-helper.c uim-helper-server.c uim-error.c uim-notify.c
+uim_helper_server_SOURCES = uim-helper.c uim-helper-server.c uim-error.c
uim_helper_server_LDADD = $(top_builddir)/replace/libreplace.la

uim_sh_LIBS =

Modified: trunk/uim/uim-error.c
==============================================================================
--- trunk/uim/uim-error.c       (original)
+++ trunk/uim/uim-error.c       Mon Jan 14 09:54:15 2008
@@ -43,7 +43,10 @@

#include "uim.h"
#include "uim-internal.h"
+#if 0 /* FIXME: temporarily disabled -- YamaKen 2008-01-15 */
#include "uim-notify.h"
+#endif
+

#ifndef EX_SOFTWARE
#define EX_SOFTWARE 70
@@ -60,6 +63,7 @@
static int guarded;
static const char *err_msg;

+
void
uim_init_error(void)
{
@@ -73,7 +77,13 @@
print_caught_error(void)
{
  if (err_msg) {
+#if 0 /* FIXME: temporarily disabled -- YamaKen 2008-01-15 */
+    /* Since this function will also be called on hard situations such
+     * as memory exhaustion, this uim_notify_fatal() call need a
+     * careful review. I'll do it until uim 1.5.0.
+     *   -- YamaKen 2008-01-15 */
uim_notify_fatal(err_msg); /* XXX: stdout messges will be duplicated */
+#else
    fputs("libuim: ", stderr);
    if (fatal_errored)
      fputs("fatal error: ", stderr);
@@ -83,6 +93,7 @@
fputs("libuim: all functionality has been disabled to save user application data", stderr);
      fputs("\n", stderr);
    }
+#endif
  }
}

@@ -200,4 +211,3 @@

  return copied;
}
-

Modified: trunk/uim/uim-helper-server.c
==============================================================================
--- trunk/uim/uim-helper-server.c       (original)
+++ trunk/uim/uim-helper-server.c       Mon Jan 14 09:54:15 2008
@@ -54,7 +54,6 @@
#include "uim.h"
#include "uim-internal.h"
#include "uim-helper.h"
-#include "uim-notify.h"


struct client {
@@ -280,7 +279,7 @@
        fprintf(stderr, "EAGAIN: fd = %d\n", cl->fd);
#endif
      } else {
-       uim_notify_fatal("uim-helper-server: %s", strerror(errno));
+       perror("uim-helper_server write(2) failed");
        if (errno == EPIPE) {
          fprintf(stderr, "fd = %d\n", cl->fd);
          FD_CLR(cl->fd, &s_fdset_read);

Modified: trunk/uim/uim-helper.c
==============================================================================
--- trunk/uim/uim-helper.c      (original)
+++ trunk/uim/uim-helper.c      Mon Jan 14 09:54:15 2008
@@ -51,7 +51,17 @@
#include "uim-internal.h"
#include "uim-helper.h"
#include "uim-util.h"
+
+/*
+ * uim-notify is disabled since I'm not confident about:
+ *   1. its stability when low-level error handling is being involved
+ *   2. whether these errors should be notified to endusers
+ * -- 2008-01-15 YamaKen */
+#define USE_UIM_NOTIFY 0
+
+#if USE_UIM_NOTIFY
#include "uim-notify.h"
+#endif

#ifndef HAVE_SIG_T
typedef void (*sig_t)(int);
@@ -203,11 +213,19 @@
  uid_t euid;
  gid_t egid;
  if (getpeereid(fd, &euid, &egid) < 0) {
+#if USE_UIM_NOTIFY
    uim_notify_fatal("uim_helper: %s", strerror(errno));
+#else
+    perror("getpeereid failed");
+#endif
    return -1;
  }
  if ((euid != 0) && (euid != getuid())) {
+#if USE_UIM_NOTIFY
    uim_notify_fatal("uim_helper: uid mismatch");
+#else
+    fprintf(stderr, "uid mismatch\n");
+#endif
    return -1;
  }
  return 0;

Modified: trunk/uim/uim-internal.h
==============================================================================
--- trunk/uim/uim-internal.h    (original)
+++ trunk/uim/uim-internal.h    Mon Jan 14 09:54:15 2008
@@ -156,6 +156,7 @@
void uim_init_im_subrs(void);
void uim_init_key_subrs(void);
void uim_init_util_subrs(void);
+void uim_init_notify_subrs(void);

void uim_init_rk_subrs(void);
void uim_init_intl_subrs(void);

Modified: trunk/uim/uim-notify.c
==============================================================================
--- trunk/uim/uim-notify.c      (original)
+++ trunk/uim/uim-notify.c      Mon Jan 14 09:54:15 2008
@@ -59,6 +59,7 @@
static void uim_notify_load_stderr(void);

/* builtin notify module */
+static const uim_notify_desc* uim_notify_stderr_get_desc(void);
static int uim_notify_stderr_init(void);
static void uim_notify_stderr_quit(void);
static int uim_notify_stderr_info(const char *);
@@ -209,12 +210,115 @@
  return uim_notify_fatal_func(msg);
}

+/*
+ * Scheme interfaces
+ */
+static uim_lisp
+uim_scm_notify_get_plugins(void)
+{
+  uim_lisp ret_;
+  DIR *dirp;
+  struct dirent *dp;
+  size_t plen, slen;
+  const uim_notify_desc* desc;
+  void *handle;
+  uim_notify_desc* (*desc_func)(void);
+  char *str;
+
+  plen = strlen(NOTIFY_PLUGIN_PREFIX);
+  slen = strlen(NOTIFY_PLUGIN_SUFFIX);
+
+  desc = uim_notify_stderr_get_desc();
+  ret_ = CONS(LIST3(MAKE_SYM(desc->name),
+                   MAKE_STR(desc->name),
+                   MAKE_STR(desc->desc)),
+             uim_scm_null());
+  dirp = opendir(NOTIFY_PLUGIN_PATH);
+  if (dirp) {
+    while ((dp = readdir(dirp)) != NULL) {
+      size_t len = strlen(dp->d_name);
+      char path[PATH_MAX];
+
+      if ((len < plen + slen) ||
+         (PATH_MAX < (strlen(NOTIFY_PLUGIN_PATH "/") + len + 1)) ||
+         (strcmp(dp->d_name, NOTIFY_PLUGIN_PREFIX) <= 0) ||
+         (strcmp(dp->d_name + len - slen, NOTIFY_PLUGIN_SUFFIX) != 0))
+       continue;
+
+      snprintf(path, PATH_MAX, "%s/%s", NOTIFY_PLUGIN_PATH, dp->d_name);
+      handle = dlopen(path, RTLD_NOW);
+      if ((str = dlerror()) != NULL) {
+       fprintf(stderr, "load failed %s(%s)\n", path, str);
+       continue;
+      }
+      desc_func = (uim_notify_desc* (*)(void))dlfunc(handle, 
"uim_notify_plugin_get_desc");
+      if (!desc_func) {
+       fprintf(stderr, "cannot found 'uim_notify_get_desc()' in %s\n", path);
+       dlclose(handle);
+       continue;
+      }
+
+      desc = desc_func();
+
+      ret_ = CONS(LIST3(MAKE_SYM(desc->name),
+                       MAKE_STR(desc->name),
+                       MAKE_STR(desc->desc)),
+                 ret_);
+
+      dlclose(handle);
+    }
+    (void)closedir(dirp);
+  }
+  return uim_scm_callf("reverse", "o", ret_);
+}
+
+static uim_lisp
+uim_scm_notify_load(uim_lisp name_)
+{
+  const char *name = REFER_C_STR(name_);
+
+  if (uim_notify_load(name))
+    return uim_scm_t();
+  else
+    return uim_scm_f();
+}
+
+static uim_lisp
+uim_scm_notify_info(uim_lisp msg_)
+{
+  const char *msg = REFER_C_STR(msg_);
+
+  if (uim_notify_info("%s", msg))
+    return uim_scm_t();
+  else
+    return uim_scm_f();
+}
+
+static uim_lisp
+uim_scm_notify_fatal(uim_lisp msg_)
+{
+  const char *msg = REFER_C_STR(msg_);
+
+  if (uim_notify_fatal("%s", msg))
+    return uim_scm_t();
+  else
+    return uim_scm_f();
+}
+
+void
+uim_init_notify_subrs(void)
+{
+  uim_scm_init_proc0("uim-notify-get-plugins", uim_scm_notify_get_plugins);
+  uim_scm_init_proc1("uim-notify-load", uim_scm_notify_load);
+  uim_scm_init_proc1("uim-notify-info", uim_scm_notify_info);
+  uim_scm_init_proc1("uim-notify-fatal", uim_scm_notify_fatal);
+}


/*
 * builtin functions
 */
-const uim_notify_desc*
+static const uim_notify_desc*
uim_notify_stderr_get_desc(void)
{
  return &uim_notify_stderr_desc;

Modified: trunk/uim/uim-notify.h
==============================================================================
--- trunk/uim/uim-notify.h      (original)
+++ trunk/uim/uim-notify.h      Mon Jan 14 09:54:15 2008
@@ -65,9 +65,6 @@
int uim_notify_plugin_info(const char *msg);
int uim_notify_plugin_fatal(const char *msg);

-/* builtin notify module */
-const uim_notify_desc* uim_notify_stderr_get_desc(void);
-
#ifdef __cplusplus
}
#endif

Modified: trunk/uim/uim-util.c
==============================================================================
--- trunk/uim/uim-util.c        (original)
+++ trunk/uim/uim-util.c        Mon Jan 14 09:54:15 2008
@@ -46,7 +46,6 @@
#include "uim-scm.h"
#include "uim-scm-abbrev.h"
#include "uim-util.h"
-#include "uim-notify.h"

static uim_lisp protected;

@@ -286,103 +285,6 @@
  return MAKE_BOOL(uim_issetugid());
}

-#ifndef HAVE_DLFUNC
-#define dlfunc(handle, symbol) \
-  ((void (*)(void))(uintptr_t)dlsym((handle), (symbol)))
-#endif
-
-static uim_lisp
-uim_scm_notify_get_plugins(void)
-{
-  uim_lisp ret_;
-  DIR *dirp;
-  struct dirent *dp;
-  size_t plen, slen;
-  const uim_notify_desc* desc;
-  void *handle;
-  uim_notify_desc* (*desc_func)(void);
-  char *str;
-
-  plen = strlen(NOTIFY_PLUGIN_PREFIX);
-  slen = strlen(NOTIFY_PLUGIN_SUFFIX);
-
-  desc = uim_notify_stderr_get_desc();
-  ret_ = CONS(LIST3(MAKE_SYM(desc->name),
-                   MAKE_STR(desc->name),
-                   MAKE_STR(desc->desc)),
-             uim_scm_null());
-  dirp = opendir(NOTIFY_PLUGIN_PATH);
-  if (dirp) {
-    while ((dp = readdir(dirp)) != NULL) {
-      size_t len = strlen(dp->d_name);
-      char path[PATH_MAX];
-
-      if ((len < plen + slen) ||
-         (PATH_MAX < (strlen(NOTIFY_PLUGIN_PATH "/") + len + 1)) ||
-         (strcmp(dp->d_name, NOTIFY_PLUGIN_PREFIX) <= 0) ||
-         (strcmp(dp->d_name + len - slen, NOTIFY_PLUGIN_SUFFIX) != 0))
-       continue;
-
-      snprintf(path, PATH_MAX, "%s/%s", NOTIFY_PLUGIN_PATH, dp->d_name);
-      handle = dlopen(path, RTLD_NOW);
-      if ((str = dlerror()) != NULL) {
-       fprintf(stderr, "load failed %s(%s)\n", path, str);
-       continue;
-      }
-      desc_func = (uim_notify_desc* (*)(void))dlfunc(handle, 
"uim_notify_plugin_get_desc");
-      if (!desc_func) {
-       fprintf(stderr, "cannot found 'uim_notify_get_desc()' in %s\n", path);
-       dlclose(handle);
-       continue;
-      }
-
-      desc = desc_func();
-
-      ret_ = CONS(LIST3(MAKE_SYM(desc->name),
-                       MAKE_STR(desc->name),
-                       MAKE_STR(desc->desc)),
-                 ret_);
-
-      dlclose(handle);
-    }
-    (void)closedir(dirp);
-  }
-  return uim_scm_callf("reverse", "o", ret_);
-}
-
-static uim_lisp
-uim_scm_notify_load(uim_lisp name_)
-{
-  const char *name = REFER_C_STR(name_);
-
-  if (uim_notify_load(name))
-    return uim_scm_t();
-  else
-    return uim_scm_f();
-}
-
-static uim_lisp
-uim_scm_notify_info(uim_lisp msg_)
-{
-  const char *msg = REFER_C_STR(msg_);
-
-  if (uim_notify_info("%s", msg))
-    return uim_scm_t();
-  else
-    return uim_scm_f();
-}
-
-static uim_lisp
-uim_scm_notify_fatal(uim_lisp msg_)
-{
-  const char *msg = REFER_C_STR(msg_);
-
-  if (uim_notify_fatal("%s", msg))
-    return uim_scm_t();
-  else
-    return uim_scm_f();
-}
-
void
uim_init_util_subrs(void)
{
@@ -416,10 +318,4 @@

  /* SRFI-43 */
  uim_scm_init_proc1("vector-copy", vector_copy);
-
-  /* notify */
-  uim_scm_init_proc0("uim-notify-get-plugins", uim_scm_notify_get_plugins);
-  uim_scm_init_proc1("uim-notify-load", uim_scm_notify_load);
-  uim_scm_init_proc1("uim-notify-info", uim_scm_notify_info);
-  uim_scm_init_proc1("uim-notify-fatal", uim_scm_notify_fatal);
}

Modified: trunk/uim/uim.c
==============================================================================
--- trunk/uim/uim.c     (original)
+++ trunk/uim/uim.c     Mon Jan 14 09:54:15 2008
@@ -121,6 +121,7 @@
  uim_init_im_subrs();
  uim_init_intl_subrs();
  uim_init_util_subrs();
+  uim_init_notify_subrs();
  uim_init_key_subrs();
  uim_init_rk_subrs();
  uim_init_plugin();

Reply via email to