Summary:ASTERISK-18207: externnotify script called with (null) context parameter during pollmessages run, essentially stopping it from running.
Reporter:Barry L. Kline (blkline)Labels:
Date Opened:2011-07-28 17:02:08Date Closed:2013-06-10 16:28:11
Versions: Frequency of
Environment:CentOS5.6, Asterisk 1.8.5, IMAP voicemail storage.Attachments:( 0) patch-20130306
Description:The documentation for Voicemail notes that the externnotify script will be called whenever a voicemail message is left.  Provided that pollmailboxes is set to 'yes' and pollfreq is non-zero.  I have been unable to get the script to run when I've listened to the voicemail message via an email client.

With debug sent to the messages log and turning on debug, I note:
[asterisk@crpsvvoip001 asterisk]$ tail -f /var/log/asterisk/messages -n500 | grep mwi.pl
[Jul 28 17:45:41] DEBUG[17349] app_voicemail.c: Executing /opt/asterisk/bin/mwi.pl (null) 134@VREC 0 3 0 &
[Jul 28 17:46:02] DEBUG[17358] app_voicemail.c: Executing /opt/asterisk/bin/mwi.pl VREC 134 1 3 0 &
[Jul 28 17:46:11] DEBUG[17354] app_voicemail.c: Executing /opt/asterisk/bin/mwi.pl (null) 134@VREC 1 3 0 &
[Jul 28 17:47:11] DEBUG[17354] app_voicemail.c: Executing /opt/asterisk/bin/mwi.pl (null) 134@VREC 0 4 0 &
[Jul 28 17:47:41] DEBUG[17354] app_voicemail.c: Executing /opt/asterisk/bin/mwi.pl (null) 134@VREC 0 0 0 &

The only time the parameters will called with the correct order was when the message was left.  The times where is was called from the polling routine is incorrect and causes the script to be ignored.

To perhaps make clearer what I'm trying to convey, the problem is like this:

* A voicemail is left in a mailbox, in this case 134.

* Asterisk executes properly the mwi script:
    [Jul 28 17:46:02] DEBUG[17358] app_voicemail.c: Executing /opt/asterisk/bin/mwi.pl VREC 134 1 3 0 &

* The voicemail is listened to (doesn't matter how)

* Asterisk then executes the mwi script:
     app_voicemail.c: Executing /opt/asterisk/bin/mwi.pl (null) 134@VREC 0 3 0 &

* Because of the (null) the script will not be executed by the shell.
Comments:By: Barry L. Kline (blkline) 2011-07-28 18:10:32.428-0500

I can see where its coming from:

static void poll_subscribed_mailbox(struct mwi_sub *mwi_sub)
  int new = 0, old = 0, urgent = 0;

  inboxcount2(mwi_sub->mailbox, &urgent, &new, &old);

  if (urgent != mwi_sub->old_urgent || new != mwi_sub->old_new || old != mwi_sub->old_old) {
     mwi_sub->old_urgent = urgent;
     mwi_sub->old_new = new;
     mwi_sub->old_old = old;
     queue_mwi_event(mwi_sub->mailbox, urgent, new, old);
     run_externnotify(NULL, mwi_sub->mailbox, NULL);

By: Karsten Wemheuer (kwemheuer) 2013-03-06 11:57:49.507-0600


I stumbled into the same issue and created a patch (See attached patch-20130306).
The message in the log is printed, because "poll_subscribed_mailbox" calls {code}run_externnotify(NULL, mwi_sub->mailbox, NULL);{code}
In all other cases the first parameter is not NULL.
This NULL parameter leads to the text "(null)" in the logging. Directly behind the logging there is a call to "ast_safe_system". The string in the log is used as parameter „s“ for a shell in „ast_safe_system“:{code}execl("/bin/sh", "/bin/sh", "-c", s, (char *) NULL);{code}
The external script is not executed because the shell command is broken.

The attached patch sets an empty parameter in the call to the external script. In my case the logging is changed from {code}Executing /usr/bin/voicemail_notify (null) 289@default 0 2 0 &{code} to {code}Executing /usr/bin/voicemail_notify "" 289@default 0 2 0 &{code}

The patch works for asterisk 1.8 (trunk)

By: Karsten Wemheuer (kwemheuer) 2013-03-06 11:58:44.637-0600

Patch to avoid the (null) in the shell command

By: Matt Jordan (mjordan) 2013-03-07 11:41:20.495-0600

Thanks for the patch!

By: Jonathan Rose (jrose) 2013-03-29 11:16:46.383-0500

This definitely looks like the correct thing to do, but I'm going to have it not use the if statement and instead just use S_OR for the context argument like so:

S_OR(context, "\"\"")

Thanks for the patch. I'll commit the modified version shortly.