The patch fixes below things:-
1. Do not call fork when arguments not present.
2. Do not call waitpid when fork returned pid as -1 from fork.
3. Corrected wrong english usage in function name by changing name
of is_rule_exists => is_rule_present.
Change-Id: Ic42233a846df91cc1b7871a52b830fd59433a970
Signed-off-by: Nishant Chaprana <n.chaprana@samsung.com>
Name: stc-manager
Summary: STC(Smart Traffic Control) manager
Name: stc-manager
Summary: STC(Smart Traffic Control) manager
Release: 0
Group: Network & Connectivity/Other
License: Apache-2.0
Release: 0
Group: Network & Connectivity/Other
License: Apache-2.0
pid_t ret_pid;
char buf[BUF_SIZE_FOR_ERR] = { 0 };
pid_t ret_pid;
char buf[BUF_SIZE_FOR_ERR] = { 0 };
+ if (!pid || pid == -1) {
STC_LOGD("no need to wait");
return;
}
STC_LOGD("no need to wait");
return;
}
ret_pid = waitpid(pid, &status, 0);
if (ret_pid < 0)
STC_LOGD("can't wait for a pid %d %d %s", pid, status,
ret_pid = waitpid(pid, &status, 0);
if (ret_pid < 0)
STC_LOGD("can't wait for a pid %d %d %s", pid, status,
-static bool is_rule_exists(const char *cmd_buf)
+static bool is_rule_present(const char *cmd_buf)
{
size_t buf_len;
char *exec_buf;
{
size_t buf_len;
char *exec_buf;
stc_error_e exec_iptables_cmd(const char *cmd_buf, pid_t *cmd_pid)
{
stc_error_e exec_iptables_cmd(const char *cmd_buf, pid_t *cmd_pid)
{
+ const size_t args_number = get_args_number(cmd_buf);
+ *cmd_pid = 0;
+
+ ret_value_msg_if(args_number == 0, STC_ERROR_FAIL, "no arguments");
+
pid_t pid = fork();
if (pid == 0) {
char *cmd;
unsigned int i;
pid_t pid = fork();
if (pid == 0) {
char *cmd;
unsigned int i;
- const size_t args_number = get_args_number(cmd_buf);
char *args[args_number + 2];
int ret;
char *save_ptr = NULL;
char *args[args_number + 2];
int ret;
char *save_ptr = NULL;
STC_LOGD("executing iptables cmd %s in forked process",
cmd_buf);
STC_LOGD("executing iptables cmd %s in forked process",
cmd_buf);
- ret_value_msg_if(args_number == 0, STC_ERROR_FAIL, "no arguments");
-
- if (is_rule_exists(cmd_buf)) {
- STC_LOGD("Rule %s already exists", cmd_buf);
+ if (is_rule_present(cmd_buf)) {
+ STC_LOGD("Rule %s already present", cmd_buf);
args[0] = "iptables";
cmd = strtok_r((char *)cmd_buf, " ", &save_ptr);
args[0] = "iptables";
cmd = strtok_r((char *)cmd_buf, " ", &save_ptr);
- ret_value_msg_if(cmd == NULL, STC_ERROR_FAIL, "no arguments");
+ if (cmd == NULL) {
+ STC_LOGE("no arguments");
+ exit(-EINVAL);
+ }
+
for (i = 1; i <= args_number; ++i)
args[i] = strtok_r(NULL, " ", &save_ptr);
for (i = 1; i <= args_number; ++i)
args[i] = strtok_r(NULL, " ", &save_ptr);
ret = execv(cmd, args);
if (ret)
STC_LOGE("Can't execute %s: %s",
ret = execv(cmd, args);
if (ret)
STC_LOGE("Can't execute %s: %s",
- cmd_buf, strerror_r(errno, buf, BUF_SIZE_FOR_ERR));
+ cmd_buf, strerror_r(errno, buf,
+ BUF_SIZE_FOR_ERR));
stc_error_e exec_ip6tables_cmd(const char *cmd_buf, pid_t *cmd_pid)
{
stc_error_e exec_ip6tables_cmd(const char *cmd_buf, pid_t *cmd_pid)
{
+ const size_t args_number = get_args_number(cmd_buf);
+ *cmd_pid = 0;
+
+ ret_value_msg_if(args_number == 0, STC_ERROR_FAIL, "no arguments");
+
pid_t pid = fork();
if (pid == 0) {
char *cmd;
unsigned int i;
pid_t pid = fork();
if (pid == 0) {
char *cmd;
unsigned int i;
- const size_t args_number = get_args_number(cmd_buf);
char *args[args_number + 2];
int ret;
char *save_ptr = NULL;
char *args[args_number + 2];
int ret;
char *save_ptr = NULL;
STC_LOGD("executing ip6tables cmd %s in forked process",
cmd_buf);
STC_LOGD("executing ip6tables cmd %s in forked process",
cmd_buf);
- ret_value_msg_if(args_number == 0, STC_ERROR_FAIL, "no arguments");
-
- if (is_rule_exists(cmd_buf)) {
- STC_LOGD("Rule %s already exists", cmd_buf);
+ if (is_rule_present(cmd_buf)) {
+ STC_LOGD("Rule %s already present", cmd_buf);
args[0] = "ip6tables";
cmd = strtok_r((char *)cmd_buf, " ", &save_ptr);
args[0] = "ip6tables";
cmd = strtok_r((char *)cmd_buf, " ", &save_ptr);
- ret_value_msg_if(cmd == NULL, STC_ERROR_FAIL, "no arguments");
+ if (cmd == NULL) {
+ STC_LOGE("no arguments");
+ exit(-EINVAL);
+ }
+
for (i = 1; i <= args_number; ++i)
args[i] = strtok_r(NULL, " ", &save_ptr);
for (i = 1; i <= args_number; ++i)
args[i] = strtok_r(NULL, " ", &save_ptr);