• 10 dec 2017: forum version update. In case of issues use this topic.
  • 30 nov 2017: pilight moved servers. In case of issues use this topic.
Hello There, Guest! Login Register


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
action arguments not being checked at startup
#1
Today I created my first lua action.

During testing I noticed that when mandatory arguments are omitted in the rule, the daemon started without error any message.

To make sure  that this was not caused by an error in the action I made myself, I added a rule with a standard "toggle" action without providing the mandatory "BETWEEN" argument and even without defining the "test" device in the config.

Code:
 "rule": "IF (dt.second % 5) == 0 THEN toggle DEVICE test",
 "active": 1

As  shown, the BETWEEN argument is omitted, but the daemon starts and keeps running despite this error.
 
Reply
#2
Nice catch.

...and fixed.
 
Reply
#3
I can confirm that the arguments check itself is OK now.

When I was testing this by removing an argument from my rule, I got a segfault Apparently this occurs when a rule has a (bogus) space at the end of the line:

Code:
"IF (dt.second % 5) == 0 THEN write TO /home/pi/test.txt TEXT DATE_FORMAT(dt, \"%H%M%S\") ",

Then I get a parsing error:
Code:
... DATE_FORMAT(dt, "%H%M%S")
                             ^ unexpected symbol, expected an action argument

and then after the common garbage collection messages it segfaults:

Code:
DEBUG: garbage collected log library

Program received signal SIGSEGV, Segmentation fault.
__wcslen (s=0xa0 <error: Cannot access memory at address 0xa0>, s@entry=0x0) at wcslen.c:31
31      wcslen.c: Bestand of map bestaat niet.
(gdb) backtrace
#0  __wcslen (s=0xa0 <error: Cannot access memory at address 0xa0>, s@entry=0x0) at wcslen.c:31
#1  0x7641482c in __wcsrtombs (dst=0x0, src=src@entry=0x7effdd08, len=<optimized out>, ps=ps@entry=0x7effdd0c) at wcsrtombs.c:68
#2  0x763d457c in printf_positional (s=s@entry=0x7effe668,
   format=format@entry=0x4ac10 "ERROR: \n... DATE_FORMAT(dt, \"%H%M%S\")  \n", ' ' <repeats 30 times>, "^ unexpected symbol, expected an action argument", readonly_format=0, ap=...,
   ap_savep=<optimized out>, ap_savep@entry=0x7effe214, done=<optimized out>, done@entry=29, nspecs_done=2, nspecs_done@entry=0, lead_str_end=<optimized out>,
   work_buffer=<optimized out>, work_buffer@entry=0x7effe250 "", save_errno=<optimized out>, grouping=<optimized out>, thousands_sep=<optimized out>) at vfprintf.c:2028
#3  0x763d4c64 in _IO_vfprintf_internal (s=s@entry=0x7effe668,
   format=format@entry=0x4ac10 "ERROR: \n... DATE_FORMAT(dt, \"%H%M%S\")  \n", ' ' <repeats 30 times>, "^ unexpected symbol, expected an action argument", ap=..., ap@entry=...)
   at vfprintf.c:1682
#4  0x763f3274 in __IO_vsprintf (string=0x7effe8f1 "ERROR: \n... DATE_FORMAT(dt, \"%H%M",
   format=0x4ac10 "ERROR: \n... DATE_FORMAT(dt, \"%H%M%S\")  \n", ' ' <repeats 30 times>, "^ unexpected symbol, expected an action argument", args=...) at iovsprintf.c:42
#5  0x767da68c in logerror (format_str=0x4ac10 "ERROR: \n... DATE_FORMAT(dt, \"%H%M%S\")  \n", ' ' <repeats 30 times>, "^ unexpected symbol, expected an action argument")
   at /home/pi/pilight/libs/pilight/core/log.c:507
#6  0x767d9150 in log_gc () at /home/pi/pilight/libs/pilight/core/log.c:120
#7  0x0001a9c0 in main_gc () at /home/pi/pilight/daemon.c:2550
#8  0x0001cca0 in start_pilight (argc=2, argv=0x7efff7a4) at /home/pi/pilight/daemon.c:3336
#9  0x0001ccf8 in main (argc=2, argv=0x7efff7a4) at /home/pi/pilight/daemon.c:3504
(gdb
 
Reply
#4
I can't confirm this using my default staging installation.
 
Reply
#5
Did some more testing and it appears that the segfault occurs if a rule has a function at the end followed by a bogus space:

Code:
IF (dt.second % 5) == 0 THEN label DEVICE testlabel TO DATE_FORMAT(dt, \"%H%M%S\") "
 
Reply
#6
Can you post your new lua action and the config you're using?
 
Reply
#7
Attached the config and the write action I have been testing with.

But the  issue is not related to that action, because:

- if I don't install the write action, the segfault still occurs
- the daemon doesn't even get to parsing the writetest rule, because it already segfaults when initially parsing the segfaulttest rule  with the bogus space at the end.

If I remove that space and write.lua has been installed in the proper directory, pilight starts.

BUT... and this I found out after my previous posts,  if the segfult rule is really being executed for the first time I get a different segfault:

Code:
[ Jul 01 17:13:50:79953] pilight-daemon: DEBUG: rule #1 segfaulttest was parsed in 0.001236 seconds
Thread 11 "pilight-daemon" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x712da470 (LWP 23486)]
__GI_strcmp (p1=<optimized out>, p2=<optimized out>) at strcmp.c:38
38      strcmp.c: Bestand of map bestaat niet.
(gdb) backtrace
#0  __GI_strcmp (p1=<optimized out>, p2=<optimized out>) at strcmp.c:38
#1  0x000163f0 in control_device (dev=0x45c40, state=0x0, values=0x73e005c0,
    origin=NODE) at /home/pi/pilight/daemon.c:1135
#2  0x00016754 in control_device1 (reason=1, param=0x73e005a0)
    at /home/pi/pilight/daemon.c:1190
#3  0x767ca088 in fib (req=0x49dc8)
    at /home/pi/pilight/libs/pilight/core/eventpool.c:126
#4  0x76795ff4 in uv__queue_work (w=0x49df4)
    at /home/pi/pilight/libs/libuv/threadpool.c:301
#5  0x767954b4 in worker (arg=0x46f78)
    at /home/pi/pilight/libs/libuv/threadpool.c:104
#6  0x766bdfc4 in start_thread (arg=0x712da470) at pthread_create.c:335
#7  0x76465c68 in ?? () at ../sysdeps/unix/sysv/linux/arm/clone.S:76
   from /lib/arm-linux-gnueabihf/libc.so.6
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
(gdb)

Possibly the parser doesn't handle actions with a function at the end of the rule properly?


Attached Files
.zip   config.zip (Size: 831 bytes / Downloads: 3)
.zip   write.zip (Size: 1.16 KB / Downloads: 2)
 
Reply
#8
I found the bug when executing the rule. I can't replicate the validation bug. But, maybe both errors were triggered by the same bug.

PS. the write action looks nice. Great to see you using Lua functionality in a pilight action. Also check the pilight.common.explode function instead of your split implementation.
 
Reply
#9
OK, thanks. I will test asap and I will look at pilight.common.explode too.
 
Reply
#10
The lua actions are the last addition for a new version, so if you can confirm there are no more issues i will create a new release.
 
Reply
  


Possibly Related Threads...
Thread Author Replies Views Last Post
  Enhanced lua label action Niek 5 530 07-04-2018, 05:28 PM
Last Post: curlymo
  IP addresses not accepted as option value for an action Niek 4 514 06-25-2018, 01:59 PM
Last Post: Niek

Forum Jump:


Browsing: 1 Guest(s)