gpt4 book ai didi

c++ - 如何在看门狗执行之前将日志复制到闪存?

转载 作者:太空宇宙 更新时间:2023-11-04 05:10:38 27 4
gpt4 key购买 nike

如何在看门狗执行之前执行一些脚本(在我的例子中,它将编写将日志复制到闪存或远程复制日志的脚本)?

我应该修改Linux内核看门狗驱动程序吗?如果是的话用什么方法?或者也许可以通过以下方式进行配置:

/etc/default/watchdog
/etc/watchdog.conf

但是我们安装了 busybox,但看门狗配置受到限制。我在谷歌上找不到任何东西,令人惊讶的是,这是需要解决的基本问题 - 每个人都希望在看门狗重置后在持久内存中拥有日志,闪存不是/var/log/路径的内容。

当然,在正常设备生命周期中不时将日志复制到闪存的解决方案并不是一个好主意,因为应该有一些解决方案,当喂食/dev/watchdog 的看门狗超时到期时如何执行此操作。

最佳答案

On a linux kernel newer than 4.9 you should have the availability of the pretimeout governor framework which would allow you to write a linux kernel driver which would react on the detection of a pre-timeout. A solution like this is well beyond the scope of a simple question and answer, so I'm leaving my original answer stand.

TL;博士:

If the problem is detectable while the OS is still running you can flush the logs. If the problem is caused by the OS locking up then you won't have an opportunity to fix the issue as hardware will reset the box.

这里有两件事:

  • 看门狗设备
  • 看门狗程序

看门狗设备通常是一个硬件计时器,当计时器到期时,它会执行“特别低级别的操作”。最常见的低级操作是重置盒子。如果发生在硬件中,则操作系统不参与其中。一旦计时器用完,你将没有机会做任何高级别的事情 - 例如在某处写入日志文件。

看门狗程序是一种工具,只要满足检查条件,它就会定期向看门狗设备保证安全。

busybox 看门狗定时器的条件是一个简单的循环(伪代码):

while (1) {
# reassure watchdog
# sleep some time
}

所以如果程序停止运行 - 例如通过操作系统锁定或程序终止,底层硬件将直接启动。

“更大”的看门狗二进制文件提供了一系列检查,如果它们失败,它将触发 /etc/watchdog.conf 中的 repair-binary 选项来尝试恢复。这将是刷新日志的潜在点。

关于c++ - 如何在看门狗执行之前将日志复制到闪存?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55845216/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com