+int stc_commit_iptables(char *cmd, int *err_num, char **err_str)
+{
+ pid_t pid = 0;
+ int status = 0;
+ int ret = 0;
+ char err_buf[BUF_SIZE_FOR_ERR] = { 0, };
+ gchar **args = NULL;
+
+ if (cmd == NULL) {
+ STC_LOGE("Invalid arguments");
+ return STC_ERROR_INVALID_PARAMETER;
+ }
+
+ args = g_strsplit_set(cmd, " ", -1);
+
+ errno = 0;
+ pid = fork();
+
+ if (pid == 0) {
+ errno = 0;
+ if (execv(args[0], args) == -1) {
+ STC_LOGE("Failed to execute [%s]", err_str);
+ g_strfreev(args);
+ exit(-1);
+ }
+ } else if (pid > 0) {
+ if (waitpid(pid, &status, 0) == -1)
+ STC_LOGD("wait pid [%u] status [%d] ", pid, status);
+
+ if (WIFEXITED(status)) {
+ ret = WEXITSTATUS(status);
+ STC_LOGD("exited, status [%d]", status);
+ } else if (WIFSIGNALED(status)) {
+ STC_LOGD("killed by signal [%d]", WTERMSIG(status));
+ } else if (WIFSTOPPED(status)) {
+ STC_LOGD("stopped by signal [%d]", WSTOPSIG(status));
+ } else if (WIFCONTINUED(status)) {
+ STC_LOGD("continued");
+ }
+
+ *err_num = ret;
+ *err_str = strerror_r(ret, err_buf, BUF_SIZE_FOR_ERR);
+ STC_LOGD("return err_num [%d] err_str [%s]", *err_num, *err_str);
+
+ g_strfreev(args);
+ if (ret == 0)
+ return STC_ERROR_NONE;
+ else
+ return STC_ERROR_FAIL;
+ }
+
+ *err_num = errno;
+ *err_str = strerror_r(errno, err_buf, BUF_SIZE_FOR_ERR);
+ STC_LOGD("Failed to fork [%d:%s]", *err_num, *err_str);
+
+ g_strfreev(args);
+ return STC_ERROR_FAIL;
+}
+