Replace file execution method 45/15045/1
authorJiung Yu <jiung.yu@samsung.com>
Wed, 15 Jan 2014 08:48:28 +0000 (17:48 +0900)
committerJiung Yu <jiung.yu@samsung.com>
Wed, 15 Jan 2014 08:48:32 +0000 (17:48 +0900)
Change-Id: Icb1ed25bee0f61d17bb4b1a77afcc6c2009bd8ff
Signed-off-by: Yu jiung <jiung.yu@samsung.com>
include/wifi-direct-util.h
packaging/wifi-direct-manager.changes
packaging/wifi-direct-manager.spec
plugin/wpasupplicant/wfd-plugin-wpasupplicant.c
src/wifi-direct-util.c

index 3dbc33d..505fbc5 100644 (file)
@@ -71,6 +71,7 @@
 
 #endif /* USE_DLOG */
 
+gboolean wfd_util_execute_file(const char *file_path, char *const args[], char *const envs[]);
 int wfd_util_freq_to_channel(int freq);
 int wfd_util_get_phone_name(char *phone_name);
 void wfd_util_set_dev_name_notification();
index db4e2c8..5114721 100644 (file)
@@ -1,3 +1,6 @@
+Tue, 15 Jan 2014 Jiung Yu <jiung.yu@samaung.com> (1.0.7)
+  * Replace file execution method
+
 Tue, 15 Jan 2014 Jiung Yu <jiung.yu@samaung.com> (1.0.6)
   * Add cancel connection fuction to manager
   * Add reject connection fuction to manager
index fbd7612..d318e74 100644 (file)
@@ -1,6 +1,6 @@
 Name:       wifi-direct-manager
 Summary:    Wi-Fi Direct manger
-Version:    1.0.6
+Version:    1.0.7
 Release:    1
 Group:      Network & Connectivity/Wireless
 License:    Apache-2.0
index 325faf9..378245a 100644 (file)
 #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>
 
@@ -286,6 +289,48 @@ static int _ws_freq_to_channel(int freq)
                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;
index c3747a8..67d07f0 100644 (file)
@@ -33,6 +33,7 @@
 #include <netinet/in.h>
 #include <arpa/inet.h>
 #include <net/if.h>
+#include <unistd.h>
 #include <errno.h>
 
 #include <glib.h>
@@ -81,6 +82,48 @@ static int _txt_to_ip(char *txt, unsigned char *ip)
        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) {
@@ -463,11 +506,20 @@ static gboolean _polling_ip(gpointer user_data)
 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;
@@ -492,13 +544,21 @@ int wfd_util_dhcps_wait_ip_leased(wfd_device_s *peer)
 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;
@@ -507,15 +567,24 @@ int wfd_util_dhcps_stop()
 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__;
@@ -525,10 +594,18 @@ int wfd_util_dhcpc_start(wfd_device_s *peer)
 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;