SDB_MUTEX_DEFINE( D_lock );
#endif
+#define SDB_LOGCONF_PATH "/tmp/.sdbdlog.conf"
+
int HOST = 0;
// sdk user
exit(-1);
}
+static char* get_sdb_log_conf(const char* key)
+{
+ int fd;
+ char line[256] = {0,};
+ char value[256] = {0,};
+
+ if (access(SDB_LOGCONF_PATH, F_OK)) {
+ return NULL;
+ }
+
+ fd = unix_open(SDB_LOGCONF_PATH, O_RDONLY);
+ if (fd < 0) {
+ D("failed to open '%s' file: %d\n", SDB_LOGCONF_PATH, errno);
+ return NULL;
+ }
+
+ if (read_line(fd, line, sizeof(line)) > 0) {
+ char* start = strstr(line, key);
+ if (start != NULL) {
+ // move one more character to remove '=',
+ // including the length of the key string
+ start = start + strlen(key) + 1;
+ char* end = strstr(start, " ");
+ if (end != NULL) {
+ strncpy(value, start, end - start);
+ } else {
+ strncpy(value, start, sizeof(value));
+ }
+ } else {
+ sdb_close(fd);
+ return NULL;
+ }
+ }
+ sdb_close(fd);
+ return strdup(value);
+}
+
static int is_enable_sdbd_log()
{
return (!strncmp(g_capabilities.log_enable, PLUGIN_RET_ENABLED, strlen(PLUGIN_RET_ENABLED)));
*/
void sdb_trace_init(void)
{
- const char* p = getenv("SDB_TRACE");
+ char* ptr = get_sdb_log_conf("SDB_TRACE");
+ const char* p;
const char* q;
static const struct {
{ NULL, 0 }
};
- if (p == NULL) {
+ if (ptr == NULL) {
if (is_enable_sdbd_log())
p = "all";
else
return;
+ } else {
+ p = ptr;
}
/* use a comma/column/semi-colum/space separated list */
int flag = tags[tagn].flag;
if (flag == 0) {
sdb_trace_mask = ~0;
+ free(ptr);
return;
}
sdb_trace_mask |= (1 << flag);
if (*p)
p++;
}
+ free(ptr);
}
/*
struct tm now;
time_t t;
// char value[PROPERTY_VALUE_MAX];
- const char* p_trace = getenv("SDB_TRACE");
- const char* p_path = getenv("SDBD_LOG_PATH");
+ char* p_trace = get_sdb_log_conf("SDB_TRACE");
+ char* p_path = get_sdb_log_conf("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 ((p_trace == NULL ) && !is_enable_sdbd_log()) {
return;
+ } else {
+ free(p_trace);
}
- if (p_path)
+ if (p_path) {
snprintf(path_folder, sizeof(path_folder), "%s", p_path);
- else if (g_capabilities.log_path[0] != '\0')
+ free(p_path);
+ } else if (g_capabilities.log_path[0] != '\0')
snprintf(path_folder, sizeof(path_folder), "%s", g_capabilities.log_path);
else
return;