I have some bash command which I want to execute from C file:
root@/some# /sbin/iptables -t raw -I PREROUTING 5 -m set --match-set list src -j DROP
Chain PREROUTING (policy ACCEPT)
num target prot opt source destination
root@/some# echo $?
0
This works fine. When I do it from regular C file like:
int main(void) {
int ret;
ret = system("/sbin/iptables -t raw -I PREROUTING 5 -m set --match-set list src -j DROP");
printf("%d\n", ret);
}
It prints 0
, so it's okay.
But when I call this command from daemonized program (after usual daemonization process) inside pthread it returns -1
but the rule is inserted, so it works fine but for some reason system()
returns -1
. What could be a reason?
UPD: From daemon the result of a system()
call I'm writing to syslog, and it has -1
and errno - No child processes
.