病毒四项检查都有什么| 为什么会有生长纹| 吃什么改善睡眠| 盘古是一个什么样的人| 榨菜炒什么好吃| 特警属于什么编制| mrsa医学上是什么意思| 腋毛癣用什么药膏最好| 竖中指是什么意思| 为什么肝区隐隐作痛| 芋头什么时候种植最好| 牙周炎是什么症状| 元五行属性是什么| 束脚裤配什么鞋子| 什么运动瘦脸| 绿色的大便是什么原因| 为的多音字是什么| 纪梵希为什么不娶赫本| 执着什么意思| 巨蟹座女和什么座最配| hbcag是什么意思| 双手发麻是什么原因| 多种维生素什么时候吃效果最好| 面藕是什么做的| 青蒜是什么| 皮下囊肿挂什么科| 来月经量少吃什么可以增加月经量| btob是什么意思| 肚脐周围是什么肠| 血脂高喝什么茶好| 考拉是什么意思| 可爱是什么意思| 欺骗餐是什么意思| mbti测试是什么| 红加黄等于什么颜色| 鼻子突然出血是什么原因| 阳虚是什么原因引起的| 羊肉和什么菜搭配最好| 鼻炎不能吃什么食物| 不想吃饭是什么原因| 鸡眼长什么样| 拿什么让你幸福| nmol是什么单位| 手被辣椒辣了用什么方法解辣| sandisk是什么牌子| 什么叫一桌餐| 做梦梦见拉屎是什么意思| 舌苔腻是什么意思| 手腕发麻是什么原因| 什么是结缔组织病| 包皮过长是什么样的| 多潘立酮片治什么病| 前置胎盘需要注意什么| 卫衣是什么| 水痘吃什么药| 阑尾粪石是什么意思| 梅杰综合症是什么病| 双抗是什么药| 女孩断掌纹代表什么| 什么是眼底病| 空调制热效果不好什么原因| 超凡脱俗是什么意思| 菊花茶喝多了有什么坏处| 吃什么降火| 为什么印度叫阿三| 美的不可方物什么意思| 查凝血酶能查出什么病| 西安有什么好吃的特产| 什么是电解质饮料| 阴阳两虚用什么药| 鲍鱼是什么| 玉米淀粉是什么| 生姜泡醋有什么功效| 水痘什么样| kumpoo是什么牌子| 武林外传的客栈叫什么| 成都是什么气候| 人次是什么意思| 尿频吃什么药最好| 明月照沟渠是什么意思| 颓废是什么意思| 11.20是什么星座| 3的倒数是什么| 子宫切除后要注意什么| 出轨是什么意思| 鼻子发干是什么原因造成的| 算五行缺什么免费测试| 什么牛奶最好| 口腔溃疡长什么样| 上海什么时候解放的| 用维生素e擦脸有什么好处和坏处| 输血前四项检查是什么| 中国最大的湖泊是什么湖| 什么地望着| 咽喉炎吃什么药好| dxm是什么药| 天目湖白茶属于什么茶| 男生生理期是什么表现| 肝主什么| 打鼾是什么原因引起的| 高血压喝什么茶| item是什么意思| 开拔是什么意思| 性无能是什么意思| 卵巢囊性占位是什么意思| 欢喜冤家是什么意思| 医院特需门诊什么意思| 10月15号是什么星座的| 树脂是什么材料| 为什么会梦游| 胃一阵一阵的疼是什么原因| 治字五行属什么| 腰间盘突出挂什么科| 9月24号是什么星座| 颧骨长斑是什么原因| 猪肚炖什么| 8月27号是什么星座| 拉姆是什么意思| 早泄吃什么好| samsung是什么牌子| 花椰菜是什么菜| 种植牙为什么那么贵| 4月19号是什么星座| runosd是什么牌子的手表| pta是什么意思| 为什么脸上总是出油| 普工是什么| peek是什么材料| 贫血吃什么补| 什么不安成语| 补肾壮阳吃什么药好| 唯女子与小人难养也是什么意思| 冬枣为什么叫冬枣| joan是什么意思| 燕子进屋来有什么兆头| 赘肉是什么意思| 毒瘤是什么意思| 虎皮羊质是指什么生肖| 耳鸣什么原因引起| 淳朴是什么意思| 吃什么水果对心脏有好处| 血小板高是什么原因| 艾滋病阳性是什么意思| 唇系带断了有什么影响| 吃蒲公英有什么好处| 大便黑色是什么原因| 土命适合什么颜色| 淮山和山药有什么区别| 生男孩女孩取决于什么| 血糖低吃什么补的最快| 早上口干舌燥是什么原因| 1月生日是什么星座| 火牛命五行缺什么| 史迪仔是什么动物| 驾驶证b2能开什么车| 肌层彩色血流星点状是什么意思| 最高学历是什么| 风林火山是什么意思| 尿气味重是什么原因| 药师是干什么的| rp是什么| mep是什么意思| 黑色代表什么| 女人尿多是什么原因| 害羞的近义词是什么| 单抗主要治疗什么| 土界读什么| 囊壁钙化是什么意思| 附件炎是什么| 月经每个月都推迟是什么原因| 均码是什么码| 孕妇喝咖啡有什么危害| 肛瘘是什么原因引起的| 蓝加红是什么颜色| 蛋白糖是什么糖| 贫血吃什么食物最好| 字号是什么意思| 辟加木念什么| 三文鱼又叫什么鱼| 胆囊结石用什么药好| 2005年属鸡是什么命| 做孕检都检查什么项目| 学业有成是什么意思| 出的汗是凉的什么原因| 海带和什么菜搭配好吃| 竹笙是什么| 过敏性结膜炎用什么药| 青霉素过敏可以吃什么消炎药| exo什么时候出道的| 偏光是什么意思| 为什么一热脸就特别红| 什么时候人流| 优甲乐是治什么病的| 肾虚吃什么药好| 小孩出虚汗是什么原因| 吃什么子宫肌瘤会消除| 乌冬面是什么做的| 腰椎间盘突吃什么药| 养膘是什么意思| 晕车药吃多了有什么副作用| 怀孕初期分泌物是什么样的| 7月生日是什么星座| 嗓子发炎挂什么科| 幽门螺旋杆菌的症状吃什么药| 7月6号是什么星座| 脖子上长小肉粒是什么| 什么叫静脉曲张| 宫腔内囊性结构是什么意思| 鸡血藤手镯有什么功效| 句加一笔是什么字| 小便憋不住尿裤子是什么情况| 6月23日是什么节日| 花五行属什么| ur是什么牌子| 拉拉裤和纸尿裤有什么区别| 欠缺是什么意思| 痔疮和肛周脓肿有什么区别| 什么时候做nt| 抠鼻表情是什么意思| 脑梗吃什么| 籺是什么意思| 农历10月19日是什么星座| 什么的荷花| 回心转意是什么意思| 舌尖痛什么原因| 杀鸡给猴看什么意思| 楚楚动人是什么意思| 拌嘴是什么意思| 真我是什么意思| 吉数是什么生肖| bmi什么意思| 汉堡里面的白色酱是什么酱| 气管炎吃什么药好| 帕罗西汀是什么药| 酸奶有什么好处| 1985属什么| 本子什么意思| 虫草花是什么| 糖尿病人能喝什么饮料| 佛跳墙是什么| 什么生火| 白痰多是什么原因造成的| 为什么挠脚心会痒| 发小是什么意思| 蚊子会传播什么疾病| 老是打嗝是什么病的征兆| 左心房扩大是什么意思| 菠萝是什么意思| 朝秦暮楚是什么意思| 芝士可以做什么美食| 一什么羊| 勿误是什么意思| 24节气分别是什么| 火加同念什么| 肝实质回声细密是什么意思| 为什么会长血管瘤| 拉稀水是什么原因| 7.17是什么日子| 腹直肌分离是什么意思| 梦见表姐是什么意思| 住院带什么必备物品| 3月26号是什么星座| 脖子痛挂什么科| 强磁对人体有什么危害| 百度
blob: fe3774405b11c7292ab60d4d88cb4aaf21958d8b [file] [log] [blame] [edit]
/*
* Simple Linux HW watchdog daemon
*
* Copyright (c) 2010 Daniel Widyanko. All rights reserved.
* Copyright 2012 The ChromiumOS Authors
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <getopt.h>
#include <malloc.h>
#include <string.h>
#include <signal.h>
#include <errno.h>
#include <unistd.h>
#include <linux/watchdog.h>
#define WATCHDOGDEV "/dev/watchdog"
#define MIN_WD_TIMEOUT 5 /* WD must be at least 5 seconds */
#define DEFAULT_INTERVAL_SECS 30
#define PETTING_SECS 2 /* Try to pet every 2 seconds */
/* "volatile" prevents gcc from optimizing accesses to terminated. */
static volatile sig_atomic_t terminated;
static const char short_options[] = "hcd:i:";
static const struct option long_options[] = {
{"help", 0, NULL, 'h'},
{"check", 0, NULL, 'c'},
{"dev", 1, NULL, 'd'},
{"interval", 1, NULL, 'i'},
{NULL, 0, NULL, 0},
};
static void print_usage(FILE * stream, char *app_name, int exit_code)
{
fprintf(stream, "Usage: %s [options]\n", app_name);
fprintf(stream,
" -h --help Display this usage information.\n"
" -c --check Exit right away after printing info.\n"
" -d --dev <device_file> Use <device_file> as HW watchdog device file.\n"
" The default is '/dev/watchdog'\n"
" -i --interval <interval> Change the HW watchdog interval time\n"
" Must be at least %d seconds\n", MIN_WD_TIMEOUT
);
exit(exit_code);
}
static void daisydog_sigterm(int signal)
{
terminated = 1;
}
/*
* Writing 'V' into watchdog device indicates the close/stop
* of the watchdog was intentional. Otherwise, debug message
* 'Watchdog timer closed unexpectedly' will be printed to
* dmesg and the system will reboot in wd_timeout seconds since
* the last time the watchdog was pet.
*/
static void close_watchdog(int fd, const char *dev)
{
int ret = write(fd, "V", 1);
if (ret != 1)
warn("%s: Writing magic close sequence failed."
" The driver may not stop the watchdog", dev);
if (close(fd))
warn("%s: close(%i) failed", dev, fd);
}
int main(int argc, char **argv)
{
int fd; /* File handler for HW watchdog */
int bootstatus; /* HW Watchdog last boot status */
char *dev = WATCHDOGDEV;/* HW Watchdog default device file */
int next_option; /* getopt iteration var */
int wd_timeout; /* when HW watchdog goes balistic */
int interval = 0; /* user parameter for wd_timeout */
int ret = 0; /* write/sleep call return value */
/* Parse options if any */
do {
next_option = getopt_long(argc, argv, short_options,
long_options, NULL);
switch (next_option) {
case 'h':
print_usage(stdout, argv[0], EXIT_SUCCESS);
case 'c':
terminated = 1;
break;
case 'd':
dev = optarg;
break;
case 'i':
interval = atoi(optarg);
if (interval < MIN_WD_TIMEOUT) {
warnx("Interval %d is too small; must be at least %d",
interval, MIN_WD_TIMEOUT);
print_usage(stderr, argv[0], -EINVAL);
}
break;
case '?': /* Invalid options */
print_usage(stderr, argv[0], -EINVAL);
case -1: /* Done with options */
break;
default: /* Unexpected stuffs */
abort();
}
} while (next_option != -1);
/* Once the watchdog device file is open, the watchdog will
* be activated by the driver.
*/
fd = open(dev, O_RDWR|O_CLOEXEC);
if (-1 == fd)
err(EXIT_FAILURE, "open(%s) failed", dev);
signal(SIGTERM, daisydog_sigterm);
signal(SIGHUP, daisydog_sigterm);
signal(SIGINT, daisydog_sigterm);
/* If user wants to change the HW watchdog timeout. */
if (interval) {
if (ioctl(fd, WDIOC_SETTIMEOUT, &interval) != 0) {
err(EXIT_FAILURE, "could not set HW watchdog"
"interval to %d", interval);
}
}
/* Get/Display current HW watchdog interval.
* Let user know if it's not exactly what they specified.
*/
if (ioctl(fd, WDIOC_GETTIMEOUT, &wd_timeout) == 0) {
printf("HW watchdog interval is %d seconds",
wd_timeout);
if (interval && interval != wd_timeout)
printf(" (user asked for %d seconds)",
interval);
printf("\n");
if (wd_timeout < MIN_WD_TIMEOUT) {
warnx("Existing HW watchdog interval %d is below "
"required %d minimum, changing to %d",
wd_timeout, MIN_WD_TIMEOUT, DEFAULT_INTERVAL_SECS);
interval = DEFAULT_INTERVAL_SECS;
if (ioctl(fd, WDIOC_SETTIMEOUT, &interval) != 0) {
err(EXIT_FAILURE, "could not set HW watchdog"
" interval to %d", DEFAULT_INTERVAL_SECS);
}
}
} else {
err(EXIT_FAILURE, "cannot read HW watchdog interval");
}
/* Check if last boot is caused by HW watchdog. */
if (ioctl(fd, WDIOC_GETBOOTSTATUS, &bootstatus) == 0) {
printf("%s reported boot status: ", dev);
if (bootstatus == 0)
printf("normal-boot");
else if (bootstatus == -1)
printf("UNKNOWN");
else {
/* Show hex value in case unknown bits are set. */
printf("%#0x", bootstatus);
if (bootstatus & WDIOF_CARDRESET)
printf(" watchdog-timeout");
if (bootstatus & WDIOF_OVERHEAT)
printf(" CPU-overheat");
if (bootstatus & WDIOF_POWERUNDER)
printf(" power-undervoltage");
if (bootstatus & WDIOF_POWEROVER)
printf(" power-overvoltage");
if (bootstatus & WDIOF_FANFAULT)
printf(" fan-fault");
}
printf("\n");
} else {
err(EXIT_FAILURE, "%s: cannot read boot status", dev);
}
/* Before we start the main loop, release any caches we don't need. */
malloc_trim(0);
/* Flush out any buffered writes so they can be captured by logger. */
fflush(NULL);
while (!terminated) {
ret = ioctl(fd, WDIOC_KEEPALIVE, 0);
/* Force immediate exit of loop if keepalive fails. */
if (ret) {
warn("Terminating");
ret = EXIT_FAILURE;
break;
}
/* Check terminate again in case of interruption after entering the loop. */
if (!terminated)
sleep(PETTING_SECS);
/* SIGTERM/HUP/INT will cause sleep(3) to return early.
* SIGKILL will exit anyway.
* If something else caused us to return early, just
* pretend it was a hiccup and keep looping.
*/
}
close_watchdog(fd, dev);
fflush(NULL);
exit(ret);
}
散光有什么症状 芋圆是什么做的 5月28日什么星座 ect是什么检查 whatsapp是什么软件
督邮相当于现在什么官 cip号是什么 hcg什么时候查最准确 coolmax是什么面料 什么人心什么
可转债是什么 大红袍属于什么茶类 脱发挂什么科 细小是什么病什么症状 头发痒是什么原因
心肌炎吃什么药效果好 怀孕肚子上长毛是什么原因 小孩积食发烧吃什么药 初心不改是什么意思 减肥有什么好方法
沅字五行属什么hcv8jop4ns2r.cn 轻断食是什么意思hcv9jop6ns4r.cn 死于非命是什么意思hcv9jop7ns4r.cn 世界上笔画最多的字是什么字zsyouku.com 6月25日是世界什么日hcv9jop1ns4r.cn
恶性贫血是什么意思hcv8jop0ns4r.cn 大黄米和小黄米有什么区别hcv9jop5ns3r.cn 子宫增厚是什么原因hcv9jop2ns7r.cn 籍贯一般填什么hcv9jop2ns5r.cn 婴儿感冒吃什么药hcv8jop0ns4r.cn
妞字五行属什么cj623037.com 高血脂是什么原因引起的hcv7jop9ns7r.cn 出汗吃什么药hcv7jop6ns4r.cn 牛肉不能跟什么一起吃hcv7jop7ns2r.cn 做梦笑出声是什么预兆yanzhenzixun.com
ami是什么意思hcv8jop7ns3r.cn 紫茉莉什么时候开花hcv8jop1ns6r.cn 科目三考什么内容hcv9jop0ns9r.cn 打太极拳有什么好处hcv9jop7ns2r.cn 胆囊壁毛糙吃什么药hcv8jop8ns9r.cn
百度