Added client API that it is possible to obtain a fail msg.
authorKim Gunsoo <gunsoo83.kim@samsung.com>
Tue, 14 Jun 2016 06:32:09 +0000 (15:32 +0900)
committerKim Gunsoo <gunsoo83.kim@samsung.com>
Tue, 14 Jun 2016 07:25:08 +0000 (16:25 +0900)
- Existing API has been output directly failmsg to stderr.
  By using the new API, failmsg can be passed without output to stderr.

Change-Id: I4b95c57e0c530842b476b949e70e93d512abee99
Signed-off-by: Kim Gunsoo <gunsoo83.kim@samsung.com>
src/commandline.c
src/sdb_client.c
src/sdb_client.h

index 20768ecdda2bcbec1aae3ec6557b9b6040f55da0..4752751981cddfb18318769478de95961b2cd9e8 100755 (executable)
@@ -462,9 +462,10 @@ static int check_syncwinsz_support() {
     uint16_t len = 0;
     int supported = SYNCWINSZ_UNSUPPORTED;
     int fd = -1;
+    char* failmsg = NULL;
 
     snprintf(full_cmd, sizeof(full_cmd), "capability:");
-    fd = sdb_connect(full_cmd);
+    fd = sdb_connect_getfailmsg(full_cmd, &failmsg);
     if (fd >= 0) {
         readx(fd, &len, sizeof(uint16_t));
         if (len > CAPBUF_SIZE-1) {
@@ -478,7 +479,14 @@ static int check_syncwinsz_support() {
         if (ret == 1) {
             supported = SYNCWINSZ_SUPPORTED;
         }
+    } else {
+        D("This platform does not support the capability service.\n");
+        if (failmsg != NULL) {
+            D("sdb_connect() fail message : %s\n", failmsg);
+            SAFE_FREE(failmsg);
+        }
     }
+
     return supported;
 }
 
index dde050d276a721d1258871cc730b495dc7d6c994..8c1da5e1c99178416709bba374c06042cad2a975 100644 (file)
@@ -252,7 +252,8 @@ error:
     return -1;
 }
 
-int sdb_status(int fd, int host_fd)
+#define SDB_FAILMSG_BUF_SIZE    255
+int sdb_status_getfailmsg(int fd, int host_fd, char** pp_failmsg)
 {
     unsigned char buf[5];
 
@@ -296,7 +297,7 @@ int sdb_status(int fd, int host_fd)
     if(len > 254) len = 254;
 
 
-    char error[255];
+    char error[SDB_FAILMSG_BUF_SIZE] = {0,};
     if(readx(fd, error, len)) {
         if(host_fd == 0) {
             print_error(SDB_MESSAGE_ERROR, "protocol fault", "status read");
@@ -308,7 +309,15 @@ int sdb_status(int fd, int host_fd)
     }
     error[len] = '\0';
     if(host_fd == 0) {
-        fprintf(stderr,"%s\n", error);
+        if (pp_failmsg != NULL) {
+            *pp_failmsg = malloc(SDB_FAILMSG_BUF_SIZE);
+            if ((*pp_failmsg) == NULL) {
+                return -1;
+            }
+            strncpy(*pp_failmsg, error, SDB_FAILMSG_BUF_SIZE);
+        } else {
+            fprintf(stderr,"%s\n", error);
+        }
     }
     else {
         char err_msg[255];
@@ -318,12 +327,17 @@ int sdb_status(int fd, int host_fd)
     return -1;
 }
 
+int sdb_status(int fd, int host_fd)
+{
+    return sdb_status_getfailmsg(fd, host_fd, NULL);
+}
+
 /**
  * First check whether host service or transport service,
  * If transport service, send transport prefix. Then, do the service.
  * If host service, do the service. does not have to get transport.
  */
-int _sdb_connect(const char *service)
+int _sdb_connect_getfailmsg(const char *service, char** pp_failmsg)
 {
     int fd;
 
@@ -349,7 +363,7 @@ int _sdb_connect(const char *service)
         return -1;
     }
 
-    if(sdb_status(fd, 0)) {
+    if(sdb_status_getfailmsg(fd, 0, pp_failmsg)) {
         sdb_close(fd);
         return -1;
     }
@@ -358,6 +372,11 @@ int _sdb_connect(const char *service)
     return fd;
 }
 
+int _sdb_connect(const char *service)
+{
+    return _sdb_connect_getfailmsg(service, NULL);
+}
+
 int read_msg_size(int fd) {
     char buf[5];
 
@@ -390,7 +409,7 @@ static int __inline__ write_msg_size(int fd, int size, int host_fd) {
  * First, check the host version.
  * Then, send the service using _sdb_connect
  */
-int sdb_connect(const char *service)
+int sdb_connect_getfailmsg(const char *service, char** pp_failmsg)
 {
     int only_detect_tizen_device;
     // check version before sending a sdb command
@@ -466,7 +485,7 @@ launch_server:
         }
     }
 
-    fd = _sdb_connect(service);
+    fd = _sdb_connect_getfailmsg(service, pp_failmsg);
     if(fd == -2) {
         print_error(SDB_MESSAGE_ERROR, ERR_GENERAL_SERVER_NOT_RUN, NULL);
     }
@@ -475,6 +494,10 @@ launch_server:
     return fd;
 }
 
+int sdb_connect(const char *service)
+{
+    return sdb_connect_getfailmsg(service, NULL);
+}
 
 int sdb_command(const char *service)
 {
index f8690a22e3d76286a64bccc760b6ce6f043849dd..2b64d9de1195c2c46ad31a0bb252886a25c17737 100644 (file)
@@ -28,6 +28,7 @@ extern transport_type target_ttype;
 
 int send_service_with_length(int fd, const char* service, int host_fd);
 int sdb_status(int fd, int host_fd);
+int sdb_status_getfailmsg(int fd, int host_fd, char** pp_failmsg);
 
 /* connect to sdb, connect to the named service, and return
 ** a valid fd for interacting with that service upon success
@@ -35,6 +36,14 @@ int sdb_status(int fd, int host_fd);
 */
 int sdb_connect(const char *service);
 int _sdb_connect(const char *service);
+/* function to get a failmsg.
+** pp_failmsg :
+**  If pp_failmsg is NULL, outputs a failmsg to stderr.
+**  If pp_failmsg is not NULL, returns allocated failmsg buffer pointer.
+**  The failmsg buffer must be free in the caller.
+*/
+int sdb_connect_getfailmsg(const char *service, char** pp_failmsg);
+int _sdb_connect_getfailmsg(const char *service, char** pp_failmsg);
 
 /* connect to sdb, connect to the named service, return 0 if
 ** the connection succeeded AND the service returned OKAY