[Home]

Summary:ASTERISK-11163: app_system() sets SYSTEMSTATUS randomly not dependant on the return result of the linux system call
Reporter:dave cantera (dcantera)Labels:
Date Opened:2008-01-05 19:48:24.000-0600Date Closed:2011-06-07 14:03:16
Priority:MajorRegression?No
Status:Closed/CompleteComponents:Applications/app_system
Versions:Frequency of
Occurrence
Related
Issues:
Environment:Attachments:
Description:System() sets SYSTEMSTATUS to random values of SUCCESS or APPERROR on sequential tests w/o any other changes to the dialplan or configuration...

the scenario is call screening.  in sounds/callerannounce directory, we store a file containing a .gsm recording.  the filename is the CALLERID(num).gsm.  when a call starts we check for the existance of the file. if the file exists, we connect to the extension.  if the file does not exist, we ask the caller to record his/her name and store it in the sounds/callscreen directory. we tried the STAT() call and it did not stat the file correctly so we went for the System() and used the Linux stat command.  the * system() did not fair any better.  here is the output of three sequential tests...

dialplan segment
----------------

;; use the STAT command when the bug is fixed, until then use Linux stat() w/ * System()
exten => s,n,NoOp(DEBUG:  (before) system() set as   ${SYSTEMSTATUS})
exten => s,n,System(stat -c '%b'  -f ${SCREEN_FILE})
exten => s,n,NoOp(DEBUG:  (after)  system() returned ${SYSTEMSTATUS})
exten => s,n,System(stat -f ${SCREEN_FILE})
exten => s,n,NoOp(DEBUG:  (after)  system() returned ${SYSTEMSTATUS})
exten => s,n,GotoIf($[ ${SYSTEMSTATUS} = APPERROR ]?s,record-announcement:s,I-know-them)
exten => s,n(record-announcement),Swift(At the tone)
exten => s,n,Swift(Please tell me who is calling.)
exten => s,n,Record(${SCREEN_FILE}.gsm|2|4)
exten => s,n,Goto(s,connect-call)
exten => s,n(I-know-them),Playback(${SCREEN_FILE}|2|4)
exten => s,n(connect-call),Playback(pls-wait-connect-call)








test sequence #1

run one: callerid(num).gsm does not exist (works as expected asks to record)
-------------------------------------------------------------
   -- Executing [s@custom-screen:3] Set("Zap/4-1", "SCREEN_FILE=/var/lib/asterisk/sounds/callerannounce/5202") in new stack
   -- Executing [s@custom-screen:4] Set("Zap/4-1", "TMPFILE=/var/lib/asterisk/sounds/callerannounce/5202.gsm") in new stack
   -- Executing [s@custom-screen:5] NoOp("Zap/4-1", "DEBUG:  (before) system() set as   ") in new stack
   -- Executing [s@custom-screen:6] System("Zap/4-1", "stat -c %b  -f /var/lib/asterisk/sounds/callerannounce/5202") in new stack
   -- Executing [s@custom-screen:7] NoOp("Zap/4-1", "DEBUG:  (after)  system() returned APPERROR") in new stack
   -- Executing [s@custom-screen:8] System("Zap/4-1", "stat -f /var/lib/asterisk/sounds/callerannounce/5202") in new stack
   -- Executing [s@custom-screen:9] NoOp("Zap/4-1", "DEBUG:  (after)  system() returned APPERROR") in new stack
   -- Executing [s@custom-screen:10] GotoIf("Zap/4-1", "1?s|record-announcement:s|I-know-them") in new stack
   -- Goto (custom-screen,s,11)

run two: callerid(num).gsm does exist (works as expected found file)
----------------------------------------------------------
   -- Executing [s@custom-screen:3] Set("Zap/4-1", "SCREEN_FILE=/var/lib/asterisk/sounds/callerannounce/5202") in new stack
   -- Executing [s@custom-screen:4] Set("Zap/4-1", "TMPFILE=/var/lib/asterisk/sounds/callerannounce/5202.gsm") in new stack
   -- Executing [s@custom-screen:5] NoOp("Zap/4-1", "DEBUG:  (before) system() set as   ") in new stack
   -- Executing [s@custom-screen:6] System("Zap/4-1", "stat -c %b  -f /var/lib/asterisk/sounds/callerannounce/5202") in new stack
   -- Executing [s@custom-screen:7] NoOp("Zap/4-1", "DEBUG:  (after)  system() returned APPERROR") in new stack
   -- Executing [s@custom-screen:8] System("Zap/4-1", "stat -f /var/lib/asterisk/sounds/callerannounce/5202") in new stack
   -- Executing [s@custom-screen:9] NoOp("Zap/4-1", "DEBUG:  (after)  system() returned SUCCESS") in new stack
   -- Executing [s@custom-screen:10] GotoIf("Zap/4-1", "0?s|record-announcement:s|I-know-them") in new stack
   -- Goto (custom-screen,s,15)


run three: callerid(num).gsm does exist (does not work as expected, can't find file)
-------------------------------------------------------------------
   -- Executing [s@custom-screen:3] Set("Zap/4-1", "SCREEN_FILE=/var/lib/asterisk/sounds/callerannounce/5202") in new stack
   -- Executing [s@custom-screen:4] Set("Zap/4-1", "TMPFILE=/var/lib/asterisk/sounds/callerannounce/5202.gsm") in new stack
   -- Executing [s@custom-screen:5] NoOp("Zap/4-1", "DEBUG:  (before) system() set as   ") in new stack
   -- Executing [s@custom-screen:6] System("Zap/4-1", "stat -c %b  -f /var/lib/asterisk/sounds/callerannounce/5202") in new stack
   -- Executing [s@custom-screen:7] NoOp("Zap/4-1", "DEBUG:  (after)  system() returned APPERROR") in new stack
   -- Executing [s@custom-screen:8] System("Zap/4-1", "stat -f /var/lib/asterisk/sounds/callerannounce/5202") in new stack
   -- Executing [s@custom-screen:9] NoOp("Zap/4-1", "DEBUG:  (after)  system() returned APPERROR") in new stack
   -- Executing [s@custom-screen:10] GotoIf("Zap/4-1", "1?s|record-announcement:s|I-know-them") in new stack
   -- Goto (custom-screen,s,11)
   -- Executing [s@custom-screen:11] Swift("Zap/4-1", "At the tone") in new stack
   -- Executing [s@custom-screen:12] Swift("Zap/4-1", "Please tell me who is calling.") in new stack


run four:  callerid(num).gsm does exist (works as expected, file is found)
-----------------------------------------------------------
   -- Executing [s@custom-screen:3] Set("Zap/4-1", "SCREEN_FILE=/var/lib/asterisk/sounds/callerannounce/5202") in new stack
   -- Executing [s@custom-screen:4] Set("Zap/4-1", "TMPFILE=/var/lib/asterisk/sounds/callerannounce/5202.gsm") in new stack
   -- Executing [s@custom-screen:5] NoOp("Zap/4-1", "DEBUG:  (before) system() set as   ") in new stack
   -- Executing [s@custom-screen:6] System("Zap/4-1", "stat -c %b  -f /var/lib/asterisk/sounds/callerannounce/5202") in new stack
   -- Executing [s@custom-screen:7] NoOp("Zap/4-1", "DEBUG:  (after)  system() returned APPERROR") in new stack
   -- Executing [s@custom-screen:8] System("Zap/4-1", "stat -f /var/lib/asterisk/sounds/callerannounce/5202") in new stack
   -- Executing [s@custom-screen:9] NoOp("Zap/4-1", "DEBUG:  (after)  system() returned SUCCESS") in new stack
   -- Executing [s@custom-screen:10] GotoIf("Zap/4-1", "0?s|record-announcement:s|I-know-them") in new stack
   -- Goto (custom-screen,s,15)
   -- Executing [s@custom-screen:15] Playback("Zap/4-1", "/var/lib/asterisk/sounds/callerannounce/5202|2|4") in new stack
   -- <Zap/4-1> Playing '/var/lib/asterisk/sounds/callerannounce/5202' (language 'en')


run five:  callerid(num) does exist (worked as expected)
--------------------------------------------------------
yadda,

run six:  callerid(num) does exist (worked as expected)
-------------------------------------------------------
yadda

on test sequence #2
I'll spare the details
run one, two, three, four found the file
run five,six could not find the file


Comments:By: Tilghman Lesher (tilghman) 2008-01-07 10:28:32.000-0600

I have no idea what you think you're doing:

1) stat from System doesn't return a value
2) stat -f checks the filesystem status, not the file status
3) You haven't adequately explained why STAT() is deficient.

By: dave cantera (dcantera) 2008-01-07 11:48:50.000-0600

ok, perhaps I do not understand the function System()...  stat -f isn't the issue.  System(stat(...)) returned a floating value under the same condition with multiple runs...  lets try this example.

dialplan and output below.
file /etc/motd exists, system(stat()) returns success
file /etc/motd.shit does not exist, system(stat()) returns succees
file /etc/motd exists, options for stat are invalid system(stat()) returns APPERROR

;
exten => 103,n,NoOp(---------)
exten => 103,n,Set(SCREEN_FILE=/etc/motd)
exten => 103,n,NoOp(DEBUG:   SCREEN_FILE=${SCREEN_FILE})
exten => 103,n,System(stat -t -c '%s' ${SCREEN_FILE})
exten => 103,n,NoOp(DEBUG:  (after)  system() returned SYSTEMSTATUS=${SYSTEMSTATUS})
exten => 103,n,NoOp(---------)
exten => 103,n,Set(SCREEN_FILE=/etc/motd.shit)
exten => 103,n,NoOp(DEBUG:   SCREEN_FILE=${SCREEN_FILE})
exten => 103,n,System(stat -t -c '%s' ${SCREEN_FILE})
exten => 103,n,NoOp(DEBUG:  (after)  system() returned SYSTEMSTATUS=${SYSTEMSTATUS})
exten => 103,n,NoOp(---------)
exten => 103,n,System(stat -t -s '%s' ${SCREEN_FILE})
exten => 103,n,NoOp(DEBUG:  (after)  system() returned ${SYSTEMSTATUS})
exten => 103,n,Set(RESULT=${System(stat -t -c '%s' ${SCREEN_FILE})})
exten => 103,n,NoOp(DEBUG:  (after)  set(system()) returned RESULT=${RESULT})
exten => 103,n,NoOp(---------)
;exten => 103,n,GotoIf($[ ${SYSTEMSTATUS} = APPERROR ]?s,record-announcement:s,I-know-them)
;

   -- Executing [103@local-sip:15] NoOp("SIP/300-08a1dcb0", "---------") in new stack
   -- Executing [103@local-sip:16] Set("SIP/300-08a1dcb0", "SCREEN_FILE=/etc/motd") in new stack
   -- Executing [103@local-sip:17] NoOp("SIP/300-08a1dcb0", "DEBUG:   SCREEN_FILE=/etc/motd") in new stack
   -- Executing [103@local-sip:18] System("SIP/300-08a1dcb0", "stat -t -c %s /etc/motd") in new stack
   -- Executing [103@local-sip:19] NoOp("SIP/300-08a1dcb0", "DEBUG:  (after)  system() returned SYSTEMSTATUS=SUCCESS") in new stack
   -- Executing [103@local-sip:20] NoOp("SIP/300-08a1dcb0", "---------") in new stack
   -- Executing [103@local-sip:21] Set("SIP/300-08a1dcb0", "SCREEN_FILE=/etc/motd.shit") in new stack
   -- Executing [103@local-sip:22] NoOp("SIP/300-08a1dcb0", "DEBUG:   SCREEN_FILE=/etc/motd.shit") in new stack
   -- Executing [103@local-sip:23] System("SIP/300-08a1dcb0", "stat -t -c %s /etc/motd.shit") in new stack
   -- Executing [103@local-sip:24] NoOp("SIP/300-08a1dcb0", "DEBUG:  (after)  system() returned SYSTEMSTATUS=SUCCESS") in new stack
   -- Executing [103@local-sip:25] NoOp("SIP/300-08a1dcb0", "---------") in new stack
   -- Executing [103@local-sip:26] System("SIP/300-08a1dcb0", "stat -t -s %s /etc/motd.shit") in new stack
   -- Executing [103@local-sip:27] NoOp("SIP/300-08a1dcb0", "DEBUG:  (after)  system() returned APPERROR") in new stack
[Jan  7 12:24:47] ERROR[840]: pbx.c:1523 ast_func_read: Function System not registered
   -- Executing [103@local-sip:28] Set("SIP/300-08a1dcb0", "RESULT=") in new stack
   -- Executing [103@local-sip:29] NoOp("SIP/300-08a1dcb0", "DEBUG:  (after)  set(system()) returned RESULT=") in new stack
   -- Executing [103@local-sip:30] NoOp("SIP/300-08a1dcb0", "---------") in new stack


what is the purpose of having functions [system()] that always returns success?  I don't understand???

-and-
exten => 103,n,Set(RESULT=System(stat -t -c '%s' ${SCREEN_FILE}))
sets RESULT="System(stat -t -c '%s' ${SCREEN_FILE})"   straight text?!?

-and-
exten => 103,n,Set(RESULT=${System(stat -t -c '%s' ${SCREEN_FILE})})
sets RESULT=""     blank?!?
   -- Executing [103@local-sip:28] Set("SIP/300-08a1dcb0", "RESULT=") in new stack
   -- Executing [103@local-sip:29] NoOp("SIP/300-08a1dcb0", "DEBUG:  (after)  set(system()) returned RESULT=") in new stack


a) what is the purpose of system() or STAT() if it always returns success
b) how do you get a value/result back into the dialplan from functions system/stat/... ???
thanks,
daveC

By: Tilghman Lesher (tilghman) 2008-01-07 11:54:49.000-0600

The purpose of the System call is to EXECUTE a command, not to get output.  Please use the STAT() dialplan function, as in:

GotoIf($[0${STAT(f,/etc/motd)}]?exists:dne)

By: Tilghman Lesher (tilghman) 2008-01-08 15:28:25.000-0600

I think it's fairly clear that this was a misunderstanding of what the System command does.  Please come see a bug marshal on #asterisk-bugs on the Freenode network if you disagree, and we'll see if we can come to a better resolution.