From 787c094dbbee6bd8008663f428fcbcfcebe3ec7a Mon Sep 17 00:00:00 2001 From: aixiao Date: Thu, 13 Mar 2025 23:20:15 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Makefile | 4 ++-- conf/config.ini | 6 +++--- reboot_temperature.c | 11 ++++++++--- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 0a8b094..a573239 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,8 @@ CROSS_COMPILE ?= CC := $(CROSS_COMPILE)gcc CFLAGS += -Wall -Os -g -L../libini -I../libini -fno-builtin -LIB += -Wl,-rpath,/root/libini/ /root/libini/libini.so -BIN = reboot_temperature +LIB += -Wl,-rpath,/root/libini/ ../libini/libini.so +BIN = boot all: reboot_temperature.o $(CC) $(CFLAGS) $^ -o $(BIN) $(LIB) diff --git a/conf/config.ini b/conf/config.ini index 6b4214d..512b333 100644 --- a/conf/config.ini +++ b/conf/config.ini @@ -1,8 +1,8 @@ [global] thermal_zone = "/sys/class/thermal/thermal_zone0/temp"; -temperature = 85 -log_file = "log_reboot.log"; -second = 60 +temperature = 70 +log_file = "boot.log"; +second = 30 nice = -20 off_power = 0 diff --git a/reboot_temperature.c b/reboot_temperature.c index d9fb25f..0efdd75 100644 --- a/reboot_temperature.c +++ b/reboot_temperature.c @@ -45,7 +45,6 @@ static int error_log(float l_t, int c_t, char *log_file, char *recv_mail, int _i if (_is == 1) { - if (_alert == 1) { // 关机重启时 @@ -126,22 +125,28 @@ int main(int argc, char *argv[], char **env) perror("nice"); - while (1) { + while (1) + { getinikeystring("global", "thermal_zone", inifile, buffer); // 获取thermal_zone路径 getinikeystring("global", "log_file", inifile, log_file); // 获取日志文件名 getinikeystring("global", "recv_mail", inifile, recv_mail); // 获取接收者邮箱 if (get_temperature(buffer) >= getinikeyint("global", "temperature", inifile)) // 达到重启或者关机温度 { + sync(); sync(); if (getinikeyint("global", "off_power", inifile) == 1) { error_log(get_temperature(buffer), getinikeyint("global", "temperature", inifile), log_file, recv_mail, getinikeyint("global", "is_alert", inifile), 1); return reboot(RB_POWER_OFF); // 关机 - } else { + } + + if (getinikeyint("global", "off_power", inifile) == 0) + { error_log(get_temperature(buffer), getinikeyint("global", "temperature", inifile), log_file, recv_mail, getinikeyint("global", "is_alert", inifile), 1); return reboot(RB_AUTOBOOT); // 重启 } + } else // 未达到重启或者关机温度 {