diff --git a/smartmontools/ChangeLog b/smartmontools/ChangeLog index 5ee0b5e6c4954f6f857a8fb40d1627ff3cbcd9d1..d9d6e4545b74d73c1aef3d4eaece636a59bff3b2 100644 --- a/smartmontools/ChangeLog +++ b/smartmontools/ChangeLog @@ -1,5 +1,10 @@ $Id$ +2022-06-07 themylogin <themylogin@gmail.com> + + smartd.cpp: Prevent systemd unit startup timeout when registering + many devices (GH pull/138). + 2022-05-30 Douglas Gilbert <dgilbert@interlog.com> [SCSI]: rework scsiGetIEString() so it should now output diff --git a/smartmontools/smartd.cpp b/smartmontools/smartd.cpp index 74c0332027d5961f8397afd9141ee87f1fb3792a..2b3c81c188cbd4c0b09c8eace1df6f6c2a764e97 100644 --- a/smartmontools/smartd.cpp +++ b/smartmontools/smartd.cpp @@ -236,6 +236,7 @@ static void PrintOut(int priority, const char *fmt, ...) // systemd notify support static bool notify_enabled = false; +static bool notify_ready = false; static inline void notify_init() { @@ -255,6 +256,20 @@ static inline bool notify_post_init() return true; } +static inline void notify_extend_timeout() +{ + if (!notify_enabled) + return; + if (notify_ready) + return; + const char * notify = "EXTEND_TIMEOUT_USEC=20000000"; // typical drive spinup time is 20s tops + if (debugmode) { + pout("sd_notify(0, \"%s\")\n", notify); + return; + } + sd_notify(0, notify); +} + static void notify_msg(const char * msg, bool ready = false) { if (!notify_enabled) @@ -285,9 +300,8 @@ static void notify_wait(time_t wakeuptime, int numdev) char msg[64]; snprintf(msg, sizeof(msg), "Next check of %d device%s will start at %s", numdev, (numdev != 1 ? "s" : ""), ts); - static bool ready = true; // first call notifies READY=1 - notify_msg(msg, ready); - ready = false; + notify_msg(msg, !notify_ready); // first call notifies READY=1 + notify_ready = true; } static void notify_exit(int status) @@ -322,6 +336,7 @@ static inline bool notify_post_init() } static inline void notify_init() { } +static inline void notify_extend_timeout() { } static inline void notify_msg(const char *) { } static inline void notify_check(int) { } static inline void notify_wait(time_t, int) { } @@ -5578,6 +5593,9 @@ static bool register_devices(const dev_config_vector & conf_entries, smart_devic } } + // Prevent systemd unit startup timeout when registering many devices + notify_extend_timeout(); + // Register device // If scanning, pass dev_idinfo of previous devices for duplicate check dev_state state;