File-specific system command execution mapping functions.
More...
#include <regex.h>
#include <stdbool.h>
#include <stdint.h>
#include "sl.h"
Go to the source code of this file.
|
struct | lcmdset_s |
| A set of system commands to execute when a file event of a specific type and file path is triggered. More...
|
|
|
#define | LCTRIG_NEW (1 << 0) |
| Trigger bit flag for new file events.
|
|
#define | LCTRIG_MOD (1 << 1) |
| Trigger bit flag for modified file events.
|
|
#define | LCTRIG_DEL (1 << 2) |
| Trigger bit flag for deleted file events.
|
|
#define | LCTRIG_NOP (1 << 3) |
| Trigger bit flag for no operation/unmodified file events.
|
|
#define | LCTRIG_ALL (LCTRIG_NEW | LCTRIG_MOD | LCTRIG_DEL | LCTRIG_NOP) |
| Trigger bit flag for all file events.
|
|
#define | LCTOPT_TRACE (1 << 7) |
| Option bit flag for tracing command set matches by printing to stdout.
|
|
#define | LCTOPT_VERBOSE (1 << 8) |
| Option bit flag for printing commands to stdout before execution.
|
|
|
void | lcmdfree_r (struct lcmdset_s **cs) |
| Iterates and frees all memory allocated by the command set array.
|
|
struct lcmdset_s ** | lcmdparse (const char *fp) |
| Prses the provided file path and populates an array of command sets. The file must be a valid JSON file containing an array of objects. Each object must contain the following keys:
|
|
bool | lcmdmatchany (struct lcmdset_s **cs, const char *fp) |
| Checks if the provided file path matches any of the file patterns in the command set.
|
|
int | lcmdexec (struct lcmdset_s **cs, const struct inode_s *node, const struct fdset_s *fds, int flags) |
| Sequentially iterates the command set and executes the configured system commands on the provided file node if the trigger flags and file patterns match.
|
|
File-specific system command execution mapping functions.
◆ LCTOPT_TRACE
#define LCTOPT_TRACE (1 << 7) |
Option bit flag for tracing command set matches by printing to stdout.
◆ LCTOPT_VERBOSE
#define LCTOPT_VERBOSE (1 << 8) |
Option bit flag for printing commands to stdout before execution.
◆ LCTRIG_ALL
Trigger bit flag for all file events.
◆ LCTRIG_DEL
#define LCTRIG_DEL (1 << 2) |
Trigger bit flag for deleted file events.
◆ LCTRIG_MOD
#define LCTRIG_MOD (1 << 1) |
Trigger bit flag for modified file events.
◆ LCTRIG_NEW
#define LCTRIG_NEW (1 << 0) |
Trigger bit flag for new file events.
◆ LCTRIG_NOP
#define LCTRIG_NOP (1 << 3) |
Trigger bit flag for no operation/unmodified file events.
◆ lcmdexec()
Sequentially iterates the command set and executes the configured system commands on the provided file node if the trigger flags and file patterns match.
- Parameters
-
cs | The command set array to filter and execute |
node | The file node to execute on |
fds | The file descriptor set to use for stdout/stderr redirection |
flags | The trigger flags to match, see LCTRIG_* . If LCTOPT_VERBOSE is set, the commands will be printed to stdout before execution. If LCTOPT_TRACE is set, the true/false match result for each command set will be printed to stdout. |
- Returns
- 0 if successful, otherwise the first non-zero return value from
system(3)
is returned.
◆ lcmdfree_r()
Iterates and frees all memory allocated by the command set array.
- Parameters
-
cs | The command set array to free |
◆ lcmdmatchany()
bool lcmdmatchany |
( |
struct lcmdset_s ** | cs, |
|
|
const char * | fp ) |
Checks if the provided file path matches any of the file patterns in the command set.
- Parameters
-
cs | The command set array to filter |
fp | The file path to match |
- Returns
- true if the file path matches any file pattern, otherwise false
◆ lcmdparse()
struct lcmdset_s ** lcmdparse |
( |
const char * | fp | ) |
|
Prses the provided file path and populates an array of command sets. The file must be a valid JSON file containing an array of objects. Each object must contain the following keys:
on
: An array of trigger flags to match
patterns
: An array of file patterns to match
commands
: An array of system commands to execute The on
array must contain one or more of the following strings:
new
: Trigger on new files
mod
: Trigger on modified files
del
: Trigger on deleted files
nop
: Trigger on no operation The patterns
array must contain one or more strings that are used to match the file path. The commands
array must contain one or more strings that are passed to system(3)
for execution. - Parameters
-
- Returns
- An array of command sets if successful, otherwise NULL.