gchar* buf;
buf = expand_vars(argv_idx(argv, 0));
- puts(buf); /*TODO: result?*/
+ g_string_assign(result, buf);
g_free(buf);
}
GString *result_print = g_string_new("");
c->function(uzbl.gui.web_view, a, result_print);
- if (uzbl.state.verbose)
- printf("%s returned %s\n", cmd, result_print->str);
+ if (result_print->len)
+ printf("%*s\n", result_print->len, result_print->str);
g_string_free(result_print, TRUE);
} else {
ret = g_io_channel_read_line(clientchan, &ctl_line, &len, NULL, &error);
if (ret == G_IO_STATUS_ERROR) {
- g_error ("Error reading: %s\n", error->message);
+ g_warning ("Error reading: %s\n", error->message);
+ g_io_channel_shutdown(clientchan, TRUE, &error);
return FALSE;
} else if (ret == G_IO_STATUS_EOF) {
- /* socket closed, remove channel watch from main loop */
+ /* shutdown and remove channel watch from main loop */
+ g_io_channel_shutdown(clientchan, TRUE, &error);
return FALSE;
}
if (ctl_line) {
parse_cmd_line (ctl_line, result);
+ g_string_append_c(result, '\n');
ret = g_io_channel_write_chars (clientchan, result->str, result->len,
&len, &error);
if (ret == G_IO_STATUS_ERROR) {
- g_error ("Error writing: %s", error->message);
+ g_warning ("Error writing: %s", error->message);
}
+ g_io_channel_flush(clientchan, &error);
}
+ if (error) g_error_free (error);
g_string_free(result, TRUE);
g_free(ctl_line);
return TRUE;
/* Socket code more or less completely copied from here: http://www.ecst.csuchico.edu/~beej/guide/ipc/usock.html */
#include <gtk/gtk.h>
-#include <gdk/gdkx.h>
-#include <gdk/gdkkeysyms.h>
-#include <webkit/webkit.h>
-#include <pthread.h>
#include <stdio.h>
-#include <string.h>
-#include <sys/stat.h>
-#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
-#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
if (sockpath && command) {
int s, len;
struct sockaddr_un remote;
+ char tmp;
if ((s = socket (AF_UNIX, SOCK_STREAM, 0)) == -1) {
perror ("socket");
exit (1);
}
- if (send (s, command, strlen (command), 0) == -1) {
+ if ((send (s, command, strlen (command), 0) == -1) ||
+ (send (s, "\n", 1, 0) == -1)) {
perror ("send");
exit (1);
}
+ while ((len = recv (s, &tmp, 1, 0))) {
+ putchar(tmp);
+ if (tmp == '\n')
+ break;
+ }
+
close(s);
return 0;