Support watchdog timer 76/185276/8
authorHwankyu Jhun <h.jhun@samsung.com>
Fri, 27 Jul 2018 07:32:21 +0000 (16:32 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Wed, 8 Aug 2018 09:48:30 +0000 (18:48 +0900)
New APIs and commands are added for supporting watchdog timer.

Adds:
 - aul_watchdog_enable()
 - aul_watchdog_disable()
 - aul_watchdog_kick()

Requires:
 - https://review.tizen.org/gerrit/#/c/185276/ [aul-1]
 - https://review.tizen.org/gerrit/#/c/185882/ [app-core]
 - https://review.tizen.org/gerrit/#/c/185884/ [amd]
 - https://review.tizen.org/gerrit/#/c/186247/ [app-common]

Change-Id: I52c61b8bccc9070603900878a5044c0ab6325829
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
CMakeLists.txt
include/aul_cmd.h
include/aul_watchdog.h [new file with mode: 0644]
src/aul_cmd.c
src/aul_watchdog.c [new file with mode: 0644]
src/launch.c

index 65b07db..5dc9810 100755 (executable)
@@ -64,6 +64,7 @@ INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/aul_job_scheduler.h DESTINATIO
 INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/aul_rpc_port.h DESTINATION include/aul)
 INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/aul_complication.h DESTINATION include/aul)
 INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/aul_debug_info.h DESTINATION include/aul)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/aul_watchdog.h DESTINATION include/aul)
 INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/aul.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
 INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/feature/preexec_list.txt DESTINATION ${SHARE_INSTALL_PREFIX}/aul )
 INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/data/miregex DESTINATION ${SHARE_INSTALL_PREFIX}/aul )
index 34181dc..fa7ee7b 100755 (executable)
@@ -134,6 +134,10 @@ enum app_cmd {
        RPC_PORT_NOTIFY_RPC_FINISHED = 102,
        COMPLICATION_UPDATE_REQUEST = 103,
        APP_NOTIFY_START = 104,
+       WATCHDOG_ENABLE = 105,
+       WATCHDOG_DISABLE = 106,
+       WATCHDOG_PING = 107,
+       WATCHDOG_KICK = 108,
 
        APP_CMD_MAX
 };
diff --git a/include/aul_watchdog.h b/include/aul_watchdog.h
new file mode 100644 (file)
index 0000000..23d5294
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2018 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 __AUL_WATCHDOG_H__
+#define __AUL_WATCHDOG_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @brief Enables watchdog timer.
+ *
+ * @return      @c 0 on success,
+ *              otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_watchdog_enable(void);
+
+/**
+ * @brief Disables watchdog timer.
+ *
+ * @return      @c 0 on success,
+ *              otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_watchdog_disable(void);
+
+/**
+ * @brief Kicks whatchdog timer.
+ *
+ * @return      @c 0 on success,
+ *              otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_watchdog_kick(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __AUL_WATCHDOG_H__ */
index 357ecd3..61eaf15 100755 (executable)
@@ -234,6 +234,14 @@ API const char *aul_cmd_convert_to_string(int cmd)
                return "COMPLICATION_UPDATE_REQUEST";
        case APP_NOTIFY_START:
                return "APP_NOTIFY_START";
+       case WATCHDOG_ENABLE:
+               return "WATCHDOG_ENABLE";
+       case WATCHDOG_DISABLE:
+               return "WATCHDOG_DISABLE";
+       case WATCHDOG_PING:
+               return "WATCHDOG_PING";
+       case WATCHDOG_KICK:
+               return "WATCHDOG_KICK";
        default:
                return "CUSTOM_COMMAND";
        }
diff --git a/src/aul_watchdog.c b/src/aul_watchdog.c
new file mode 100644 (file)
index 0000000..cd59cb0
--- /dev/null
@@ -0,0 +1,95 @@
+/*
+ * Copyright (c) 2018 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 <stdio.h>
+#include <stdbool.h>
+#include <glib.h>
+
+#include "aul_api.h"
+#include "aul_util.h"
+#include "aul_sock.h"
+#include "aul_error.h"
+#include "aul_watchdog.h"
+#include "aul.h"
+
+typedef struct watchdog_context_s {
+       bool enabled;
+} watchdog_context;
+
+static watchdog_context __context;
+
+API int aul_watchdog_enable(void)
+{
+       int r;
+
+       if (__context.enabled) {
+               _W("Watchdog is already enabled");
+               return AUL_R_OK;
+       }
+
+       r = aul_sock_send_raw(AUL_UTIL_PID, getuid(),
+                       WATCHDOG_ENABLE, NULL, 0, AUL_SOCK_NONE);
+       if (r < 0) {
+               _E("Failed to send the watchdog request. ret(%d)", r);
+               return aul_error_convert(r);
+       }
+
+       __context.enabled = true;
+       _D("[__WATCHDOG__] enabled, result(%d)", r);
+       return AUL_R_OK;
+}
+
+API int aul_watchdog_disable(void)
+{
+       int r;
+
+       if (!__context.enabled) {
+               _W("Watchdog is not enabled");
+               return AUL_R_ERROR;
+       }
+
+       r = aul_sock_send_raw(AUL_UTIL_PID, getuid(),
+                       WATCHDOG_DISABLE, NULL, 0, AUL_SOCK_NONE);
+       if (r < 0) {
+               _E("Failed to send the watchdog request. ret(%d)", r);
+               return aul_error_convert(r);
+       }
+
+       __context.enabled = false;
+       _D("[__WATCHDOG__] disabled, result(%d)", r);
+       return AUL_R_OK;
+}
+
+API int aul_watchdog_kick(void)
+{
+       int r;
+
+       if (!__context.enabled) {
+               _W("Watchdog is not enabled");
+               return AUL_R_ERROR;
+       }
+
+       r = aul_sock_send_raw(AUL_UTIL_PID, getuid(),
+                       WATCHDOG_KICK, NULL, 0, AUL_SOCK_NONE);
+       if (r < 0) {
+               _E("Failed to send the watchdog request. ret(%d)", r);
+               return aul_error_convert(r);
+       }
+
+       _D("[__WATCHDOG__] kicked, result(%d)", r);
+       return AUL_R_OK;
+}
index ccfc883..188c24b 100755 (executable)
@@ -429,8 +429,9 @@ int aul_sock_handler(int fd)
        bundle *kbundle = NULL;
        int clifd;
        struct ucred cr;
-
        const char *pid_str;
+       const char *start_time;
+       struct timeval tv;
        int pid = -1;
        int ret;
 
@@ -445,6 +446,9 @@ int aul_sock_handler(int fd)
                } else {
                        ret = __send_result_to_launchpad(clifd, 0);
                        if (ret < 0) {
+                               _E("Failed to send the result. cmd(%s:%d)",
+                                       aul_cmd_convert_to_string(pkt->cmd),
+                                       pkt->cmd);
                                free(pkt);
                                return -1;
                        }
@@ -516,6 +520,13 @@ int aul_sock_handler(int fd)
        case APP_UPDATE_REQUESTED:
                app_update_requested();
                break;
+       case WATCHDOG_PING:
+               gettimeofday(&tv, NULL);
+               start_time = bundle_get_val(kbundle, AUL_K_STARTTIME);
+               _W("[__WATCHDOG__] Start time: %s, response time: %ld/%ld",
+                               start_time ? start_time : "Unknown",
+                               tv.tv_sec, tv.tv_usec);
+               break;
        default:
                _E("no support packet");
        }