BuildRequires: pkgconfig(dbus-1)
BuildRequires: pkgconfig(iniparser)
BuildRequires: pkgconfig(libxml-2.0)
+BuildRequires: pkgconfig(libsmack)
Requires(post): /sbin/ldconfig
Requires(post): /usr/bin/systemctl
+++ /dev/null
-/*
- * 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__ */
+++ /dev/null
-/*
- * 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;
-}
gio-2.0
iniparser
libcap
+ libsmack
libsystemd
libtzplatform-config
security-manager
--- /dev/null
+/*
+ * 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__ */
--- /dev/null
+/*
+ * 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/smack.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 __set_smack_label(const char *path, const char *label)
+{
+ int ret;
+
+ ret = smack_setlabel(path, label, SMACK_LABEL_ACCESS);
+ if (ret != 0) {
+ ret = -errno;
+ _E("smack_setlabel() is failed. path(%s), label(%s), errno(%d)",
+ path, label, errno);
+ return ret;
+ }
+
+ return 0;
+}
+
+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 = __set_smack_label(LAUNCHPAD_LOG_APPFW_PATH, "_");
+ if (ret < 0)
+ return ret;
+
+ ret = __create_directory(LAUNCHPAD_LOG_PATH);
+ if (ret < 0)
+ return ret;
+
+ ret = __set_smack_label(LAUNCHPAD_LOG_PATH, "User");
+ 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;
+ }
+
+ ret = __set_smack_label(path, "User");
+ if (ret < 0) {
+ _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;
+}