Author: ek.kato
Date: Thu Jan 3 20:41:18 2008
New Revision: 5097
Modified:
trunk/fep/Makefile.am
trunk/fep/README
trunk/fep/README.ja
trunk/fep/udsock.c
trunk/fep/udsock.h
trunk/fep/uim-fep.c
Log:
* fep/uim-fep.c
- (check_dir)
- (get_ud_path)
- Move to udsock.c.
- (main) : Plug leak.
- Don't include uim-helper.h.
* fep/udsock.c
- (check_dir)
- (get_ud_path)
- Moved from uim-fep.c
- (usersockname): BUG #11409. Use ~/.uim.d/fep/backtik for the
default socket.
- (init_sendsocket)
- (init_recvsocket)
- Cleanup.
- Include uim.h and uim-helper.h.
* fep/udsock.h
- Add get_ud_path().
* fep/README: Update.
* fep/README.ja: Ditto.
* fep/Makefile.am (uim_fep_tick_LDADD) : Add libuim.la and remove
libreplace.la.
Modified: trunk/fep/Makefile.am
==============================================================================
--- trunk/fep/Makefile.am (original)
+++ trunk/fep/Makefile.am Thu Jan 3 20:41:18 2008
@@ -12,6 +12,6 @@
$(top_builddir)/uim/libuim.la @FEP_LIBADD@
uim_fep_tick_SOURCES = uim-fep-tick.c uim-fep.h udsock.c udsock.h
-uim_fep_tick_LDADD = $(top_builddir)/replace/libreplace.la
+uim_fep_tick_LDADD = $(top_builddir)/uim/libuim.la
endif
Modified: trunk/fep/README
==============================================================================
--- trunk/fep/README (original)
+++ trunk/fep/README Thu Jan 3 20:41:18 2008
@@ -41,10 +41,6 @@
o LC_ALL LC_CTYPE LANG
Detecting the language and encoding in accordance with this order.
- o TMP
- uim-fep-tick���̿����뤿���socket���֤��ǥ��쥯�ȥ�Ǥ���
- If this variable not defined, /tmp will be used.
-
o WINDOW
backtick��ȤäƤ���Ȥ���ɽ������ޤ���
@@ -74,7 +70,7 @@
o -b <file>
Set the socket path which is used by backtik.
- When you set relative path, its base path is $TMP or /tmp
+ When you set relative path, its base path is ~/.uim.d/fep/
o -w <num>
Width of status line. This variable is used if it's in from 1 to
width of terminal.
@@ -124,7 +120,7 @@
o Options of uim-fep-tick
* -s <file>
You can specify the socket path.
- When you set relative path, its base path is $TMP or /tmp
+ When you set relative path, its base path is ~/.uim.d/fep/
* -h Display the help message
Modified: trunk/fep/README.ja
==============================================================================
--- trunk/fep/README.ja (original)
+++ trunk/fep/README.ja Thu Jan 3 20:41:18 2008
@@ -61,10 +61,6 @@
o LC_ALL LC_CTYPE LANG
ʸ���ɤ����Ȥ��ˤ��ν��֤Ǹ��ޤ���
- o TMP
- uim-fep-tick���̿����뤿���socket���֤��ǥ��쥯�ȥ�Ǥ���
- ������Ƥ��ʤ��Ȥ���/tmp���Ȥ��ޤ���
-
o WINDOW
backtick��ȤäƤ���Ȥ���ɽ������ޤ���
@@ -92,8 +88,8 @@
-sl, -sb, -sn�Τ褦�˾�ά�Ǥ��ޤ���
o -b <file>
- backtick�ǻȤ�socket�Υѥ�����ꤷ�ޤ������Хѥ��ΤȤ��ϡ��Ķ��ѿ�TMP
- ��/tmp����Υѥ��ˤʤ�ޤ���
+ backtick�ǻȤ�socket�Υѥ�����ꤷ�ޤ������Хѥ��ΤȤ��ϡ�~/.uim.d/fep/
+ ����Υѥ��ˤʤ�ޤ���
o -w <����>
���ơ������饤�����Ǥ���
@@ -216,8 +212,8 @@
o uim-fep-tick�Υ��ץ����
* -s <file>
- socket�Υѥ������Ǥ��ޤ������Хѥ��ΤȤ��ϡ��Ķ��ѿ�TMP
- ��/tmp����Υѥ��ˤʤ�ޤ���
+ socket�Υѥ������Ǥ��ޤ������Хѥ��ΤȤ��ϡ�~/.uim.d/fep/
+ ����Υѥ��ˤʤ�ޤ���
* -h �إ�ץ�å�������ɽ�����ޤ���
Modified: trunk/fep/udsock.c
==============================================================================
--- trunk/fep/udsock.c (original)
+++ trunk/fep/udsock.c Thu Jan 3 20:41:18 2008
@@ -60,40 +60,103 @@
#include <sys/stat.h>
#endif
+#include <uim/uim.h>
+#include <uim/uim-helper.h>
#include "udsock.h"
static int s_send_sockfd = -1;
static int s_recv_sockfd = -1;
static struct sockaddr_un s_servaddr;
+static uim_bool
+check_dir(const char *dir)
+{
+ struct stat st;
+
+ if (dir == NULL)
+ return UIM_FALSE;
+
+ if (stat(dir, &st) < 0)
+ return (mkdir(dir, 0700) < 0) ? UIM_FALSE : UIM_TRUE;
+ else {
+ mode_t mode = S_IFDIR | S_IRUSR | S_IWUSR | S_IXUSR;
+ return ((st.st_mode & mode) == mode) ? UIM_TRUE : UIM_FALSE;
+ }
+}
+
+char *
+get_ud_path(void)
+{
+ char *path, *home = NULL;
+ struct passwd *pw;
+
+ pw = getpwuid(getuid());
+ if (pw)
+ home = pw->pw_dir;
+
+ if (!home && !uim_helper_is_setugid())
+ home = getenv("HOME");
+
+ if (!home)
+ return NULL;
+
+ if (asprintf(&path, "%s/.uim.d", home) == -1)
+ return NULL; /* XXX: fatal */
+
+ if (!check_dir(path)) {
+ free(path);
+ return NULL;
+ }
+ free(path);
+
+ if (asprintf(&path, "%s/.uim.d/fep", home) == -1)
+ return NULL; /* XXX: fatal */
+
+ if (!check_dir(path)) {
+ free(path);
+ return NULL;
+ }
+
+ return path;
+}
+
+
const char *usersockname(const char *file)
{
static char buf[UNIX_PATH_MAX];
char filebuf[UNIX_PATH_MAX];
+ char *sock_dir;
+
if (file != NULL && file[0] == '/') {
return file;
}
+
if (file == NULL) {
- struct passwd *pw = getpwuid(getuid());
- snprintf(filebuf, UNIX_PATH_MAX, "uim-fep-%s", pw->pw_name);
+ strlcpy(filebuf, "backtick", UNIX_PATH_MAX);
} else {
strlcpy(filebuf, file, UNIX_PATH_MAX);
}
- if (getenv("TMP")) {
- snprintf(buf, UNIX_PATH_MAX, "%s/%s", getenv("TMP"), filebuf);
- } else {
- snprintf(buf, UNIX_PATH_MAX, "/tmp/%s", filebuf);
+
+ sock_dir = get_ud_path();
+ if (!sock_dir) {
+ sendline("uim-fep cannot create directory");
+ exit(EXIT_FAILURE);
}
+ snprintf(buf, UNIX_PATH_MAX, "%s/%s", sock_dir, filebuf);
+ free(sock_dir);
+
return buf;
}
void init_sendsocket(const char *sock_path)
{
- sock_path = usersockname(sock_path);
+ const char *path;
+
+ path = usersockname(sock_path);
s_send_sockfd = socket(PF_UNIX, SOCK_DGRAM, 0);
memset(&s_servaddr, 0, sizeof(s_servaddr));
s_servaddr.sun_family = AF_UNIX;
- strlcpy(s_servaddr.sun_path, sock_path, UNIX_PATH_MAX);
+ strlcpy(s_servaddr.sun_path, path, UNIX_PATH_MAX);
}
void sendline(const char *buf)
@@ -107,17 +170,19 @@
*/
void init_recvsocket(const char *sock_path)
{
- sock_path = usersockname(sock_path);
- unlink(sock_path);
+ const char *path;
+
+ path = usersockname(sock_path);
+ unlink(path);
s_recv_sockfd = socket(PF_UNIX, SOCK_DGRAM, 0);
memset(&s_servaddr, 0, sizeof(s_servaddr));
s_servaddr.sun_family = AF_UNIX;
- strlcpy(s_servaddr.sun_path, sock_path, UNIX_PATH_MAX);
+ strlcpy(s_servaddr.sun_path, path, UNIX_PATH_MAX);
if (bind(s_recv_sockfd, (struct sockaddr *)&s_servaddr,
sizeof(s_servaddr)) < 0) {
- perror(sock_path);
+ perror(path);
exit(EXIT_FAILURE);
}
- chmod(sock_path, S_IRUSR|S_IWUSR);
+ chmod(path, S_IRUSR|S_IWUSR);
}
void close_socket(void)
Modified: trunk/fep/udsock.h
==============================================================================
--- trunk/fep/udsock.h (original)
+++ trunk/fep/udsock.h Thu Jan 3 20:41:18 2008
@@ -44,5 +44,6 @@
void init_recvsocket(const char *sock_path);
int recvline(char *buf, int n);
void close_socket(void);
+char *get_ud_path(void);
#endif
Modified: trunk/fep/uim-fep.c
==============================================================================
--- trunk/fep/uim-fep.c (original)
+++ trunk/fep/uim-fep.c Thu Jan 3 20:41:18 2008
@@ -110,7 +110,6 @@
#endif
#include <uim/uim.h>
-#include <uim/uim-helper.h>
#include "udsock.h"
#include "str.h"
@@ -226,58 +225,6 @@
return engine;
}
-static uim_bool
-check_dir(const char *dir)
-{
- struct stat st;
-
- if (dir == NULL)
- return UIM_FALSE;
-
- if (stat(dir, &st) < 0)
- return (mkdir(dir, 0700) < 0) ? UIM_FALSE : UIM_TRUE;
- else {
- mode_t mode = S_IFDIR | S_IRUSR | S_IWUSR | S_IXUSR;
- return ((st.st_mode & mode) == mode) ? UIM_TRUE : UIM_FALSE;
- }
-}
-
-static char *
-get_ud_path(void)
-{
- char *path, *home = NULL;
- struct passwd *pw;
-
- pw = getpwuid(getuid());
- if (pw)
- home = pw->pw_dir;
-
- if (!home && !uim_helper_is_setugid())
- home = getenv("HOME");
-
- if (!home)
- return NULL;
-
- if (asprintf(&path, "%s/.uim.d", home) == -1)
- return NULL; /* XXX: fatal */
-
- if (!check_dir(path)) {
- free(path);
- return NULL;
- }
- free(path);
-
- if (asprintf(&path, "%s/.uim.d/fep", home) == -1)
- return NULL; /* XXX: fatal */
-
- if (!check_dir(path)) {
- free(path);
- return NULL;
- }
-
- return path;
-}
-
int main(int argc, char **argv)
{
/* command will be execed on pty */
@@ -296,7 +243,7 @@
};
FILE *fp;
const char *suffix = NULL;
- const char *uim_dir;
+ char *uim_dir;
const char *sty_str;
const char *win_str;
struct stat stat_buf;
@@ -528,6 +475,7 @@
}
}
}
+ free(uim_dir);
snprintf(pid_str, sizeof(pid_str), "%d", getpid());
setenv("UIM_FEP_PID", pid_str, 1);