Hi Neo, After creating a server socket in your program, set the FD_CLOEXEC file descriptor flag on it, i.e. add something like
fcntl(sock, F_SETFD, FD_CLOEXEC); The reason why this is happening is that, on *nix, by default, when you create a child process using fork() and exec() (or system(), which is a wrapper around the these), the child will inherit all of its parent's open file descriptors. So, when you're calling "wifi" from your program, it and its children (wpa_supplicant and the rest) are inheriting your socket file descriptor and keeping it open and bound to the address/port. If, however, you set the close-on-exec flag on your file descriptor, it will be automatically closed in the child process just before the child starts executing. See the fcntl(2) man page. Regards, Aleksandar On 09/30/2010 10:09 AM, Neo Tida wrote: > Hi > > I've writen a tcp socket based program to config my Openwrt system. I > found a strange problem when my program faces a crash. If I do some > configs before a crash via my program ( It means that I change > wireless config file and run "wifi" command via my program), the port > that used by my program will capture by wpa_supplicant or hostapd > after crashing. I find it when I use "netstat -n -l -p". So it will > cause to see "Bind Failed" error when I run my program again and > prevent it to run properly without killing that process. > > It's really strange. > > Any help will be greatly appreciated. > > > _______________________________________________ > openwrt-devel mailing list > [email protected] > https://lists.openwrt.org/mailman/listinfo/openwrt-devel >
_______________________________________________ openwrt-devel mailing list [email protected] https://lists.openwrt.org/mailman/listinfo/openwrt-devel
