summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHwankyu Jhun <h.jhun@samsung.com>2020-06-26 15:31:58 +0900
committerHwankyu Jhun <h.jhun@samsung.com>2020-06-30 09:33:53 +0900
commit5acb3702c72394e966b78b5c0863f22587b10e29 (patch)
tree9302fcae8ea268cacece2105954d39429a4d2fbd
parentf15e2ec921d5eb11495345db0fe2e6f2c0001d5c (diff)
downloadlaunchpad-5acb3702c72394e966b78b5c0863f22587b10e29.tar.gz
launchpad-5acb3702c72394e966b78b5c0863f22587b10e29.tar.bz2
launchpad-5acb3702c72394e966b78b5c0863f22587b10e29.zip
Add a file log for debugging launchpad
"/var/log/appfw/launchpad/launchpad.log" is added. Change-Id: I280d010bb048671c66f4fe0eed698977335a4a61 Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
-rw-r--r--src/common/inc/launchpad_logger.h40
-rw-r--r--src/common/src/launchpad_logger.c195
-rw-r--r--src/launchpad/inc/launchpad_log.h34
-rw-r--r--src/launchpad/src/launchpad.c12
-rw-r--r--src/launchpad/src/launchpad_log.c71
5 files changed, 351 insertions, 1 deletions
diff --git a/src/common/inc/launchpad_logger.h b/src/common/inc/launchpad_logger.h
new file mode 100644
index 0000000..a54ebb7
--- /dev/null
+++ b/src/common/inc/launchpad_logger.h
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __LAUNCHPAD_LOGGER_H__
+#define __LAUNCHPAD_LOGGER_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define LAUNCHPAD_LOG_MAX_STRING_SIZE 128
+
+typedef struct logger_s *logger_h;
+
+int _logger_create(const char *path, logger_h *handle);
+
+int _logger_destroy(logger_h handle);
+
+int _logger_print(logger_h handle, const char *tag, const char *format, ...);
+
+int _logger_get_fd(logger_h handle, int *fd);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __LAUNCHPAD_LOGGER_H__ */
diff --git a/src/common/src/launchpad_logger.c b/src/common/src/launchpad_logger.c
new file mode 100644
index 0000000..a4e6b7f
--- /dev/null
+++ b/src/common/src/launchpad_logger.c
@@ -0,0 +1,195 @@
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#define _GNU_SOURCE
+#include <errno.h>
+#include <fcntl.h>
+#include <grp.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <time.h>
+#include <unistd.h>
+
+#include "launchpad_logger.h"
+#include "log_private.h"
+
+#define LAUNCHPAD_LOG_APPFW_PATH "/var/log/appfw"
+#define LAUNCHPAD_LOG_PATH "/var/log/appfw/launchpad"
+#define LAUNCHPAD_LOG_MAX_SIZE 2500
+#define LAUNCHPAD_LOG_MAX_BUFFER_SIZE 256
+
+struct logger_s {
+ int fd;
+ int index;
+};
+
+static int __create_directory(const char *path)
+{
+ mode_t mode;
+ int ret;
+
+ ret = access(path, F_OK);
+ if (ret == 0)
+ return 0;
+
+ mode = S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP;
+ ret = mkdir(path, mode);
+ if (ret < 0) {
+ ret = -errno;
+ _E("Failed to create directory(%s). errno(%d)", path, errno);
+ return ret;
+ }
+
+ return 0;
+}
+
+static int __create_launchpad_directories(void)
+{
+ int ret;
+
+ ret = __create_directory(LAUNCHPAD_LOG_APPFW_PATH);
+ if (ret < 0)
+ return ret;
+
+ ret = __create_directory(LAUNCHPAD_LOG_PATH);
+ if (ret < 0)
+ return ret;
+
+ return 0;
+}
+
+int _logger_create(const char *path, logger_h *handle)
+{
+ struct logger_s *logger;
+ off_t offset;
+ int ret;
+
+ if (!path || !handle) {
+ _E("Invalid parameter");
+ return -EINVAL;
+ }
+
+ ret = __create_launchpad_directories();
+ if (ret < 0)
+ return ret;
+
+ logger = calloc(1, sizeof(struct logger_s));
+ if (!logger) {
+ _E("Out of memory");
+ return -ENOMEM;
+ }
+
+ logger->fd = open(path, O_CREAT | O_WRONLY, 0640);
+ if (logger->fd < 0) {
+ ret = -errno;
+ _E("Failed to open path(%s), errno(%d)", path, errno);
+ _logger_destroy(logger);
+ return ret;
+ }
+
+ offset = lseek(logger->fd, 0, SEEK_END);
+ if (offset != 0) {
+ logger->index = (int)(offset / LAUNCHPAD_LOG_MAX_STRING_SIZE);
+ if (logger->index >= LAUNCHPAD_LOG_MAX_SIZE) {
+ logger->index = 0;
+ lseek(logger->fd, 0, SEEK_SET);
+ }
+ }
+
+ *handle = logger;
+
+ return 0;
+}
+
+int _logger_destroy(logger_h handle)
+{
+ if (!handle) {
+ _E("Invalid parameter");
+ return -EINVAL;
+ }
+
+ if (handle->fd > 0)
+ close(handle->fd);
+
+ free(handle);
+
+ return 0;
+}
+
+int _logger_print(logger_h handle, const char *tag, const char *format, ...)
+{
+ char buf[LAUNCHPAD_LOG_MAX_BUFFER_SIZE];
+ char format_buf[128];
+ struct tm tm = { 0, };
+ time_t t;
+ ssize_t ret;
+ va_list ap;
+ off_t offset;
+
+ if (!handle || !tag || !format) {
+ _E("Invalid parameter");
+ return -EINVAL;
+ }
+
+ t = time(NULL);
+ localtime_r(&t, &tm);
+
+ if (handle->index != 0)
+ offset = lseek(handle->fd, 0, SEEK_CUR);
+ else
+ offset = lseek(handle->fd, 0, SEEK_SET);
+
+ if (offset == -1)
+ _E("lseek() is failed. errno(%d)", errno);
+
+ va_start(ap, format);
+ vsnprintf(format_buf, sizeof(format_buf), format, ap);
+ va_end(ap);
+
+ snprintf(buf, sizeof(buf),
+ "[%6d] %04d-%02d-%02d %02d:%02d:%02d %-16s %-100s\n",
+ handle->index,
+ tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
+ tm.tm_hour, tm.tm_min, tm.tm_sec,
+ tag, format_buf);
+ ret = write(handle->fd, buf, strlen(buf));
+ if (ret < 0) {
+ ret = -errno;
+ _E("Failed to write log message. errno(%d)", errno);
+ return ret;
+ }
+
+ if (++handle->index >= LAUNCHPAD_LOG_MAX_SIZE)
+ handle->index = 0;
+
+ return ret;
+}
+
+int _logger_get_fd(logger_h handle, int *fd)
+{
+ if (!handle || !fd) {
+ _E("Invalid parameter");
+ return -EINVAL;
+ }
+
+ *fd = handle->fd;
+
+ return 0;
+}
diff --git a/src/launchpad/inc/launchpad_log.h b/src/launchpad/inc/launchpad_log.h
new file mode 100644
index 0000000..8e3cd89
--- /dev/null
+++ b/src/launchpad/inc/launchpad_log.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __LAUNCHPAD_LOG_H__
+#define __LAUNCHPAD_LOG_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int _log_print(const char *tag, const char *format, ...);
+
+int _log_init(void);
+
+void _log_fini(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __LAUNCHPAD_LOG_H__ */
diff --git a/src/launchpad/src/launchpad.c b/src/launchpad/src/launchpad.c
index 9751138..1f1d21c 100644
--- a/src/launchpad/src/launchpad.c
+++ b/src/launchpad/src/launchpad.c
@@ -47,6 +47,7 @@
#include "launchpad_debug.h"
#include "launchpad_inotify.h"
#include "launchpad_io_channel.h"
+#include "launchpad_log.h"
#include "launchpad_memory_monitor.h"
#include "launchpad_plugin.h"
#include "launchpad_proc.h"
@@ -893,6 +894,8 @@ static int __prepare_candidate_process(int type, int loader_id)
__set_live_timer(cpt);
}
+ _log_print("[CANDIDATE]", "pid(%7d) | type(%d) | loader(%s)",
+ pid, cpt->loader_id, cpt->loader_name);
_memory_monitor_reset_timer();
return 0;
@@ -1493,6 +1496,7 @@ static void __handle_sigchild(int pid, void *user_data)
g_hash_table_remove(__pid_table, GINT_TO_POINTER(pid));
}
+ _log_print("[SIGCHLD]", "pid(%7d)", pid);
cpc = __find_slot_from_pid(pid);
if (cpc != NULL) {
cpc->pid = CANDIDATE_NONE;
@@ -1525,7 +1529,7 @@ static bool __handle_label_monitor(int fd, io_condition_e cond, void *data)
return false;
}
- _D("%s()", __FUNCTION__);
+ _log_print("[LABEL]", "fd(%d), condition(%d)", fd, cond);
security_manager_app_labels_monitor_process(label_monitor);
while (iter) {
@@ -2209,6 +2213,8 @@ end:
_dbus_send_app_launch_signal(pid, menu_info->appid);
g_hash_table_insert(__pid_table, GINT_TO_POINTER(pid),
strdup(menu_info->appid));
+ _log_print("[LAUNCH]", "pid(%7d) | appid(%s)",
+ pid, menu_info->appid);
}
if (menu_info != NULL)
@@ -2883,6 +2889,8 @@ static bool __handle_logger(int fd, io_condition_e cond, void *data)
}
_E("[%d] %s", cr.pid, (const char *)pkt->data);
+ _log_print("[ERROR]", "pid(%7d) | message(%s)",
+ cr.pid, (const char *)pkt->data);
end:
if (clifd != -1)
close(clifd);
@@ -3045,12 +3053,14 @@ static int __before_loop(int argc, char **argv)
__init_app_defined_loader_monitor();
_memory_monitor_init();
_memory_monitor_set_event_cb(__memory_monitor_cb, NULL);
+ _log_init();
return 0;
}
static void __after_loop(void)
{
+ _log_fini();
_memory_monitor_fini();
__unregister_vconf_events();
if (__pid_table)
diff --git a/src/launchpad/src/launchpad_log.c b/src/launchpad/src/launchpad_log.c
new file mode 100644
index 0000000..00acc46
--- /dev/null
+++ b/src/launchpad/src/launchpad_log.c
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#define _GNU_SOURCE
+#include <stdarg.h>
+#include <stdio.h>
+
+#include "launchpad_log.h"
+#include "launchpad_logger.h"
+#include "log_private.h"
+
+#define PATH_LAUNCHPAD_LOG "/var/log/appfw/launchpad/launchpad.log"
+
+static logger_h __logger;
+
+int _log_print(const char *tag, const char *format, ...)
+{
+ char formatted_buf[LAUNCHPAD_LOG_MAX_STRING_SIZE];
+ va_list ap;
+ int ret;
+
+ if (!__logger) {
+ ret = _logger_create(PATH_LAUNCHPAD_LOG, &__logger);
+ if (ret != 0) {
+ _E("Failed to create log file. error(%d)", ret);
+ return -1;
+ }
+ }
+
+ va_start(ap, format);
+ vsnprintf(formatted_buf, sizeof(formatted_buf), format, ap);
+ va_end(ap);
+
+ return _logger_print(__logger, tag, formatted_buf);
+}
+
+int _log_init(void)
+{
+ int ret;
+
+ _W("LOG_INIT");
+
+ ret = _logger_create(PATH_LAUNCHPAD_LOG, &__logger);
+ if (ret != 0) {
+ _E("Failed to create log file. error(%d)", ret);
+ return ret;
+ }
+
+ return 0;
+}
+
+void _log_fini(void)
+{
+ _W("LOG_FINI");
+
+ if (__logger)
+ _logger_destroy(__logger);
+}