Modify the method that launch dbus server not to use system() function 80/15680/1
authorJiung Yu <jiung.yu@samsung.com>
Mon, 27 Jan 2014 01:23:45 +0000 (10:23 +0900)
committerJiung Yu <jiung.yu@samsung.com>
Mon, 27 Jan 2014 01:25:08 +0000 (10:25 +0900)
Change-Id: I491b6c53b3de0f7c2b0b47aa7b6926b40001ad89
Signed-off-by: Yu jiung <jiung.yu@samsung.com>
include/wifi-direct.h
packaging/libwifi-direct.changes
packaging/libwifi-direct.spec
src/include/wifi-direct-client-proxy.h
src/wifi-direct-client-proxy.c

index 87935fb..311bead 100644 (file)
@@ -323,8 +323,6 @@ typedef void (*wifi_direct_client_ip_address_assigned_cb) (const char *mac_addre
                                                                                                                 const char *interface_address,
                                                                                                                 void *user_data);
 
-
-
 /*=============================================================================
                                         Wifi Direct Client APIs
 =============================================================================*/
@@ -749,8 +747,6 @@ int wifi_direct_set_client_ip_address_assigned_cb(wifi_direct_client_ip_address_
 int wifi_direct_unset_client_ip_address_assigned_cb(void);
 
 
-
-
 /*****************************************************************************************/
 /* wifi_direct_activate API function prototype
  * int wifi_direct_activate(void);
index 8dfd1d3..8aa708b 100644 (file)
@@ -1,5 +1,9 @@
+* Mon, 13 Jan 2014 Jiung Yu <jiung.yu@samsung.com> (1.0.6)
+  - Modify the method that launch dbus server not to use system() function
+
 * Fri, 10 Jan 2014 Jiung Yu <jiung.yu@samsung.com> (1.0.5)
-  - clean the code, add ALREADY_INITITALIZED error and change some commands
+  - Clean the code, add ALREADY_INITITALIZED error and change some commands
+
 * Fri, 10 Jan 2014 Jiung Yu <jiung.yu@samsung.com> (1.0.4)
   - Add cancel_connection function
 
index 4d67feb..57f1d67 100644 (file)
@@ -1,6 +1,6 @@
 Name:       libwifi-direct
 Summary:    Wifi Direct Library
-Version:    1.0.5
+Version:    1.0.6
 Release:    1
 Group:      Network & Connectivity/Wireless 
 License:    Apache-2.0
index f39eb3a..281fbe1 100644 (file)
@@ -74,8 +74,6 @@
 #define MACADDR_LEN 6
 #define IPSTR_LEN 16
 #define WFD_SOCK_FILE_PATH "/tmp/wfd_client_socket"
-#define WFD_LAUNCH_SERVER_DBUS "dbus-send --system --print-reply --dest=net.netconfig /net/netconfig/wifi net.netconfig.wifi.LaunchDirect"
-
 typedef struct
 {
        bool is_registered;
index 941d936..909bb36 100644 (file)
@@ -786,6 +786,65 @@ static int __wfd_client_async_event_init(int clientid)
        return sockfd;
 }
 
+static gboolean wfd_client_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) {
+               WDC_LOGD("[%s]", args[index]);
+               index++;
+       }
+
+       if (!(pid = fork())) {
+               WDC_LOGD("pid(%d), ppid(%d)", getpid(), getppid());
+               WDC_LOGD("Inside child, exec (%s) command", file_path);
+
+               errno = 0;
+               if (execve(file_path, args, envs) == -1) {
+                       WDC_LOGE("Fail to execute command (%s)", strerror(errno));
+                       exit(1);
+               }
+       } else if (pid > 0) {
+               if (waitpid(pid, &rv, 0) == -1)
+                       WDC_LOGD("wait pid (%u) rv (%d)", pid, rv);
+               if (WIFEXITED(rv)) {
+                       WDC_LOGD("exited, rv=%d", WEXITSTATUS(rv));
+               } else if (WIFSIGNALED(rv)) {
+                       WDC_LOGD("killed by signal %d", WTERMSIG(rv));
+               } else if (WIFSTOPPED(rv)) {
+                       WDC_LOGD("stopped by signal %d", WSTOPSIG(rv));
+               } else if (WIFCONTINUED(rv)) {
+                       WDC_LOGD("continued");
+               }
+
+               return TRUE;
+       }
+
+       WDC_LOGE("failed to fork (%s)", strerror(errno));
+       return FALSE;
+}
+
+static int __wfd_client_launch_server_dbus(void)
+{
+       gboolean rv = FALSE;
+       const char *path = "/usr/bin/dbus-send";
+       char *const args[] = { "/usr/bin/dbus-send", "--system", "--print-reply", "--dest=net.netconfig", "/net/netconfig/wifi", "net.netconfig.wifi.LaunchDirect", NULL };
+       char *const envs[] = { NULL };
+
+       rv = wfd_client_execute_file(path, args, envs);
+
+       if (rv != TRUE) {
+               WDC_LOGE("Failed to launch wfd-manager");
+               return -1;
+       }
+
+       WDC_LOGD("Successfully launched wfd-manager");
+       return 0;
+}
 
 int wifi_direct_initialize(void)
 {
@@ -826,7 +885,7 @@ int wifi_direct_initialize(void)
                }
 
                WDC_LOGD("Launching wfd-server..\n");
-               res = system(WFD_LAUNCH_SERVER_DBUS);
+               res = __wfd_client_launch_server_dbus();
                if (res == -1)
                        WDC_LOGE("Failed to send dbus msg[%s]", strerror(errno));
                retry_count--;