Improved the handling of GIOChannels(for named pipes), ensure they are closed in a proper way.
git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@432 ea778897-0a13-0410-b9d1-a72fbfd435f5
This commit is contained in:
parent
886b90f3d0
commit
e8cb22a8d7
@ -101,6 +101,11 @@ gint destroyapp(GtkWidget *widget, gpointer gdata)
|
|||||||
{
|
{
|
||||||
gchar *fifo = g_strconcat(app->configdir, G_DIR_SEPARATOR_S, GEANY_FIFO_NAME, NULL);
|
gchar *fifo = g_strconcat(app->configdir, G_DIR_SEPARATOR_S, GEANY_FIFO_NAME, NULL);
|
||||||
// delete the fifo early, because we don't accept new files anymore
|
// delete the fifo early, because we don't accept new files anymore
|
||||||
|
if (app->fifo_ioc != NULL)
|
||||||
|
{
|
||||||
|
g_io_channel_unref(app->fifo_ioc);
|
||||||
|
g_io_channel_shutdown(app->fifo_ioc, FALSE, NULL);
|
||||||
|
}
|
||||||
unlink(fifo);
|
unlink(fifo);
|
||||||
g_free(fifo);
|
g_free(fifo);
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,7 @@
|
|||||||
#define GEANY_HOME_DIR g_get_home_dir()
|
#define GEANY_HOME_DIR g_get_home_dir()
|
||||||
#define GEANY_FILEDEFS_SUBDIR "filedefs"
|
#define GEANY_FILEDEFS_SUBDIR "filedefs"
|
||||||
#define GEANY_FIFO_NAME "geany_fifo.0"
|
#define GEANY_FIFO_NAME "geany_fifo.0"
|
||||||
#define GEANY_CODENAME "Ravik"
|
#define GEANY_CODENAME "Kadir"
|
||||||
#define GEANY_HOMEPAGE "http://geany.uvena.de/"
|
#define GEANY_HOMEPAGE "http://geany.uvena.de/"
|
||||||
#define GEANY_MAX_OPEN_FILES 25
|
#define GEANY_MAX_OPEN_FILES 25
|
||||||
#define GEANY_SESSION_FILES 25
|
#define GEANY_SESSION_FILES 25
|
||||||
@ -159,6 +159,7 @@ typedef struct MyApp
|
|||||||
gint long_line_column;
|
gint long_line_column;
|
||||||
#ifdef HAVE_FIFO
|
#ifdef HAVE_FIFO
|
||||||
gboolean ignore_fifo;
|
gboolean ignore_fifo;
|
||||||
|
GIOChannel *fifo_ioc;
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_VTE
|
#ifdef HAVE_VTE
|
||||||
gboolean load_vte;
|
gboolean load_vte;
|
||||||
|
21
src/main.c
21
src/main.c
@ -335,8 +335,10 @@ static gboolean read_fifo(GIOChannel *source, GIOCondition condition, gpointer d
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
GIOChannel *ioc = g_io_channel_unix_new(open(fifo_name, O_RDONLY | O_NONBLOCK));
|
g_io_channel_unref(app->fifo_ioc);
|
||||||
g_io_add_watch(ioc, G_IO_IN | G_IO_PRI, read_fifo, NULL);
|
g_io_channel_shutdown(app->fifo_ioc, FALSE, NULL);
|
||||||
|
app->fifo_ioc = g_io_channel_unix_new(open(fifo_name, O_RDONLY | O_NONBLOCK));
|
||||||
|
g_io_add_watch(app->fifo_ioc, G_IO_IN | G_IO_PRI, read_fifo, NULL);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -362,7 +364,7 @@ static void write_fifo(gint argc, gchar **argv)
|
|||||||
|
|
||||||
/* creates a named pipe in GEANY_FIFO_NAME, to communicate with new instances of Geany
|
/* creates a named pipe in GEANY_FIFO_NAME, to communicate with new instances of Geany
|
||||||
* to submit filenames and possibly other things */
|
* to submit filenames and possibly other things */
|
||||||
static void create_fifo(gint argc, gchar **argv, const gchar *config_dir)
|
static GIOChannel *create_fifo(gint argc, gchar **argv, const gchar *config_dir)
|
||||||
{
|
{
|
||||||
struct stat st;
|
struct stat st;
|
||||||
gchar *tmp;
|
gchar *tmp;
|
||||||
@ -400,11 +402,13 @@ static void create_fifo(gint argc, gchar **argv, const gchar *config_dir)
|
|||||||
if ((mkfifo(fifo_name, S_IRUSR | S_IWUSR)) == -1)
|
if ((mkfifo(fifo_name, S_IRUSR | S_IWUSR)) == -1)
|
||||||
{
|
{
|
||||||
if (errno != EEXIST) geany_debug("creating of a named pipe for IPC failed! (%s)", g_strerror(errno));
|
if (errno != EEXIST) geany_debug("creating of a named pipe for IPC failed! (%s)", g_strerror(errno));
|
||||||
return;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ioc = g_io_channel_unix_new(open(fifo_name, O_RDONLY | O_NONBLOCK));
|
ioc = g_io_channel_unix_new(open(fifo_name, O_RDONLY | O_NONBLOCK));
|
||||||
g_io_add_watch(ioc, G_IO_IN | G_IO_PRI, read_fifo, NULL);
|
g_io_add_watch(ioc, G_IO_IN | G_IO_PRI, read_fifo, NULL);
|
||||||
|
|
||||||
|
return ioc;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -413,6 +417,9 @@ gint main(gint argc, gchar **argv)
|
|||||||
{
|
{
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
GOptionContext *context;
|
GOptionContext *context;
|
||||||
|
#ifdef HAVE_FIFO
|
||||||
|
GIOChannel *ioc = NULL;
|
||||||
|
#endif
|
||||||
gint mkdir_result = 0;
|
gint mkdir_result = 0;
|
||||||
gint idx;
|
gint idx;
|
||||||
gchar *config_dir;
|
gchar *config_dir;
|
||||||
@ -454,7 +461,7 @@ gint main(gint argc, gchar **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_FIFO
|
#ifdef HAVE_FIFO
|
||||||
if (! ignore_fifo) create_fifo(argc, argv, config_dir);
|
if (! ignore_fifo) ioc = create_fifo(argc, argv, config_dir);
|
||||||
#endif
|
#endif
|
||||||
g_free(config_dir);
|
g_free(config_dir);
|
||||||
|
|
||||||
@ -474,7 +481,9 @@ gint main(gint argc, gchar **argv)
|
|||||||
app->have_vte = app->load_vte;
|
app->have_vte = app->load_vte;
|
||||||
if (no_vte) app->have_vte = FALSE;
|
if (no_vte) app->have_vte = FALSE;
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef HAVE_FIFO
|
||||||
|
app->fifo_ioc = ioc;
|
||||||
|
#endif
|
||||||
filetypes_init_types();
|
filetypes_init_types();
|
||||||
configuration_read_filetype_extensions();
|
configuration_read_filetype_extensions();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user