From 597a05ca47795b91fae03815e01cf8fb7467ecb9 Mon Sep 17 00:00:00 2001 From: "yoonki.park" Date: Fri, 4 Mar 2016 17:41:43 +0900 Subject: [PATCH 01/16] Fixed build warning "implicit declaration of function" Change-Id: I15989e44823099736c39f600716e0e559bb45850 Signed-off-by: shingil.kang --- packaging/sdbd.spec | 2 +- packaging/sdbd_device.service | 2 +- src/file_sync_service.c | 3 ++- src/sdb.c | 37 +++++++++++++++--------------- src/sdb.h | 1 + src/services.c | 2 +- src/utils.c | 53 +++++++++++++++++++++++++++++-------------- src/utils.h | 2 +- 8 files changed, 61 insertions(+), 41 deletions(-) diff --git a/packaging/sdbd.spec b/packaging/sdbd.spec index dc6d083..00d6fd4 100644 --- a/packaging/sdbd.spec +++ b/packaging/sdbd.spec @@ -2,7 +2,7 @@ Name: sdbd Summary: SDB daemon -Version: 3.0.3 +Version: 3.0.4 Release: 0 License: Apache-2.0 Summary: SDB daemon diff --git a/packaging/sdbd_device.service b/packaging/sdbd_device.service index 949ca4e..e83b1f7 100644 --- a/packaging/sdbd_device.service +++ b/packaging/sdbd_device.service @@ -11,4 +11,4 @@ RemainAfterExit=yes ExecStart=/usr/sbin/sdbd [Install] -WantedBy=multi-user.target \ No newline at end of file +WantedBy=multi-user.target diff --git a/src/file_sync_service.c b/src/file_sync_service.c index 2efe0ea..cfe3e7f 100644 --- a/src/file_sync_service.c +++ b/src/file_sync_service.c @@ -35,6 +35,7 @@ #include "file_sync_service.h" #include "sdktools.h" #include "sdbd_plugin.h" +#include "utils.h" #define SYNC_TIMEOUT 15 @@ -65,7 +66,7 @@ void init_sdk_sync_permit_rule_regx(void) { 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); 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); - asprintf(&sdk_sync_permit_rule[2].regx, "da", "^(/tmp/da/)*+[a-zA-Z0-9_\\-\\.]{1,50}\\.png$"); + asprintf(&sdk_sync_permit_rule[2].regx, "^(/tmp/da/)*+[a-zA-Z0-9_\\-\\.]{1,50}\\.png$"); } diff --git a/src/sdb.c b/src/sdb.c index 10198ab..52e520f 100644 --- a/src/sdb.c +++ b/src/sdb.c @@ -1262,6 +1262,24 @@ static void pwlock_cb(keynode_t *key, void* data) { send_device_status(); } +void register_pwlock_cb() { + int ret = vconf_notify_key_changed(VCONFKEY_IDLE_LOCK_STATE, pwlock_cb, NULL); + if(ret != 0) { + D("cannot register vconf callback.\n"); + return; + } + D("registered vconf callback\n"); +} + +void unregister_pwlock_cb() { + int ret = vconf_ignore_key_changed(VCONFKEY_IDLE_LOCK_STATE, pwlock_cb); + if(ret != 0) { + D("cannot unregister vconf callback.\n"); + return; + } + D("unregistered vconf callback\n"); +} + static void *pwlock_thread(void *x) { GMainLoop *loop; loop = g_main_loop_new(NULL, FALSE); @@ -1272,7 +1290,6 @@ static void *pwlock_thread(void *x) { return 0; } - void create_pwlock_thread() { sdb_thread_t t; if(sdb_thread_create( &t, pwlock_thread, NULL)) { @@ -1282,24 +1299,6 @@ void create_pwlock_thread() { D("created pwlock_thread\n"); } -void register_pwlock_cb() { - int ret = vconf_notify_key_changed(VCONFKEY_IDLE_LOCK_STATE, pwlock_cb, NULL); - if(ret != 0) { - D("cannot register vconf callback.\n"); - return; - } - D("registered vconf callback\n"); -} - -void unregister_pwlock_cb() { - int ret = vconf_ignore_key_changed(VCONFKEY_IDLE_LOCK_STATE, pwlock_cb); - if(ret != 0) { - D("cannot unregister vconf callback.\n"); - return; - } - D("unregistered vconf callback\n"); -} - #include #include #include diff --git a/src/sdb.h b/src/sdb.h index 9cef525..295aa32 100644 --- a/src/sdb.h +++ b/src/sdb.h @@ -309,6 +309,7 @@ void init_transport_registration(void); int list_transports(char *buf, size_t bufsize); void update_transports(void); void broadcast_transport(apacket *p); +int get_connected_count(transport_type type); asocket* create_device_tracker(void); diff --git a/src/services.c b/src/services.c index f5c62f3..739e36f 100644 --- a/src/services.c +++ b/src/services.c @@ -39,6 +39,7 @@ #endif #include "strutils.h" +#include "utils.h" #include #include @@ -596,7 +597,6 @@ static int create_subproc_thread(const char *name, int lines, int columns) snprintf(path, sizeof(path), "%s", trim_value); } envp[3] = path; - free(trim_value); } else { snprintf(path, sizeof(path), "%s", value); envp[3] = path; diff --git a/src/utils.c b/src/utils.c index b111a16..ae7d51d 100644 --- a/src/utils.c +++ b/src/utils.c @@ -23,6 +23,7 @@ #include #include #include +#include #define STRING_MAXLEN 1024 char* @@ -112,24 +113,42 @@ buff_add (char* buff, char* buffEnd, const char* format, ... ) return buff; } -char *str_trim(const char* string) -{ - const char* s = string; - const char* e = string + (strlen(string) - 1); - char* ret; - - while(*s == ' ' || *s == '\t') // ltrim - s++; - while(*e == ' ' || *e == '\t') // rtrim - e--; - - ret = strdup(s); - if(ret == NULL) { - return NULL; - } - ret[e - s + 1] = 0; +char *str_trim(char *str) { + size_t len = 0; + char *frontp = str; + char *endp = NULL; - return ret; + if (str == NULL) { + return NULL; + } + if (str[0] == '\0') { + return str; + } + + len = strlen(str); + endp = str + len; + + while (isspace(*frontp)) { + ++frontp; + } + if (endp != frontp) { + while (isspace(*(--endp)) && endp != frontp) { + } + } + + if (str + len - 1 != endp) + *(endp + 1) = '\0'; + else if (frontp != str && endp == frontp) + *str = '\0'; + + endp = str; + if (frontp != str) { + while (*frontp) { + *endp++ = *frontp++; + } + *endp = '\0'; + } + return str; } int spawn(char* program, char** arg_list) diff --git a/src/utils.h b/src/utils.h index 6904377..11a63c8 100644 --- a/src/utils.h +++ b/src/utils.h @@ -66,7 +66,7 @@ char* buff_add (char* buff, char* buffEnd, const char* format, ... ); #define BUFF_DECL(_buff,_cursor,_end,_size) \ char _buff[_size], *_cursor=_buff, *_end = _cursor + (_size) -char *str_trim(const char* string); +char *str_trim(char* string); /* * spawn a process and returns the process id of the new spawned process. -- 2.7.4 From 61de9b7f320a41726123e0916cffb440d7b494ef Mon Sep 17 00:00:00 2001 From: Kim Gunsoo Date: Tue, 8 Mar 2016 17:48:52 +0900 Subject: [PATCH 02/16] Fixed the incorrect version information for profile_command. - Modified to 3.0 from the 4.0. Change-Id: I06cfade7942f8a14fee763adc523afaa9f24c769 Signed-off-by: Kim Gunsoo --- script/profile_command | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script/profile_command b/script/profile_command index cdaef64..27efe39 100755 --- a/script/profile_command +++ b/script/profile_command @@ -1,6 +1,6 @@ #!/bin/bash -VERSION="4.0" +VERSION="3.0" KILL=/usr/bin/killall MANAGER=/usr/bin/da_manager FIND=/usr/bin/find -- 2.7.4 From 89e53405f7396e065018326fdc4fb945d70196f6 Mon Sep 17 00:00:00 2001 From: Kim Gunsoo Date: Tue, 8 Mar 2016 18:41:06 +0900 Subject: [PATCH 03/16] MISC: package version up(3.0.5) - Fixed the incorrect version information for profile_command. Change-Id: I8ed08c3e4d63badbe5b314ec85a4272ec3c44e1a Signed-off-by: Kim Gunsoo --- packaging/sdbd.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/sdbd.spec b/packaging/sdbd.spec index 00d6fd4..8372f3c 100644 --- a/packaging/sdbd.spec +++ b/packaging/sdbd.spec @@ -2,7 +2,7 @@ Name: sdbd Summary: SDB daemon -Version: 3.0.4 +Version: 3.0.5 Release: 0 License: Apache-2.0 Summary: SDB daemon -- 2.7.4 From 845160f17df2ae504382893ab1374aa5b02968d7 Mon Sep 17 00:00:00 2001 From: "shingil.kang" Date: Wed, 9 Mar 2016 11:02:10 +0900 Subject: [PATCH 04/16] Fixed sources reported by static code analysis tool. Change-Id: I5307232da32f736c3686ea0a080eea18a09db962 Signed-off-by: shingil.kang --- src/file_sync_service.c | 4 ++-- src/properties.c | 13 ++++++++----- src/sdb.c | 6 +++--- src/transport_local.c | 5 +++-- src/usb_funcfs_client.c | 8 ++++---- 5 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/file_sync_service.c b/src/file_sync_service.c index cfe3e7f..61842a7 100644 --- a/src/file_sync_service.c +++ b/src/file_sync_service.c @@ -92,7 +92,7 @@ static void set_syncfile_smack_label(char *src) { rc = smack_getlabel(dirname, &label, SMACK_LABEL_ACCESS); if (rc == 0 && label != NULL) { if (smack_setlabel(src, label, SMACK_LABEL_ACCESS) == -1) { - D("unable to set sync file smack label %s due to %s\n", label, strerror(errno)); + D("unable to set sync file smack label %s due to (errno:%d)\n", label, errno); } /* Todo: The following code is from tizen 2.4 @@ -109,7 +109,7 @@ static void set_syncfile_smack_label(char *src) { free(label_transmuted); } else { if (smack_setlabel(src, SMACK_SYNC_FILE_LABEL, SMACK_LABEL_ACCESS) == -1) { - D("unable to set sync file smack label %s due to %s\n", SMACK_SYNC_FILE_LABEL, strerror(errno)); + D("unable to set sync file smack label %s due to (errno:%d)\n", SMACK_SYNC_FILE_LABEL, errno); } /* Todo: The following code is from tizen 2.4 diff --git a/src/properties.c b/src/properties.c index 42e5785..dc76a69 100644 --- a/src/properties.c +++ b/src/properties.c @@ -60,6 +60,7 @@ static void property_init(void) int i = 0; char buffer[PROPERTY_KEY_MAX+PROPERTY_VALUE_MAX+1]; char *tok = NULL; + char *ptr; fd = unix_open(TIZEN_PROPERTY_FILE, O_RDONLY); if (fd < 0) @@ -67,12 +68,14 @@ static void property_init(void) for(;;) { if(read_line(fd, buffer, PROPERTY_KEY_MAX+PROPERTY_VALUE_MAX+1) < 0) break; - tok = strtok(buffer, PROPERTY_SEPARATOR); + tok = strtok_r(buffer, PROPERTY_SEPARATOR, &ptr); for (i = 0; i < sdbd_config_element_cnt && sdbd_config[i].key ; i++) { if (!strcmp(tok, sdbd_config[i].key)) { - tok = strtok(NULL, PROPERTY_SEPARATOR); - strncpy(sdbd_config[i].value, tok, PROPERTY_VALUE_MAX); - D("property init key=%s, value=%s\n", sdbd_config[i].key, tok); + tok = strtok_r(NULL, PROPERTY_SEPARATOR, &ptr); + if(tok) { + snprintf(sdbd_config[i].value, PROPERTY_VALUE_MAX, "%s", tok); + D("property init key=%s, value=%s\n", sdbd_config[i].key, tok); + } } } @@ -113,7 +116,7 @@ int property_set(const char *key, const char *value) for (i = 0; i < sdbd_config_element_cnt && sdbd_config[i].key; i++) { if (!strcmp(key,sdbd_config[i].key)) { - strncpy(sdbd_config[i].value, value, PROPERTY_VALUE_MAX); + snprintf(sdbd_config[i].value, PROPERTY_VALUE_MAX, "%s", value); D("property set key=%s, value=%s\n", key, value); break; } diff --git a/src/sdb.c b/src/sdb.c index 52e520f..175c3ff 100644 --- a/src/sdb.c +++ b/src/sdb.c @@ -1416,10 +1416,10 @@ int set_developer_privileges() { } } // TODO: use pam later - char * env = malloc(strlen("HOME=") + strlen(HOME_DEV_PATH) + 1); + int env_size = strlen("HOME=") + strlen(HOME_DEV_PATH) + 1; + char * env = malloc(env_size); if(env == 0) fatal("failed to allocate for env string"); - strcpy(env, "HOME="); - strcat(env, HOME_DEV_PATH); + snprintf(env, env_size, "HOME=%s", HOME_DEV_PATH); putenv(env); free(env); diff --git a/src/transport_local.c b/src/transport_local.c index 8e8029b..1daa143 100644 --- a/src/transport_local.c +++ b/src/transport_local.c @@ -431,7 +431,8 @@ static const char _ok_resp[] = "ok"; */ static int send_msg_to_host_from_guest(const char *hostname, int host_port, char *request, int protocol) { int sock = -1; - char port[32]; /* string decimal representation for getaddrinfo */ + int PORT_SIZE = 32; + char port[PORT_SIZE]; /* string decimal representation for getaddrinfo */ struct addrinfo hints = {0}; struct addrinfo *addresses, *curr_addr; int getaddr_ret; @@ -455,7 +456,7 @@ static int send_msg_to_host_from_guest(const char *hostname, int host_port, char hints.ai_family = AF_INET; - sprintf(port, "%d", host_port); + snprintf(port, PORT_SIZE, "%d", host_port); getaddr_ret = getaddrinfo(hostname, port, &hints, &addresses); if (getaddr_ret != 0) { diff --git a/src/usb_funcfs_client.c b/src/usb_funcfs_client.c index 0237e5a..ef28284 100644 --- a/src/usb_funcfs_client.c +++ b/src/usb_funcfs_client.c @@ -532,8 +532,8 @@ int ffs_usb_write(usb_handle *h, const void *data, int len) D("about to write (fd=%d, len=%d)\n", h->bulk_in, len); n = bulk_write(h->bulk_in, data, len); if(n != len) { - D("ERROR: fd = %d, n = %d, errno = %d (%s)\n", - h->bulk_in, n, errno, strerror(errno)); + D("ERROR: fd = %d, n = %d, errno = %d\n", + h->bulk_in, n, errno); return -1; } D("[ done fd=%d ]\n", h->bulk_in); @@ -555,8 +555,8 @@ int ffs_usb_read(usb_handle *h, void *data, int len) D("%d: about to read (fd=%d, len=%d)\n", getpid(), h->bulk_out, len); n = bulk_read(h->bulk_out, data, len); if(n != len) { - D("ERROR: fd = %d, n = %d, errno = %d (%s)\n", - h->bulk_out, n, errno, strerror(errno)); + D("ERROR: fd = %d, n = %d, errno = %d\n", + h->bulk_out, n, errno); return -1; } D("[ done fd=%d ]\n", h->bulk_out); -- 2.7.4 From b60aa8d7ce56eb3c392b1ae12bc3ce691fa111d4 Mon Sep 17 00:00:00 2001 From: Kim Gunsoo Date: Thu, 10 Mar 2016 20:54:01 +0900 Subject: [PATCH 05/16] Modify the fixed SDK constant(developer). - changed to obtained using the platform API(tizen-platform-config). Change-Id: I0c975660c8fda8868561750d747162487733af62 Signed-off-by: Kim Gunsoo --- src/commandline.c | 2 +- src/file_sync_service.c | 2 +- src/sdb.c | 178 ++++++++++++++++++++++++++++++++++++++++-------- src/sdb.h | 10 ++- src/sdktools.c | 2 +- src/sdktools.h | 2 +- src/services.c | 31 +++++---- 7 files changed, 177 insertions(+), 50 deletions(-) diff --git a/src/commandline.c b/src/commandline.c index 740cd2b..1d88c7a 100644 --- a/src/commandline.c +++ b/src/commandline.c @@ -127,7 +127,7 @@ void help() " sdb status-window - continuously print device status for a specified device\n" // " sdb usb - restarts the sdbd daemon listing on USB\n" // " sdb tcpip - restarts the sdbd daemon listing on TCP\n" - " sdb root - switch to root or developer account mode\n" + " sdb root - switch to root or sdk user account mode\n" " 'on' means to root mode, and vice versa" "\n" ); diff --git a/src/file_sync_service.c b/src/file_sync_service.c index 61842a7..3f49e39 100644 --- a/src/file_sync_service.c +++ b/src/file_sync_service.c @@ -672,7 +672,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)) { - set_developer_privileges(); + set_sdk_user_privileges(); } switch(msg.req.id) { diff --git a/src/sdb.c b/src/sdb.c index 175c3ff..c29e51f 100644 --- a/src/sdb.c +++ b/src/sdb.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -68,6 +69,11 @@ SDB_MUTEX_DEFINE( D_lock ); int HOST = 0; #define HOME_DEV_PATH tzplatform_getenv(TZ_SDK_HOME) #define DEV_NAME tzplatform_getenv(TZ_SDK_USER_NAME) +uid_t g_sdk_user_id = -1; +gid_t g_sdk_group_id = -1; +char* g_sdk_home_dir = NULL; +char* g_sdk_home_dir_env = NULL; + #if !SDB_HOST SdbdCommandlineArgs sdbd_commandline_args; #endif @@ -1391,41 +1397,108 @@ void register_bootdone_cb() { } } -int set_developer_privileges() { - gid_t groups[] = { SID_DEVELOPER, SID_APP_LOGGING, SID_SYS_LOGGING, SID_INPUT }; - if (setgroups(sizeof(groups) / sizeof(groups[0]), groups) != 0) { +static int sdbd_set_groups() { + gid_t *groups = NULL; + int ngroups = 0; + int default_ngroups = 0; + int i, j = 0; + int group_match = 0; + int added_group_cnt = 0; + gid_t default_groups[] = { SID_DEVELOPER, SID_APP_LOGGING, SID_SYS_LOGGING, SID_INPUT }; + + default_ngroups = sizeof(default_groups) / sizeof(default_groups[0]); + + getgrouplist(SDK_USER_NAME, g_sdk_group_id, NULL, &ngroups); + D("group list : ngroups = %d\n", ngroups); + groups = malloc((ngroups + default_ngroups) * sizeof(gid_t)); + if (groups == NULL) { + D("failed to allocate groups(%d)\n", (ngroups + default_ngroups) * sizeof(gid_t)); + return -1; + } + if (getgrouplist(SDK_USER_NAME, g_sdk_group_id, groups, &ngroups) == -1) { + D("failed to getgrouplist(), ngroups = %d\n", ngroups); + free(groups); + return -1; + } + + for (i = 0; i < default_ngroups; i++) { + for (j = 0; j < ngroups; j++) { + if (groups[j] == default_groups[i]) { + group_match = 1; + break; + } + } + if (group_match == 0) { + groups[ngroups + added_group_cnt] = default_groups[i]; + added_group_cnt ++; + } + group_match = 0; + } + + if (setgroups(ngroups+added_group_cnt, groups) != 0) { + D("failed to setgroups().\n"); + free(groups); + return -1; + } + + free(groups); + return 0; +} + +static int sdbd_get_user_pwd(const char* user_name, struct passwd* pwd, char* buf, size_t bufsize) { + struct passwd *result = NULL; + int ret = 0; + + ret = getpwnam_r(user_name, pwd, buf, bufsize, &result); + if (result == NULL) { + if (ret == 0) { + D("Not found passwd : username(%s)\n", user_name); + } else { + errno = ret; + D("failed to getpwuid_r\n"); + } + free(buf); + return -1; + } + + return 0; +} + +int set_sdk_user_privileges() { + if (g_sdk_user_id < 0 || g_sdk_group_id < 0 || + g_sdk_home_dir == NULL || g_sdk_home_dir_env == NULL) { + D("failed to init sdk user information.\n"); + return -1; + } + + if (sdbd_set_groups() < 0) { D("set groups failed (errno: %d)\n", errno); + + // set default group list + gid_t default_groups[] = { SID_DEVELOPER, SID_APP_LOGGING, SID_SYS_LOGGING, SID_INPUT }; + int default_ngroups = sizeof(default_groups) / sizeof(default_groups[0]); + setgroups(default_ngroups, default_groups); } - // then switch user and group to developer - if (setgid(SID_DEVELOPER) != 0) { + if (setgid(g_sdk_group_id) != 0) { D("set group id failed (errno: %d)\n", errno); return -1; } - if (setuid(SID_DEVELOPER) != 0) { + if (setuid(g_sdk_user_id) != 0) { D("set user id failed (errno: %d)\n", errno); return -1; } - if (chdir(HOME_DEV_PATH) < 0) { - D("sdbd: unable to change working directory to %s\n", HOME_DEV_PATH); - } else { - if (chdir("/") < 0) { - D("sdbd: unable to change working directory to /\n"); - } + 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 - int env_size = strlen("HOME=") + strlen(HOME_DEV_PATH) + 1; - char * env = malloc(env_size); - if(env == 0) fatal("failed to allocate for env string"); - snprintf(env, env_size, "HOME=%s", HOME_DEV_PATH); - putenv(env); - free(env); - return 1; + // TODO: use pam later + putenv(g_sdk_home_dir_env); + return 0; } -#define ONDEMAND_ROOT_PATH tzplatform_getenv(TZ_SDK_HOME) static void execute_required_process() { char *cmd_args[] = {"/usr/bin/debug_launchpad_preloading_preinitializing_daemon",NULL}; @@ -1647,6 +1720,52 @@ static void load_sdbd_plugin() { D("using sdbd plugin interface.(%s)\n", SDBD_PLUGIN_PATH); } +static int init_sdk_userinfo() { + struct passwd pwd; + char *buf = NULL; + size_t bufsize = 0; + + if (g_sdk_user_id > 0 && g_sdk_group_id > 0 && + g_sdk_home_dir != NULL && g_sdk_home_dir_env != NULL) { + return 0; + } + + bufsize = sysconf(_SC_GETPW_R_SIZE_MAX); + if (bufsize < 0) { + bufsize = (16*1024); + } + buf = malloc(bufsize); + if (buf == NULL) { + D("failed to allocate passwd buf(%d)\n", bufsize); + return -1; + } + + if (sdbd_get_user_pwd(SDK_USER_NAME, &pwd, buf, bufsize) < 0) { + D("get user passwd info.(errno: %d)\n", errno); + 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); + + 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) { + D("failed to allocate for home dir env string\n"); + free(g_sdk_home_dir); + g_sdk_home_dir = NULL; + return -1; + } + snprintf(g_sdk_home_dir_env, env_size, "HOME=%s", g_sdk_home_dir); + + return 0; +} + static void init_sdk_requirements() { struct stat st; @@ -1660,14 +1779,15 @@ static void init_sdk_requirements() { putenv("HOME=/root"); } - if (stat(ONDEMAND_ROOT_PATH, &st) == -1) { - return; - } - if (st.st_uid != SID_DEVELOPER || st.st_gid != GID_DEVELOPER) { - char cmd[128]; - snprintf(cmd, sizeof(cmd), "chown %s:%s %s -R", DEV_NAME, DEV_NAME, ONDEMAND_ROOT_PATH); - if (system(cmd) < 0) { - D("failed to change ownership to developer to %s\n", ONDEMAND_ROOT_PATH); + init_sdk_userinfo(); + + if (g_sdk_home_dir != NULL && stat(g_sdk_home_dir, &st) == 0) { + if (st.st_uid != g_sdk_user_id || st.st_gid != g_sdk_group_id) { + char cmd[128]; + snprintf(cmd, sizeof(cmd), "chown %s:%s %s -R", SDK_USER_NAME, SDK_USER_NAME, g_sdk_home_dir); + if (system(cmd) < 0) { + D("failed to change ownership to sdk user to %s\n", g_sdk_home_dir); + } } } diff --git a/src/sdb.h b/src/sdb.h index 295aa32..750e9a6 100644 --- a/src/sdb.h +++ b/src/sdb.h @@ -374,7 +374,7 @@ void log_service(int fd, void *cookie); void remount_service(int fd, void *cookie); char * get_log_file_path(const char * log_name); -int rootshell_mode; // 0: developer, 1: root +int rootshell_mode; // 0: sdk user, 1: root int booting_done; // 0: platform booting is in progess 1: platform booting is done // This is the users and groups config for the platform @@ -383,16 +383,20 @@ int booting_done; // 0: platform booting is in progess 1: platform booting is do #define SID_TTY 5 /* group for /dev/ptmx */ #define SID_APP tzplatform_getuid(TZ_USER_NAME) /* application */ #define SID_DEVELOPER tzplatform_getuid(TZ_SDK_USER_NAME) /* developer with SDK */ -#define GID_DEVELOPER 100 /* developer will be member of users with SDK */ #define SID_APP_LOGGING 6509 #define SID_SYS_LOGGING 6527 #define SID_INPUT 1004 +#define SDK_USER_NAME tzplatform_getenv(TZ_SDK_USER_NAME) +extern uid_t g_sdk_user_id; +extern gid_t g_sdk_group_id; +extern char* g_sdk_home_dir; +extern char* g_sdk_home_dir_env; #endif int is_pwlocked(void); int should_drop_privileges(void); -int set_developer_privileges(); +int set_sdk_user_privileges(); void set_root_privileges(); int get_emulator_forward_port(void); diff --git a/src/sdktools.c b/src/sdktools.c index 814e066..f24bccc 100644 --- a/src/sdktools.c +++ b/src/sdktools.c @@ -178,7 +178,7 @@ int verify_root_commands(const char *arg1) { } } - D("doing the cmd as a %s\n", ret == 1 ? "root" : "developer"); + D("doing the cmd as a %s\n", ret == 1 ? "root" : SDK_USER_NAME); if (cnt) { free_strings(tokens, cnt); diff --git a/src/sdktools.h b/src/sdktools.h index 59d8d98..50b68de 100644 --- a/src/sdktools.h +++ b/src/sdktools.h @@ -13,7 +13,7 @@ struct sudo_command const char *path; const char *arguments[PERMITTED_ARGUMENT_SIZE]; //const char *regx; - //int permission; /* 0: root, 1: developer, 2: app*/ + //int permission; /* 0: root, 1: sdk user, 2: app*/ }; diff --git a/src/services.c b/src/services.c index 739e36f..78cd4aa 100644 --- a/src/services.c +++ b/src/services.c @@ -186,7 +186,7 @@ void rootshell_service(int fd, void *cookie) if (!strcmp(mode, "on")) { if (getuid() == 0) { if (rootshell_mode == 1) { - //snprintf(buf, sizeof(buf), "Already changed to developer mode\n"); + //snprintf(buf, sizeof(buf), "Already changed to sdk user mode\n"); // do not show message } else { if (is_support_rootonoff()) { @@ -207,14 +207,14 @@ void rootshell_service(int fd, void *cookie) } else if (!strcmp(mode, "off")) { if (rootshell_mode == 1) { rootshell_mode = 0; - snprintf(buf, sizeof(buf), "Switched to 'developer' account mode\n"); + snprintf(buf, sizeof(buf), "Switched to 'sdk user' account mode\n"); writex(fd, buf, strlen(buf)); } } else { snprintf(buf, sizeof(buf), "Unknown command option : %s\n", mode); writex(fd, buf, strlen(buf)); } - D("set rootshell to %s\n", rootshell_mode == 1 ? "root" : "developer"); + D("set rootshell to %s\n", rootshell_mode == 1 ? "root" : SDK_USER_NAME); free(mode); sdb_close(fd); } @@ -459,7 +459,7 @@ static int create_subprocess(const char *cmd, pid_t *pid, const char *argv[], co // do nothing D("sdb: executes root commands!!:%s\n", argv[2]); } else { - set_developer_privileges(); + set_sdk_user_privileges(); } } redirect_and_exec(pts, cmd, argv, envp); @@ -478,7 +478,6 @@ static int create_subprocess(const char *cmd, pid_t *pid, const char *argv[], co #define SHELL_COMMAND "/bin/sh" #define LOGIN_COMMAND "/bin/login" -#define SDK_USER "developer" #define SUPER_USER "root" #define LOGIN_CONFIG "/etc/login.defs" @@ -578,15 +577,19 @@ static int create_subproc_thread(const char *name, int lines, int columns) }; if (should_drop_privileges()) { - envp[2] = "HOME=/home/developer"; - get_env("ENV_PATH", &value); - } else { - get_env("ENV_SUPATH", &value); - if(value == NULL) { - get_env("ENV_ROOTPATH", &value); - } - envp[2] = "HOME=/root"; - } + if (g_sdk_home_dir_env) { + envp[2] = g_sdk_home_dir_env; + } else { + envp[2] = "HOME=/home/owner"; + } + get_env("ENV_PATH", &value); + } else { + get_env("ENV_SUPATH", &value); + if(value == NULL) { + get_env("ENV_ROOTPATH", &value); + } + envp[2] = "HOME=/root"; + } if (value != NULL) { trim_value = str_trim(value); if (trim_value != NULL) { -- 2.7.4 From 9f4dd3a9a340c2d0e7a1b8f0364c7c10fb11d3fb Mon Sep 17 00:00:00 2001 From: "shingil.kang" Date: Thu, 10 Mar 2016 22:06:52 +0900 Subject: [PATCH 06/16] Removed hard-coded path to support multi-user. Change-Id: I48871f1e2b98511c94e916fc291f94dfe861b9a6 Signed-off-by: shingil.kang --- packaging/sdbd.spec | 8 ++++---- src/file_sync_service.c | 21 ++++++++++----------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/packaging/sdbd.spec b/packaging/sdbd.spec index 8372f3c..aaba56d 100644 --- a/packaging/sdbd.spec +++ b/packaging/sdbd.spec @@ -2,7 +2,7 @@ Name: sdbd Summary: SDB daemon -Version: 3.0.5 +Version: 3.0.6 Release: 0 License: Apache-2.0 Summary: SDB daemon @@ -72,8 +72,8 @@ ln -s %{_libdir}/systemd/system/sdbd.service %{buildroot}/%{_libdir}/systemd/sys mkdir -p %{buildroot}%{_prefix}/sbin install -m 755 script/sdk_launch %{buildroot}%{_prefix}/sbin/ -mkdir -p %{buildroot}/usr/bin -install -m 755 script/profile_command %{buildroot}/usr/bin/ +mkdir -p %{buildroot}%{TZ_SYS_BIN} +install -m 755 script/profile_command %{buildroot}%{TZ_SYS_BIN}/ %post . %{_sysconfdir}/tizen-platform.conf @@ -101,6 +101,6 @@ fi %{_libdir}/systemd/system/multi-user.target.wants/sdbd.service %endif /usr/share/license/%{name} -/usr/bin/profile_command +%{TZ_SYS_BIN}/profile_command %changelog diff --git a/src/file_sync_service.c b/src/file_sync_service.c index 61842a7..67ba692 100644 --- a/src/file_sync_service.c +++ b/src/file_sync_service.c @@ -40,7 +40,7 @@ #define SYNC_TIMEOUT 15 #define APP_INSTALL_PATH_PREFIX1 tzplatform_getenv(TZ_SYS_RW_APP) -#define APP_INSTALL_PATH_PREFIX2 tzplatform_getenv(TZ_USER_APP) +#define APP_INSTALL_PATH_PREFIX2 tzplatform_mkpath(TZ_SDK_HOME, "apps_rw") struct sync_permit_rule { @@ -50,10 +50,9 @@ struct sync_permit_rule }; struct sync_permit_rule sdk_sync_permit_rule[] = { -// /* 0 */ {"rds", "^((/opt/apps)|(/opt/usr/apps))/[a-zA-Z0-9]{10}/info/\\.sdk_delta\\.info$", 1}, - /* 1 */ {"unitest", "^((/tmp)|(/opt/apps)|(/opt/usr/apps))/[a-zA-Z0-9]{10}/data/[a-zA-Z0-9_\\-]{1,50}\\.xml$", 1}, - /* 2 */ {"codecoverage", "^((/tmp)|(/opt/apps)|(/opt/usr/apps))/[a-zA-Z0-9]{10}/data/+(.)*\\.gcda$", 1}, - /* 3 */ {"da", "^(/tmp/da/)*+[a-zA-Z0-9_\\-\\.]{1,50}\\.png$", 1}, + /* 0 */ {"unitest", "", 1}, + /* 1 */ {"codecoverage", "", 1}, + /* 2 */ {"da", "", 1}, /* end */ {NULL, NULL, 0} }; @@ -67,7 +66,6 @@ void init_sdk_sync_permit_rule_regx(void) 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); 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); asprintf(&sdk_sync_permit_rule[2].regx, "^(/tmp/da/)*+[a-zA-Z0-9_\\-\\.]{1,50}\\.png$"); - } static void set_syncfile_smack_label(char *src) { @@ -295,11 +293,11 @@ static int fail_errno(int s) } // FIXME: should get the following paths with api later but, do it for simple and not having dependency on other packages -#define VAR_ABS_PATH "/opt/var" -#define CMD_MEDIADB_UPDATE "/usr/bin/mediadb-update" -#define MEDIA_CONTENTS_PATH1 "/opt/media" -#define MEDIA_CONTENTS_PATH2 "/opt/usr/media" -#define MEDIA_CONTENTS_PATH3 "/opt/storage/sdcard" +#define VAR_ABS_PATH "/opt/var" +#define CMD_MEDIADB_UPDATE tzplatform_mkpath(TZ_SYS_BIN, "mediadb-update") +#define MEDIA_CONTENTS_PATH1 tzplatform_getenv(TZ_SYS_STORAGE) +#define MEDIA_CONTENTS_PATH2 tzplatform_getenv(TZ_USER_CONTENT) +#define MEDIA_CONTENTS_PATH3 tzplatform_mkpath(TZ_SYS_STORAGE, "sdcard") static void sync_mediadb(char *path) { if (access(CMD_MEDIADB_UPDATE, F_OK) != 0) { @@ -669,6 +667,7 @@ void file_sync_service(int fd, void *cookie) name[namelen] = 0; msg.req.namelen = 0; + D("sync: '%s' '%s'\n", (char*) &msg.req, name); if (should_drop_privileges() && !verify_sync_rule(name)) { -- 2.7.4 From 6296c63f624fc49a467666a2c74f603c35dd8714 Mon Sep 17 00:00:00 2001 From: "shingil.kang" Date: Fri, 11 Mar 2016 16:12:10 +0900 Subject: [PATCH 07/16] Fixed sdk_launch script (merged from tizen_2.4) Change-Id: I7d07e5749d08647c87477748c809d304ed3e9d23 Signed-off-by: shingil.kang --- script/sdk_launch | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/script/sdk_launch b/script/sdk_launch index 941f236..6206e59 100755 --- a/script/sdk_launch +++ b/script/sdk_launch @@ -132,7 +132,7 @@ then if [ "" != "$attach_id" ] #debug attach then - cmd="$COV_TEST_PREFIX ${TZ_SDK_TOOLS}/gdbserver/gdbserver :$port --attach $attach_id" + cmd="/usr/bin/launch_debug $launch_app_arg1 __AUL_SDK__ ATTACH __DLP_ATTACH_ARG__ --attach,:$port,$attach_id" #debug else if [ "" != "$result_mode" ] @@ -141,7 +141,7 @@ then else result_mode="DEBUG" fi - cmd="/usr/bin/launch_app $pkgid.$exe __AUL_SDK__ $result_mode __DLP_DEBUG_ARG__ :$port $launch_app_mode" + cmd="/usr/bin/launch_app $launch_app_arg1 __AUL_SDK__ $result_mode __DLP_DEBUG_ARG__ :$port $launch_app_mode $args" # cmd="$COV_TEST_PREFIX ${TZ_SDK_TOOLS}/gdbserver/gdbserver :$port ${TZ_SYS_RW_APP}/$pkgid/bin/$exe" fi else @@ -149,9 +149,14 @@ else then if [ "" != "$result_mode" ] then - cmd="/usr/bin/launch_app $pkgid.$exe __AUL_SDK__ $result_mode $launch_app_mode" + if [ "$result_mode" = "UNIT_TEST" ] + then + cmd="/usr/bin/launch_app $launch_app_arg1 __AUL_SDK__ $result_mode $launch_app_mode" + else + cmd="/usr/bin/launch_app $launch_app_arg1 __AUL_SDK__ $result_mode $launch_app_mode $args" + fi else - cmd="/usr/bin/launch_app $pkgid.$exe" + cmd="/usr/bin/launch_app $launch_app_arg1" fi else if [ "$mode" = "da" ] @@ -170,7 +175,7 @@ else result_mode="OPROFILE" fi fi - cmd="/usr/bin/launch_app $pkgid.$exe __AUL_SDK__ $result_mode" + cmd="/usr/bin/launch_app $launch_app_arg1 __AUL_SDK__ $result_mode" fi fi -- 2.7.4 From d37f4532dc78177ce37d0cf86e58eec3057d4615 Mon Sep 17 00:00:00 2001 From: "shingil.kang" Date: Thu, 17 Mar 2016 17:11:55 +0900 Subject: [PATCH 08/16] Removed unnecessary codes Change-Id: I797f401fe9597d6f03462e252d508f459e859183 Signed-off-by: shingil.kang --- src/sdb.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/sdb.c b/src/sdb.c index c29e51f..1686af2 100644 --- a/src/sdb.c +++ b/src/sdb.c @@ -69,10 +69,11 @@ SDB_MUTEX_DEFINE( D_lock ); int HOST = 0; #define HOME_DEV_PATH tzplatform_getenv(TZ_SDK_HOME) #define DEV_NAME tzplatform_getenv(TZ_SDK_USER_NAME) -uid_t g_sdk_user_id = -1; -gid_t g_sdk_group_id = -1; +uid_t g_sdk_user_id; +gid_t g_sdk_group_id; char* g_sdk_home_dir = NULL; char* g_sdk_home_dir_env = NULL; +int is_init_sdk_userinfo = 0; #if !SDB_HOST SdbdCommandlineArgs sdbd_commandline_args; @@ -1465,8 +1466,7 @@ static int sdbd_get_user_pwd(const char* user_name, struct passwd* pwd, char* bu } int set_sdk_user_privileges() { - if (g_sdk_user_id < 0 || g_sdk_group_id < 0 || - g_sdk_home_dir == NULL || g_sdk_home_dir_env == NULL) { + if (!is_init_sdk_userinfo) { D("failed to init sdk user information.\n"); return -1; } @@ -1723,17 +1723,17 @@ static void load_sdbd_plugin() { static int init_sdk_userinfo() { struct passwd pwd; char *buf = NULL; - size_t bufsize = 0; + long bufsize = 0; - if (g_sdk_user_id > 0 && g_sdk_group_id > 0 && - g_sdk_home_dir != NULL && g_sdk_home_dir_env != NULL) { + if (is_init_sdk_userinfo) { return 0; } bufsize = sysconf(_SC_GETPW_R_SIZE_MAX); - if (bufsize < 0) { + if(bufsize < 0) { bufsize = (16*1024); } + buf = malloc(bufsize); if (buf == NULL) { D("failed to allocate passwd buf(%d)\n", bufsize); @@ -1763,6 +1763,7 @@ static int init_sdk_userinfo() { } snprintf(g_sdk_home_dir_env, env_size, "HOME=%s", g_sdk_home_dir); + is_init_sdk_userinfo = 1; return 0; } -- 2.7.4 From 0b202ec3594d65668ab0d1c5b1f2af87b257eb90 Mon Sep 17 00:00:00 2001 From: "shingil.kang" Date: Wed, 30 Mar 2016 12:39:50 +0900 Subject: [PATCH 09/16] Removed libprivilege-control dependency Change-Id: I6db42995d134e555ef93a024c7e0377e5977520c Signed-off-by: shingil.kang --- packaging/sdbd.spec | 1 - 1 file changed, 1 deletion(-) diff --git a/packaging/sdbd.spec b/packaging/sdbd.spec index aaba56d..db9e680 100644 --- a/packaging/sdbd.spec +++ b/packaging/sdbd.spec @@ -23,7 +23,6 @@ BuildRequires: pkgconfig(vconf) BuildRequires: pkgconfig(glib-2.0) BuildRequires: pkgconfig(dbus-1) BuildRequires: pkgconfig(dbus-glib-1) -Requires(post): libprivilege-control Requires: dbus %description -- 2.7.4 From 467ef95149819b0fe41c766ed165b1f7e6091c99 Mon Sep 17 00:00:00 2001 From: Kim Gunsoo Date: Mon, 4 Apr 2016 14:36:24 +0900 Subject: [PATCH 10/16] Add the sdk_toolpath member to sdbd capability. - The sdk_toolpath member includes a path that tool of the SDK is saved. Change-Id: Ie022bed562ea0485d263593c060041a6f4fcea14 Signed-off-by: Kim Gunsoo --- src/sdb.c | 11 +++++++++-- src/sdb.h | 3 +++ src/services.c | 4 ++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/sdb.c b/src/sdb.c index 1686af2..0fa0672 100644 --- a/src/sdb.c +++ b/src/sdb.c @@ -67,8 +67,6 @@ SDB_MUTEX_DEFINE( D_lock ); #endif int HOST = 0; -#define HOME_DEV_PATH tzplatform_getenv(TZ_SDK_HOME) -#define DEV_NAME tzplatform_getenv(TZ_SDK_USER_NAME) uid_t g_sdk_user_id; gid_t g_sdk_group_id; char* g_sdk_home_dir = NULL; @@ -1933,6 +1931,15 @@ static void init_capabilities(void) { snprintf(g_capabilities.syncwinsz_support, sizeof(g_capabilities.syncwinsz_support), "%s", ENABLED); + // SDK Tool path + if (SDK_TOOL_PATH == NULL) { + D("fail to get SDK tool path.\n"); + snprintf(g_capabilities.sdk_toolpath, sizeof(g_capabilities.sdk_toolpath), + "%s", UNKNOWN); + } else { + snprintf(g_capabilities.sdk_toolpath, sizeof(g_capabilities.sdk_toolpath), + "%s", SDK_TOOL_PATH); + } // Profile name ret = system_info_get_platform_string("http://tizen.org/feature/profile", &value); diff --git a/src/sdb.h b/src/sdb.h index 750e9a6..074d165 100644 --- a/src/sdb.h +++ b/src/sdb.h @@ -245,6 +245,7 @@ typedef struct platform_info { #define CPUARCH_X86 "x86" #define CAPBUF_SIZE 4096 #define CAPBUF_ITEMSIZE 32 +#define CAPBUF_L_ITEMSIZE 256 typedef struct platform_capabilities { char secure_protocol[CAPBUF_ITEMSIZE]; // enabled or disabled @@ -260,6 +261,7 @@ typedef struct platform_capabilities 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) + char sdk_toolpath[CAPBUF_L_ITEMSIZE]; // sdk tool path char platform_version[CAPBUF_ITEMSIZE]; // platform version (ex. 2.3.0) char product_version[CAPBUF_ITEMSIZE]; // product version (ex. 1.0) @@ -388,6 +390,7 @@ int booting_done; // 0: platform booting is in progess 1: platform booting is do #define SID_INPUT 1004 #define SDK_USER_NAME tzplatform_getenv(TZ_SDK_USER_NAME) +#define SDK_TOOL_PATH tzplatform_getenv(TZ_SDK_TOOLS) extern uid_t g_sdk_user_id; extern gid_t g_sdk_group_id; extern char* g_sdk_home_dir; diff --git a/src/services.c b/src/services.c index 78cd4aa..9607462 100644 --- a/src/services.c +++ b/src/services.c @@ -885,6 +885,10 @@ static void get_capability(int fd, void *cookie) { offset += put_key_value_string(cap_buffer, offset, CAPBUF_SIZE, "cpu_arch", g_capabilities.cpu_arch); + // SDK Tool path + offset += put_key_value_string(cap_buffer, offset, CAPBUF_SIZE, + "sdk_toolpath", g_capabilities.sdk_toolpath); + // Profile name offset += put_key_value_string(cap_buffer, offset, CAPBUF_SIZE, "profile_name", g_capabilities.profile_name); -- 2.7.4 From 0795f20e22524c34b5a8fad5e920cd7010a60f9b Mon Sep 17 00:00:00 2001 From: Kim Gunsoo Date: Wed, 6 Apr 2016 08:40:21 +0900 Subject: [PATCH 11/16] Add the check routine for multi-user support. - The multi-user support information is obtained from tizen-platform-config. Change-Id: I3ce38d8a0d9070d9a93784918acf7a0746a1094c Signed-off-by: Kim Gunsoo --- src/sdb.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/sdb.c b/src/sdb.c index 0fa0672..57cbcb0 100644 --- a/src/sdb.c +++ b/src/sdb.c @@ -1922,10 +1922,17 @@ static void init_capabilities(void) { // Multi-User support - // TODO: get this information from platform. - snprintf(g_capabilities.multiuser_support, sizeof(g_capabilities.multiuser_support), - "%s", DISABLED); - + // XXX: There is no clear way to determine whether multi-user support. + // Since TZ_SYS_DEFAULT_USER is set to "owner" for multi-user support, + // guess whether multiuser support through that information. + const char* sys_default_user = tzplatform_getenv(TZ_SYS_DEFAULT_USER); + if (sys_default_user != NULL && !strcmp(sys_default_user, "owner")) { + snprintf(g_capabilities.multiuser_support, sizeof(g_capabilities.multiuser_support), + "%s", ENABLED); + } else { + snprintf(g_capabilities.multiuser_support, sizeof(g_capabilities.multiuser_support), + "%s", DISABLED); + } // Window size synchronization support snprintf(g_capabilities.syncwinsz_support, sizeof(g_capabilities.syncwinsz_support), -- 2.7.4 From 77d9bf3de8868f7ac7653c3ba713e25558a1b582 Mon Sep 17 00:00:00 2001 From: Kim Gunsoo Date: Thu, 7 Apr 2016 13:10:16 +0900 Subject: [PATCH 12/16] MISC: package version up(3.0.7) - Add the check routine for multi-user support. - Add the sdk_toolpath member to sdbd capability. Change-Id: I7121f8c2c487934e30fbcd3ddddc2092c49742d5 Signed-off-by: Kim Gunsoo --- packaging/sdbd.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/sdbd.spec b/packaging/sdbd.spec index db9e680..c9e22bf 100644 --- a/packaging/sdbd.spec +++ b/packaging/sdbd.spec @@ -2,7 +2,7 @@ Name: sdbd Summary: SDB daemon -Version: 3.0.6 +Version: 3.0.7 Release: 0 License: Apache-2.0 Summary: SDB daemon -- 2.7.4 From 5ebfb9fc5cb97861083cbdc9c553488708b3bd6c Mon Sep 17 00:00:00 2001 From: Kim Gunsoo Date: Wed, 6 Apr 2016 15:21:49 +0900 Subject: [PATCH 13/16] Add permission of the log group to sdbd service. - To obtain permission to run the dlogutil, the log group permissions has been granted to sdbd service. Change-Id: I739a3ab5dfb0b118939e2f809b32fee7d10fee04 Signed-off-by: Kim Gunsoo --- packaging/sdbd.spec | 2 +- src/sdb.c | 99 +++++++++++++++++++++++++++++++++++++---------------- src/sdb.h | 6 ---- 3 files changed, 71 insertions(+), 36 deletions(-) diff --git a/packaging/sdbd.spec b/packaging/sdbd.spec index c9e22bf..4b562e1 100644 --- a/packaging/sdbd.spec +++ b/packaging/sdbd.spec @@ -2,7 +2,7 @@ Name: sdbd Summary: SDB daemon -Version: 3.0.7 +Version: 3.0.8 Release: 0 License: Apache-2.0 Summary: SDB daemon diff --git a/src/sdb.c b/src/sdb.c index 57cbcb0..ac5f2ad 100644 --- a/src/sdb.c +++ b/src/sdb.c @@ -71,6 +71,15 @@ uid_t g_sdk_user_id; gid_t g_sdk_group_id; char* g_sdk_home_dir = NULL; char* g_sdk_home_dir_env = NULL; + +struct group_info +{ + const char *name; + gid_t gid; +}; +struct group_info g_default_groups[] = { {"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; #if !SDB_HOST @@ -1397,50 +1406,46 @@ void register_bootdone_cb() { } static int sdbd_set_groups() { - gid_t *groups = NULL; + gid_t *group_ids = NULL; int ngroups = 0; - int default_ngroups = 0; int i, j = 0; int group_match = 0; int added_group_cnt = 0; - gid_t default_groups[] = { SID_DEVELOPER, SID_APP_LOGGING, SID_SYS_LOGGING, SID_INPUT }; - - default_ngroups = sizeof(default_groups) / sizeof(default_groups[0]); getgrouplist(SDK_USER_NAME, g_sdk_group_id, NULL, &ngroups); D("group list : ngroups = %d\n", ngroups); - groups = malloc((ngroups + default_ngroups) * sizeof(gid_t)); - if (groups == NULL) { - D("failed to allocate groups(%d)\n", (ngroups + default_ngroups) * sizeof(gid_t)); + group_ids = malloc((ngroups + SDB_DEFAULT_GROUPS_CNT) * sizeof(gid_t)); + if (group_ids == NULL) { + D("failed to allocate group_ids(%d)\n", (ngroups + SDB_DEFAULT_GROUPS_CNT) * sizeof(gid_t)); return -1; } - if (getgrouplist(SDK_USER_NAME, g_sdk_group_id, groups, &ngroups) == -1) { + if (getgrouplist(SDK_USER_NAME, g_sdk_group_id, group_ids, &ngroups) == -1) { D("failed to getgrouplist(), ngroups = %d\n", ngroups); - free(groups); + free(group_ids); return -1; } - for (i = 0; i < default_ngroups; i++) { + for (i = 0; g_default_groups[i].name != NULL; i++) { for (j = 0; j < ngroups; j++) { - if (groups[j] == default_groups[i]) { + if (group_ids[j] == g_default_groups[i].gid) { group_match = 1; break; } } if (group_match == 0) { - groups[ngroups + added_group_cnt] = default_groups[i]; + group_ids[ngroups + added_group_cnt] = g_default_groups[i].gid; added_group_cnt ++; } group_match = 0; } - if (setgroups(ngroups+added_group_cnt, groups) != 0) { + if (setgroups(ngroups+added_group_cnt, group_ids) != 0) { D("failed to setgroups().\n"); - free(groups); + free(group_ids); return -1; } - free(groups); + free(group_ids); return 0; } @@ -1456,7 +1461,6 @@ static int sdbd_get_user_pwd(const char* user_name, struct passwd* pwd, char* bu errno = ret; D("failed to getpwuid_r\n"); } - free(buf); return -1; } @@ -1471,11 +1475,7 @@ int set_sdk_user_privileges() { if (sdbd_set_groups() < 0) { D("set groups failed (errno: %d)\n", errno); - - // set default group list - gid_t default_groups[] = { SID_DEVELOPER, SID_APP_LOGGING, SID_SYS_LOGGING, SID_INPUT }; - int default_ngroups = sizeof(default_groups) / sizeof(default_groups[0]); - setgroups(default_ngroups, default_groups); + return -1; } if (setgid(g_sdk_group_id) != 0) { @@ -1718,6 +1718,45 @@ static void load_sdbd_plugin() { D("using sdbd plugin interface.(%s)\n", SDBD_PLUGIN_PATH); } +static long get_passwd_bufsize() { + long bufsize = 0; + + bufsize = sysconf(_SC_GETPW_R_SIZE_MAX); + if(bufsize < 0) { + bufsize = (16*1024); + } + + return bufsize; +} + +static int init_sdb_default_groups() { + struct passwd pwd; + char *buf = NULL; + long bufsize = 0; + int i = 0; + + bufsize = get_passwd_bufsize(); + buf = malloc(bufsize); + if (buf == NULL) { + D("failed to allocate passwd 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; + } else { + D("get user passwd info.(errno: %d)\n", errno); + free(buf); + return -1; + } + } + + free(buf); + return 0; +} + static int init_sdk_userinfo() { struct passwd pwd; char *buf = NULL; @@ -1727,14 +1766,10 @@ static int init_sdk_userinfo() { return 0; } - bufsize = sysconf(_SC_GETPW_R_SIZE_MAX); - if(bufsize < 0) { - bufsize = (16*1024); - } - + bufsize = get_passwd_bufsize(); buf = malloc(bufsize); if (buf == NULL) { - D("failed to allocate passwd buf(%d)\n", bufsize); + D("failed to allocate passwd buf(%ld)\n", bufsize); return -1; } @@ -1751,6 +1786,13 @@ static int init_sdk_userinfo() { 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) { @@ -1920,7 +1962,6 @@ static void init_capabilities(void) { snprintf(g_capabilities.zone_support, sizeof(g_capabilities.zone_support), "%s", ret == 1 ? ENABLED : DISABLED); - // Multi-User support // XXX: There is no clear way to determine whether multi-user support. // Since TZ_SYS_DEFAULT_USER is set to "owner" for multi-user support, diff --git a/src/sdb.h b/src/sdb.h index 074d165..21056b6 100644 --- a/src/sdb.h +++ b/src/sdb.h @@ -382,12 +382,6 @@ int booting_done; // 0: platform booting is in progess 1: platform booting is do // This is the users and groups config for the platform #define SID_ROOT 0 /* traditional unix root user */ -#define SID_TTY 5 /* group for /dev/ptmx */ -#define SID_APP tzplatform_getuid(TZ_USER_NAME) /* application */ -#define SID_DEVELOPER tzplatform_getuid(TZ_SDK_USER_NAME) /* developer with SDK */ -#define SID_APP_LOGGING 6509 -#define SID_SYS_LOGGING 6527 -#define SID_INPUT 1004 #define SDK_USER_NAME tzplatform_getenv(TZ_SDK_USER_NAME) #define SDK_TOOL_PATH tzplatform_getenv(TZ_SDK_TOOLS) -- 2.7.4 From f71e433440041a74a3e72903dcd3e4478d310300 Mon Sep 17 00:00:00 2001 From: "shingil.kang" Date: Mon, 11 Apr 2016 13:33:49 +0900 Subject: [PATCH 14/16] Fixed sdk_launch script - Supported multi user feature Change-Id: I2c092c8ad4f332571353f12f91f50638416dc3f6 Signed-off-by: shingil.kang --- packaging/sdbd.spec | 2 +- script/sdk_launch | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packaging/sdbd.spec b/packaging/sdbd.spec index 4b562e1..0a7d9aa 100644 --- a/packaging/sdbd.spec +++ b/packaging/sdbd.spec @@ -2,7 +2,7 @@ Name: sdbd Summary: SDB daemon -Version: 3.0.8 +Version: 3.0.9 Release: 0 License: Apache-2.0 Summary: SDB daemon diff --git a/script/sdk_launch b/script/sdk_launch index 6206e59..b914363 100755 --- a/script/sdk_launch +++ b/script/sdk_launch @@ -132,7 +132,7 @@ then if [ "" != "$attach_id" ] #debug attach then - cmd="/usr/bin/launch_debug $launch_app_arg1 __AUL_SDK__ ATTACH __DLP_ATTACH_ARG__ --attach,:$port,$attach_id" + cmd="/usr/bin/launch_debug $launch_app_arg1 __AUL_SDK__ ATTACH __DLP_GDBSERVER_PATH__ ${SDK_TOOLS_PATH}/gdbserver/gdbserver __DLP_ATTACH_ARG__ --attach,:$port,$attach_id" #debug else if [ "" != "$result_mode" ] @@ -141,7 +141,7 @@ then else result_mode="DEBUG" fi - cmd="/usr/bin/launch_app $launch_app_arg1 __AUL_SDK__ $result_mode __DLP_DEBUG_ARG__ :$port $launch_app_mode $args" + cmd="/usr/bin/app_launcher -s $launch_app_arg1 __AUL_SDK__ $result_mode __DLP_DEBUG_ARG__ :$port $launch_app_mode $args __DLP_GDBSERVER_PATH__ ${SDK_TOOLS_PATH}/gdbserver/gdbserver" # cmd="$COV_TEST_PREFIX ${TZ_SDK_TOOLS}/gdbserver/gdbserver :$port ${TZ_SYS_RW_APP}/$pkgid/bin/$exe" fi else -- 2.7.4 From 2f4a9d9c1670bbe26286b8cf69169cbb7041e9db Mon Sep 17 00:00:00 2001 From: "shingil.kang" Date: Mon, 18 Apr 2016 18:17:05 +0900 Subject: [PATCH 15/16] Fixed build warnings. Change-Id: I1063d7ae01b6b28699cd90d82f9fe88c1737a34a Signed-off-by: shingil.kang --- packaging/sdbd.spec | 2 +- src/file_sync_service.c | 55 ++++++++++++++++++++------------ src/sdb.c | 17 ++++++---- src/sdb.h | 8 ++--- src/sdktools.c | 4 +-- src/sdktools.h | 2 +- src/services.c | 14 ++++---- src/transport.c | 14 +++----- src/transport_local.c | 85 ++----------------------------------------------- src/usb_funcfs_client.c | 4 +-- src/usb_libusb.c | 2 +- src/usb_linux.c | 2 +- src/usb_linux_client.c | 2 +- src/utils.c | 4 +-- src/utils.h | 2 +- 15 files changed, 74 insertions(+), 143 deletions(-) diff --git a/packaging/sdbd.spec b/packaging/sdbd.spec index 0a7d9aa..a05aff7 100644 --- a/packaging/sdbd.spec +++ b/packaging/sdbd.spec @@ -2,7 +2,7 @@ Name: sdbd Summary: SDB daemon -Version: 3.0.9 +Version: 3.0.10 Release: 0 License: Apache-2.0 Summary: SDB daemon diff --git a/src/file_sync_service.c b/src/file_sync_service.c index 0e97ab4..d142ff1 100644 --- a/src/file_sync_service.c +++ b/src/file_sync_service.c @@ -39,13 +39,10 @@ #define SYNC_TIMEOUT 15 -#define APP_INSTALL_PATH_PREFIX1 tzplatform_getenv(TZ_SYS_RW_APP) -#define APP_INSTALL_PATH_PREFIX2 tzplatform_mkpath(TZ_SDK_HOME, "apps_rw") - struct sync_permit_rule { const char *name; - const char *regx; + char *regx; int mode; // 0:push, 1: pull, 2: push&push }; @@ -63,9 +60,19 @@ struct sync_permit_rule sdk_sync_permit_rule[] = { void init_sdk_sync_permit_rule_regx(void) { - 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); - 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); - asprintf(&sdk_sync_permit_rule[2].regx, "^(/tmp/da/)*+[a-zA-Z0-9_\\-\\.]{1,50}\\.png$"); + 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) { @@ -285,11 +292,12 @@ static int fail_message(int s, const char *reason) static int fail_errno(int s) { - char buf[512]; + char* ret_str; + char buf[512]; - strerror_r(s, buf, sizeof(buf)); + ret_str = strerror_r(s, buf, sizeof(buf)); - return fail_message(s, buf); + return fail_message(s, (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 @@ -310,16 +318,16 @@ static void sync_mediadb(char *path) { } if (strstr(path, MEDIA_CONTENTS_PATH1) != NULL) { - char *arg_list[] = {CMD_MEDIADB_UPDATE, "-r", MEDIA_CONTENTS_PATH1, NULL}; - spawn(CMD_MEDIADB_UPDATE, arg_list); + const char * const arg_list[] = {CMD_MEDIADB_UPDATE, "-r", MEDIA_CONTENTS_PATH1, NULL}; + spawn(CMD_MEDIADB_UPDATE, (char * const*)arg_list); D("media db update done to %s\n", MEDIA_CONTENTS_PATH1); } else if (strstr(path, MEDIA_CONTENTS_PATH2) != NULL) { - char *arg_list[] = {CMD_MEDIADB_UPDATE, "-r", MEDIA_CONTENTS_PATH2, NULL}; - spawn(CMD_MEDIADB_UPDATE, arg_list); + const char * const arg_list[] = {CMD_MEDIADB_UPDATE, "-r", MEDIA_CONTENTS_PATH2, NULL}; + spawn(CMD_MEDIADB_UPDATE, (char * const*)arg_list); D("media db update done to %s\n", MEDIA_CONTENTS_PATH2); } else if (strstr(path, MEDIA_CONTENTS_PATH3) != NULL) { - char *arg_list[] = {CMD_MEDIADB_UPDATE, "-r", MEDIA_CONTENTS_PATH3, NULL}; - spawn(CMD_MEDIADB_UPDATE, arg_list); + const char * const arg_list[] = {CMD_MEDIADB_UPDATE, "-r", MEDIA_CONTENTS_PATH3, NULL}; + spawn(CMD_MEDIADB_UPDATE, (char * const*)arg_list); D("media db update done to %s\n", MEDIA_CONTENTS_PATH3); } return; @@ -475,7 +483,10 @@ static int do_send(int s, int noti_fd, char *path, char *buffer) { char *tmp; mode_t mode; - int is_link, ret; + int ret; +#ifdef HAVE_SYMLINKS + int is_link; +#endif // Check the capability for file push support. if(!is_support_push()) { @@ -488,9 +499,7 @@ static int do_send(int s, int noti_fd, char *path, char *buffer) *tmp = 0; errno = 0; mode = strtoul(tmp + 1, NULL, 0); -#ifndef HAVE_SYMLINKS - is_link = 0; -#else +#ifdef HAVE_SYMLINKS is_link = S_ISLNK(mode); #endif // extracts file permission from stat.mode. (ex 100644 & 0777 = 644); @@ -499,11 +508,15 @@ static int do_send(int s, int noti_fd, char *path, char *buffer) } if(!tmp || errno) { mode = 0644; // set default permission value in most of unix system. +#ifdef HAVE_SYMLINKS is_link = 0; +#endif } if (is_pkg_file_path(path)) { mode = 0644; +#ifdef HAVE_SYMLINKS is_link = 0; +#endif } // sdb does not allow to check that file exists or not. After deleting old file and creating new file again unconditionally. @@ -601,7 +614,7 @@ static int verify_sync_rule(const char* path) { } } regfree(®ex); - for (i = 0; i <= 3; i++){ + for (i=0; sdk_sync_permit_rule[i].regx != NULL; i++){ free(sdk_sync_permit_rule[i].regx); } return 0; diff --git a/src/sdb.c b/src/sdb.c index ac5f2ad..61b5bc4 100644 --- a/src/sdb.c +++ b/src/sdb.c @@ -92,7 +92,7 @@ static int is_support_sockproto(); void (*usb_init)() = NULL; void (*usb_cleanup)() = NULL; int (*usb_write)(usb_handle *h, const void *data, int len) = NULL; -int (*usb_read)(usb_handle *h, void *data, int len) = NULL; +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; @@ -128,7 +128,7 @@ void handle_sig_term(int sig) { if (access(SDB_PIDPATH, F_OK) == 0) sdb_unlink(SDB_PIDPATH); #endif - char *cmd1_args[] = {"/usr/bin/killall", "/usr/bin/debug_launchpad_preloading_preinitializing_daemon", NULL}; + char * const cmd1_args[] = {"/usr/bin/killall", "/usr/bin/debug_launchpad_preloading_preinitializing_daemon", NULL}; spawn("/usr/bin/killall", cmd1_args); sdb_sleep_ms(1000); } @@ -1361,14 +1361,17 @@ static void *bootdone_cb(void *x) { char rule[MAX_LOCAL_BUFSZ]; GMainLoop *mainloop; +/* g_type_init() is deprecated for glib version 2.35.0 or greater, */ +#if !GLIB_CHECK_VERSION(2,35,0) g_type_init(); +#endif dbus_error_init(&error); bus = dbus_bus_get(DBUS_BUS_SYSTEM, &error); if (!bus) { D("Failed to connect to the D-BUS daemon: %s", error.message); dbus_error_free(&error); - return -1; + return NULL; } dbus_connection_setup_with_g_main(bus, NULL); @@ -1379,12 +1382,12 @@ static void *bootdone_cb(void *x) { if (dbus_error_is_set(&error)) { D("Fail to rule set: %s", error.message); dbus_error_free(&error); - return -1; + return NULL; } if (dbus_connection_add_filter(bus, __sdbd_dbus_signal_filter, NULL, NULL) == FALSE) - return -1; + return NULL; D("booting signal initialized\n"); mainloop = g_main_loop_new(NULL, FALSE); @@ -1392,7 +1395,7 @@ static void *bootdone_cb(void *x) { D("dbus loop exited"); - return 0; + return NULL; } void register_bootdone_cb() { @@ -1499,7 +1502,7 @@ int set_sdk_user_privileges() { } static void execute_required_process() { - char *cmd_args[] = {"/usr/bin/debug_launchpad_preloading_preinitializing_daemon",NULL}; + char * const cmd_args[] = {"/usr/bin/debug_launchpad_preloading_preinitializing_daemon",NULL}; spawn("/usr/bin/debug_launchpad_preloading_preinitializing_daemon", cmd_args); } diff --git a/src/sdb.h b/src/sdb.h index 21056b6..dd0fe23 100644 --- a/src/sdb.h +++ b/src/sdb.h @@ -521,7 +521,7 @@ int local_connect_arbitrary_ports(int console_port, int sdb_port, const char *d void usb_init(); void usb_cleanup(); int usb_write(usb_handle *h, const void *data, int len); -int usb_read(usb_handle *h, void *data, int len); +int usb_read(usb_handle *h, void *data, size_t len); int usb_close(usb_handle *h); void usb_kick(usb_handle *h); #else @@ -529,7 +529,7 @@ void usb_kick(usb_handle *h); extern void (*usb_init)(); extern void (*usb_cleanup)(); extern int (*usb_write)(usb_handle *h, const void *data, int len); -extern int (*usb_read)(usb_handle *h, void *data, int len); +extern int (*usb_read)(usb_handle *h, void *data, size_t len); extern int (*usb_close)(usb_handle *h); extern void (*usb_kick)(usb_handle *h); @@ -537,7 +537,7 @@ extern void (*usb_kick)(usb_handle *h); void ffs_usb_init(); void ffs_usb_cleanup(); int ffs_usb_write(usb_handle *h, const void *data, int len); -int ffs_usb_read(usb_handle *h, void *data, int len); +int ffs_usb_read(usb_handle *h, void *data, size_t len); int ffs_usb_close(usb_handle *h); void ffs_usb_kick(usb_handle *h); @@ -545,7 +545,7 @@ void ffs_usb_kick(usb_handle *h); void linux_usb_init(); void linux_usb_cleanup(); int linux_usb_write(usb_handle *h, const void *data, int len); -int linux_usb_read(usb_handle *h, void *data, unsigned len); +int linux_usb_read(usb_handle *h, void *data, size_t len); int linux_usb_close(usb_handle *h); void linux_usb_kick(usb_handle *h); diff --git a/src/sdktools.c b/src/sdktools.c index f24bccc..7780101 100644 --- a/src/sdktools.c +++ b/src/sdktools.c @@ -32,10 +32,10 @@ struct sudo_command root_commands[] = { } }, /* end */ - { NULL, NULL, NULL } + { NULL, NULL, {NULL} } }; -static struct command_suffix +struct command_suffix { const char *name; // comments for human const char *suffix; //pattern diff --git a/src/sdktools.h b/src/sdktools.h index 50b68de..9027970 100644 --- a/src/sdktools.h +++ b/src/sdktools.h @@ -26,7 +26,7 @@ struct arg_permit_rule #define SDK_LAUNCH_PATH "/usr/sbin/sdk_launch" #define APP_INSTALL_PATH_PREFIX1 tzplatform_getenv(TZ_SYS_RW_APP) -#define APP_INSTALL_PATH_PREFIX2 tzplatform_getenv(TZ_USER_APP) +#define APP_INSTALL_PATH_PREFIX2 tzplatform_mkpath(TZ_SDK_HOME, "apps_rw") #define DEV_INSTALL_PATH_PREFIX tzplatform_getenv(TZ_SDK_TOOLS) #define GDBSERVER_PATH tzplatform_mkpath(TZ_SDK_TOOLS,"gdbserver/gdbserver") #define GDBSERVER_PLATFORM_PATH tzplatform_mkpath(TZ_SDK_TOOLS,"gdbserver-platform/gdbserver") diff --git a/src/services.c b/src/services.c index 9607462..dc19c14 100644 --- a/src/services.c +++ b/src/services.c @@ -387,7 +387,7 @@ static int create_service_thread(void (*func)(int, void *), void *cookie) #if !SDB_HOST -static void redirect_and_exec(int pts, const char *cmd, const char *argv[], const char *envp[]) +static void redirect_and_exec(int pts, const char *cmd, char * const argv[], char * const envp[]) { dup2(pts, 0); dup2(pts, 1); @@ -398,7 +398,7 @@ static void redirect_and_exec(int pts, const char *cmd, const char *argv[], cons execve(cmd, argv, envp); } -static int create_subprocess(const char *cmd, pid_t *pid, const char *argv[], const char *envp[]) +static int create_subprocess(const char *cmd, pid_t *pid, char * const argv[], char * const envp[]) { char devname[64]; int ptm; @@ -517,7 +517,6 @@ static void get_env(char *key, char **env) { FILE *fp; char buf[1024]; - int i; char *s, *e, *value; fp = fopen (LOGIN_CONFIG, "r"); @@ -641,7 +640,7 @@ static int create_subproc_thread(const char *name, int lines, int columns) }; args[2] = new_cmd; - ret_fd = create_subprocess(SHELL_COMMAND, &pid, args, envp); + ret_fd = create_subprocess(SHELL_COMMAND, &pid, (char * const*)args, (char * const*)envp); free(new_cmd); } else { // in case of shell interactively // Check the capability for interactive shell support. @@ -650,12 +649,12 @@ static int create_subproc_thread(const char *name, int lines, int columns) return -1; } - char *args[] = { + char * const args[] = { SHELL_COMMAND, "-", NULL, }; - ret_fd = create_subprocess(SHELL_COMMAND, &pid, args, envp); + ret_fd = create_subprocess(SHELL_COMMAND, &pid, (char * const*)args, (char * const*)envp); #if 0 // FIXME: should call login command instead of /bin/sh if (should_drop_privileges()) { char *args[] = { @@ -950,7 +949,6 @@ static void sync_windowsize(int fd, void *cookie) { const unsigned COMMAND_TIMEOUT = 10000; void get_boot(int fd, void *cookie) { char buf[2] = { 0, }; - char *mode = (char*) cookie; int time = 0; int interval = 1000; while (time < COMMAND_TIMEOUT) { @@ -1076,7 +1074,7 @@ int service_to_fd(const char *name) } } else if(!strncmp(name, "shellconf:", 10)){ if(!strncmp(name+10, "syncwinsz:", 10)){ - ret = create_service_thread(sync_windowsize, name+20); + ret = create_service_thread(sync_windowsize, (void *)name+20); } } diff --git a/src/transport.c b/src/transport.c index c4b64d7..a697eee 100644 --- a/src/transport.c +++ b/src/transport.c @@ -524,7 +524,7 @@ static int transport_read_action(int fd, struct tmsg* m) { char *p = (char*)m; - int len = sizeof(*m); + size_t len = sizeof(*m); int r; while(len > 0) { @@ -546,7 +546,7 @@ static int transport_write_action(int fd, struct tmsg* m) { char *p = (char*)m; - int len = sizeof(*m); + size_t len = sizeof(*m); int r; while(len > 0) { @@ -745,7 +745,6 @@ atransport *acquire_one_transport(int state, transport_type ttype, const char* s { atransport *t; atransport *result = NULL; - int ambiguous = 0; if (error_out) *error_out = "device not found"; @@ -769,7 +768,6 @@ atransport *acquire_one_transport(int state, transport_type ttype, const char* s if (result) { if (error_out) *error_out = "more than one device"; - ambiguous = 1; result = NULL; break; } @@ -778,7 +776,6 @@ atransport *acquire_one_transport(int state, transport_type ttype, const char* s if (result) { if (error_out) *error_out = "more than one emulator"; - ambiguous = 1; result = NULL; break; } @@ -787,7 +784,6 @@ atransport *acquire_one_transport(int state, transport_type ttype, const char* s if (result) { if (error_out) *error_out = "more than one device and emulator"; - ambiguous = 1; result = NULL; break; } @@ -1058,9 +1054,9 @@ int readx(int fd, void *ptr, size_t len) char *p = ptr; int r; #if SDB_TRACE - int len0 = len; + size_t len0 = len; #endif - D("readx: fd=%d wanted=%d\n", fd, (int)len); + D("readx: fd=%d wanted=%d\n", fd, len); while(len > 0) { r = sdb_read(fd, p, len); if(r > 0) { @@ -1091,7 +1087,7 @@ int writex(int fd, const void *ptr, size_t len) int r; #if SDB_TRACE - D("writex: fd=%d len=%d: ", fd, (int)len); + D("writex: fd=%d len=%d: ", fd, len); dump_hex( ptr, len ); #endif while(len > 0) { diff --git a/src/transport_local.c b/src/transport_local.c index 1daa143..527e1f5 100644 --- a/src/transport_local.c +++ b/src/transport_local.c @@ -415,85 +415,6 @@ static const char _ok_resp[] = "ok"; #endif // !SDB_HOST #endif -/*! - * static int send_msg_to_host_from_guest(const char *hostname, int host_port, char *request, int sock_type) - * @brief Sends \c request to host using specified protocol - * - * @param hostname Hostname -- could be domain name or IP - * @param host_port Host port - * @param request Message to be sent to host - * @param protocol IP protocol to be used: IPPROTO_TCP or IPPROTO_UDP - * - * @returns 0 on success, -1 otherwise - * - * @note SOCK_STREAM will be used for IPPROTO_TCP as socket type - * and SOCK_DGRAM for IPPROTO_UDP - */ -static int send_msg_to_host_from_guest(const char *hostname, int host_port, char *request, int protocol) { - int sock = -1; - int PORT_SIZE = 32; - char port[PORT_SIZE]; /* string decimal representation for getaddrinfo */ - struct addrinfo hints = {0}; - struct addrinfo *addresses, *curr_addr; - int getaddr_ret; - const char *protocol_name = "unknown"; /* for debug message */ - - switch(protocol) { - case IPPROTO_TCP: - protocol_name = "tcp"; - hints.ai_socktype = SOCK_STREAM; - break; - case IPPROTO_UDP: - protocol_name = "udp"; - hints.ai_socktype = SOCK_DGRAM; - break; - default: - D("unsupported protocol: %d", protocol); - return -1; - } - - D("try to send notification to host(%s:%d) using %s:[%s]\n", hostname, host_port, protocol_name, request); - - hints.ai_family = AF_INET; - - snprintf(port, PORT_SIZE, "%d", host_port); - getaddr_ret = getaddrinfo(hostname, port, &hints, &addresses); - - if (getaddr_ret != 0) { - D("could not resolve %s\n", hostname); - return -1; - } - - for(curr_addr = addresses; curr_addr != NULL; curr_addr = curr_addr->ai_next) { - sock = socket(curr_addr->ai_family, curr_addr->ai_socktype, curr_addr->ai_protocol); - if (sock == -1) - continue; - - if (connect(sock, curr_addr->ai_addr, curr_addr->ai_addrlen) != -1) - break; /* Success */ - - sdb_close(sock); - } - - if(curr_addr == NULL) { /* No address succeeded */ - freeaddrinfo(addresses); - D("could not connect to server\n"); - return -1; - } - - freeaddrinfo(addresses); - - if (sdb_write(sock, request, strlen(request)) < 0) { - D("could not send notification request to host\n"); - sdb_close(sock); - return -1; - } - sdb_close(sock); - D("sent notification request to host\n"); - - return 0; -} - int connect_nonb(int sockfd, const struct sockaddr *saptr, socklen_t salen, int nsec) { int flags, n, error; @@ -588,7 +509,7 @@ static int send_msg_to_localhost_from_guest(const char *host_ip, int local_port, } // send the "emulator" request to sdbserver -static void notify_sdbd_startup_thread() { +static void* notify_sdbd_startup_thread(void* ptr) { char buffer[512]; char request[512]; @@ -605,11 +526,11 @@ static void notify_sdbd_startup_thread() { int time = 0; //int try_limit_time = -1; // try_limit_time < 0 if unlimited if (sensors_port < 0 || emulator_port < 0 || r < 0) { - return; + return NULL; } if (get_emulator_hostip(host_ip, sizeof host_ip) == -1) { D("failed to get emulator host ip\n"); - return; + return NULL; } // XXX: Known issue - log collision while (1) { diff --git a/src/usb_funcfs_client.c b/src/usb_funcfs_client.c index ef28284..75d90aa 100644 --- a/src/usb_funcfs_client.c +++ b/src/usb_funcfs_client.c @@ -297,7 +297,7 @@ static int read_control(struct usb_handle *usb) /* Read events from control endpoint Fortunately, FunctionFS guarantees reading of full event (or nothing), so we're not bothered with ret < sizeof(read_event) */ - ret = sdb_read(usb->control, &read_event, sizeof(read_event)); + ret = sdb_read(usb->control, (void *)&read_event, sizeof(read_event)); if (ret < 0) { /* EAGAIN support will be useful, when non-blocking ep0 reads are supported in FunctionFS */ @@ -548,7 +548,7 @@ int ffs_usb_write(usb_handle *h, const void *data, int len) * * @returns 0 on success and -1 on failure (errno is set) */ -int ffs_usb_read(usb_handle *h, void *data, int len) +int ffs_usb_read(usb_handle *h, void *data, size_t len) { int n; diff --git a/src/usb_libusb.c b/src/usb_libusb.c index 8d12ea7..fc3596f 100644 --- a/src/usb_libusb.c +++ b/src/usb_libusb.c @@ -171,7 +171,7 @@ usb_write(struct usb_handle *uh, const void *_data, int len) } int -usb_read(struct usb_handle *uh, void *_data, int len) +usb_read(struct usb_handle *uh, void *_data, size_t len) { unsigned char *data = (unsigned char*) _data; int n; diff --git a/src/usb_linux.c b/src/usb_linux.c index d7e8399..95f2ee9 100644 --- a/src/usb_linux.c +++ b/src/usb_linux.c @@ -454,7 +454,7 @@ int usb_write(usb_handle *h, const void *_data, int len) return 0; } -int usb_read(usb_handle *h, void *_data, int len) +int usb_read(usb_handle *h, void *_data, size_t len) { unsigned char *data = (unsigned char*) _data; int n; diff --git a/src/usb_linux_client.c b/src/usb_linux_client.c index d2af0c4..ec8c159 100644 --- a/src/usb_linux_client.c +++ b/src/usb_linux_client.c @@ -94,7 +94,7 @@ int linux_usb_write(usb_handle *h, const void *data, int len) return 0; } -int linux_usb_read(usb_handle *h, void *data, unsigned len) +int linux_usb_read(usb_handle *h, void *data, size_t len) { int n; diff --git a/src/utils.c b/src/utils.c index ae7d51d..acf8c5a 100644 --- a/src/utils.c +++ b/src/utils.c @@ -151,7 +151,7 @@ char *str_trim(char *str) { return str; } -int spawn(char* program, char** arg_list) +int spawn(const char* program, char* const arg_list[]) { pid_t pid; int ret; @@ -167,7 +167,7 @@ int spawn(char* program, char** arg_list) // init takes the process, and the process is not able to be zombie exit(0); } - execvp (program, arg_list); + execvp(program, arg_list); fprintf(stderr, "failed to spawn: never reach here!:%s\n", program); exit(0); } diff --git a/src/utils.h b/src/utils.h index 11a63c8..ce17442 100644 --- a/src/utils.h +++ b/src/utils.h @@ -72,7 +72,7 @@ char *str_trim(char* string); * spawn a process and returns the process id of the new spawned process. * it is working as async. */ -int spawn(char* program, char** arg_list); +int spawn(const char* program, char * const arg_list[]); char** str_split(char* a_str, const char a_delim); -- 2.7.4 From 7c2595d0822b22221af68a47be06e5691fbedf20 Mon Sep 17 00:00:00 2001 From: "shingil.kang" Date: Tue, 26 Apr 2016 20:57:37 +0900 Subject: [PATCH 16/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