From: shingil.kang Date: Tue, 14 Jun 2016 08:13:22 +0000 (+0900) Subject: Added capabilities ralated to sdbd log X-Git-Tag: accepted/tizen/common/20160614.144255^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F49%2F74449%2F6;p=sdk%2Ftarget%2Fsdbd.git 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 --- 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