#include <sys/socket.h>
#include <sys/un.h>
#include <unistd.h>
+#include <fcntl.h>
#define _GNU_SOURCE
#include <poll.h>
#include <errno.h>
+#include <sys/ioctl.h>
+#include <net/if.h>
#include <glib.h>
return -1;
}
+gboolean _ws_util_execute_file(const char *file_path,
+ char *const args[], char *const envs[])
+{
+ pid_t pid = 0;
+ int rv = 0;
+ errno = 0;
+ register unsigned int index = 0;
+
+ while (args[index] != NULL) {
+ WDP_LOGD("[%s]", args[index]);
+ index++;
+ }
+
+ if (!(pid = fork())) {
+ WDP_LOGD("pid(%d), ppid(%d)", getpid(), getppid());
+ WDP_LOGD("Inside child, exec (%s) command", file_path);
+
+ errno = 0;
+ if (execve(file_path, args, envs) == -1) {
+ WDP_LOGE("Fail to execute command (%s)", strerror(errno));
+ exit(1);
+ }
+ } else if (pid > 0) {
+ if (waitpid(pid, &rv, 0) == -1)
+ WDP_LOGD("wait pid (%u) rv (%d)", pid, rv);
+ if (WIFEXITED(rv)) {
+ WDP_LOGD("exited, rv=%d", WEXITSTATUS(rv));
+ } else if (WIFSIGNALED(rv)) {
+ WDP_LOGD("killed by signal %d", WTERMSIG(rv));
+ } else if (WIFSTOPPED(rv)) {
+ WDP_LOGD("stopped by signal %d", WSTOPSIG(rv));
+ } else if (WIFCONTINUED(rv)) {
+ WDP_LOGD("continued");
+ }
+
+ return TRUE;
+ }
+
+ WDP_LOGE("failed to fork (%s)", strerror(errno));
+ return FALSE;
+}
+
static int _ws_check_socket(int sock)
{
struct pollfd p_fd;
#include <netinet/in.h>
#include <arpa/inet.h>
#include <net/if.h>
+#include <unistd.h>
#include <errno.h>
#include <glib.h>
return 0;
}
+gboolean wfd_util_execute_file(const char *file_path,
+ char *const args[], char *const envs[])
+{
+ pid_t pid = 0;
+ int rv = 0;
+ errno = 0;
+ register unsigned int index = 0;
+
+ while (args[index] != NULL) {
+ WDS_LOGD("[%s]", args[index]);
+ index++;
+ }
+
+ if (!(pid = fork())) {
+ WDS_LOGD("pid(%d), ppid(%d)", getpid(), getppid());
+ WDS_LOGD("Inside child, exec (%s) command", file_path);
+
+ errno = 0;
+ if (execve(file_path, args, envs) == -1) {
+ WDS_LOGE("Fail to execute command (%s)", strerror(errno));
+ exit(1);
+ }
+ } else if (pid > 0) {
+ if (waitpid(pid, &rv, 0) == -1)
+ WDS_LOGD("wait pid (%u) rv (%d)", pid, rv);
+ if (WIFEXITED(rv)) {
+ WDS_LOGD("exited, rv=%d", WEXITSTATUS(rv));
+ } else if (WIFSIGNALED(rv)) {
+ WDS_LOGD("killed by signal %d", WTERMSIG(rv));
+ } else if (WIFSTOPPED(rv)) {
+ WDS_LOGD("stopped by signal %d", WSTOPSIG(rv));
+ } else if (WIFCONTINUED(rv)) {
+ WDS_LOGD("continued");
+ }
+
+ return TRUE;
+ }
+
+ WDS_LOGE("failed to fork (%s)", strerror(errno));
+ return FALSE;
+}
+
int wfd_util_freq_to_channel(int freq)
{
if (freq < 2412 || freq > 5825) {
int wfd_util_dhcps_start()
{
__WDS_LOG_FUNC_ENTER__;
- int res = 0;
+ gboolean rv = FALSE;
+ const char *path = "/usr/bin/wifi-direct-dhcp.sh";
+ char *const args[] = { "/usr/bin/wifi-direct-dhcp.sh", "server", NULL };
+ char *const envs[] = { NULL };
vconf_set_int(VCONFKEY_DHCPS_IP_LEASE, 0);
- res = system("/usr/bin/wifi-direct-dhcp.sh server");
- WDS_LOGD("[/usr/bin/wifi-direct-dhcp.sh server] returns %d", res);
+
+ rv = wfd_util_execute_file(path, args, envs);
+
+ if (rv != TRUE) {
+ WDS_LOGE("Failed to start wifi-direct-dhcp.sh server");
+ return -1;
+ }
+ WDS_LOGD("Successfully started wifi-direct-dhcp.sh server");
__WDS_LOG_FUNC_EXIT__;
return 0;
int wfd_util_dhcps_stop()
{
__WDS_LOG_FUNC_ENTER__;
- int res = 0;
+ gboolean rv = FALSE;
+ const char *path = "/usr/bin/wifi-direct-dhcp.sh";
+ char *const args[] = { "/usr/bin/wifi-direct-dhcp.sh", "stop", NULL };
+ char *const envs[] = { NULL };
vconf_ignore_key_changed(VCONFKEY_DHCPS_IP_LEASE, _dhcps_ip_leased_cb);
vconf_set_int(VCONFKEY_DHCPS_IP_LEASE, 0);
- res = system("/usr/bin/wifi-direct-dhcp.sh stop");
- WDS_LOGD("[/usr/bin/wifi-direct-dhcp.sh stop] returns %d", res);
+ rv = wfd_util_execute_file(path, args, envs);
+
+ if (rv != TRUE) {
+ WDS_LOGE("Failed to stop wifi-direct-dhcp.sh");
+ return -1;
+ }
+ WDS_LOGD("Successfully stopped wifi-direct-dhcp.sh");
__WDS_LOG_FUNC_EXIT__;
return 0;
int wfd_util_dhcpc_start(wfd_device_s *peer)
{
__WDS_LOG_FUNC_ENTER__;
- int res = 0;
+ gboolean rv = FALSE;
+ const char *path = "/usr/bin/wifi-direct-dhcp.sh";
+ char *const args[] = { "/usr/bin/wifi-direct-dhcp.sh", "client", NULL };
+ char *const envs[] = { NULL };
if (!peer) {
WDS_LOGE("Invalid parameter");
return -1;
}
- res = system("/usr/bin/wifi-direct-dhcp.sh client");
- WDS_LOGD("[/usr/bin/wifi-direct-dhcp.sh client] returns %d", res);
+ rv = wfd_util_execute_file(path, args, envs);
+
+ if (rv != TRUE) {
+ WDS_LOGE("Failed to start wifi-direct-dhcp.sh client");
+ return -1;
+ }
+ WDS_LOGD("Successfully started wifi-direct-dhcp.sh client");
+
g_timeout_add(250, (GSourceFunc) _polling_ip, peer);
__WDS_LOG_FUNC_EXIT__;
int wfd_util_dhcpc_stop()
{
__WDS_LOG_FUNC_ENTER__;
- int res = 0;
+ gboolean rv = FALSE;
+ const char *path = "/usr/bin/wifi-direct-dhcp.sh";
+ char *const args[] = { "/usr/bin/wifi-direct-dhcp.sh", "stop", NULL };
+ char *const envs[] = { NULL };
+
+ rv = wfd_util_execute_file(path, args, envs);
- res = system("/usr/bin/wifi-direct-dhcp.sh stop");
- WDS_LOGD("[/usr/bin/wifi-direct-dhcp.sh stop] returns %d", res);
+ if (rv != TRUE) {
+ WDS_LOGE("Failed to stop wifi-direct-dhcp.sh");
+ return -1;
+ }
+ WDS_LOGD("Successfully stopped wifi-direct-dhcp.sh");
__WDS_LOG_FUNC_EXIT__;
return 0;