--- irssi-0.8.10.orig/src/fe-text/irssi.c 2006-08-25 13:23:26.000000000 -0400 +++ irssi-0.8.10/src/fe-text/irssi.c 2006-08-25 14:15:22.000000000 -0400 @@ -44,6 +44,12 @@ #include #include +#include +#include +#include +#include +#include + #ifdef HAVE_STATIC_PERL void perl_core_init(void); void perl_core_deinit(void); @@ -91,6 +97,8 @@ "window creation or closing, just type: /MANUAL-WINDOWS"; static int display_firsttimer = FALSE; +int init_extint(); +void check_extint(int sd); static void sig_exit(void) { @@ -376,6 +384,7 @@ } textui_finish_init(); + int sd=init_extint(); main_loop = g_main_new(TRUE); /* Does the same as g_main_run(main_loop), except we @@ -386,6 +395,7 @@ #endif if (!dummy) term_refresh_freeze(); g_main_iteration(TRUE); + check_extint(sd); // HACK! HACK! KILL IT! =( if (!dummy) term_refresh_thaw(); if (reload_config) { @@ -403,3 +413,50 @@ session_upgrade(); /* if we /UPGRADEd, start the new process */ return 0; } + +int init_extint() { + size_t len = strlen(get_irssi_dir()) + 5; + char *filename = malloc(len); + snprintf(filename, len, "%s/cmd", get_irssi_dir()); + + int sd; + struct sockaddr_un local; + + sd = socket(AF_UNIX, SOCK_STREAM, 0); + local.sun_family = AF_UNIX; + strncpy(local.sun_path, filename, UNIX_PATH_MAX); + unlink(local.sun_path); // make sure it's not there already + len = strlen(local.sun_path) + sizeof(local.sun_family); + + // Non blocking, so the rest of the main loop will happen + fcntl(sd, F_SETFL, O_NONBLOCK); + + bind(sd, (struct sockaddr *)&local, len); + listen(sd, 5); + return sd; +} + + +void check_extint(int sd) { + int len = sizeof(struct sockaddr_un); + struct sockaddr_un remote; + int csd; + csd = accept(sd, (struct sockaddr *)&remote, &len); + if (csd < 0) + return; + + + char *line = malloc(1024); + if (line == NULL) + return; + + // gui will not be responsive during this loop. That's ok, since the client only sends one line + while ((len = recv(csd, line, 1024, 0))) { + if (len < 0) + return; + line[len]=0; // die newline! + signal_emit("send command", 3, line, active_win->active_server, active_win->active); + } + + free(line); +}