mirror of
https://github.com/weechat/weechat.git
synced 2026-07-01 07:16:37 +02:00
Remove old fifo pipes before creating new pipe
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
WeeChat ChangeLog
|
||||
=================
|
||||
FlashCode <flashcode@flashtux.org>
|
||||
v0.3.1-dev, 2009-12-02
|
||||
v0.3.1-dev, 2009-12-05
|
||||
|
||||
|
||||
Version 0.3.1 (under dev!)
|
||||
@@ -39,6 +39,7 @@ Version 0.3.1 (under dev!)
|
||||
* irc: add arguments for command /rehash
|
||||
* xfer: add missing charset decoding/encoding for IRC DCC chat (bug #27482)
|
||||
* ruby: support of Ruby >= 1.9.1 (patch #6989)
|
||||
* fifo: remove old pipes before creating new pipe
|
||||
* gui: fix message "Day changed to", sometimes displayed at wrong time
|
||||
(bug #26959)
|
||||
* gui: fix bug with URL selection in some terminals (caused by horizontal lines)
|
||||
|
||||
+47
-43
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
+58
-2
@@ -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
|
||||
|
||||
@@ -48,6 +51,57 @@ char *fifo_filename;
|
||||
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
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user