From 51478d7ba957b160df138f6810ee8be6514dcfa9 Mon Sep 17 00:00:00 2001 From: Daniel Carl Date: Wed, 10 Dec 2014 23:00:35 +0100 Subject: [PATCH] Changed option --fifo-name into --fifo. The fifo with given name could not be used for new spawned vimb instances, because each instance needs it's own fifo. To not make the things to complicated the fifo is now always named vimb-fifo-{pid}. This allows to use the fifo also for new spawned instances. To get the right fifo path on startup the -d or --dump option was added to print the full fifo path to stdout. --- doc/vimb.1 | 16 +++++++++++----- src/main.c | 33 +++++++++++++++++++++------------ src/main.h | 4 ++++ 3 files changed, 36 insertions(+), 17 deletions(-) diff --git a/doc/vimb.1 b/doc/vimb.1 index 4e2e5bd..05a49af 100644 --- a/doc/vimb.1 +++ b/doc/vimb.1 @@ -45,6 +45,16 @@ on new spawned instances. .I WINID of an XEmbed-aware application, that vimb will use as its parent. .TP +.B \-d, \-\-dump +Dump the current used fifo path to stdout in case vimb is started with \-f +option. If vimb is started with `$(vimb -df > ~/vimb.fifo)' the full fifo +path can be picked up from somewhere by `echo ":o github.com" > $(< +~/vimb.fifo)' +.TP +.B \-f, \-\-fifo +If given vimb will create a control fifo in vimb's config directory +named 'vimb-fifo-{pid}'. +.TP .B "\-h, \-\-help" Show help options. .TP @@ -52,10 +62,6 @@ Show help options. Run vimb in kiosk mode with nearly no keybindings, not inputbox and no context menu. .TP -.B \-n, \-\-fifo-name -If given vimb will create a control fifo in vimb's config directory -named 'vimb-fifo-{name}'. -.TP .B "\-v, \-\-version" Print build and version information. .SH MODES @@ -1433,7 +1439,7 @@ started with -e option. .TP .B VIMB_FILE Holds the full path to the control fifo, if vimb is compiled with FIFO feature -and started with `--fifo-name' option. +and started with `--fifo' option. .TP .B http_proxy If this variable is set to an none empty value, and the configuration option diff --git a/src/main.c b/src/main.c index 54b9ef6..a7e533c 100644 --- a/src/main.c +++ b/src/main.c @@ -223,6 +223,7 @@ gboolean vb_load_uri(const Arg *arg) + (vb.embed ? 2 : 0) + (vb.config.file ? 2 : 0) + (vb.config.kioskmode ? 1 : 0) + + (vb.config.fifo ? 1 : 0) + g_slist_length(vb.config.cmdargs) * 2, sizeof(char *) ); @@ -246,6 +247,9 @@ gboolean vb_load_uri(const Arg *arg) if (vb.config.kioskmode) { cmd[i++] = "-k"; } + if (vb.config.fifo) { + cmd[i++] = "-f"; + } cmd[i++] = uri; cmd[i++] = NULL; @@ -1544,6 +1548,8 @@ static void vb_cleanup(void) #ifdef FEATURE_FIFO io_cleanup(); #endif + g_free(vb.state.pid_str); + g_free(vb.state.uri); g_slist_free_full(vb.config.cmdargs, g_free); @@ -1561,22 +1567,20 @@ static gboolean autocmdOptionArgFunc(const gchar *option_name, const gchar *valu int main(int argc, char *argv[]) { - static char *winid = NULL; -#ifdef FEATURE_FIFO - static char *fifo_name = NULL; -#endif - static gboolean ver = false; + static char *winid = NULL; + static gboolean ver = false; + static gboolean dump = false; static GError *err; - char *pid; static GOptionEntry opts[] = { {"cmd", 'C', 0, G_OPTION_ARG_CALLBACK, autocmdOptionArgFunc, "Ex command run before first page is loaded", NULL}, {"config", 'c', 0, G_OPTION_ARG_FILENAME, &vb.config.file, "Custom configuration file", NULL}, {"embed", 'e', 0, G_OPTION_ARG_STRING, &winid, "Reparents to window specified by xid", NULL}, - {"kiosk", 'k', 0, G_OPTION_ARG_NONE, &vb.config.kioskmode, "Run in kiosk mode", NULL}, #ifdef FEATURE_FIFO - {"fifo-name", 'n', 0, G_OPTION_ARG_STRING, &fifo_name, "Name used to create control fifo", NULL}, + {"dump", 'd', 0, G_OPTION_ARG_NONE, &dump, "Dump the fifo path to stdout", NULL}, + {"fifo", 'f', 0, G_OPTION_ARG_NONE, &vb.config.fifo, "Create control fifo", NULL}, #endif + {"kiosk", 'k', 0, G_OPTION_ARG_NONE, &vb.config.kioskmode, "Run in kiosk mode", NULL}, {"version", 'v', 0, G_OPTION_ARG_NONE, &ver, "Print version", NULL}, {NULL} }; @@ -1600,9 +1604,8 @@ int main(int argc, char *argv[]) vb.embed = strtol(winid, NULL, 0); } - pid = g_strdup_printf("%d", (int)getpid()); - g_setenv("VIMB_PID", pid, true); - g_free(pid); + vb.state.pid_str = g_strdup_printf("%d", (int)getpid()); + g_setenv("VIMB_PID", vb.state.pid_str, true); /* init some state variable */ vb.state.enable_register = false; @@ -1631,9 +1634,15 @@ int main(int argc, char *argv[]) #ifdef FEATURE_FIFO /* setup the control fifo - quit vimb if this failed */ - if (fifo_name && *fifo_name && !io_init_fifo(fifo_name)) { + if (vb.config.fifo && !io_init_fifo(vb.state.pid_str)) { + /* cleanup memory */ + vb_cleanup(); return EXIT_FAILURE; } + if (dump && vb.state.fifo_path) { + printf("%s\n", vb.state.fifo_path); + fflush(NULL); + } #endif /* Run the main GTK+ event loop */ diff --git a/src/main.h b/src/main.h index fc84612..4c4349d 100644 --- a/src/main.h +++ b/src/main.h @@ -313,6 +313,7 @@ typedef struct { int search_matches; /* number of matches search results */ #endif char *fifo_path; /* holds the path to the control fifo */ + char *pid_str; /* holds the pid as string */ } State; typedef struct { @@ -338,6 +339,9 @@ typedef struct { float default_zoom; /* default zoomlevel that is applied on zz zoom reset */ gboolean kioskmode; gboolean input_autohide; /* indicates if the inputbox should be hidden if it's empty */ +#ifdef FEATURE_FIFO + gboolean fifo; /* indicates if the fifo is used */ +#endif #ifdef FEATURE_HSTS HSTSProvider *hsts_provider; /* the hsts session feature that is added to soup session */ #endif -- 2.20.1