Fixes (eventcmd, otr4)
authorMyhailo Danylenko <isbear@ukrpost.net>
Fri, 18 Jan 2013 11:28:35 +0200
changeset 62 f5249c9544e5
parent 61 9b4f7e14c19c
child 63 d268aa028975
Fixes (eventcmd, otr4) * use-otr-v4: fix .tag file path * separate-extcmd: move SIGCHLD handler to extcmd init routine
modularize-extcmd.diff
separate-extcmd.diff
use-otr-v4.diff
--- a/modularize-extcmd.diff	Sun Jan 13 06:42:35 2013 +0200
+++ b/modularize-extcmd.diff	Fri Jan 18 11:28:35 2013 +0200
@@ -1,9 +1,9 @@
 Convert extcmd into a module
 
-diff -r d9fd111057c1 mcabber/configure.ac
---- a/mcabber/configure.ac	Thu Nov 22 00:53:15 2012 +0200
-+++ b/mcabber/configure.ac	Thu Nov 22 00:54:43 2012 +0200
-@@ -283,6 +283,7 @@
+diff -r b42512803fa8 mcabber/configure.ac
+--- a/mcabber/configure.ac	Thu Jan 17 23:44:36 2013 +0200
++++ b/mcabber/configure.ac	Thu Jan 17 23:45:05 2013 +0200
+@@ -292,6 +292,7 @@
                   modules/beep/Makefile
                   modules/xttitle/Makefile
                   modules/fifo/Makefile
@@ -11,9 +11,9 @@
                   modules/urlregex/Makefile
                   doc/Makefile
                   doc/guide/Makefile
-diff -r d9fd111057c1 mcabber/mcabber/Makefile.am
---- a/mcabber/mcabber/Makefile.am	Thu Nov 22 00:53:15 2012 +0200
-+++ b/mcabber/mcabber/Makefile.am	Thu Nov 22 00:54:43 2012 +0200
+diff -r b42512803fa8 mcabber/mcabber/Makefile.am
+--- a/mcabber/mcabber/Makefile.am	Thu Jan 17 23:44:36 2013 +0200
++++ b/mcabber/mcabber/Makefile.am	Thu Jan 17 23:45:05 2013 +0200
 @@ -7,7 +7,7 @@
  		  xmpp.c xmpp.h xmpp_helper.c xmpp_helper.h xmpp_defines.h \
  		  xmpp_iq.c xmpp_iq.h xmpp_iqrequest.c xmpp_iqrequest.h \
@@ -32,9 +32,9 @@
  endif
  
  #SUBDIRS =
-diff -r d9fd111057c1 mcabber/mcabber/hooks.c
---- a/mcabber/mcabber/hooks.c	Thu Nov 22 00:53:15 2012 +0200
-+++ b/mcabber/mcabber/hooks.c	Thu Nov 22 00:54:43 2012 +0200
+diff -r b42512803fa8 mcabber/mcabber/hooks.c
+--- a/mcabber/mcabber/hooks.c	Thu Jan 17 23:44:36 2013 +0200
++++ b/mcabber/mcabber/hooks.c	Thu Jan 17 23:45:05 2013 +0200
 @@ -36,7 +36,10 @@
  #include "utf8.h"
  #include "commands.h"
@@ -110,9 +110,9 @@
  }
  
  //  hk_presence_subscription_request(jid, message)
-diff -r d9fd111057c1 mcabber/mcabber/main.c
---- a/mcabber/mcabber/main.c	Thu Nov 22 00:53:15 2012 +0200
-+++ b/mcabber/mcabber/main.c	Thu Nov 22 00:54:43 2012 +0200
+diff -r b42512803fa8 mcabber/mcabber/main.c
+--- a/mcabber/mcabber/main.c	Thu Jan 17 23:44:36 2013 +0200
++++ b/mcabber/mcabber/main.c	Thu Jan 17 23:45:05 2013 +0200
 @@ -44,7 +44,10 @@
  #include "xmpp.h"
  #include "help.h"
@@ -125,7 +125,7 @@
  
  #ifndef MODULES_ENABLE
  # include "fifo.h"
-@@ -443,9 +446,11 @@
+@@ -426,9 +429,11 @@
    }
  #endif
  
@@ -137,15 +137,15 @@
  
    optstring = settings_opt_get("roster_display_filter");
    if (optstring)
-diff -r d9fd111057c1 mcabber/modules/Makefile.am
---- a/mcabber/modules/Makefile.am	Thu Nov 22 00:53:15 2012 +0200
-+++ b/mcabber/modules/Makefile.am	Thu Nov 22 00:54:43 2012 +0200
+diff -r b42512803fa8 mcabber/modules/Makefile.am
+--- a/mcabber/modules/Makefile.am	Thu Jan 17 23:44:36 2013 +0200
++++ b/mcabber/modules/Makefile.am	Thu Jan 17 23:45:05 2013 +0200
 @@ -1,1 +1,1 @@
 -SUBDIRS = beep xttitle fifo urlregex
 +SUBDIRS = beep xttitle fifo eventcmd urlregex
-diff -r d9fd111057c1 mcabber/modules/eventcmd/Makefile.am
+diff -r b42512803fa8 mcabber/modules/eventcmd/Makefile.am
 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
-+++ b/mcabber/modules/eventcmd/Makefile.am	Thu Nov 22 00:54:43 2012 +0200
++++ b/mcabber/modules/eventcmd/Makefile.am	Thu Jan 17 23:45:05 2013 +0200
 @@ -0,0 +1,13 @@
 +
 +if INSTALL_HEADERS
@@ -160,9 +160,9 @@
 +				$(ENCHANT_CFLAGS)
 +endif
 +
-diff -r d9fd111057c1 mcabber/modules/eventcmd/eventcmd.c
+diff -r b42512803fa8 mcabber/modules/eventcmd/eventcmd.c
 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
-+++ b/mcabber/modules/eventcmd/eventcmd.c	Thu Nov 22 00:54:43 2012 +0200
++++ b/mcabber/modules/eventcmd/eventcmd.c	Thu Jan 17 23:45:05 2013 +0200
 @@ -0,0 +1,221 @@
 +
 +/* Copyright 2009 Myhailo Danylenko
--- a/separate-extcmd.diff	Sun Jan 13 06:42:35 2013 +0200
+++ b/separate-extcmd.diff	Fri Jan 18 11:28:35 2013 +0200
@@ -1,8 +1,8 @@
 Move extcmd code from hooks
 
-diff -r c6f9fa178a53 mcabber/mcabber/Makefile.am
---- a/mcabber/mcabber/Makefile.am	Thu Nov 22 00:52:37 2012 +0200
-+++ b/mcabber/mcabber/Makefile.am	Thu Nov 22 00:53:15 2012 +0200
+diff -r 33b2d85d27dd mcabber/mcabber/Makefile.am
+--- a/mcabber/mcabber/Makefile.am	Sun Jan 13 06:17:12 2013 +0200
++++ b/mcabber/mcabber/Makefile.am	Fri Jan 18 00:10:18 2013 +0200
 @@ -7,7 +7,7 @@
  		  xmpp.c xmpp.h xmpp_helper.c xmpp_helper.h xmpp_defines.h \
  		  xmpp_iq.c xmpp_iq.h xmpp_iqrequest.c xmpp_iqrequest.h \
@@ -20,10 +20,10 @@
  			 $(top_builddir)/include/config.h
  
  if OTR
-diff -r c6f9fa178a53 mcabber/mcabber/extcmd.c
+diff -r 33b2d85d27dd mcabber/mcabber/extcmd.c
 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
-+++ b/mcabber/mcabber/extcmd.c	Thu Nov 22 00:53:15 2012 +0200
-@@ -0,0 +1,121 @@
++++ b/mcabber/mcabber/extcmd.c	Fri Jan 18 00:10:18 2013 +0200
+@@ -0,0 +1,152 @@
 +/*
 + * extcmd.c      -- External event handler command
 + *
@@ -45,10 +45,12 @@
 + * USA
 + */
 +
-+#include <stdlib.h>
-+#include <string.h>
-+#include <sys/types.h>
-+#include <unistd.h>
++#include <stdlib.h>    // mkstemp
++#include <string.h>    // strlen
++#include <signal.h>    // signal
++#include <sys/types.h> // waitpid
++#include <sys/wait.h>  // waitpid
++#include <unistd.h>    // fork, close, write, execl
 +#include <glib.h>
 +
 +#include "screen.h"
@@ -57,19 +59,48 @@
 +#include "utils.h"
 +#include "utf8.h"
 +
++#ifndef WAIT_ANY
++# define WAIT_ANY -1
++#endif
++
 +static char *extcmd = NULL;
 +
++//  ext_sig_handler()
++// SIGCHLD handler.
++// wait()s for any terminated childs (to avoid hanging zombies)
++// and beeps, if child terminates with exit code 2.
++static void ext_sig_handler(int signum)
++{
++  int status;
++  pid_t pid;
++  do {
++    pid = waitpid (WAIT_ANY, &status, WNOHANG);
++    // Check the exit status value if 'eventcmd_checkstatus' is set
++    if (settings_opt_get_int("eventcmd_checkstatus")) {
++      if (pid > 0) {
++        // exit status 2 -> beep
++        if (WIFEXITED(status) && WEXITSTATUS(status) == 2) {
++          scr_beep();
++        }
++      }
++    }
++  } while (pid > 0);
++}
++
 +//  hk_ext_cmd_init()
 +// Initialize external command variable.
 +// Can be called with parameter NULL to reset and free memory
 +void hk_ext_cmd_init(const char *command)
 +{
 +  if (extcmd) {
++    signal(SIGCHLD, SIG_DFL);
 +    g_free(extcmd);
 +    extcmd = NULL;
 +  }
-+  if (command)
++  if (command) {
++    signal(SIGCHLD, sig_handler);
 +    extcmd = expand_filename(command);
++  }
 +}
 +
 +//  hk_ext_cmd()
@@ -138,16 +169,16 @@
 +    if (execl(extcmd, extcmd, arg_type, arg_info, name, arg_data,
 +              (char *)NULL) == -1) {
 +      // scr_LogPrint(LPRINT_LOGNORM, "Cannot execute external command.");
-+      exit(1);
++      exit(EXIT_FAILURE);
 +    }
 +  }
 +  g_free(datafname);
 +}
 +
-+/* vim: set expandtab cindent cinoptions=>2\:2(0:  For Vim users... */
-diff -r c6f9fa178a53 mcabber/mcabber/extcmd.h
++/* vim: set expandtab cindent cinoptions=>2\:2(0 ts=2 sw=2:  For Vim users... */
+diff -r 33b2d85d27dd mcabber/mcabber/extcmd.h
 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
-+++ b/mcabber/mcabber/extcmd.h	Thu Nov 22 00:53:15 2012 +0200
++++ b/mcabber/mcabber/extcmd.h	Fri Jan 18 00:10:18 2013 +0200
 @@ -0,0 +1,15 @@
 +#ifndef __MCABBER_EXTCMD_H__
 +#define __MCABBER_EXTCMD_H__ 1
@@ -164,9 +195,9 @@
 +void hk_ext_cmd(const char *bjid, const char *type, const char *info, const char *data);
 +
 +#endif
-diff -r c6f9fa178a53 mcabber/mcabber/hooks.c
---- a/mcabber/mcabber/hooks.c	Thu Nov 22 00:52:37 2012 +0200
-+++ b/mcabber/mcabber/hooks.c	Thu Nov 22 00:53:15 2012 +0200
+diff -r 33b2d85d27dd mcabber/mcabber/hooks.c
+--- a/mcabber/mcabber/hooks.c	Sun Jan 13 06:17:12 2013 +0200
++++ b/mcabber/mcabber/hooks.c	Fri Jan 18 00:10:18 2013 +0200
 @@ -24,6 +24,7 @@
  #include <string.h>
  #include <sys/types.h>
@@ -433,9 +464,9 @@
 -}
 -
  /* vim: set expandtab cindent cinoptions=>2\:2(0 sw=2 ts=2:  For Vim users... */
-diff -r c6f9fa178a53 mcabber/mcabber/hooks.h
---- a/mcabber/mcabber/hooks.h	Thu Nov 22 00:52:37 2012 +0200
-+++ b/mcabber/mcabber/hooks.h	Thu Nov 22 00:53:15 2012 +0200
+diff -r 33b2d85d27dd mcabber/mcabber/hooks.h
+--- a/mcabber/mcabber/hooks.h	Sun Jan 13 06:17:12 2013 +0200
++++ b/mcabber/mcabber/hooks.h	Fri Jan 18 00:10:18 2013 +0200
 @@ -66,9 +66,6 @@
  guint hk_subscription(LmMessageSubType mstype, const gchar *bjid,
                        const gchar *msg);
@@ -446,10 +477,35 @@
  #endif /* __MCABBER_HOOKS_H__ */
  
  /* vim: set expandtab cindent cinoptions=>2\:2(0 sw=2 ts=2:  For Vim users... */
-diff -r c6f9fa178a53 mcabber/mcabber/main.c
---- a/mcabber/mcabber/main.c	Thu Nov 22 00:52:37 2012 +0200
-+++ b/mcabber/mcabber/main.c	Thu Nov 22 00:53:15 2012 +0200
-@@ -44,6 +44,7 @@
+diff -r 33b2d85d27dd mcabber/mcabber/main.c
+--- a/mcabber/mcabber/main.c	Sun Jan 13 06:17:12 2013 +0200
++++ b/mcabber/mcabber/main.c	Fri Jan 18 00:10:18 2013 +0200
+@@ -19,17 +19,15 @@
+  * USA
+  */
+ 
+-#include <stdio.h>
+-#include <stdlib.h>
+-#include <unistd.h>
+-#include <string.h>
+-#include <signal.h>
+-#include <termios.h>
+-#include <sys/types.h>
+-#include <sys/wait.h>
++#include <stdio.h>   // fprintf, fileno, fgets, puts
++#include <stdlib.h>  // exit, getenv
++#include <unistd.h>  // tcsetattr, tcgetattr, getopt
++#include <string.h>  // strchr, strlen, memset
++#include <signal.h>  // signal
++#include <termios.h> // tcsetattr, tcgetattr
+ #include <glib.h>
+ #include <config.h>
+-#include <poll.h>
++#include <poll.h>    // POLLIN, POLLERR, POLLPRI
+ 
+ #include "caps.h"
+ #include "screen.h"
+@@ -44,6 +42,7 @@
  #include "xmpp.h"
  #include "help.h"
  #include "events.h"
@@ -457,3 +513,47 @@
  
  #ifndef MODULES_ENABLE
  # include "fifo.h"
+@@ -58,10 +57,6 @@
+ # include "hgcset.h"
+ #endif
+ 
+-#ifndef WAIT_ANY
+-# define WAIT_ANY -1
+-#endif
+-
+ static unsigned int terminate_ui;
+ GMainContext *main_context;
+ 
+@@ -98,23 +93,7 @@
+ 
+ void sig_handler(int signum)
+ {
+-  if (signum == SIGCHLD) {
+-    int status;
+-    pid_t pid;
+-    do {
+-      pid = waitpid (WAIT_ANY, &status, WNOHANG);
+-      // Check the exit status value if 'eventcmd_checkstatus' is set
+-      if (settings_opt_get_int("eventcmd_checkstatus")) {
+-        if (pid > 0) {
+-          // exit status 2 -> beep
+-          if (WIFEXITED(status) && WEXITSTATUS(status) == 2) {
+-            scr_beep();
+-          }
+-        }
+-      }
+-    } while (pid > 0);
+-    signal(SIGCHLD, sig_handler);
+-  } else if (signum == SIGTERM) {
++  if (signum == SIGTERM) {
+     mcabber_terminate("Killed by SIGTERM");
+   } else if (signum == SIGINT) {
+     mcabber_terminate("Killed by SIGINT");
+@@ -332,7 +311,6 @@
+ 
+   signal(SIGTERM, sig_handler);
+   signal(SIGINT,  sig_handler);
+-  signal(SIGCHLD, sig_handler);
+ #ifdef USE_SIGWINCH
+   signal(SIGWINCH, sig_handler);
+ #endif
--- a/use-otr-v4.diff	Sun Jan 13 06:42:35 2013 +0200
+++ b/use-otr-v4.diff	Fri Jan 18 11:28:35 2013 +0200
@@ -4,7 +4,7 @@
 
 diff -r 1b31bdb72d83 mcabber/configure.ac
 --- a/mcabber/configure.ac	Sun Jan 13 04:35:32 2013 +0200
-+++ b/mcabber/configure.ac	Sun Jan 13 06:15:55 2013 +0200
++++ b/mcabber/configure.ac	Fri Jan 18 11:23:47 2013 +0200
 @@ -183,16 +183,26 @@
  
  # Check for otr
@@ -48,7 +48,7 @@
 +dnl vim: set expandtab cindent cinoptions=>2\:2(0 sw=2 ts=2:  For Vim users...
 diff -r 1b31bdb72d83 mcabber/mcabber/otr.c
 --- a/mcabber/mcabber/otr.c	Sun Jan 13 04:35:32 2013 +0200
-+++ b/mcabber/mcabber/otr.c	Sun Jan 13 06:15:55 2013 +0200
++++ b/mcabber/mcabber/otr.c	Fri Jan 18 11:23:47 2013 +0200
 @@ -56,6 +56,20 @@
                                           const char *protocol,
                                           const char *recipient,
@@ -157,7 +157,15 @@
  
  static char *otr_get_dir(void);
  
-@@ -145,6 +181,13 @@
+@@ -135,7 +171,6 @@
+   account = jidtodisp(fjid);
+   keyfile = g_strdup_printf("%s%s.key", root, account);
+   fprfile = g_strdup_printf("%s%s.fpr", root, account);
+-  g_free(root);
+ 
+   if (otrl_privkey_read(userstate, keyfile)){
+     scr_LogPrint(LPRINT_LOGNORM, "Could not read OTR key from %s", keyfile);
+@@ -145,6 +180,14 @@
      scr_LogPrint(LPRINT_LOGNORM, "Could not read OTR fingerprints from %s",
                   fprfile);
    }
@@ -168,6 +176,7 @@
 +    cb_create_instag(NULL, account, OTR_PROTOCOL_NAME);
 +  }
 +#endif
++  g_free(root);
  }
  
  void otr_terminate(void)
@@ -582,7 +591,7 @@
  {
 diff -r 1b31bdb72d83 mcabber/mcabber/otr.h
 --- a/mcabber/mcabber/otr.h	Sun Jan 13 04:35:32 2013 +0200
-+++ b/mcabber/mcabber/otr.h	Sun Jan 13 06:15:55 2013 +0200
++++ b/mcabber/mcabber/otr.h	Fri Jan 18 11:23:47 2013 +0200
 @@ -5,6 +5,9 @@
  
  #ifdef HAVE_LIBOTR