diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/gui-completion.c | 90 | ||||
-rw-r--r-- | src/plugins/fifo/fifo.c | 60 |
2 files changed, 105 insertions, 45 deletions
diff --git a/src/gui/gui-completion.c b/src/gui/gui-completion.c index 53e22071e..d893e8e70 100644 --- a/src/gui/gui-completion.c +++ b/src/gui/gui-completion.c @@ -551,39 +551,43 @@ gui_completion_list_add_filename_cb (void *data, buf_len = PATH_MAX; buf = malloc (buf_len); if (!buf) - return WEECHAT_RC_OK; + return WEECHAT_RC_OK; completion->add_space = 0; if ((strncmp (completion->base_word, home, 2) == 0) && getenv("HOME")) { - real_prefix = strdup (getenv("HOME")); - prefix = strdup (home); - } - else if ((strncmp (completion->base_word, DIR_SEPARATOR, 1) != 0) - || (strcmp (completion->base_word, "") == 0)) - { - real_prefix = strdup (weechat_home); - prefix = strdup (""); + real_prefix = strdup (getenv("HOME")); + prefix = strdup (home); } else { - real_prefix = strdup (DIR_SEPARATOR); - prefix = strdup (DIR_SEPARATOR); + if ((strncmp (completion->base_word, DIR_SEPARATOR, 1) != 0) + || (strcmp (completion->base_word, "") == 0)) + { + real_prefix = strdup (weechat_home); + prefix = strdup (""); + } + else + { + real_prefix = strdup (DIR_SEPARATOR); + prefix = strdup (DIR_SEPARATOR); + } } - + snprintf (buf, buf_len, "%s", completion->base_word + strlen (prefix)); p = strrchr (buf, DIR_SEPARATOR_CHAR); if (p) { - *p = '\0'; - path_d = strdup (buf); - p++; - path_b = strdup (p); + p[0] = '\0'; + path_d = strdup (buf); + p++; + path_b = strdup (p); } - else { - path_d = strdup (""); - path_b = strdup (buf); + else + { + path_d = strdup (""); + path_b = strdup (buf); } sprintf (buf, "%s%s%s", real_prefix, DIR_SEPARATOR, path_d); @@ -591,31 +595,31 @@ gui_completion_list_add_filename_cb (void *data, dp = opendir (d_name); if (dp != NULL) { - while ((entry = readdir (dp)) != NULL) - { - if (strncmp (entry->d_name, path_b, strlen (path_b)) == 0) { - - if (strcmp (entry->d_name, ".") == 0 || strcmp (entry->d_name, "..") == 0) - continue; - - snprintf(buf, buf_len, "%s%s%s", - d_name, DIR_SEPARATOR, entry->d_name); - if (stat(buf, &statbuf) == -1) - continue; - - snprintf(buf, buf_len, "%s%s%s%s%s%s", - prefix, - ((strcmp(prefix, "") == 0) - || strchr(prefix, DIR_SEPARATOR_CHAR)) ? "" : DIR_SEPARATOR, - path_d, - strcmp(path_d, "") == 0 ? "" : DIR_SEPARATOR, - entry->d_name, - S_ISDIR(statbuf.st_mode) ? DIR_SEPARATOR : ""); - - gui_completion_list_add (completion, buf, + while ((entry = readdir (dp)) != NULL) + { + if (strncmp (entry->d_name, path_b, strlen (path_b)) == 0) + { + if (strcmp (entry->d_name, ".") == 0 || strcmp (entry->d_name, "..") == 0) + continue; + + snprintf (buf, buf_len, "%s%s%s", + d_name, DIR_SEPARATOR, entry->d_name); + if (stat (buf, &statbuf) == -1) + continue; + + snprintf (buf, buf_len, "%s%s%s%s%s%s", + prefix, + ((strcmp(prefix, "") == 0) + || strchr(prefix, DIR_SEPARATOR_CHAR)) ? "" : DIR_SEPARATOR, + path_d, + strcmp(path_d, "") == 0 ? "" : DIR_SEPARATOR, + entry->d_name, + S_ISDIR(statbuf.st_mode) ? DIR_SEPARATOR : ""); + + gui_completion_list_add (completion, buf, 0, WEECHAT_LIST_POS_SORT); - } - } + } + } closedir (dp); } diff --git a/src/plugins/fifo/fifo.c b/src/plugins/fifo/fifo.c index 3b48be23d..c0e57d086 100644 --- a/src/plugins/fifo/fifo.c +++ b/src/plugins/fifo/fifo.c @@ -25,6 +25,7 @@ #include <string.h> #include <sys/types.h> #include <sys/stat.h> +#include <dirent.h> #include <fcntl.h> #include "../weechat-plugin.h" @@ -38,6 +39,8 @@ WEECHAT_PLUGIN_AUTHOR("FlashCode <flashcode@flashtux.org>"); WEECHAT_PLUGIN_VERSION(WEECHAT_VERSION); WEECHAT_PLUGIN_LICENSE("GPL3"); +#define FIFO_FILENAME_PREFIX "weechat_fifo_" + struct t_weechat_plugin *weechat_fifo_plugin = NULL; #define weechat_plugin weechat_fifo_plugin @@ -49,6 +52,57 @@ char *fifo_unterminated = NULL; /* + * fifo_remove_old_pipes: remove old fifo pipes in directory + */ + +void +fifo_remove_old_pipes () +{ + char *buf; + int buf_len, prefix_len; + const char *weechat_home, *dir_separator; + DIR *dp; + struct dirent *entry; + struct stat statbuf; + + buf_len = PATH_MAX; + buf = malloc (buf_len); + if (!buf) + return; + + weechat_home = weechat_info_get ("weechat_dir", ""); + dir_separator = weechat_info_get ("dir_separator", ""); + + prefix_len = strlen (FIFO_FILENAME_PREFIX); + + dp = opendir (weechat_home); + if (dp != NULL) + { + while ((entry = readdir (dp)) != NULL) + { + if (strcmp (entry->d_name, ".") == 0 || strcmp (entry->d_name, "..") == 0) + continue; + + if (strncmp (entry->d_name, FIFO_FILENAME_PREFIX, prefix_len) == 0) + { + snprintf (buf, buf_len, "%s%s%s", + weechat_home, dir_separator, entry->d_name); + if (stat (buf, &statbuf) != -1) + { + weechat_printf (NULL, + _("%s: removing old fifo pipe \"%s\""), + FIFO_PLUGIN_NAME, buf); + unlink (buf); + } + } + } + closedir (dp); + } + + free (buf); +} + +/* * fifo_create: create FIFO pipe for remote control * return: 1 if ok * 0 if error @@ -73,6 +127,8 @@ fifo_create () if (fifo_option && weechat_home) { + fifo_remove_old_pipes (); + if (weechat_strcasecmp (fifo_option, "on") == 0) { /* build FIFO filename: "<weechat_home>/weechat_fifo_" + process @@ -82,8 +138,8 @@ fifo_create () filename_length = strlen (weechat_home) + 64; fifo_filename = malloc (filename_length); snprintf (fifo_filename, filename_length, - "%s/weechat_fifo_%d", - weechat_home, (int) getpid()); + "%s/%s%d", + weechat_home, FIFO_FILENAME_PREFIX, (int) getpid()); } fifo_fd = -1; |