/* * Copyright (c) 2015 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. */ #include "common.h" #include #include #define SEC_TO_USEC (1000*1000) static unsigned int saved_timeout=0; /* Now, systemd support to enable/disable runtime watchdog */ /* https://github.com/systemd/systemd/commit/2787d83c2 */ int systemd_change_watchdog_timeout(unsigned int timeout) { return sd_notifyf(0, "WATCHDOG_USEC=%llu", (unsigned long long) timeout*SEC_TO_USEC); } int _aw_register(unsigned int timeout) { int ret; ret = systemd_change_watchdog_timeout(timeout); if(ret <=0) return -1; saved_timeout = timeout; return 0; } int _aw_control(aw_op_e op, void *data) { int ret=-1; unsigned int* timeout; switch(op){ case AW_OP_DISABLE: ret = systemd_change_watchdog_timeout(0); break; case AW_OP_ENABLE: ret = systemd_change_watchdog_timeout(saved_timeout); break; case AW_OP_CHANGE_TIMEOUT: timeout = (unsigned int*)(data); if(timeout == NULL){ ret = -1; break; } ret = systemd_change_watchdog_timeout(*timeout); if(ret > 0) saved_timeout = *timeout; break; default: ret = -1; break; } if(ret > 0) return 0; return -1; } int _aw_notify(void) { int err; err = sd_notify(0, "WATCHDOG=1"); if(err == 0) return -ECOMM; else if(err > 0) err = 0; return err; }