Commit graph

40 commits

Author SHA1 Message Date
Delgan
b85ba99980 Apply "clang-format" preferences globally 2024-04-07 10:05:10 +02:00
Daniel Eklöf
f2d25c8341
script: fix buffer resize bug
If the amount of data coming in is more than we can hold in our
buffer, we resized the buffer by doubling its size. However, there
were two(!) issues here:

* If this was the first resize, the buffer size was set to 1024. This
  may not be enough (i.e. there may be more than 1024 bytes to process).
* In all other cases, the buffer size was doubled. However, there is
  still no guarantee the buffer is large enough.

Fix by looping until the buffer *is* large enough.
2024-02-05 12:52:40 +01:00
Daniel Eklöf
8e4d7f04e4
module/script: path: expand ‘~’ to the user’s $HOME directory
Closes #307
2023-07-11 12:38:44 +02:00
Daniel Eklöf
e4edbd26c6
modules: change min poll interval from 500ms to 250ms 2022-12-27 13:20:31 +01:00
Daniel Eklöf
c4f820e486
module/script: poll-interval: convert value from ‘seconds’ to ‘milliseconds’ 2022-12-22 12:06:25 +01:00
Daniel Eklöf
3ca274759a
module: const:ify ‘module’ argument to module->description() 2022-12-14 12:05:17 +01:00
Daniel Eklöf
5da1cd4a38
module/script: process *all* transactions received in a single read()
When the script module received multiple transactions in a single
batch, only the first were processed. This lead to multiple,
unprocessed transactions stacking up in the receive buffer. Every time
a new transaction was received, we popped the oldest transaction from
the buffer, but never actually getting to the last one. This is
perceived as "lag" by the user, where the bar displays outdated
information.

Closes #221
2022-09-03 12:09:30 +02:00
Baptiste Daroussin
138db05d70
portability: remove unused header 2022-07-02 23:21:37 +02:00
Baptiste Daroussin
dd1280f49d
portability: add missing header for signal related functions 2022-07-02 23:21:28 +02:00
Daniel Eklöf
fd014dc33b
Don’t loop 65536 FDs, trying to close them, when fork+exec:ing
All FDs should now have the CLOEXEC flag set, and thus there’s no
longer needed to manually loop “all” possible FDs and (trying to)
close them.

Note: the alsa module (alsalib, actually) is “racy” - while booting
up, it temporarily opens the asoundrc file without CLOEXEC. If
e.g. the script module starts its script inside this window, it’ll
have a leaked FD. Not much we can do about it though :/

Closes #169
2022-03-29 18:23:55 +02:00
Daniel Eklöf
068c25d8f6
module/script: open comm-pipe + /dev/null with CLOEXEC
This ensures we don’t leak FDs when exec:ing e.g. on-click
handlers.

Note that the comm-pipe FD is *supposed* to stay open when we execing
the script. This is handled by the call to dup2(), which drops the
CLOEXEC flag. Since dup2() is called after the fork, the dup:ed FD is
never visible in the “parent” yambar process.
2022-03-29 18:22:08 +02:00
Daniel Eklöf
f166bbbf54
modules: verify: use conf_verify_unsigned() for options that should be >= 0 2021-11-15 18:17:29 +01:00
Baptiste Daroussin
26892c66b2 headers: basename is defined under libgen.h 2021-10-01 10:51:56 +02:00
Daniel Eklöf
7d3851046e
log: pull in log.{c,h} from foot 2021-08-15 11:41:12 +02:00
Daniel Eklöf
cf41d008f8
module/script: add poll-interval option
When set to a non-negative value, the script module will call the
configured script every <poll-interval> second.

In this mode, the script is expected to write one tag set and then
exit.

This is intended to simplify the implementation of scripts that would
otherwise just do a loop + sleep.

Closes #67
2021-07-04 20:23:01 +02:00
Daniel Eklöf
ed2b8c4874
modules: implement description() 2021-06-20 21:15:24 +02:00
Daniel Eklöf
60ee992a73
module/script: ‘9’ is a valid digit
The script module incorrectly rejected range tag end values containing
the digit ‘9’.

Closes #60
2021-06-19 14:19:31 +02:00
Daniel Eklöf
264c051232
module/script: fix typo in memcmp()
Patch by Jan Beich
2021-02-10 16:15:49 +01:00
Daniel Eklöf
f438ad9b44
module/script: send SIGINT, SIGTERM, SIGKILL, until child has died 2020-11-25 20:41:10 +01:00
Daniel Eklöf
ba54e709ee
module/script: no need to handle SIGCHLD
Assume that a closed pipe means the child died. Even if it hasn’t, we
can’t read anymore from it. We’ll end up killing it anyway before
returning from run().
2020-11-25 20:41:10 +01:00
Daniel Eklöf
e0169d38f3
module/script: don’t re-direct stderr to /dev/null 2020-11-25 20:41:10 +01:00
Daniel Eklöf
aa34925f54
module/script: close all unrelated FDs
While most FDs are CLOEXEC, not all are. For example, other script
modules’ re-direction pipes.
2020-11-25 20:41:10 +01:00
Daniel Eklöf
31f6a4a6a0
module/script: don’t re-close comm-pipe on failure 2020-11-25 20:41:10 +01:00
Daniel Eklöf
74754b0ab9
module/script: improved verification of tag type parameters and tag values
* Verify int/float/bool values are that, and nothing else
* Verify tag ranges are integers
* Verify a range tag value is inside its range
* Don’t allow anything but false|true for booleans
2020-11-25 20:41:09 +01:00
Daniel Eklöf
f0a34d0055
module/script: parse booleans correctly
User is expected to send ‘false’ or ‘true’. But we were parsing the
value using `strtol()`. This caused all bools to be false, since
`strtol()` would always return 0.
2020-11-25 20:36:46 +01:00
Daniel Eklöf
2bb70c6fcb
module/script: require ‘path’ to be an absolute path 2020-11-25 20:36:46 +01:00
Daniel Eklöf
5c9030129d
module/script: use NULL terminated ‘value’ when converting to int/bool/float 2020-11-25 20:36:46 +01:00
Daniel Eklöf
37447cd955
module/script: initialize string tags from our NULL-terminated ‘value’
`_value` is a pointer into the receive buffer, and may not be NULL
terminated, and may also contain data belonging to the next tag.
2020-11-25 20:36:46 +01:00
Daniel Eklöf
9945fce2d2
module/script: explicitly ignore return value of write(3) 2020-11-25 20:36:45 +01:00
Daniel Eklöf
7f1ffd126b
module/script: close script communication pipe FD on error 2020-11-25 20:36:45 +01:00
Daniel Eklöf
fb0d443e1d
module/script: plug memory leak: free ‘tags’ array 2020-11-25 20:36:45 +01:00
Daniel Eklöf
73407853e4
module/script: can’t use logical OR when building a base 10 number 2020-11-25 20:36:45 +01:00
Daniel Eklöf
08bac77907
module/script: script arguments
Add new config attribute, ‘args’. This is a list of strings, that will
be passed as arguments to the script.
2020-11-25 20:36:45 +01:00
Daniel Eklöf
8702378c74
module/script: restore signal handlers and mask in child process
This fixes the issue where `killpg()` didn’t manage to kill the
sub-process tree.
2020-11-25 20:36:45 +01:00
Daniel Eklöf
c911d20e73
module/script: add debug logging of raw received data 2020-11-25 20:36:45 +01:00
Daniel Eklöf
f2814f786e
module/script: copy ‘value’ to a NULL-terminated string
This ensures e.g. strtol() doesn’t parse data beyond current
tag/value.
2020-11-25 20:36:45 +01:00
Daniel Eklöf
430e505bd2
module/script: remove debug output that wasn’t actually using LOG_DBG() 2020-11-25 20:36:44 +01:00
Daniel Eklöf
fbaa208768
module/script: disable debug output 2020-11-25 20:36:44 +01:00
Daniel Eklöf
80d0025e64
module/script: drop setsid() call 2020-11-25 20:36:44 +01:00
Daniel Eklöf
19fe2f5a6f
module/script: wip: new plugin, reads data from a user provided script/binary
This module exec’s a script (or binary), specified by the ‘path’
attribute in the configuration.

It then reads tags from the script’s stdout.

The format of the output is:

  tag|type|value
  tag|type|value
  <empty line>

I.e. the script writes N tags followed by an empty  line. This
constitutes a transaction.

When a new transaction is received, its tags replaces *all* previous
tags.
2020-11-25 20:36:44 +01:00