-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.cpp
More file actions
37 lines (29 loc) · 871 Bytes
/
util.cpp
File metadata and controls
37 lines (29 loc) · 871 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//
// Created by amoncusir on 06/10/23.
//
#include "util.h"
#include "ubus.h"
#include <stdexcept>
#include <unistd.h>
namespace Logtrigger
{
void run_and_forget_script(const char* script_path, const ubus_log_event& event)
{
pid_t pid = fork();
if (pid == -1)
{
throw std::runtime_error("Error when try to fork. Code: -1");
}
else if (pid == 0)
{
//child
std::string command {script_path};
command += ' ' + std::to_string(event.id);
command += ' ' + std::to_string(event.priority);
command += ' ' + std::to_string(event.source);
command += ' ' + std::to_string(event.time);
command += " '" + std::string {event.data} + '\'';
execl("/bin/sh", "sh", "-c", command.c_str(), nullptr);
}
}
}