forked from sonic-net/sonic-swss
-
Notifications
You must be signed in to change notification settings - Fork 0
/
shellcmd.h
32 lines (27 loc) · 1 KB
/
shellcmd.h
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
#ifndef __SHELLCMD__
#define __SHELLCMD__
#include <iomanip>
#include <regex>
#define IP_CMD "/sbin/ip"
#define BRIDGE_CMD "/sbin/bridge"
#define BRCTL_CMD "/sbin/brctl"
#define ECHO_CMD "/bin/echo"
#define BASH_CMD "/bin/bash"
#define GREP_CMD "/bin/grep"
#define TEAMD_CMD "/usr/bin/teamd"
#define TEAMDCTL_CMD "/usr/bin/teamdctl"
#define IPTABLES_CMD "/sbin/iptables"
#define CONNTRACK_CMD "/usr/sbin/conntrack"
#define EXEC_WITH_ERROR_THROW(cmd, res) ({ \
int ret = swss::exec(cmd, res); \
if (ret != 0) \
{ \
throw runtime_error(cmd + " : " + res); \
} \
})
static inline std::string shellquote(const std::string& str)
{
static const std::regex re("([$`\"\\\n])");
return "\"" + std::regex_replace(str, re, "\\$1") + "\"";
}
#endif /* __SHELLCMD__ */