From 7c2595d0822b22221af68a47be06e5691fbedf20 Mon Sep 17 00:00:00 2001 From: "shingil.kang" Date: Tue, 26 Apr 2016 20:57:37 +0900 Subject: [PATCH 01/16] Fixed a bug where sdbd shows incorrect error message Change-Id: I1107e20525547327f7f97431c581c647aa6570d9 Signed-off-by: shingil.kang --- src/file_sync_service.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/file_sync_service.c b/src/file_sync_service.c index d142ff1..5fc6642 100644 --- a/src/file_sync_service.c +++ b/src/file_sync_service.c @@ -276,12 +276,13 @@ done: static int fail_message(int s, const char *reason) { syncmsg msg; - int len = strlen(reason); + size_t len = strlen(reason); D("sync: failure: %s\n", reason); msg.data.id = ID_FAIL; msg.data.size = htoll(len); + if(writex(s, &msg.data, sizeof(msg.data)) || writex(s, reason, len)) { return -1; @@ -290,14 +291,14 @@ static int fail_message(int s, const char *reason) } } -static int fail_errno(int s) +static int fail_errno(int fd, int err_no) { char* ret_str; - char buf[512]; + char buf[512] = {0, }; - ret_str = strerror_r(s, buf, sizeof(buf)); + ret_str = strerror_r(err_no, buf, sizeof(buf)); - return fail_message(s, (const char*)ret_str); + return fail_message(fd, (const char*)ret_str); } // FIXME: should get the following paths with api later but, do it for simple and not having dependency on other packages @@ -348,7 +349,7 @@ static int handle_send_file(int s, int noti_fd, char *path, mode_t mode, char *b fd = sdb_open_mode(path, O_WRONLY, mode); } if(fd < 0) { - if(fail_errno(s)) + if(fail_errno(s, errno)) return -1; fd = -1; } @@ -385,7 +386,7 @@ static int handle_send_file(int s, int noti_fd, char *path, mode_t mode, char *b sdb_unlink(path); fd = -1; errno = saved_errno; - if(fail_errno(s)) return -1; + if(fail_errno(s, errno)) return -1; } } @@ -446,7 +447,7 @@ static int handle_send_link(int s, int noti_fd, char *path, char *buffer) ret = symlink(buffer, path); } if(ret) { - fail_errno(s); + fail_errno(s, errno); return -1; } @@ -556,7 +557,7 @@ static int do_recv(int s, const char *path, char *buffer) fd = sdb_open(path, O_RDONLY); if(fd < 0) { - if(fail_errno(s)) return -1; + if(fail_errno(s, errno)) return -1; return 0; } @@ -566,7 +567,7 @@ static int do_recv(int s, const char *path, char *buffer) if(r <= 0) { if(r == 0) break; if(errno == EINTR) continue; - r = fail_errno(s); + r = fail_errno(s, errno); sdb_close(fd); return r; } -- 2.7.4 From 7d6427a05082be14e01e0620d2955300e392925a Mon Sep 17 00:00:00 2001 From: Kim Gunsoo Date: Wed, 27 Apr 2016 14:51:55 +0900 Subject: [PATCH 02/16] Modify the sdk groups routine for sdb shell/sync service. - Add the groups for sdbd shell/sync default group. ("priv_externalstorage", "priv_externalstorage_appdata", "priv_mediastorage") - Modify the sdk group init routine that receives group infomation from platform. Change-Id: I7273df2e05f65a62953e7e4f6003e3bc928aaae4 Signed-off-by: Kim Gunsoo --- src/sdb.c | 115 ++++++++++++++++++++++++++++++++++++++++---------------------- src/sdb.h | 3 ++ 2 files changed, 77 insertions(+), 41 deletions(-) diff --git a/src/sdb.c b/src/sdb.c index 61b5bc4..793d8ec 100644 --- a/src/sdb.c +++ b/src/sdb.c @@ -77,7 +77,13 @@ struct group_info const char *name; gid_t gid; }; -struct group_info g_default_groups[] = { {"log", -1}, {NULL, -1}}; +struct group_info g_default_groups[] = { + {"priv_externalstorage", -1}, + {"priv_externalstorage_appdata", -1}, + {"priv_mediastorage", -1}, + {"log", -1}, + {NULL, -1} +}; #define SDB_DEFAULT_GROUPS_CNT ((sizeof(g_default_groups)/sizeof(g_default_groups[0]))-1) int is_init_sdk_userinfo = 0; @@ -1435,7 +1441,7 @@ static int sdbd_set_groups() { break; } } - if (group_match == 0) { + if (group_match == 0 && g_default_groups[i].gid != -1) { group_ids[ngroups + added_group_cnt] = g_default_groups[i].gid; added_group_cnt ++; } @@ -1462,7 +1468,25 @@ static int sdbd_get_user_pwd(const char* user_name, struct passwd* pwd, char* bu D("Not found passwd : username(%s)\n", user_name); } else { errno = ret; - D("failed to getpwuid_r\n"); + D("failed to getpwnam_r\n"); + } + return -1; + } + + return 0; +} + +static int sdbd_get_group(const char* group_name, struct group* grp, char* buf, size_t bufsize) { + struct group *result = NULL; + int ret = 0; + + ret = getgrnam_r(group_name, grp, buf, bufsize, &result); + if (result == NULL) { + if (ret == 0) { + D("Not found group : groupname(%s)\n", group_name); + } else { + errno = ret; + D("failed to getgrnam_r\n"); } return -1; } @@ -1478,26 +1502,25 @@ int set_sdk_user_privileges() { if (sdbd_set_groups() < 0) { D("set groups failed (errno: %d)\n", errno); - return -1; } if (setgid(g_sdk_group_id) != 0) { D("set group id failed (errno: %d)\n", errno); - return -1; } if (setuid(g_sdk_user_id) != 0) { D("set user id failed (errno: %d)\n", errno); - return -1; } if (chdir(g_sdk_home_dir) < 0) { D("unable to change working directory to %s\n", g_sdk_home_dir); - return -1; } // TODO: use pam later - putenv(g_sdk_home_dir_env); + if (g_sdk_home_dir_env) { + putenv(g_sdk_home_dir_env); + } + return 0; } @@ -1721,38 +1744,48 @@ static void load_sdbd_plugin() { D("using sdbd plugin interface.(%s)\n", SDBD_PLUGIN_PATH); } +#define SDB_PW_GR_DEFAULT_SIZE (16*1024) static long get_passwd_bufsize() { long bufsize = 0; bufsize = sysconf(_SC_GETPW_R_SIZE_MAX); if(bufsize < 0) { - bufsize = (16*1024); + bufsize = SDB_PW_GR_DEFAULT_SIZE; + } + + return bufsize; +} + +static long get_group_bufsize() { + long bufsize = 0; + + bufsize = sysconf(_SC_GETGR_R_SIZE_MAX); + if(bufsize < 0) { + bufsize = SDB_PW_GR_DEFAULT_SIZE; } return bufsize; } static int init_sdb_default_groups() { - struct passwd pwd; + struct group grp; char *buf = NULL; long bufsize = 0; int i = 0; - bufsize = get_passwd_bufsize(); + bufsize = get_group_bufsize(); buf = malloc(bufsize); if (buf == NULL) { - D("failed to allocate passwd buf(%ld)\n", bufsize); + D("failed to allocate gruop buf(%ld)\n", bufsize); return -1; } for (i = 0; g_default_groups[i].name != NULL; i++) { memset(buf, 0, bufsize); - if (sdbd_get_user_pwd(g_default_groups[i].name, &pwd, buf, bufsize) == 0) { - g_default_groups[i].gid = pwd.pw_gid; + if (sdbd_get_group(g_default_groups[i].name, &grp, buf, bufsize) == 0) { + g_default_groups[i].gid = grp.gr_gid; } else { - D("get user passwd info.(errno: %d)\n", errno); - free(buf); - return -1; + D("failed get group info.(errno: %d)\n", errno); } } @@ -1760,6 +1793,12 @@ static int init_sdb_default_groups() { return 0; } +static void set_static_userinfo() { + g_sdk_user_id = STATIC_SDK_USER_ID; + g_sdk_group_id = STATIC_SDK_GROUP_ID; + g_sdk_home_dir = STATIC_SDK_HOME_DIR; +} + static int init_sdk_userinfo() { struct passwd pwd; char *buf = NULL; @@ -1769,42 +1808,36 @@ static int init_sdk_userinfo() { return 0; } + if (init_sdb_default_groups() < 0) { + D("failed to initialize default groups.\n"); + } + bufsize = get_passwd_bufsize(); buf = malloc(bufsize); if (buf == NULL) { D("failed to allocate passwd buf(%ld)\n", bufsize); - return -1; - } + set_static_userinfo(); + } else { + if (sdbd_get_user_pwd(SDK_USER_NAME, &pwd, buf, bufsize) < 0) { + D("get user passwd info.(errno: %d)\n", errno); + set_static_userinfo(); + } else { + D("username=%s, uid=%d, gid=%d, dir=%s\n", pwd.pw_name, pwd.pw_uid, pwd.pw_gid, pwd.pw_dir); - if (sdbd_get_user_pwd(SDK_USER_NAME, &pwd, buf, bufsize) < 0) { - D("get user passwd info.(errno: %d)\n", errno); + g_sdk_user_id = pwd.pw_uid; + g_sdk_group_id = pwd.pw_gid; + g_sdk_home_dir = strdup(pwd.pw_dir); + } free(buf); - return -1; - } - D("username=%s, uid=%d, gid=%d, dir=%s\n", pwd.pw_name, pwd.pw_uid, pwd.pw_gid, pwd.pw_dir); - - g_sdk_user_id = pwd.pw_uid; - g_sdk_group_id = pwd.pw_gid; - g_sdk_home_dir = strdup(pwd.pw_dir); - - free(buf); - - if (init_sdb_default_groups() < 0) { - D("failed to initialize default groups.\n"); - free(g_sdk_home_dir); - g_sdk_home_dir = NULL; - return -1; } int env_size = strlen("HOME=") + strlen(g_sdk_home_dir) + 1; g_sdk_home_dir_env = malloc(env_size); - if(g_sdk_home_dir_env == 0) { + if(g_sdk_home_dir_env == NULL) { D("failed to allocate for home dir env string\n"); - free(g_sdk_home_dir); - g_sdk_home_dir = NULL; - return -1; + } else { + snprintf(g_sdk_home_dir_env, env_size, "HOME=%s", g_sdk_home_dir); } - snprintf(g_sdk_home_dir_env, env_size, "HOME=%s", g_sdk_home_dir); is_init_sdk_userinfo = 1; return 0; diff --git a/src/sdb.h b/src/sdb.h index dd0fe23..7e3d1f1 100644 --- a/src/sdb.h +++ b/src/sdb.h @@ -385,6 +385,9 @@ int booting_done; // 0: platform booting is in progess 1: platform booting is do #define SDK_USER_NAME tzplatform_getenv(TZ_SDK_USER_NAME) #define SDK_TOOL_PATH tzplatform_getenv(TZ_SDK_TOOLS) +#define STATIC_SDK_USER_ID 5001 +#define STATIC_SDK_GROUP_ID 100 +#define STATIC_SDK_HOME_DIR "/home/owner" extern uid_t g_sdk_user_id; extern gid_t g_sdk_group_id; extern char* g_sdk_home_dir; -- 2.7.4 From 7dff08909ee26b253d7465803ae2820783e87cb3 Mon Sep 17 00:00:00 2001 From: "yoonki.park" Date: Tue, 10 May 2016 17:37:32 +0900 Subject: [PATCH 03/16] Added to check validation of pointer - If packet pointer has invalid address then restart SDBD. Change-Id: Ieff9343bba35dcfe5122c18ddea60eec615bac76 Signed-off-by: shingil.kang --- packaging/sdbd.spec | 2 +- packaging/sdbd_device.service | 2 +- src/fdevent.c | 2 +- src/sdb.c | 7 +++++++ src/transport.c | 8 ++++++++ 5 files changed, 18 insertions(+), 3 deletions(-) diff --git a/packaging/sdbd.spec b/packaging/sdbd.spec index a05aff7..826c4f0 100644 --- a/packaging/sdbd.spec +++ b/packaging/sdbd.spec @@ -2,7 +2,7 @@ Name: sdbd Summary: SDB daemon -Version: 3.0.10 +Version: 3.0.11 Release: 0 License: Apache-2.0 Summary: SDB daemon diff --git a/packaging/sdbd_device.service b/packaging/sdbd_device.service index e83b1f7..4fe803f 100644 --- a/packaging/sdbd_device.service +++ b/packaging/sdbd_device.service @@ -7,7 +7,7 @@ After=tmp.mount Type=forking EnvironmentFile=-/run/tizen-system-env PIDFile=/tmp/.sdbd.pid -RemainAfterExit=yes +Restart=on-failure ExecStart=/usr/sbin/sdbd [Install] diff --git a/src/fdevent.c b/src/fdevent.c index ca1bf3c..2e8a45a 100644 --- a/src/fdevent.c +++ b/src/fdevent.c @@ -50,7 +50,7 @@ static void fatal(const char *fn, const char *fmt, ...) fprintf(stderr, "%s:", fn); vfprintf(stderr, fmt, ap); va_end(ap); - abort(); + exit(-1); } #define FATAL(x...) fatal(__FUNCTION__, x) diff --git a/src/sdb.c b/src/sdb.c index 793d8ec..1fbd885 100644 --- a/src/sdb.c +++ b/src/sdb.c @@ -630,6 +630,13 @@ void parse_banner(char *banner, atransport *t) void handle_packet(apacket *p, atransport *t) { + // Verify pointer p + int result = access((const char *) p, F_OK); + if ((result == -1) && (errno == EFAULT)) { + D("Invalid apacket = [0x%x]", p); + fatal("Invalid apacket = [0x%x]", p); + } + asocket *s; D("handle_packet() %c%c%c%c\n", ((char*) (&(p->msg.command)))[0], diff --git a/src/transport.c b/src/transport.c index a697eee..1fe4b9d 100644 --- a/src/transport.c +++ b/src/transport.c @@ -323,6 +323,14 @@ static void *input_thread(void *_t) t->serial, t->fd ); break; } + + // Verify pointer p + int result = access((const char *) p, F_OK); + if ((result == -1) && (errno == EFAULT)) { + D("Invalid apacket = [0x%x]", p); + fatal("Invalid apacket = [0x%x]", p); + } + if(p->msg.command == A_SYNC){ if(p->msg.arg0 == 0) { D("%s: transport SYNC offline\n", t->serial); -- 2.7.4 From 98350bb2861dd178c159f3ab00310d77038942c0 Mon Sep 17 00:00:00 2001 From: Kim Gunsoo Date: Mon, 18 Apr 2016 13:21:57 +0900 Subject: [PATCH 04/16] Change the routine for determining whether the emulator or device. - Determined to look at kernel parameters that includes the vm_name in case of emulator. Change-Id: I06734a63eb3afcb9b9638bc1044275e5291fc5eb Signed-off-by: Kim Gunsoo --- src/sdb.c | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/src/sdb.c b/src/sdb.c index 1fbd885..4f9040b 100644 --- a/src/sdb.c +++ b/src/sdb.c @@ -102,11 +102,18 @@ int (*usb_read)(usb_handle *h, void *data, size_t len) = NULL; int (*usb_close)(usb_handle *h) = NULL; void (*usb_kick)(usb_handle *h) = NULL; +int g_is_emulator = -1; int is_emulator(void) { #if SDB_HOST - return 0; + return 0; #else - return sdbd_commandline_args.emulator.host != NULL; + if (g_is_emulator >= 0) { + return g_is_emulator; + } else { + D("failed to initialize check emulator\n"); + } + + return sdbd_commandline_args.emulator.host != NULL; #endif } @@ -2112,9 +2119,33 @@ static int is_support_sockproto() return (!strncmp(g_capabilities.sockproto_support, SDBD_CAP_RET_ENABLED, strlen(SDBD_CAP_RET_ENABLED))); } +#define EMULATOR_MODEL_NAME "Emulator" +static check_emulator_or_device() +{ + char model_name[256]={0,}; + int ret = -1; + + // Get the model name from model_config.xml + ret = get_device_name(model_name, sizeof model_name); + if (ret == 0) { + if(!strncmp(model_name, EMULATOR_MODEL_NAME, sizeof(EMULATOR_MODEL_NAME))){ + g_is_emulator = 1; + D("This target type is Emulator\n"); + } else { + g_is_emulator = 0; + D("This target type is Device\n"); + } + } else { + g_is_emulator = -1; + D("failed to get the model name.\n"); + } +} + int sdb_main(int is_daemon, int server_port) { #if !SDB_HOST + check_emulator_or_device(); + load_sdbd_plugin(); init_capabilities(); -- 2.7.4 From c0cc4c69e65107bb2b0f955c2589ca53551c6940 Mon Sep 17 00:00:00 2001 From: "shingil.kang" Date: Wed, 27 Apr 2016 17:43:11 +0900 Subject: [PATCH 05/16] Modify modules that need root permission. - Removed to permit root permission for push/pull(unitest, codecoverage, DA) - Changed uid/gid of SDBD into sdk Change-Id: Idd874377159afa3d387c9abb59aada2a9d34dbc3 Signed-off-by: shingil.kang --- packaging/sdbd.spec | 2 +- packaging/sdbd_device.service | 2 ++ packaging/sdbd_emulator.service | 2 ++ src/file_sync_service.c | 64 +---------------------------------------- 4 files changed, 6 insertions(+), 64 deletions(-) diff --git a/packaging/sdbd.spec b/packaging/sdbd.spec index 826c4f0..6e1ba42 100644 --- a/packaging/sdbd.spec +++ b/packaging/sdbd.spec @@ -2,7 +2,7 @@ Name: sdbd Summary: SDB daemon -Version: 3.0.11 +Version: 3.0.12 Release: 0 License: Apache-2.0 Summary: SDB daemon diff --git a/packaging/sdbd_device.service b/packaging/sdbd_device.service index 4fe803f..5aaac68 100644 --- a/packaging/sdbd_device.service +++ b/packaging/sdbd_device.service @@ -4,6 +4,8 @@ Requires=tizen-system-env.service After=tmp.mount [Service] +User=sdk +Group=sdk Type=forking EnvironmentFile=-/run/tizen-system-env PIDFile=/tmp/.sdbd.pid diff --git a/packaging/sdbd_emulator.service b/packaging/sdbd_emulator.service index 1a2f298..01d3d04 100644 --- a/packaging/sdbd_emulator.service +++ b/packaging/sdbd_emulator.service @@ -5,6 +5,8 @@ After=tmp.mount dbus.service #DefaultDependencies=false [Service] +User=sdk +Group=sdk Type=forking Environment=DISPLAY=:0 PIDFile=/tmp/.sdbd.pid diff --git a/src/file_sync_service.c b/src/file_sync_service.c index 5fc6642..c15ae10 100644 --- a/src/file_sync_service.c +++ b/src/file_sync_service.c @@ -39,42 +39,11 @@ #define SYNC_TIMEOUT 15 -struct sync_permit_rule -{ - const char *name; - char *regx; - int mode; // 0:push, 1: pull, 2: push&push -}; - -struct sync_permit_rule sdk_sync_permit_rule[] = { - /* 0 */ {"unitest", "", 1}, - /* 1 */ {"codecoverage", "", 1}, - /* 2 */ {"da", "", 1}, - /* end */ {NULL, NULL, 0} -}; - /* The typical default value for the umask is S_IWGRP | S_IWOTH (octal 022). * Before use the DIR_PERMISSION, the process umask value should be set 0 using umask(). */ #define DIR_PERMISSION 0777 -void init_sdk_sync_permit_rule_regx(void) -{ - int ret; - ret = asprintf(&sdk_sync_permit_rule[0].regx, "^((/tmp)|(%s)|(%s))/[a-zA-Z0-9]{10}/data/[a-zA-Z0-9_\\-]{1,50}\\.xml$", APP_INSTALL_PATH_PREFIX1, APP_INSTALL_PATH_PREFIX2); - if(ret < 0) { - D("failed to run asprintf for unittest\n"); - } - ret = asprintf(&sdk_sync_permit_rule[1].regx, "^((/tmp)|(%s)|(%s))/[a-zA-Z0-9]{10}/data/+(.)*\\.gcda$", APP_INSTALL_PATH_PREFIX1, APP_INSTALL_PATH_PREFIX2); - if (ret < 0) { - D("failed to run asprintf for codecoverage\n"); - } - ret = asprintf(&sdk_sync_permit_rule[2].regx, "^(/tmp/da/)*+[a-zA-Z0-9_\\-\\.]{1,50}\\.png$"); - if (ret < 0) { - D("failed to run asprintf for da\n"); - } -} - static void set_syncfile_smack_label(char *src) { char *label_transmuted = NULL; char *label = NULL; @@ -589,37 +558,6 @@ static int do_recv(int s, const char *path, char *buffer) return 0; } -static int verify_sync_rule(const char* path) { - regex_t regex; - int ret; - char buf[PATH_MAX]; - int i=0; - - init_sdk_sync_permit_rule_regx(); - for (i=0; sdk_sync_permit_rule[i].regx != NULL; i++) { - ret = regcomp(®ex, sdk_sync_permit_rule[i].regx, REG_EXTENDED); - if(ret){ - return 0; - } - // execute regular expression - ret = regexec(®ex, path, 0, NULL, 0); - if(!ret){ - regfree(®ex); - D("found matched rule(%s) from %s path\n", sdk_sync_permit_rule[i].name, path); - return 1; - } else if( ret == REG_NOMATCH ){ - // do nothin - } else{ - regerror(ret, ®ex, buf, sizeof(buf)); - D("regex match failed(%s): %s\n",sdk_sync_permit_rule[i].name, buf); - } - } - regfree(®ex); - for (i=0; sdk_sync_permit_rule[i].regx != NULL; i++){ - free(sdk_sync_permit_rule[i].regx); - } - return 0; -} void file_sync_service(int fd, void *cookie) { @@ -684,7 +622,7 @@ void file_sync_service(int fd, void *cookie) D("sync: '%s' '%s'\n", (char*) &msg.req, name); - if (should_drop_privileges() && !verify_sync_rule(name)) { + if (should_drop_privileges()) { set_sdk_user_privileges(); } -- 2.7.4 From 7038519e1a244ae6d26ac00ec520b211ad62e085 Mon Sep 17 00:00:00 2001 From: Kim Gunsoo Date: Wed, 25 May 2016 13:18:15 +0900 Subject: [PATCH 06/16] Fixed SVACE issue. - Invalid function definition. Change-Id: I9b3367185add114459359d25422985ab9599d4c7 Signed-off-by: Kim Gunsoo --- src/sdb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sdb.c b/src/sdb.c index 4f9040b..4c3009f 100644 --- a/src/sdb.c +++ b/src/sdb.c @@ -2120,7 +2120,7 @@ static int is_support_sockproto() } #define EMULATOR_MODEL_NAME "Emulator" -static check_emulator_or_device() +static void check_emulator_or_device() { char model_name[256]={0,}; int ret = -1; -- 2.7.4 From ff03cf6d6131893619b03875c15b5039901dcd32 Mon Sep 17 00:00:00 2001 From: "shingil.kang" Date: Thu, 26 May 2016 17:11:31 +0900 Subject: [PATCH 07/16] Added sdbd service to emulator_preinit.target - Sdbd needs to be booted early for debugging. - Moved the target of sdbd service to emulator_preinit.target from emulator.target Change-Id: I55708052dd8b831684a0a83139935cd14e96af98 Signed-off-by: shingil.kang --- packaging/sdbd.spec | 8 ++++---- packaging/sdbd_emulator.service | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packaging/sdbd.spec b/packaging/sdbd.spec index 826c4f0..6a3da0b 100644 --- a/packaging/sdbd.spec +++ b/packaging/sdbd.spec @@ -2,7 +2,7 @@ Name: sdbd Summary: SDB daemon -Version: 3.0.11 +Version: 3.0.12 Release: 0 License: Apache-2.0 Summary: SDB daemon @@ -59,8 +59,8 @@ mkdir -p %{buildroot}%{_libdir}/systemd/system mkdir -p %{buildroot}%{_unitdir} %ifarch %{ix86} 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/ +mkdir -p %{buildroot}/%{_libdir}/systemd/system/emulator_preinit.target.wants +ln -s %{_libdir}/systemd/system/sdbd.service %{buildroot}/%{_libdir}/systemd/system/emulator_preinit.target.wants/ %else install -m 0644 %SOURCE1001 %{buildroot}%{_unitdir}/sdbd.service install -m 0644 %SOURCE1004 %{buildroot}%{_unitdir}/sdbd_tcp.service @@ -94,7 +94,7 @@ fi %attr(0755, root, root) %{_sysconfdir}/init.d/sdbd %{_unitdir}/sdbd.service %ifarch %{ix86} -%{_libdir}/systemd/system/emulator.target.wants/sdbd.service +%{_libdir}/systemd/system/emulator_preinit.target.wants/sdbd.service %else %{_unitdir}/sdbd_tcp.service %{_libdir}/systemd/system/multi-user.target.wants/sdbd.service diff --git a/packaging/sdbd_emulator.service b/packaging/sdbd_emulator.service index 1a2f298..3db25cf 100644 --- a/packaging/sdbd_emulator.service +++ b/packaging/sdbd_emulator.service @@ -14,5 +14,5 @@ SmackProcessLabel=User ExecStart=/bin/sh -c "/usr/sbin/sdbd `/usr/bin/awk '{match($0, /sdb_port=([0-9]+)/,port_match); match($0, /vm_name=([^, ]*)/,vm_match); print \"--emulator=\" vm_match[1] \":\" port_match[1] \" --connect-to=10.0.2.2:26099\" \" --sensors=10.0.2.2:\"port_match[1]+3 }' /proc/cmdline`" [Install] -WantedBy=emulator.target +WantedBy=emulator_preinit.target -- 2.7.4 From 935e0b600c01ef6c81e22053453fe32e2c53995c Mon Sep 17 00:00:00 2001 From: Taeyoung Kim Date: Thu, 26 May 2016 14:27:32 +0900 Subject: [PATCH 08/16] sdb: change group and owner of sdb device node - The owner and group of sdbd are changed from "root "to "sdk". Thus the udev rule is changed for it. - Previous: bash-3.2# ls -alZ /dev/samsung_sdb crw------- 1 root root * 10, 15 Jan 1 23:41 /dev/samsung_sdb bash-3.2# - Now: bash-3.2# ls -alZ /dev/samsung_sdb crw-rw---- 1 sdk sdk * 10, 15 Jan 2 04:09 /dev/samsung_sdb bash-3.2# Change-Id: Ifef41987d391bc544cd8792fc21458624306ce29 Signed-off-by: Taeyoung Kim --- packaging/sdbd.spec | 8 +++++++- rules/99-sdbd.rules | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 rules/99-sdbd.rules diff --git a/packaging/sdbd.spec b/packaging/sdbd.spec index 6a3da0b..22f6be6 100644 --- a/packaging/sdbd.spec +++ b/packaging/sdbd.spec @@ -2,7 +2,7 @@ Name: sdbd Summary: SDB daemon -Version: 3.0.12 +Version: 3.0.13 Release: 0 License: Apache-2.0 Summary: SDB daemon @@ -74,6 +74,11 @@ install -m 755 script/sdk_launch %{buildroot}%{_prefix}/sbin/ mkdir -p %{buildroot}%{TZ_SYS_BIN} install -m 755 script/profile_command %{buildroot}%{TZ_SYS_BIN}/ +%ifnarch %{ix86} +mkdir -p %{buildroot}%{_prefix}/lib/udev/rules.d/ +install -m 644 rules/99-sdbd.rules %{buildroot}%{_prefix}/lib/udev/rules.d/ +%endif + %post . %{_sysconfdir}/tizen-platform.conf if ! getent passwd "${TZ_SDK_USER_NAME}" > /dev/null; then @@ -98,6 +103,7 @@ fi %else %{_unitdir}/sdbd_tcp.service %{_libdir}/systemd/system/multi-user.target.wants/sdbd.service +%{_prefix}/lib/udev/rules.d/99-sdbd.rules %endif /usr/share/license/%{name} %{TZ_SYS_BIN}/profile_command diff --git a/rules/99-sdbd.rules b/rules/99-sdbd.rules new file mode 100644 index 0000000..c441d87 --- /dev/null +++ b/rules/99-sdbd.rules @@ -0,0 +1 @@ +KERNEL=="samsung_sdb", OWNER="sdk", GROUP="sdk", SECLABEL{smack}="*" -- 2.7.4 From 45bfe8e57fd16c8bc2ad8073afeb3a842c3eb810 Mon Sep 17 00:00:00 2001 From: Sangjin Kim Date: Tue, 31 May 2016 01:40:09 -0700 Subject: [PATCH 09/16] Revert "sdb: change group and owner of sdb device node" This reverts commit 935e0b600c01ef6c81e22053453fe32e2c53995c. Change-Id: I4d6b1fcf839d8b4e222a1c50f2267bb03b7f8e23 --- packaging/sdbd.spec | 8 +------- rules/99-sdbd.rules | 1 - 2 files changed, 1 insertion(+), 8 deletions(-) delete mode 100644 rules/99-sdbd.rules diff --git a/packaging/sdbd.spec b/packaging/sdbd.spec index 22f6be6..6a3da0b 100644 --- a/packaging/sdbd.spec +++ b/packaging/sdbd.spec @@ -2,7 +2,7 @@ Name: sdbd Summary: SDB daemon -Version: 3.0.13 +Version: 3.0.12 Release: 0 License: Apache-2.0 Summary: SDB daemon @@ -74,11 +74,6 @@ install -m 755 script/sdk_launch %{buildroot}%{_prefix}/sbin/ mkdir -p %{buildroot}%{TZ_SYS_BIN} install -m 755 script/profile_command %{buildroot}%{TZ_SYS_BIN}/ -%ifnarch %{ix86} -mkdir -p %{buildroot}%{_prefix}/lib/udev/rules.d/ -install -m 644 rules/99-sdbd.rules %{buildroot}%{_prefix}/lib/udev/rules.d/ -%endif - %post . %{_sysconfdir}/tizen-platform.conf if ! getent passwd "${TZ_SDK_USER_NAME}" > /dev/null; then @@ -103,7 +98,6 @@ fi %else %{_unitdir}/sdbd_tcp.service %{_libdir}/systemd/system/multi-user.target.wants/sdbd.service -%{_prefix}/lib/udev/rules.d/99-sdbd.rules %endif /usr/share/license/%{name} %{TZ_SYS_BIN}/profile_command diff --git a/rules/99-sdbd.rules b/rules/99-sdbd.rules deleted file mode 100644 index c441d87..0000000 --- a/rules/99-sdbd.rules +++ /dev/null @@ -1 +0,0 @@ -KERNEL=="samsung_sdb", OWNER="sdk", GROUP="sdk", SECLABEL{smack}="*" -- 2.7.4 From 9395230cf70cc07bfd036f8aa374f5f9443c7983 Mon Sep 17 00:00:00 2001 From: Sangjin Kim Date: Tue, 31 May 2016 01:39:53 -0700 Subject: [PATCH 10/16] Revert "Modify modules that need root permission." This reverts commit c0cc4c69e65107bb2b0f955c2589ca53551c6940. Change-Id: I669f55ba15c9757ef34e5c041b85585633d3a0e8 --- packaging/sdbd.spec | 2 +- packaging/sdbd_device.service | 2 -- packaging/sdbd_emulator.service | 2 -- src/file_sync_service.c | 64 ++++++++++++++++++++++++++++++++++++++++- 4 files changed, 64 insertions(+), 6 deletions(-) diff --git a/packaging/sdbd.spec b/packaging/sdbd.spec index 6a3da0b..7bde2d9 100644 --- a/packaging/sdbd.spec +++ b/packaging/sdbd.spec @@ -2,7 +2,7 @@ Name: sdbd Summary: SDB daemon -Version: 3.0.12 +Version: 3.0.11 Release: 0 License: Apache-2.0 Summary: SDB daemon diff --git a/packaging/sdbd_device.service b/packaging/sdbd_device.service index 5aaac68..4fe803f 100644 --- a/packaging/sdbd_device.service +++ b/packaging/sdbd_device.service @@ -4,8 +4,6 @@ Requires=tizen-system-env.service After=tmp.mount [Service] -User=sdk -Group=sdk Type=forking EnvironmentFile=-/run/tizen-system-env PIDFile=/tmp/.sdbd.pid diff --git a/packaging/sdbd_emulator.service b/packaging/sdbd_emulator.service index 995d546..3db25cf 100644 --- a/packaging/sdbd_emulator.service +++ b/packaging/sdbd_emulator.service @@ -5,8 +5,6 @@ After=tmp.mount dbus.service #DefaultDependencies=false [Service] -User=sdk -Group=sdk Type=forking Environment=DISPLAY=:0 PIDFile=/tmp/.sdbd.pid diff --git a/src/file_sync_service.c b/src/file_sync_service.c index c15ae10..5fc6642 100644 --- a/src/file_sync_service.c +++ b/src/file_sync_service.c @@ -39,11 +39,42 @@ #define SYNC_TIMEOUT 15 +struct sync_permit_rule +{ + const char *name; + char *regx; + int mode; // 0:push, 1: pull, 2: push&push +}; + +struct sync_permit_rule sdk_sync_permit_rule[] = { + /* 0 */ {"unitest", "", 1}, + /* 1 */ {"codecoverage", "", 1}, + /* 2 */ {"da", "", 1}, + /* end */ {NULL, NULL, 0} +}; + /* The typical default value for the umask is S_IWGRP | S_IWOTH (octal 022). * Before use the DIR_PERMISSION, the process umask value should be set 0 using umask(). */ #define DIR_PERMISSION 0777 +void init_sdk_sync_permit_rule_regx(void) +{ + int ret; + ret = asprintf(&sdk_sync_permit_rule[0].regx, "^((/tmp)|(%s)|(%s))/[a-zA-Z0-9]{10}/data/[a-zA-Z0-9_\\-]{1,50}\\.xml$", APP_INSTALL_PATH_PREFIX1, APP_INSTALL_PATH_PREFIX2); + if(ret < 0) { + D("failed to run asprintf for unittest\n"); + } + ret = asprintf(&sdk_sync_permit_rule[1].regx, "^((/tmp)|(%s)|(%s))/[a-zA-Z0-9]{10}/data/+(.)*\\.gcda$", APP_INSTALL_PATH_PREFIX1, APP_INSTALL_PATH_PREFIX2); + if (ret < 0) { + D("failed to run asprintf for codecoverage\n"); + } + ret = asprintf(&sdk_sync_permit_rule[2].regx, "^(/tmp/da/)*+[a-zA-Z0-9_\\-\\.]{1,50}\\.png$"); + if (ret < 0) { + D("failed to run asprintf for da\n"); + } +} + static void set_syncfile_smack_label(char *src) { char *label_transmuted = NULL; char *label = NULL; @@ -558,6 +589,37 @@ static int do_recv(int s, const char *path, char *buffer) return 0; } +static int verify_sync_rule(const char* path) { + regex_t regex; + int ret; + char buf[PATH_MAX]; + int i=0; + + init_sdk_sync_permit_rule_regx(); + for (i=0; sdk_sync_permit_rule[i].regx != NULL; i++) { + ret = regcomp(®ex, sdk_sync_permit_rule[i].regx, REG_EXTENDED); + if(ret){ + return 0; + } + // execute regular expression + ret = regexec(®ex, path, 0, NULL, 0); + if(!ret){ + regfree(®ex); + D("found matched rule(%s) from %s path\n", sdk_sync_permit_rule[i].name, path); + return 1; + } else if( ret == REG_NOMATCH ){ + // do nothin + } else{ + regerror(ret, ®ex, buf, sizeof(buf)); + D("regex match failed(%s): %s\n",sdk_sync_permit_rule[i].name, buf); + } + } + regfree(®ex); + for (i=0; sdk_sync_permit_rule[i].regx != NULL; i++){ + free(sdk_sync_permit_rule[i].regx); + } + return 0; +} void file_sync_service(int fd, void *cookie) { @@ -622,7 +684,7 @@ void file_sync_service(int fd, void *cookie) D("sync: '%s' '%s'\n", (char*) &msg.req, name); - if (should_drop_privileges()) { + if (should_drop_privileges() && !verify_sync_rule(name)) { set_sdk_user_privileges(); } -- 2.7.4 From 33654ea3464ae548f366eefe9de4f08df304e34d Mon Sep 17 00:00:00 2001 From: "shingil.kang" Date: Tue, 7 Jun 2016 18:08:36 +0900 Subject: [PATCH 11/16] Get the path where crash file is generated by using TZ_SYS_CRASH environment variable. Change-Id: I954a722b617b90ed8741b6080ed7fa1d20365ee0 Signed-off-by: shingil.kang --- src/services.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/services.c b/src/services.c index dc19c14..2672394 100644 --- a/src/services.c +++ b/src/services.c @@ -264,7 +264,7 @@ void reboot_service(int fd, void *arg) #if !SDB_HOST #define EVENT_SIZE ( sizeof (struct inotify_event) ) #define BUF_LEN ( 1024 * ( EVENT_SIZE + 16 ) ) -#define CS_PATH tzplatform_mkpath(TZ_USER_SHARE,"crash/report") +#define CS_PATH tzplatform_getenv(TZ_SYS_CRASH) void inoti_service(int fd, void *arg) { @@ -281,6 +281,12 @@ void inoti_service(int fd, void *arg) } wd = inotify_add_watch( ifd, CS_PATH, IN_CREATE); + if ( wd < 0 ) { + D("inotify_add_watch failed (errno :%d)\n", errno); + sdb_close(ifd); + sdb_close(fd); + return; + } for ( ; ; ) { int length, i = 0; -- 2.7.4 From 2146e6e0df3f4a1d46115653a4eed2313c3a693b Mon Sep 17 00:00:00 2001 From: "shingil.kang" Date: Tue, 7 Jun 2016 18:16:57 +0900 Subject: [PATCH 12/16] Added the new protocol to get the value of environment variable. - 'env:{environment_variable}' prototol is used to get the value of {environment_variable} Change-Id: Ie96c2318665c45950c7c17d156da378b62b1ea1e Signed-off-by: shingil.kang --- src/services.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/services.c b/src/services.c index 2672394..94558c6 100644 --- a/src/services.c +++ b/src/services.c @@ -219,6 +219,23 @@ void rootshell_service(int fd, void *cookie) sdb_close(fd); } +void get_tzplatform_env(int fd, void *cookie) { + char buf[PATH_MAX] = { 0, }; + char *env_name = (char*) cookie; + D("environment variable name: %s\n", env_name); + enum tzplatform_variable env_id = tzplatform_getid(env_name); + if (env_id != _TZPLATFORM_VARIABLES_INVALID_) { + char *env_value = tzplatform_getenv(env_id); + if (env_value) { + D("environment value : %s\n", env_value); + snprintf(buf, sizeof(buf), env_value); + writex(fd, buf, strlen(buf)); + } + } + free(env_name); + sdb_close(fd); +} + void restart_usb_service(int fd, void *cookie) { char buf[100]; @@ -1082,6 +1099,10 @@ int service_to_fd(const char *name) if(!strncmp(name+10, "syncwinsz:", 10)){ ret = create_service_thread(sync_windowsize, (void *)name+20); } + } else if(!strncmp(name, "tzplatformenv:", 14)) { + char* env_variable = NULL; + env_variable = strdup(name+14); + ret = create_service_thread(get_tzplatform_env, (void *)(env_variable)); } if (ret >= 0) { -- 2.7.4 From e6f8c1ddc5d7d940e89f69860f3015304e60b769 Mon Sep 17 00:00:00 2001 From: "shingil.kang" Date: Fri, 10 Jun 2016 14:58:36 +0900 Subject: [PATCH 13/16] Returns error code when it fails to get the value of tzplatform envrionment variable. - return 0 when succeeded - return 1 when error is occured while getting the value of tzplatform environment variable. - return 2 when tzplatform environment variable is not valid. Change-Id: Ie4530148c43d757f69a3e8457777cbf25cb4dc3d Signed-off-by: shingil.kang --- src/services.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/services.c b/src/services.c index 94558c6..a1c0008 100644 --- a/src/services.c +++ b/src/services.c @@ -219,6 +219,12 @@ void rootshell_service(int fd, void *cookie) sdb_close(fd); } +enum tzplatform_get_env_error_status { + NO_ERROR_TZPLATFORM_ENV = 0, + ERROR_TZPLATFORM_ENV_GENERAL = 1, + ERROR_TZPLATFORM_ENV_INVALID_VARIABLES = 2, +}; + void get_tzplatform_env(int fd, void *cookie) { char buf[PATH_MAX] = { 0, }; char *env_name = (char*) cookie; @@ -228,10 +234,16 @@ void get_tzplatform_env(int fd, void *cookie) { char *env_value = tzplatform_getenv(env_id); if (env_value) { D("environment value : %s\n", env_value); - snprintf(buf, sizeof(buf), env_value); - writex(fd, buf, strlen(buf)); + snprintf(buf, sizeof(buf), "%d%s", NO_ERROR_TZPLATFORM_ENV, env_value); + } else { + D("failed to get environment value using tzplatform_getenv"); + snprintf(buf, sizeof(buf), "%d", ERROR_TZPLATFORM_ENV_GENERAL); } + } else { + D("environment name (%s) is invalid\n", env_name); + snprintf(buf, sizeof(buf), "%d", ERROR_TZPLATFORM_ENV_INVALID_VARIABLES); } + writex(fd, buf, strlen(buf)); free(env_name); sdb_close(fd); } -- 2.7.4 From 2622cb18c0871fd97c8235d308362fe4b97b05d4 Mon Sep 17 00:00:00 2001 From: Kim Gunsoo Date: Mon, 13 Jun 2016 18:04:58 +0900 Subject: [PATCH 14/16] Remove unnecessary smack label for running sdbd. - The label(User) of the running sdbd no longer needed. Change-Id: I6b4918d332e73d6db71a584c6a1d37906b8f6a8d Signed-off-by: Kim Gunsoo --- packaging/sdbd.spec | 2 +- packaging/sdbd_emulator.service | 1 - packaging/sdbd_tcp.service | 1 - 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/packaging/sdbd.spec b/packaging/sdbd.spec index 7bde2d9..6a3da0b 100644 --- a/packaging/sdbd.spec +++ b/packaging/sdbd.spec @@ -2,7 +2,7 @@ Name: sdbd Summary: SDB daemon -Version: 3.0.11 +Version: 3.0.12 Release: 0 License: Apache-2.0 Summary: SDB daemon diff --git a/packaging/sdbd_emulator.service b/packaging/sdbd_emulator.service index 3db25cf..b477d5a 100644 --- a/packaging/sdbd_emulator.service +++ b/packaging/sdbd_emulator.service @@ -9,7 +9,6 @@ Type=forking Environment=DISPLAY=:0 PIDFile=/tmp/.sdbd.pid RemainAfterExit=yes -SmackProcessLabel=User #ExecStartPre=/bin/bash -c "/bin/echo '10.0.2.15/32 system::debugging_network' >> /smack/netlabel" ExecStart=/bin/sh -c "/usr/sbin/sdbd `/usr/bin/awk '{match($0, /sdb_port=([0-9]+)/,port_match); match($0, /vm_name=([^, ]*)/,vm_match); print \"--emulator=\" vm_match[1] \":\" port_match[1] \" --connect-to=10.0.2.2:26099\" \" --sensors=10.0.2.2:\"port_match[1]+3 }' /proc/cmdline`" diff --git a/packaging/sdbd_tcp.service b/packaging/sdbd_tcp.service index 4ded27c..46b4266 100644 --- a/packaging/sdbd_tcp.service +++ b/packaging/sdbd_tcp.service @@ -7,5 +7,4 @@ Type=forking Environment=DISPLAY=:0 PIDFile=/tmp/.sdbd.pid RemainAfterExit=yes -SmackProcessLabel=User ExecStart=/usr/sbin/sdbd --listen-port=26101 -- 2.7.4 From 41f7c54b77f54c04078ed9ac28fe247f56cc154b Mon Sep 17 00:00:00 2001 From: "shingil.kang" Date: Tue, 14 Jun 2016 17:13:22 +0900 Subject: [PATCH 15/16] Added capabilities ralated to sdbd log - sdbd_log_enable : enable or disable sdbd log - sdbd_log_path : the folder location of sdbd log Change-Id: I52b91ba2242536474fe6b6f0e34dd48ddebc8a50 Signed-off-by: shingil.kang --- packaging/sdbd_device.service | 2 ++ packaging/sdbd_emulator.service | 2 ++ src/sdb.c | 70 +++++++++++++++++++++++++++++++++++------ src/sdb.h | 4 +++ src/sdbd_plugin.h | 3 ++ src/services.c | 8 +++++ 6 files changed, 79 insertions(+), 10 deletions(-) diff --git a/packaging/sdbd_device.service b/packaging/sdbd_device.service index 4fe803f..ac0ad44 100644 --- a/packaging/sdbd_device.service +++ b/packaging/sdbd_device.service @@ -5,6 +5,8 @@ After=tmp.mount [Service] Type=forking +#location of SDBD log file +#Environment=SDBD_LOG_PATH=/tmp EnvironmentFile=-/run/tizen-system-env PIDFile=/tmp/.sdbd.pid Restart=on-failure diff --git a/packaging/sdbd_emulator.service b/packaging/sdbd_emulator.service index b477d5a..5427780 100644 --- a/packaging/sdbd_emulator.service +++ b/packaging/sdbd_emulator.service @@ -6,6 +6,8 @@ After=tmp.mount dbus.service [Service] Type=forking +#location of SDBD log file +#Environment=SDBD_LOG_PATH=/tmp Environment=DISPLAY=:0 PIDFile=/tmp/.sdbd.pid RemainAfterExit=yes diff --git a/src/sdb.c b/src/sdb.c index 4c3009f..0120c7b 100644 --- a/src/sdb.c +++ b/src/sdb.c @@ -170,6 +170,11 @@ void fatal_errno(const char *fmt, ...) exit(-1); } +static int is_enable_sdbd_log() +{ + return (!strncmp(g_capabilities.log_enable, SDBD_CAP_RET_ENABLED, strlen(SDBD_CAP_RET_ENABLED))); +} + int sdb_trace_mask; /* read a comma/space/colum/semi-column separated list of tags @@ -203,8 +208,12 @@ void sdb_trace_init(void) { NULL, 0 } }; - if (p == NULL) + if (p == NULL) { + if (is_enable_sdbd_log()) + p = "all"; + else return; + } /* use a comma/column/semi-colum/space separated list */ while (*p) { @@ -1018,14 +1027,18 @@ void start_logging(void) } #if !SDB_HOST + void start_device_log(void) { int fd; - char path[PATH_MAX]; + char path[PATH_MAX] = {0, }; + char path_folder[PATH_MAX] = {0, }; + char path_file[PATH_MAX] = {0, }; struct tm now; time_t t; // char value[PROPERTY_VALUE_MAX]; - const char* p = getenv("SDB_TRACE"); + const char* p_trace = getenv("SDB_TRACE"); + const char* p_path = getenv("SDBD_LOG_PATH"); // read the trace mask from persistent property persist.sdb.trace_mask // give up if the property is not set or cannot be parsed #if 0 /* tizen specific */ @@ -1034,16 +1047,28 @@ void start_device_log(void) return; #endif - if (p == NULL) { + if ((p_trace == NULL ) && !is_enable_sdbd_log()) { return; } + + if (p_path) + snprintf(path_folder, sizeof(path_folder), "%s", p_path); + else if (g_capabilities.log_path[0] != '\0') + snprintf(path_folder, sizeof(path_folder), "%s", g_capabilities.log_path); + else + return; + tzset(); time(&t); localtime_r(&t, &now); - strftime(path, sizeof(path), - "/tmp/sdbd-%Y-%m-%d-%H-%M-%S.txt", - &now); - fd = unix_open(path, O_WRONLY | O_CREAT | O_TRUNC, 0640); + + strftime(path_file, sizeof(path_file), + "sdbd-%Y-%m-%d-%H-%M-%S.txt", + &now); + + snprintf(path, sizeof(path), "%s/%s", path_folder, path_file); + + fd = unix_open(path, O_WRONLY | O_CREAT | O_TRUNC, 0644); if (fd < 0) { return; } @@ -1592,6 +1617,12 @@ static int get_plugin_capability(const char* in_buf, sdbd_plugin_param out) { } else if (SDBD_CMP_CAP(in_buf, PRODUCT_VER)) { snprintf(out.data, out.len, "%s", UNKNOWN); ret = SDBD_PLUGIN_RET_SUCCESS; + } else if (SDBD_CMP_CAP(in_buf, LOG_ENABLE)) { + snprintf(out.data, out.len, "%s", SDBD_CAP_RET_DISABLED); + ret = SDBD_PLUGIN_RET_SUCCESS; + } else if (SDBD_CMP_CAP(in_buf, LOG_PATH)) { + snprintf(out.data, out.len, "%s", "/tmp"); + ret = SDBD_PLUGIN_RET_SUCCESS; } return ret; @@ -2107,6 +2138,24 @@ static void init_capabilities(void) { snprintf(g_capabilities.sdbd_plugin_version, sizeof(g_capabilities.sdbd_plugin_version), "%s", UNKNOWN); } + + // sdbd log enable + if(!request_plugin_cmd(SDBD_CMD_PLUGIN_CAP, SDBD_CAP_TYPE_LOG_ENABLE, + g_capabilities.log_enable, + sizeof(g_capabilities.log_enable))) { + D("failed to request. (%s:%s) \n", SDBD_CMD_PLUGIN_CAP, SDBD_CAP_TYPE_LOG_ENABLE); + snprintf(g_capabilities.log_enable, sizeof(g_capabilities.log_enable), + "%s", DISABLED); + } + + // sdbd log path + if(!request_plugin_cmd(SDBD_CMD_PLUGIN_CAP, SDBD_CAP_TYPE_LOG_PATH, + g_capabilities.log_path, + sizeof(g_capabilities.log_path))) { + D("failed to request. (%s:%s) \n", SDBD_CMD_PLUGIN_CAP, SDBD_CAP_TYPE_LOG_PATH); + snprintf(g_capabilities.log_path, sizeof(g_capabilities.log_path), + "%s", UNKNOWN); + } } static int is_support_usbproto() @@ -2149,6 +2198,9 @@ int sdb_main(int is_daemon, int server_port) load_sdbd_plugin(); init_capabilities(); + sdb_trace_init(); + start_device_log(); + init_drop_privileges(); init_sdk_requirements(); if (!request_plugin_verification(SDBD_CMD_VERIFY_LAUNCH, NULL)) { @@ -2615,7 +2667,6 @@ int recovery_mode = 0; int main(int argc, char **argv) { - sdb_trace_init(); /* tizen specific */ #if SDB_HOST sdb_sysdeps_init(); sdb_trace_init(); @@ -2654,7 +2705,6 @@ int main(int argc, char **argv) fatal("daemonize() failed: errno:%d", errno); #endif - start_device_log(); D("Handling main()\n"); //sdbd will never die on emulator! diff --git a/src/sdb.h b/src/sdb.h index 7e3d1f1..c9a9e0c 100644 --- a/src/sdb.h +++ b/src/sdb.h @@ -246,6 +246,7 @@ typedef struct platform_info { #define CAPBUF_SIZE 4096 #define CAPBUF_ITEMSIZE 32 #define CAPBUF_L_ITEMSIZE 256 +#define CAPBUF_LL_ITEMSIZE PATH_MAX typedef struct platform_capabilities { char secure_protocol[CAPBUF_ITEMSIZE]; // enabled or disabled @@ -258,6 +259,9 @@ typedef struct platform_capabilities char usbproto_support[CAPBUF_ITEMSIZE]; // enabled or disabled char sockproto_support[CAPBUF_ITEMSIZE]; // enabled or disabled + char log_enable[CAPBUF_ITEMSIZE]; // enabled or disabled + char log_path[CAPBUF_LL_ITEMSIZE]; // path of sdbd log + char cpu_arch[CAPBUF_ITEMSIZE]; // cpu architecture (ex. x86) char profile_name[CAPBUF_ITEMSIZE]; // profile name (ex. mobile) char vendor_name[CAPBUF_ITEMSIZE]; // vendor name (ex. Tizen) diff --git a/src/sdbd_plugin.h b/src/sdbd_plugin.h index 81c590a..9bfc4b9 100644 --- a/src/sdbd_plugin.h +++ b/src/sdbd_plugin.h @@ -36,6 +36,9 @@ #define SDBD_CAP_TYPE_ROOTONOFF "root_onoff_support" #define SDBD_CAP_TYPE_PLUGIN_VER "sdbd_plugin_version" #define SDBD_CAP_TYPE_PRODUCT_VER "product_version" +#define SDBD_CAP_TYPE_LOG_ENABLE "sdbd_log_enable" +#define SDBD_CAP_TYPE_LOG_PATH "sdbd_log_path" + /* capability return string */ #define SDBD_CAP_RET_ENABLED "enabled" #define SDBD_CAP_RET_DISABLED "disabled" diff --git a/src/services.c b/src/services.c index a1c0008..33c5c76 100644 --- a/src/services.c +++ b/src/services.c @@ -951,6 +951,14 @@ static void get_capability(int fd, void *cookie) { offset += put_key_value_string(cap_buffer, offset, CAPBUF_SIZE, "syncwinsz_support", g_capabilities.syncwinsz_support); + // Sdbd log enable + offset += put_key_value_string(cap_buffer, offset, CAPBUF_SIZE, + "log_enable", g_capabilities.log_enable); + + // Sdbd log path + offset += put_key_value_string(cap_buffer, offset, CAPBUF_SIZE, + "log_path", g_capabilities.log_path); + offset++; // for '\0' character -- 2.7.4 From bfd54375ee15471f2a6d12f7212f9d13e585c4f5 Mon Sep 17 00:00:00 2001 From: "shingil.kang" Date: Thu, 16 Jun 2016 11:57:30 +0900 Subject: [PATCH 16/16] Disabled OOM killing for SDBD process on TV profile Change-Id: I721285019b58a7f2d1004bac25c52606aa3d3738 Signed-off-by: shingil.kang --- packaging/sdbd.spec | 12 ++++++++++++ packaging/sdbd_device_tv.service | 17 +++++++++++++++++ packaging/sdbd_emulator_tv.service | 20 ++++++++++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 packaging/sdbd_device_tv.service create mode 100644 packaging/sdbd_emulator_tv.service diff --git a/packaging/sdbd.spec b/packaging/sdbd.spec index 6a3da0b..e8539f8 100644 --- a/packaging/sdbd.spec +++ b/packaging/sdbd.spec @@ -12,6 +12,8 @@ Source1001: sdbd_device.service Source1002: sdbd_emulator.service Source1003: %{name}.manifest Source1004: sdbd_tcp.service +Source1005: sdbd_device_tv.service +Source1006: sdbd_emulator_tv.service BuildRequires: capi-system-info-devel >= 0.2.0 BuildRequires: cmake >= 2.8.3 @@ -57,12 +59,22 @@ cp LICENSE %{buildroot}/usr/share/license/%{name} %make_install mkdir -p %{buildroot}%{_libdir}/systemd/system mkdir -p %{buildroot}%{_unitdir} + %ifarch %{ix86} +%if "%{profile}" == "tv" +install -m 0644 %SOURCE1006 %{buildroot}%{_libdir}/systemd/system/sdbd.service +%else install -m 0644 %SOURCE1002 %{buildroot}%{_libdir}/systemd/system/sdbd.service +%endif mkdir -p %{buildroot}/%{_libdir}/systemd/system/emulator_preinit.target.wants ln -s %{_libdir}/systemd/system/sdbd.service %{buildroot}/%{_libdir}/systemd/system/emulator_preinit.target.wants/ + +%else +%if "%{profile}" == "tv" +install -m 0644 %SOURCE1005 %{buildroot}%{_unitdir}/sdbd.service %else install -m 0644 %SOURCE1001 %{buildroot}%{_unitdir}/sdbd.service +%endif install -m 0644 %SOURCE1004 %{buildroot}%{_unitdir}/sdbd_tcp.service mkdir -p %{buildroot}/%{_libdir}/systemd/system/multi-user.target.wants ln -s %{_libdir}/systemd/system/sdbd.service %{buildroot}/%{_libdir}/systemd/system/multi-user.target.wants/ diff --git a/packaging/sdbd_device_tv.service b/packaging/sdbd_device_tv.service new file mode 100644 index 0000000..fe3c965 --- /dev/null +++ b/packaging/sdbd_device_tv.service @@ -0,0 +1,17 @@ +[Unit] +Description=sdbd +Requires=tizen-system-env.service +After=tmp.mount + +[Service] +Type=forking +#location of SDBD log file +#Environment=SDBD_LOG_PATH=/tmp +EnvironmentFile=-/run/tizen-system-env +OOMScoreAdjust=-1000 +PIDFile=/tmp/.sdbd.pid +Restart=on-failure +ExecStart=/usr/sbin/sdbd + +[Install] +WantedBy=multi-user.target diff --git a/packaging/sdbd_emulator_tv.service b/packaging/sdbd_emulator_tv.service new file mode 100644 index 0000000..4d81fd2 --- /dev/null +++ b/packaging/sdbd_emulator_tv.service @@ -0,0 +1,20 @@ +[Unit] +Description=sdbd +Before=sensord.service +After=tmp.mount dbus.service +#DefaultDependencies=false + +[Service] +Type=forking +#location of SDBD log file +#Environment=SDBD_LOG_PATH=/tmp +Environment=DISPLAY=:0 +PIDFile=/tmp/.sdbd.pid +RemainAfterExit=yes +OOMScoreAdjust=-1000 +#ExecStartPre=/bin/bash -c "/bin/echo '10.0.2.15/32 system::debugging_network' >> /smack/netlabel" +ExecStart=/bin/sh -c "/usr/sbin/sdbd `/usr/bin/awk '{match($0, /sdb_port=([0-9]+)/,port_match); match($0, /vm_name=([^, ]*)/,vm_match); print \"--emulator=\" vm_match[1] \":\" port_match[1] \" --connect-to=10.0.2.2:26099\" \" --sensors=10.0.2.2:\"port_match[1]+3 }' /proc/cmdline`" + +[Install] +WantedBy=emulator_preinit.target + -- 2.7.4