Author: yamakenz
Date: Mon Aug 13 00:15:22 2007
New Revision: 4839
Modified:
trunk/uim/Makefile.am
trunk/uim/uim-helper-client.c
trunk/uim/uim-helper-server.c
trunk/uim/uim-helper.c
Log:
* uim/uim-helper.c
- (uim_helper_buffer_append): Replace libc memory allocation
function with uim_*()
- (uim_helper_send_message, uim_helper_get_pathname,
uim_helper_buffer_get_message):
* Ditto
* Add fatal error handling
* uim/uim-helper-client.c
- (uim_helper_init_client_fd): Replace libc memory allocation
function with uim_*()
* uim/uim-helper-server.c
- Include uim-internal.h for fatal error handlings
- (get_unused_client, close_client, write_message): Replace libc
memory allocation function with uim_*()
- (main): Add uim_init_error()
* uim/Makefile.am
- (uim_helper_server_SOURCES): Add uim-error.c
Modified: trunk/uim/Makefile.am
==============================================================================
--- trunk/uim/Makefile.am (original)
+++ trunk/uim/Makefile.am Mon Aug 13 00:15:22 2007
@@ -173,7 +173,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_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-helper-client.c
==============================================================================
--- trunk/uim/uim-helper-client.c (original)
+++ trunk/uim/uim-helper-client.c Mon Aug 13 00:15:22 2007
@@ -127,7 +127,7 @@
if (uim_helper_check_connection_fd(fd))
goto error;
- uim_read_buf = strdup("");
+ uim_read_buf = uim_strdup("");
uim_disconnect_cb = disconnect_cb;
uim_fd = fd;
Modified: trunk/uim/uim-helper-server.c
==============================================================================
--- trunk/uim/uim-helper-server.c (original)
+++ trunk/uim/uim-helper-server.c Mon Aug 13 00:15:22 2007
@@ -52,6 +52,7 @@
#endif
#include "uim.h"
+#include "uim-internal.h"
#include "uim-helper.h"
@@ -140,9 +141,9 @@
}
nr_client_slots++;
- clients = realloc(clients, sizeof(struct client) * nr_client_slots);
- clients[nr_client_slots - 1].rbuf = strdup("");
- clients[nr_client_slots - 1].wbuf = strdup("");
+ clients = uim_realloc(clients, sizeof(struct client) * nr_client_slots);
+ clients[nr_client_slots - 1].rbuf = uim_strdup("");
+ clients[nr_client_slots - 1].wbuf = uim_strdup("");
return &clients[nr_client_slots - 1];
}
@@ -153,11 +154,11 @@
close(cl->fd);
if (cl->rbuf) {
free(cl->rbuf);
- cl->rbuf = strdup("");
+ cl->rbuf = uim_strdup("");
}
if (cl->wbuf) {
free(cl->wbuf);
- cl->wbuf = strdup("");
+ cl->wbuf = uim_strdup("");
}
cl->fd = -1;
}
@@ -296,7 +297,7 @@
}
if (out_len == 0) {
free(cl->wbuf);
- cl->wbuf = strdup("");
+ cl->wbuf = uim_strdup("");
FD_CLR(cl->fd, &s_fdset_write);
} else {
uim_helper_buffer_shift(cl->wbuf, message_len - out_len);
@@ -369,6 +370,8 @@
{
char *path;
int server_fd;
+
+ uim_init_error();
path = uim_helper_get_pathname();
if (!path)
Modified: trunk/uim/uim-helper.c
==============================================================================
--- trunk/uim/uim-helper.c (original)
+++ trunk/uim/uim-helper.c Mon Aug 13 00:15:22 2007
@@ -95,11 +95,14 @@
sig_t old_sigpipe;
char *buf, *bufp;
- if (fd < 0 || !message)
+ if (uim_catch_error_begin())
return;
+ if (fd < 0 || !message)
+ uim_fatal_error("uim_helper_send_message()");
+
len = strlen(message) + 1;
- buf = malloc(len + 1);
+ buf = uim_malloc(len + 1);
snprintf(buf, len + 1, "%s\n", message);
old_sigpipe = signal(SIGPIPE, SIG_IGN);
@@ -119,6 +122,9 @@
}
free(buf);
signal(SIGPIPE, old_sigpipe);
+
+ uim_catch_error_end();
+
return;
}
@@ -142,6 +148,9 @@
struct passwd *pw;
int len;
+ if (uim_catch_error_begin())
+ return NULL;
+
pw = getpwuid(getuid());
if (pw)
home = pw->pw_dir;
@@ -150,30 +159,32 @@
home = getenv("HOME");
if (!home)
- return NULL;
+ uim_fatal_error("uim_helper_get_pathname()");
/* check ~/.uim.d/ */
len = strlen(home) + strlen("/.uim.d");
- path = (char *)malloc(len + 1);
+ path = uim_malloc(len + 1);
snprintf(path, len + 1, "%s/.uim.d", home);
if (!check_dir(path)) {
free(path);
- return NULL;
+ uim_fatal_error("uim_helper_get_pathname()");
}
/* check ~/.uim.d/socket/ */
len += strlen("/socket");
- path = (char *)realloc(path, len + 1);
+ path = uim_realloc(path, len + 1);
strlcat(path, "/socket", len + 1);
if (!check_dir(path)) {
free(path);
- return NULL;
+ uim_fatal_error("uim_helper_get_pathname()");
}
len += strlen("/uim-helper");
- path = (char *)realloc(path, len + 1);
+ path = uim_realloc(path, len + 1);
strlcat(path, "/uim-helper", len + 1);
+ uim_catch_error_end();
+
return path;
}
@@ -224,7 +235,7 @@
buf_size = strlen(buf);
extended_size = buf_size + fragment_size + 1;
- buf = (char *)realloc(buf, extended_size);
+ buf = realloc(buf, extended_size);
if (buf) {
memcpy(&buf[buf_size], fragment, fragment_size);
buf[extended_size - 1] = '\0';
@@ -247,15 +258,21 @@
size_t msg_size;
char *msg, *msg_term;
+ if (uim_catch_error_begin())
+ return NULL;
+
msg_term = strstr(buf, "\n\n");
if (msg_term) {
msg_size = msg_term + 2 - buf;
- msg = (char *)malloc(msg_size + 1);
+ msg = uim_malloc(msg_size + 1);
memcpy(msg, buf, msg_size);
msg[msg_size] = '\0';
uim_helper_buffer_shift(buf, msg_size);
return msg;
}
+
+ uim_catch_error_end();
+
return NULL;
}