submit to obs submit/tizen_2.2/20131107.093759
authorSehong Na <sehong.na@samsung.com>
Thu, 7 Nov 2013 09:37:15 +0000 (18:37 +0900)
committerSehong Na <sehong.na@samsung.com>
Thu, 7 Nov 2013 09:37:15 +0000 (18:37 +0900)
12 files changed:
Makefile
packaging/sdbd.changes [new file with mode: 0644]
packaging/sdbd.spec
packaging/sdbd_device.service [new file with mode: 0644]
packaging/sdbd_emulator.service [new file with mode: 0644]
script/sdk_launch [new file with mode: 0755]
src/file_sync_client.c
src/sdb.c
src/sdb.h
src/sdktools.c
src/services.c
src/transport_local.c

index 02c3437..dc0eb36 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,67 +1,8 @@
 #
 #
-# Makefile for sdb
+# Makefile for sdbd
 #
 
-#
-HOST_OS := $(shell uname -s | tr A-Z a-z)
-
-# sdb host tool
-# =========================================================
-
-# Default to a virtual (sockets) usb interface
-USB_SRCS :=
-EXTRA_SRCS :=
-
-ifeq ($(HOST_OS),linux)
-       USB_SRCS := usb_linux.c
-       EXTRA_SRCS := get_my_path_linux.c
-       LOCAL_LDLIBS += -lrt -lncurses -lpthread
-endif
-
-ifeq ($(HOST_OS),darwin)
-       USB_SRCS := usb_osx.c
-       EXTRA_SRCS := get_my_path_darwin.c
-       LOCAL_LDLIBS += -lpthread -framework CoreFoundation -framework IOKit -framework Carbon
-       SDB_EXTRA_CFLAGS := -mmacosx-version-min=10.4
-endif
-
-ifeq ($(HOST_OS),freebsd)
-       USB_SRCS := usb_libusb.c
-       EXTRA_SRCS := get_my_path_freebsd.c
-       LOCAL_LDLIBS += -lpthread -lusb
-endif
-
-
-
-SDB_SRC_FILES := \
-       src/sdb.c \
-       src/console.c \
-       src/transport.c \
-       src/transport_local.c \
-       src/transport_usb.c \
-       src/commandline.c \
-       src/sdb_client.c \
-       src/sockets.c \
-       src/services.c \
-       src/file_sync_client.c \
-       src/$(EXTRA_SRCS) \
-       src/$(USB_SRCS) \
-       src/utils.c \
-       src/usb_vendors.c \
-       src/fdevent.c \
-       src/socket_inaddr_any_server.c \
-       src/socket_local_client.c \
-       src/socket_local_server.c \
-       src/socket_loopback_client.c \
-       src/socket_loopback_server.c \
-       src/socket_network_client.c
-
-SDB_CFLAGS := -O2 -g -DSDB_HOST=1 -DSDB_HOST_ON_TARGET=1 -Wall -Wno-unused-parameter
-SDB_CFLAGS += -D_XOPEN_SOURCE -D_GNU_SOURCE
-SDB_CFLAGS += -DHAVE_FORKEXEC -DHAVE_TERMIO_H -DHAVE_SYMLINKS
-SDB_LFLAGS := $(LOCAL_LDLIBS)
-
 SDBD_SRC_FILES := \
        src/sdb.c \
        src/fdevent.c \
@@ -89,57 +30,25 @@ SDBD_SRC_FILES := \
 SDBD_CFLAGS := -O2 -g -DSDB_HOST=0 -Wall -Wno-unused-parameter
 SDBD_CFLAGS += -D_XOPEN_SOURCE -D_GNU_SOURCE
 SDBD_CFLAGS += -DHAVE_FORKEXEC -fPIE -D_DROP_PRIVILEGE -D_FILE_OFFSET_BITS=64
-
-IFLAGS := -Iinclude -Isrc
+SDBD_LFLAGS := -lcapi-system-info
+IFLAGS := -Iinclude -Isrc -I/usr/include/system
 OBJDIR := bin
 INSTALLDIR := usr/sbin
 INITSCRIPTDIR := etc/init.d
-RCSCRIPTDIR := etc/rc.d/rc3.d
-LAUNCH_SCRIPT := sdk_launch
-
-UNAME := $(shell uname -sm)
-ifneq (,$(findstring 86,$(UNAME)))
-       HOST_ARCH := x86
-endif
 
-TARGET_ARCH = $(HOST_ARCH)
-ifeq ($(TARGET_ARCH),)
-       TARGET_ARCH := arm
-endif
-
-ifeq ($(TARGET_ARCH),arm)
-       MODULE := sdbd
-       SDBD_CFLAGS += -DANDROID_GADGET=1
-else
-ifeq ($(TARGET_HOST),true)
-       MODULE := sdb
-else
-       MODULE := sdbd
-endif
-endif
+MODULE := sdbd
 
 all : $(MODULE)
 
-sdb : $(SDB_SRC_FILES)
-       mkdir -p $(OBJDIR)
-       $(CC) -pthread -o $(OBJDIR)/$(MODULE) $(SDB_CFLAGS) $(SDB_EXTRA_CFLAGS) $(SDB_LFLAGS) $(IFLAGS) $(SDB_SRC_FILES)
-
 sdbd : $(SDBD_SRC_FILES)
        mkdir -p $(OBJDIR)
-       $(CC) -pthread -o $(OBJDIR)/$(MODULE) $(SDBD_CFLAGS) $(IFLAGS) $(SDBD_SRC_FILES)
+       $(CC) -pthread -o $(OBJDIR)/$(MODULE) $(SDBD_CFLAGS) $(IFLAGS) $(SDBD_SRC_FILES) $(SDBD_LFLAGS)
 
 install :
        mkdir -p $(DESTDIR)/$(INSTALLDIR)
        install $(OBJDIR)/$(MODULE) $(DESTDIR)/$(INSTALLDIR)/$(MODULE)
-       install $(LAUNCH_SCRIPT) $(DESTDIR)/$(INSTALLDIR)/$(LAUNCH_SCRIPT)
-ifeq ($(MODULE),sdbd)
        mkdir -p $(DESTDIR)/$(INITSCRIPTDIR)
        install script/sdbd $(DESTDIR)/$(INITSCRIPTDIR)/sdbd
-endif
-ifeq ($(TARGET_ARCH),x86)
-       mkdir -p $(DESTDIR)/$(RCSCRIPTDIR)
-       install script/S06sdbd $(DESTDIR)/$(RCSCRIPTDIR)/S06sdbd
-endif
 
 clean :
        rm -rf $(OBJDIR)/*
diff --git a/packaging/sdbd.changes b/packaging/sdbd.changes
new file mode 100644 (file)
index 0000000..89f04c3
--- /dev/null
@@ -0,0 +1,10 @@
+* Wed Apr 04 2013 Ho Namkoong <ho.namkoong@samsung.com>
+ - supports platform gdbserver
+* Mon Dec 02 2012 Yoonki Park <yoonki.park@samsung.com>
+ - supports cs report service using inotify
+* Mon Dec 02 2012 Yoonki Park <yoonki.park@samsung.com>
+ - sdb code dropped from adb (Ice Cream Samdwich 4.1.1)
+* Wed Apr 18 2012 Yoonki Park <yoonki.park@samsung.com>
+ - set dir permission to 777
+* Sat Mar 31 2012 Yoonki Park <yoonki.park@samsung.com>
+ - let sshd be daemon and create sshd.pid file
\ No newline at end of file
index ce73689..d802bff 100644 (file)
@@ -1,10 +1,15 @@
 Name:       sdbd
 Summary:    SDB daemon
-Version:    2.2.8
-Release:    1
-Group:      TO_BE/FILLED_IN
-License:    TO BE FILLED IN
+Version:    2.2.14
+Release:    0
+License:    Apache-2.0
+Summary:    SDB daemon
+Group:      System/Utilities
 Source0:    %{name}-%{version}.tar.gz
+Source1001:    sdbd_device.service
+Source1002:    sdbd_emulator.service
+
+BuildRequires: capi-system-info-devel
 Requires(post): pkgmgr
 Requires(post): pkgmgr-server
 Requires(post): wrt
@@ -15,7 +20,7 @@ Requires: debug-launchpad
 Requires: dbus
 
 %description
-Description: SDB daemon
+Description: SDB daemon.
 
 
 %prep
@@ -30,7 +35,19 @@ rm -rf %{buildroot}
 mkdir -p %{buildroot}/usr/share/license
 cp LICENSE %{buildroot}/usr/share/license/%{name}
 
+
 %make_install
+mkdir -p %{buildroot}%{_libdir}/systemd/system
+%if 0%{?simulator}
+install -m 0644 %SOURCE1002 %{buildroot}%{_libdir}/systemd/system/sdbd.service
+mkdir -p %{buildroot}/%{_libdir}/systemd/system/emulator.target.wants
+ln -s %{_libdir}/systemd/system/sdbd.service %{buildroot}/%{_libdir}/systemd/system/emulator.target.wants/
+%else
+install -m 0644 %SOURCE1001 %{buildroot}%{_libdir}/systemd/system/sdbd.service
+%endif
+
+mkdir -p %{buildroot}%{_prefix}/sbin
+install -m 755 script/sdk_launch %{buildroot}%{_prefix}/sbin/
 
 %post
 chsmack -a sdbd::home /home/developer
@@ -38,24 +55,14 @@ chsmack -t /home/developer
 
 %files
 %manifest sdbd.manifest
-%defattr(-,root,root,-) 
+%defattr(-,root,root,-)
 %{_prefix}/sbin/sdbd
 %{_prefix}/sbin/sdk_launch
 %{_sysconfdir}/init.d/sdbd
 /usr/share/license/%{name}
-
-%ifarch %{ix86}
-    %{_sysconfdir}/rc.d/rc3.d
+%{_libdir}/systemd/system/sdbd.service
+%if 0%{?simulator}
+%{_libdir}/systemd/system/emulator.target.wants/sdbd.service
 %endif
 
 %changelog
-* Wed Apr 04 2013 Ho Namkoong <ho.namkoong@samsung.com>
- - supports platform gdbserver
-* Mon Dec 02 2012 Yoonki Park <yoonki.park@samsung.com>
- - supports cs report service using inotify
-* Mon Dec 02 2012 Yoonki Park <yoonki.park@samsung.com>
- - sdb code dropped from adb (Ice Cream Samdwich 4.1.1)
-* Wed Apr 18 2012 Yoonki Park <yoonki.park@samsung.com>
- - set dir permission to 777
-* Sat Mar 31 2012 Yoonki Park <yoonki.park@samsung.com>
- - let sshd be daemon and create sshd.pid file
diff --git a/packaging/sdbd_device.service b/packaging/sdbd_device.service
new file mode 100644 (file)
index 0000000..0b92d85
--- /dev/null
@@ -0,0 +1,10 @@
+[Unit]
+Description=sdbd
+After=default.target
+
+[Service]
+Type=forking
+Environment=DISPLAY=:0
+PIDFile=/tmp/.sdbd.pid
+RemainAfterExit=yes
+ExecStart=/usr/sbin/sdbd
diff --git a/packaging/sdbd_emulator.service b/packaging/sdbd_emulator.service
new file mode 100644 (file)
index 0000000..274c3e9
--- /dev/null
@@ -0,0 +1,15 @@
+[Unit]
+Description=sdbd
+Before=sensord.service
+
+[Service]
+Type=forking
+Environment=DISPLAY=:0
+PIDFile=/tmp/.sdbd.pid
+RemainAfterExit=yes
+ExecStartPre=/bin/bash -c "/bin/echo `/bin/sed 's/^.*sdb_port=\([^, ]*\).*$/\1/g' /proc/cmdline` > /opt/home/sdb_port.txt"
+ExecStart=/usr/sbin/sdbd
+
+[Install]
+WantedBy=emulator.target
+
diff --git a/script/sdk_launch b/script/sdk_launch
new file mode 100755 (executable)
index 0000000..2166781
--- /dev/null
@@ -0,0 +1,161 @@
+#!/bin/bash
+
+# Authors:
+#      Kangho Kim <kh5325.kim@samsung.com>, Yoonki Park <yoonki.park@samsung.com>
+#
+# Description: front hand of app launcher
+
+APP_PATH_PREFIX=/opt/apps
+SDK_TOOLS_PATH=/home/developer/sdk_tools
+
+print_usage()
+{
+    echo "usage: $0 -p <pkgid> -e <executable> -m <run|debug|da|oprofile> [-P <port>] [-attach <pid>] -t <gtest,gcov> [<args...>]"
+}
+
+first="true"
+
+until [ -z "$1" ]; do
+    case "$1" in
+    -p)
+        if [ -z "$2" ]
+        then
+            print_usage
+            exit 1;
+        fi
+        pkgid=$2
+        shift 2;
+        ;;
+    -e)
+        if [ -z "$2" ]
+        then
+            print_usage
+            exit 1;
+        fi
+        exe=${2/%.exe/}
+        shift 2;
+        ;;
+    -m)
+        if [ "$2" != "run" ] && [ "$2" != "debug" ] && [ "$2" != "da" ] && [ "$2" != "oprofile" ]
+        then
+            print_usage
+            exit 1;
+        fi
+        mode=$2
+        shift 2;
+        ;;
+    -P)
+        if [ -z "$2" ]
+        then
+            print_usage
+            exit 1;
+        fi
+        port=$2
+        shift 2;
+        ;;
+    -attach)
+        if [ -z "$2" ]
+        then
+            print_usage
+            exit 1;
+        fi
+        attach_id=$2
+        shift 2;
+        ;;
+    -t)
+        if [ "$2" = "" ] || [ ${2:0:1} = "-" ]
+        then
+            shift 1;
+        else
+# parse -t option
+        OLD_IFS=$IFS;IFS=,;
+        for type in $2;do
+            if [ "$type" = "gtest" ]
+            then
+                COV_TEST_PREFIX="export LD_LIBRARY_PATH=%s/gtest/usr/lib && $COV_TEST_PREFIX"
+                if [ "" != "$result_mode" ]
+                then
+                    result_mode="$result_mode,UNIT_TEST"
+                else
+                    launch_app_mode="__LAUNCH_APP_MODE__ SYNC"
+                    result_mode="UNIT_TEST"
+                fi
+            fi
+            if [ "$type" = "gcov" ]
+            then
+                COV_TEST_PREFIX="export GCOV_PREFIX=/tmp/%s/data && export GCOV_PREFIX_STRIP=0 && $COV_TEST_PREFIX"
+                if [ "" != "$result_mode" ]
+                then
+                    result_mode="$result_mode,CODE_COVERAGE"
+                else
+                    launch_app_mode="__LAUNCH_APP_MODE__ SYNC"
+                    result_mode="CODE_COVERAGE"
+                fi
+            fi
+        done;
+        IFS=$OLD_IFS
+
+        shift 2;
+        fi
+        ;;
+    *)
+        if [ "$first" = "true" ]
+        then
+            first="false"
+            args="__DLP_UNIT_TEST_ARG__ $1"
+        else
+            args="$args","$1"
+        fi
+        shift 1;
+    esac
+done
+
+if [ "$mode" = "debug" ]
+then
+    if [ "" != "$attach_id" ]
+    #debug attach
+    then
+        cmd="$COV_TEST_PREFIX /home/developer/sdk_tools/gdbserver/gdbserver :$port --attach $attach_id"
+    #debug
+    else
+        if [ "" != "$result_mode" ]
+        then
+            result_mode="DEBUG,$result_mode"
+        else
+            result_mode="DEBUG"
+        fi
+        cmd="/usr/bin/launch_app $pkgid.$exe __AUL_SDK__ $result_mode __DLP_DEBUG_ARG__ :$port $launch_app_mode"
+#       cmd="$COV_TEST_PREFIX /home/developer/sdk_tools/gdbserver/gdbserver :$port /opt/apps/$pkgid/bin/$exe"
+    fi
+else
+    if [ "$mode" = "run" ]
+    then
+        if [ "" != "$result_mode" ]
+        then
+            cmd="/usr/bin/launch_app $pkgid.$exe __AUL_SDK__ $result_mode $launch_app_mode"
+        else
+            cmd="/usr/bin/launch_app $pkgid.$exe"
+        fi
+    else
+        if [ "$mode" = "da" ]
+        then
+            if [ "" != "$result_mode" ]
+            then
+                result_mode="DYNAMIC_ANALYSIS,$result_mode"
+            else
+                result_mode="DYNAMIC_ANALYSIS"
+            fi
+        fi
+        if [ "$mode" = "oprofile" ]
+        then
+            if [ "" == "$result_mode" ]
+            then
+                result_mode="OPROFILE"
+            fi
+        fi
+        cmd="/usr/bin/launch_app $pkgid.$exe __AUL_SDK__ $result_mode"
+    fi
+fi
+
+# execute command
+$cmd $args
index 8561250..0e80efd 100644 (file)
@@ -650,7 +650,7 @@ static int local_build_list(copyinfo **filelist,
                 return -1;
             }
             if(!S_ISREG(st.st_mode) && !S_ISLNK(st.st_mode)) {
-                fprintf(stderr, "skipping special file '%s'\n", ci->src);
+                fprintf(stderr, "skipping special file\n");
                 free(ci);
             } else {
                 ci->time = st.st_mtime;
index 563dd18..b726574 100644 (file)
--- a/src/sdb.c
+++ b/src/sdb.c
@@ -29,6 +29,7 @@
 
 #include "sysdeps.h"
 #include "sdb.h"
+#include "strutils.h"
 
 #if !SDB_HOST
 #include <linux/prctl.h>
@@ -36,7 +37,8 @@
 #else
 #include "usb_vendors.h"
 #endif
-
+#include <system_info.h>
+#define PROC_CMDLINE_PATH "/proc/cmdline"
 #if SDB_TRACE
 SDB_MUTEX_DEFINE( D_lock );
 #endif
@@ -298,7 +300,7 @@ static void send_close(unsigned local, unsigned remote, atransport *t)
     p->msg.arg1 = remote;
     send_packet(p, t);
 }
-
+static int device_status = 0; // 0:online, 1: password locked later
 static void send_connect(atransport *t)
 {
     D("Calling send_connect \n");
@@ -306,9 +308,24 @@ static void send_connect(atransport *t)
     cp->msg.command = A_CNXN;
     cp->msg.arg0 = A_VERSION;
     cp->msg.arg1 = MAX_PAYLOAD;
-    snprintf((char*) cp->data, sizeof cp->data, "%s::",
-            HOST ? "host" : sdb_device_banner);
+
+    char device_name[256]={0,};
+    int r = 0;
+
+    if (is_emulator()) {
+        r = get_emulator_name(device_name, sizeof device_name);
+    } else {
+        r = get_device_name(device_name, sizeof device_name);
+    }
+    if (r < 0) {
+        snprintf((char*) cp->data, sizeof cp->data, "%s::%s::%d", sdb_device_banner, DEFAULT_DEVICENAME, device_status);
+    } else {
+        snprintf((char*) cp->data, sizeof cp->data, "%s::%s::%d", sdb_device_banner, device_name, device_status);
+    }
+
+    D("CNXN data:%s\n", (char*)cp->data);
     cp->msg.data_length = strlen((char*) cp->data) + 1;
+
     send_packet(cp, t);
 #if SDB_HOST
         /* XXX why sleep here? */
@@ -335,6 +352,104 @@ static char *connection_state_name(atransport *t)
     }
 }
 
+static int get_str_cmdline(char *src, char *dest, char str[], int str_size) {
+    char *s = strstr(src, dest);
+    if (s == NULL) {
+        return -1;
+    }
+    char *e = strstr(s, " ");
+    if (e == NULL) {
+        return -1;
+    }
+
+    int len = e-s-strlen(dest);
+
+    if (len >= str_size) {
+        D("buffer size(%d) should be bigger than %d\n", str_size, len+1);
+        return -1;
+    }
+
+    s_strncpy(str, s + strlen(dest), len);
+    return len;
+}
+
+int get_emulator_forward_port() {
+    char cmdline[512];
+    int fd = unix_open(PROC_CMDLINE_PATH, O_RDONLY);
+    char *port_str = "sdb_port=";
+    char port_buf[7]={0,};
+    int port = -1;
+
+    if (fd < 0) {
+        return -1;
+    }
+    if(read_line(fd, cmdline, sizeof(cmdline))) {
+        D("qemu cmd: %s\n", cmdline);
+        if (get_str_cmdline(cmdline, port_str, port_buf, sizeof(port_buf)) < 1) {
+            D("could not get port from cmdline\n");
+            sdb_close(fd);
+            return -1;
+        }
+        // FIXME: remove comma!
+        port_buf[strlen(port_buf)-1]='\0';
+        port = strtol(port_buf, NULL, 10);
+    }
+    sdb_close(fd);
+    return port;
+}
+
+int get_emulator_name(char str[], int str_size) {
+    char cmdline[512];
+    int fd = unix_open(PROC_CMDLINE_PATH, O_RDONLY);
+    char *name_str = "vm_name=";
+
+    if (fd < 0) {
+        D("fail to read /proc/cmdline\n");
+        return -1;
+    }
+    if(read_line(fd, cmdline, sizeof(cmdline))) {
+        D("qemu cmd: %s\n", cmdline);
+        if (get_str_cmdline(cmdline, name_str, str, str_size) < 1) {
+            D("could not get emulator name from cmdline\n");
+            sdb_close(fd);
+            return -1;
+        }
+    }
+    sdb_close(fd);
+    return 0;
+}
+
+int get_device_name(char str[], int str_size) {
+    char *value = NULL;
+    int r = system_info_get_value_string(SYSTEM_INFO_KEY_MODEL, &value);
+    if (r != SYSTEM_INFO_ERROR_NONE) {
+        D("fail to get system model:%d\n", errno);
+        return -1;
+    } else {
+        s_strncpy(str, value, str_size);
+        D("returns model_name:%s\n", value);
+        if (value != NULL) {
+            free(value);
+        }
+        return 0;
+    }
+    /*
+    int fd = unix_open(USB_SERIAL_PATH, O_RDONLY);
+    if (fd < 0) {
+        D("fail to read:%s (%d)\n", USB_SERIAL_PATH, errno);
+        return -1;
+    }
+
+    if(read_line(fd, str, str_size)) {
+        D("device serial name: %s\n", str);
+        sdb_close(fd);
+        return 0;
+    }
+    sdb_close(fd);
+    */
+    return -1;
+}
+
 void parse_banner(char *banner, atransport *t)
 {
     char *type, *product, *end;
index 958fc40..01c8b40 100644 (file)
--- a/src/sdb.h
+++ b/src/sdb.h
@@ -338,6 +338,9 @@ int should_drop_privileges(void);
 int set_developer_privileges();
 void set_root_privileges();
 
+int get_emulator_forward_port(void);
+int get_emulator_name(char str[], int str_size);
+int get_device_name(char str[], int str_size);
 /* packet allocator */
 apacket *get_apacket(void);
 void put_apacket(apacket *p);
@@ -487,12 +490,13 @@ int sendfailmsg(int fd, const char *reason);
 int handle_host_request(char *service, transport_type ttype, char* serial, int reply_fd, asocket *s);
 
 int is_emulator(void);
+#define DEFAULT_DEVICENAME "unknown"
 
 #if SDB_HOST /* tizen-specific */
 #define DEVICEMAP_SEPARATOR ":"
 #define DEVICENAME_MAX 256
 #define VMS_PATH OS_PATH_SEPARATOR_STR "vms" OS_PATH_SEPARATOR_STR // should include sysdeps.h above
-#define DEFAULT_DEVICENAME "<unknown>"
+
 void register_device_name(const char *device_type, const char *device_name, int port);
 int get_devicename_from_shdmem(int port, char *device_name);
 int read_line(const int fd, char* ptr, const size_t maxlen);
index 5770fe6..c288831 100644 (file)
@@ -98,7 +98,7 @@ int verify_root_commands(const char *arg1) {
     case 3: {
         if (!strcmp(tokens[1], "valgrind") && cnt >= 3) {
             char *appid = NULL;
-           // the tokens[2] should be apppath
+            // the tokens[2] should be apppath
             int rc = smack_lgetlabel(tokens[2], &appid, SMACK_LABEL_ACCESS);
             if (rc == 0 && appid != NULL) {
                 if (apply_sdb_rules(SDBD_LABEL_NAME, appid, "rwax") < 0) {
index dfc2735..4af9982 100644 (file)
@@ -38,6 +38,9 @@
 #   include "sdktools.h"
 #endif
 
+#include "strutils.h"
+#include <system_info.h>
+
 typedef struct stinfo stinfo;
 
 struct stinfo {
@@ -577,6 +580,79 @@ static int create_syncproc_thread()
 
 #endif
 
+#define UNKNOWN "unknown"
+#define INFOBUF_MAXLEN 64
+#define INFO_VERSION "2.2.0"
+typedef struct platform_info {
+    
+    char platform_info_version[INFOBUF_MAXLEN];
+    char model_name[INFOBUF_MAXLEN]; // Emulator
+    char platform_name[INFOBUF_MAXLEN]; // Tizen
+    char platform_version[INFOBUF_MAXLEN]; // 2.2.1
+    char profile_name[INFOBUF_MAXLEN]; // 2.2.1
+} pinfo;
+
+static void get_platforminfo(int fd, void *cookie) {
+    pinfo sysinfo;
+
+    char *value = NULL;
+    s_strncpy(sysinfo.platform_info_version, INFO_VERSION, strlen(INFO_VERSION));
+
+    int r = system_info_get_value_string(SYSTEM_INFO_KEY_MODEL, &value);
+    if (r != SYSTEM_INFO_ERROR_NONE) {
+        s_strncpy(sysinfo.model_name, UNKNOWN, strlen(UNKNOWN));
+        D("fail to get system model:%d\n", errno);
+    } else {
+        s_strncpy(sysinfo.model_name, value, sizeof(sysinfo.model_name));
+        D("returns model_name:%s\n", value);
+        if (value != NULL) {
+            free(value);
+        }
+    }
+
+    r = system_info_get_value_string(SYSTEM_INFO_KEY_PLATFORM_NAME, &value);
+    if (r != SYSTEM_INFO_ERROR_NONE) {
+        s_strncpy(sysinfo.platform_name, UNKNOWN, strlen(UNKNOWN));
+        D("fail to get platform name:%d\n", errno);
+    } else {
+        s_strncpy(sysinfo.platform_name, value, sizeof(sysinfo.platform_name));
+        D("returns platform_name:%s\n", value);
+        if (value != NULL) {
+            free(value);
+        }
+
+    }
+
+    // FIXME: the result is different when using SYSTEM_INFO_KEY_TIZEN_VERSION_NAME
+    r = system_info_get_platform_string("tizen.org/feature/platform.version", &value);
+    if (r != SYSTEM_INFO_ERROR_NONE) {
+        s_strncpy(sysinfo.platform_version, UNKNOWN, strlen(UNKNOWN));
+        D("fail to get platform version:%d\n", errno);
+    } else {
+        s_strncpy(sysinfo.platform_version, value, sizeof(sysinfo.platform_version));
+        D("returns platform_version:%s\n", value);
+        if (value != NULL) {
+            free(value);
+        }
+    }
+
+    r = system_info_get_platform_string("tizen.org/feature/profile", &value);
+    if (r != SYSTEM_INFO_ERROR_NONE) {
+        s_strncpy(sysinfo.profile_name, UNKNOWN, strlen(UNKNOWN));
+        D("fail to get profile name:%d\n", errno);
+    } else {
+        s_strncpy(sysinfo.profile_name, value, sizeof(sysinfo.profile_name));
+        D("returns profile name:%s\n", value);
+        if (value != NULL) {
+            free(value);
+        }
+    }
+
+    writex(fd, &sysinfo, sizeof(pinfo));
+
+    sdb_close(fd);
+}
+
 int service_to_fd(const char *name)
 {
     int ret = -1;
@@ -664,10 +740,8 @@ int service_to_fd(const char *name)
     } else if(!strncmp(name, "cs:", 5)) {
         ret = create_service_thread(inoti_service, NULL);
 #endif
-#if 0
-    } else if(!strncmp(name, "echo:", 5)){
-        ret = create_service_thread(echo_service, 0);
-#endif
+    } else if(!strncmp(name, "sysinfo:", 8)){
+        ret = create_service_thread(get_platforminfo, 0);
     }
     if (ret >= 0) {
         if (close_on_exec(ret) < 0) {
index 6811f61..ee59551 100644 (file)
@@ -270,8 +270,11 @@ static void *server_socket_thread(void * arg)
 
         alen = sizeof(addr);
         D("server: trying to get new connection from %d\n", port);
-        // im ready to accept new client!
-        pthread_cond_broadcast(&noti_cond);
+
+        if (is_emulator()) {
+            // im ready to accept new client!
+            pthread_cond_broadcast(&noti_cond);
+        }
 
         fd = sdb_socket_accept(serverfd, &addr, &alen);
         if(fd >= 0) {
@@ -400,27 +403,6 @@ static const char _ok_resp[]    = "ok";
 #endif  // !SDB_HOST
 #endif
 
-static int get_str_cmdline(char *src, char *dest, char str[], int str_size) {
-    char *s = strstr(src, dest);
-    if (s == NULL) {
-        return -1;
-    }
-    char *e = strstr(s, " ");
-    if (e == NULL) {
-        return -1;
-    }
-
-    int len = e-s-strlen(dest);
-
-    if (len >= str_size) {
-        printf("buffer size should be over %d\n", len+1);
-        return -1;
-    }
-
-    s_strncpy(str, s + strlen(dest), len);
-    return len;
-}
-
 static int send_msg_to_localhost_from_guest(int local_port, char *request, int sock_type) {
     int                  ret, s;
     struct sockaddr_in   server;
@@ -430,6 +412,8 @@ static int send_msg_to_localhost_from_guest(int local_port, char *request, int s
     server.sin_port        = htons(local_port);
     server.sin_addr.s_addr = inet_addr(QEMU_FORWARD_IP);
 
+    D("try to send notification to host(%s:%d) using %s:[%s]\n", QEMU_FORWARD_IP, local_port, (sock_type == 0) ? "tcp" : "udp", request);
+
     if (sock_type == 0) {
         s = socket(AF_INET, SOCK_STREAM, 0);
     } else {
@@ -446,67 +430,43 @@ static int send_msg_to_localhost_from_guest(int local_port, char *request, int s
         return -1;
     }
     if (sdb_write(s, request, strlen(request)) < 0) {
-        D("could not send sdbd noti request\n");
+        D("could not send notification request to host\n");
+        sdb_close(s);
+        return -1;
     }
-
     sdb_close(s);
+    D("sent notification request to host\n");
+
     return 0;
 }
 
 static void notify_sdbd_startup() {
-    int                  ret;
     char                 buffer[512];
     char                 request[512];
 
     // send the request to sdbserver
-    char cmdline[512];
-    int fd = unix_open("/proc/cmdline", O_RDONLY);
-    char *port_str = "sdb_port=";
-    char *name_str = "vm_name=";
-    char port[7]={0,};
     char vm_name[256]={0,};
+    int base_port = get_emulator_forward_port();
+    int r = get_emulator_name(vm_name, sizeof vm_name);
 
-    if (fd < 0) {
-        D("fail to read /proc/cmdline\n");
+    if (base_port < 0 || r < 0) {
         return;
     }
-    if(read_line(fd, cmdline, sizeof(cmdline))) {
-        D("qemu cmd: %s\n", cmdline);
-        ret = get_str_cmdline(cmdline, port_str, port, sizeof(port));
-        if (ret < 1) {
-            D("could not get port from cmdline\n");
-            sdb_close(fd);
-            return;
-        }
-        // FIXME: remove comma!
-        port[strlen(port)-1]='\0';
-
-        ret = get_str_cmdline(cmdline, name_str, vm_name, sizeof(vm_name));
-        if (ret < 1) {
-            D("could not get port from cmdline\n");
-            sdb_close(fd);
-            return;
-        }
-        int base_port = strtol(port, NULL, 10);
-        snprintf(request, sizeof request, "host:emulator:%d:%s",base_port + 1, vm_name);
-
-        snprintf( buffer, sizeof buffer, "%04x%s", strlen(request), request );
-        D("[%s]\n", buffer);
-        if (send_msg_to_localhost_from_guest(DEFAULT_SDB_PORT, buffer, 0) <0) {
-            D("could not send sdbd noti request\n");
-            sdb_close(fd);
-            return;
-        }
-        // send to sensord with udp
-        char sensord_buf[16];
-        snprintf(sensord_buf, sizeof sensord_buf, "2\n");
-        if (send_msg_to_localhost_from_guest(base_port + 3, sensord_buf, 1) < 0) {
-            D("could not send senserd noti request\n");
-            sdb_close(fd);
-            return;
-        }
+
+    // tell qemu sdbd is just started with udp
+    char sensord_buf[16];
+    snprintf(sensord_buf, sizeof sensord_buf, "2\n");
+    if (send_msg_to_localhost_from_guest(base_port + 3, sensord_buf, 1) < 0) {
+        D("could not send sensord noti request\n");
+    }
+
+    // tell sdb server emulator's vms name
+    snprintf(request, sizeof request, "host:emulator:%d:%s",base_port + 1, vm_name);
+    snprintf(buffer, sizeof buffer, "%04x%s", strlen(request), request );
+
+    if (send_msg_to_localhost_from_guest(DEFAULT_SDB_PORT, buffer, 0) <0) {
+        D("could not send sdbd noti request. it might sdb server has not been started yet.\n");
     }
-    sdb_close(fd);
 }
 
 void local_init(int port)
@@ -548,12 +508,13 @@ void local_init(int port)
      * wait until server socket thread made!
      * get noti from server_socket_thread
      */
+    if (is_emulator()) {
+        sdb_mutex_lock(&register_noti_lock);
+        pthread_cond_wait(&noti_cond, &register_noti_lock);
 
-    sdb_mutex_lock(&register_noti_lock);
-    pthread_cond_wait(&noti_cond, &register_noti_lock);
-
-    notify_sdbd_startup();
-    sdb_mutex_unlock(&register_noti_lock);
+        notify_sdbd_startup();
+        sdb_mutex_unlock(&register_noti_lock);
+    }
 }
 
 static void remote_kick(atransport *t)