diff --git a/smartmontools/ChangeLog b/smartmontools/ChangeLog index 08893ef75132f0a993774054b9c24907aa35ef72..ff29b612ce4091dbd08810f3d3c67ee2d0c065e7 100644 --- a/smartmontools/ChangeLog +++ b/smartmontools/ChangeLog @@ -1,5 +1,12 @@ $Id$ +2022-02-22 Christian Franke <franke@computer.org> + + smartd.cpp: Add '-q *nodev0*' option variants. + These change the exit status to 0 if there are no devices + to monitor. + smartd.8.in: Document new functionality. + 2022-02-20 Douglas Gilbert <dgilbert@interlog.com> smartctl.cpp, scsiprint.cpp: implement the change to diff --git a/smartmontools/smartd.8.in b/smartmontools/smartd.8.in index ff9585dd4befbc31cbce385386be73b463e70c64..a4b7f5f0dcedc42bdfcd3cff7c43e53dd2ec99c4 100644 --- a/smartmontools/smartd.8.in +++ b/smartmontools/smartd.8.in @@ -369,7 +369,8 @@ arguments are to this option are: .Sp .I nodev \- Exit if there are no devices to monitor, or if any errors are found -at startup in the configuration file. This is the default. +at startup in the configuration file. +This is the default. .Sp .I errors \- Exit if there are no devices to monitor, or if any errors are found @@ -383,10 +384,25 @@ reloaded. .Sp .I never \- Only exit if a fatal error occurs (no remaining system memory, -invalid command line arguments). In this mode, even if there are no -devices to monitor, or if the configuration file -\fB/usr/local/etc/smartd.conf\fP has errors, \fBsmartd\fP will continue to run, -waiting to load a configuration file listing valid devices. +invalid command line arguments). +In this mode, even if there are no devices to monitor, or if the configuration +file \fB/usr/local/etc/smartd.conf\fP has errors, \fBsmartd\fP will continue +to run, waiting to load a configuration file listing valid devices. +.Sp +.I nodev0 +\- [NEW EXPERIMENTAL SMARTD FEATURE] +Same as \*(Aqnodev\*(Aq, except that the exit status is 0 if there are no +devices to monitor. +.Sp +.I nodev0startup +\- [NEW EXPERIMENTAL SMARTD FEATURE] +Same as \*(Aqnodevstartup\*(Aq, except that the exit status is 0 if there are no +devices to monitor. +.Sp +.I errors,nodev0 +\- [NEW EXPERIMENTAL SMARTD FEATURE] +Same as \*(Aqerrors\*(Aq, except that the exit status is 0 if there are no +devices to monitor. .Sp .I onecheck \- Start \fBsmartd\fP in debug mode, then register devices, then check @@ -796,6 +812,10 @@ can't be monitored. .B 17: \fBsmartd\fP didn't find any devices to monitor. +.br +[NEW EXPERIMENTAL SMARTD FEATURE] +This could be changed to \fB0\fP (success) with one of the +\*(Aq-q *nodev0*\*(Aq options, see above. .TP .B 254: When in daemon mode, diff --git a/smartmontools/smartd.cpp b/smartmontools/smartd.cpp index 80c6b54e57442c549086e07489134834ccf2b370..5655b5bc368fecad2f9f3afe4085dc675b8a3b54 100644 --- a/smartmontools/smartd.cpp +++ b/smartmontools/smartd.cpp @@ -200,6 +200,7 @@ enum quit_t { QUIT_SHOWTESTS, QUIT_ERRORS }; static quit_t quit = QUIT_NODEV; +static bool quit_nodev0 = false; // command-line; this is the default syslog(3) log facility to use. static int facility=LOG_DAEMON; @@ -1555,7 +1556,7 @@ static const char *GetValidArgList(char opt) case 'l': return "daemon, local0, local1, local2, local3, local4, local5, local6, local7"; case 'q': - return "nodev, errors, nodevstartup, never, onecheck, showtests"; + return "nodev[0], errors[,nodev0], nodev[0]startup, never, onecheck, showtests"; case 'r': return "ioctl[,N], ataioctl[,N], scsiioctl[,N], nvmeioctl[,N]"; case 'p': @@ -5045,10 +5046,25 @@ static int parse_options(int argc, char **argv) switch(optchar) { case 'q': // when to quit + quit_nodev0 = false; if (!strcmp(optarg, "nodev")) quit = QUIT_NODEV; + else if (!strcmp(optarg, "nodev0")) { + quit = QUIT_NODEV; + quit_nodev0 = true; + } else if (!strcmp(optarg, "nodevstartup")) quit = QUIT_NODEVSTARTUP; + else if (!strcmp(optarg, "nodev0startup")) { + quit = QUIT_NODEVSTARTUP; + quit_nodev0 = true; + } + else if (!strcmp(optarg, "errors")) + quit = QUIT_ERRORS; + else if (!strcmp(optarg, "errors,nodev0")) { + quit = QUIT_ERRORS; + quit_nodev0 = true; + } else if (!strcmp(optarg, "never")) quit = QUIT_NEVER; else if (!strcmp(optarg, "onecheck")) { @@ -5059,8 +5075,6 @@ static int parse_options(int argc, char **argv) quit = QUIT_SHOWTESTS; debugmode = 1; } - else if (!strcmp(optarg, "errors")) - quit = QUIT_ERRORS; else badarg = true; break; @@ -5680,7 +5694,7 @@ static int main_worker(int argc, char **argv) || (quit == QUIT_NODEVSTARTUP && !firstpass))) { PrintOut(LOG_INFO, "Unable to monitor any SMART enabled devices. %sExiting...\n", (!debugmode ? "Try debug (-d) option. " : "")); - status = EXIT_NODEV; + status = EXIT_NODEV; // later changed to 0 if quit_nodev0 is set break; } @@ -5791,7 +5805,7 @@ static int main_worker(int argc, char **argv) // and this should be the final output from smartd before it exits PrintOut((status ? LOG_CRIT : LOG_INFO), "smartd is exiting (exit status %d)\n", - status); + (!(status == EXIT_NODEV && quit_nodev0) ? status : 0)); } return status; @@ -5833,6 +5847,11 @@ static int smartd_main(int argc, char **argv) PrintOut(LOG_CRIT, "Please inform " PACKAGE_BUGREPORT ", including output of smartd -V.\n"); notify_exit(status); + + // Return success if no devices to monitor and '-q *nodev0*' was specified + if (status == EXIT_NODEV && quit_nodev0) + status = 0; + #ifdef _WIN32 daemon_winsvc_exitcode = status; #endif