smartmontools SVN Rev 5474
Utility to control and monitor storage systems with "S.M.A.R.T."
|
#include "config.h"
#include <inttypes.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <signal.h>
#include <fcntl.h>
#include <string.h>
#include <syslog.h>
#include <stdarg.h>
#include <stdlib.h>
#include <errno.h>
#include <time.h>
#include <limits.h>
#include <getopt.h>
#include <algorithm>
#include <map>
#include <stdexcept>
#include <string>
#include <vector>
#include <sys/wait.h>
#include "atacmds.h"
#include "dev_interface.h"
#include "knowndrives.h"
#include "scsicmds.h"
#include "nvmecmds.h"
#include "utility.h"
Go to the source code of this file.
Classes | |
class | attribute_flags |
struct | dev_config |
Configuration data for a device. More... | |
struct | mailinfo |
struct | persistent_dev_state |
Persistent state data for a device. More... | |
struct | persistent_dev_state::ata_attribute |
struct | persistent_dev_state::scsi_error_counter_t |
struct | persistent_dev_state::scsi_error_counter_t::errCounter |
struct | persistent_dev_state::scsi_nonmedium_error_t |
struct | persistent_dev_state::scsi_nonmedium_error_t::nme |
struct | temp_dev_state |
Non-persistent state data for a device. More... | |
struct | dev_state |
Runtime state data for a device. More... | |
class | env_buffer |
Macros | |
#define | __STDC_FORMAT_MACROS 1 |
#define | SIGQUIT_KEYNAME "CONTROL-\\" |
#define | EXIT_BADCMD 1 |
#define | EXIT_BADCONF 2 |
#define | EXIT_STARTUP 3 |
#define | EXIT_PID 4 |
#define | EXIT_NOCONF 5 |
#define | EXIT_READCONF 6 |
#define | EXIT_NOMEM 8 |
#define | EXIT_BADCODE 10 |
#define | EXIT_BADDEV 16 |
#define | EXIT_NODEV 17 |
#define | EXIT_SIGNAL 254 |
#define | EBUFLEN 1024 |
#define | SELFTEST_ERRORCOUNT(x) (x & 0xff) |
#define | SELFTEST_ERRORHOURS(x) ((x >> 8) & 0xffff) |
#define | SCANDIRECTIVE "DEVICESCAN" |
Typedefs | |
typedef void(* | signal_handler_type) (int) |
typedef std::vector< dev_config > | dev_config_vector |
Container for configuration info for each device. | |
typedef std::vector< dev_state > | dev_state_vector |
Container for state info for each device. | |
Enumerations | |
enum | quit_t { QUIT_NODEV , QUIT_NODEVSTARTUP , QUIT_NEVER , QUIT_ONECHECK , QUIT_SHOWTESTS , QUIT_ERRORS } |
enum class | emailfreqs : unsigned char { unknown , once , always , daily , diminishing } |
enum | { MONITOR_IGN_FAILUSE = 0x01 , MONITOR_IGNORE = 0x02 , MONITOR_RAW_PRINT = 0x04 , MONITOR_RAW = 0x08 , MONITOR_AS_CRIT = 0x10 , MONITOR_RAW_AS_CRIT = 0x20 } |
Functions | |
static void | set_signal_if_not_ignored (int sig, signal_handler_type handler) |
static void | PrintOut (int priority, const char *fmt,...) __attribute_format_printf(2 |
static void static bool | notify_post_init () |
static void | notify_init () |
static void | notify_extend_timeout () |
static void | notify_msg (const char *) |
static void | notify_check (int) |
static void | notify_wait (time_t, int) |
static void | notify_exit (int) |
static bool | parse_dev_state_line (const char *line, persistent_dev_state &state) |
static bool | read_dev_state (const char *path, persistent_dev_state &state) |
static void | write_dev_state_line (FILE *f, const char *name, uint64_t val) |
static void | write_dev_state_line (FILE *f, const char *name1, int id, const char *name2, uint64_t val) |
static bool | write_dev_state (const char *path, const persistent_dev_state &state) |
static bool | write_dev_attrlog (const char *path, const dev_state &state) |
static void | write_all_dev_states (const dev_config_vector &configs, dev_state_vector &states, bool write_always=true) |
static void | write_all_dev_attrlogs (const dev_config_vector &configs, dev_state_vector &states) |
static void | USR1handler (int sig) |
static void | HUPhandler (int sig) |
static void | sighandler (int sig) |
static void | capabilities_drop_now () |
static void | capabilities_log_error_hint () |
static void | MailWarning (const dev_config &cfg, dev_state &state, int which, const char *fmt,...) __attribute_format_printf(4 |
static void | reset_warning_mail (const dev_config &cfg, dev_state &state, int which, const char *fmt,...) __attribute_format_printf(4 |
__attribute_format_printf (2, 0) static void vsyslog_lines(int priority | |
vsnprintf (buf, sizeof(buf), fmt, ap) | |
for (char *p=buf, *q;p &&*p;p=q) | |
void | pout (const char *fmt,...) |
void | checksumwarning (const char *string) |
static bool | WaitForPidFile () |
static int | daemon_init () |
static bool | write_pid_file () |
static void | PrintHead () |
static void | Directives () |
static const char * | GetValidArgList (char opt) |
static void | Usage () |
static int | CloseDevice (smart_device *device, const char *name) |
static bool | sanitize_dev_idinfo (std::string &s) |
static bool | not_allowed_in_filename (char c) |
static int | read_ata_error_count (ata_device *device, const char *name, firmwarebug_defs firmwarebugs, bool extended) |
static int | SelfTestErrorCount (ata_device *device, const char *name, firmwarebug_defs firmwarebugs) |
static bool | is_offl_coll_in_progress (unsigned char status) |
static bool | is_self_test_in_progress (unsigned char status) |
static void | log_offline_data_coll_status (const char *name, unsigned char status) |
static void | log_self_test_exec_status (const char *name, unsigned char status) |
static bool | check_pending_id (const dev_config &cfg, const dev_state &state, unsigned char id, const char *msg) |
static void | finish_device_scan (dev_config &cfg, dev_state &state) |
static void | format_set_result_msg (std::string &msg, const char *name, bool ok, int set_option=0, bool has_value=false) |
static bool | is_duplicate_dev_idinfo (const dev_config &cfg, const dev_config_vector &prev_cfgs) |
static int | ATADeviceScan (dev_config &cfg, dev_state &state, ata_device *atadev, const dev_config_vector *prev_cfgs) |
static int | SCSIDeviceScan (dev_config &cfg, dev_state &state, scsi_device *scsidev, const dev_config_vector *prev_cfgs) |
static uint64_t | le128_to_uint64 (const unsigned char(&val)[16]) |
static int | nvme_get_max_temp_kelvin (const nvme_smart_log &smart_log) |
static bool | check_nvme_error_log (const dev_config &cfg, dev_state &state, nvme_device *nvmedev, uint64_t newcnt=0) |
static int | NVMeDeviceScan (dev_config &cfg, dev_state &state, nvme_device *nvmedev, const dev_config_vector *prev_cfgs) |
static bool | open_device (const dev_config &cfg, dev_state &state, smart_device *device, const char *type) |
static void | CheckSelfTestLogs (const dev_config &cfg, dev_state &state, int newi) |
static char | next_scheduled_test (const dev_config &cfg, dev_state &state, bool scsi, time_t usetime=0) |
static void | PrintTestSchedule (const dev_config_vector &configs, dev_state_vector &states, const smart_device_list &devices) |
static int | DoSCSISelfTest (const dev_config &cfg, dev_state &state, scsi_device *device, char testtype) |
static int | DoATASelfTest (const dev_config &cfg, dev_state &state, ata_device *device, char testtype) |
static void | check_pending (const dev_config &cfg, dev_state &state, unsigned char id, bool increase_only, const ata_smart_values &smartval, int mailtype, const char *msg) |
static const char * | fmt_temp (unsigned char x, char(&buf)[20]) |
static void | CheckTemperature (const dev_config &cfg, dev_state &state, unsigned char currtemp, unsigned char triptemp) |
static void | check_attribute (const dev_config &cfg, dev_state &state, const ata_smart_attribute &attr, const ata_smart_attribute &prev, int attridx, const ata_smart_threshold_entry *thresholds) |
static int | ATACheckDevice (const dev_config &cfg, dev_state &state, ata_device *atadev, bool firstpass, bool allow_selftests) |
static int | SCSICheckDevice (const dev_config &cfg, dev_state &state, scsi_device *scsidev, bool allow_selftests) |
static int | NVMeCheckDevice (const dev_config &cfg, dev_state &state, nvme_device *nvmedev) |
static void | init_disable_standby_check (const dev_config_vector &configs) |
static void | do_disable_standby_check (const dev_config_vector &configs, const dev_state_vector &states) |
static void | CheckDevicesOnce (const dev_config_vector &configs, dev_state_vector &states, smart_device_list &devices, bool firstpass, bool allow_selftests) |
static void | install_signal_handlers () |
time_t | calc_next_wakeuptime (time_t wakeuptime, time_t timenow, int ct) |
static time_t | dosleep (time_t wakeuptime, const dev_config_vector &configs, dev_state_vector &states, bool &sigwakeup) |
static void | printoutvaliddirectiveargs (int priority, char d) |
static int | GetInteger (const char *arg, const char *name, const char *token, int lineno, const char *cfgfile, int min, int max, char *suffix=0) |
static int | Get3Integers (const char *arg, const char *name, const char *token, int lineno, const char *cfgfile, unsigned char *val1, unsigned char *val2, unsigned char *val3) |
static int | ParseToken (char *token, dev_config &cfg, smart_devtype_list &scan_types) |
static int | ParseConfigLine (dev_config_vector &conf_entries, dev_config &default_conf, smart_devtype_list &scan_types, int lineno, char *line) |
static int | ParseConfigFile (dev_config_vector &conf_entries, smart_devtype_list &scan_types) |
static void | PrintValidArgs (char opt) |
static bool | check_abs_path (char option, const std::string &path) |
static int | parse_options (int argc, char **argv) |
static int | MakeConfigEntries (const dev_config &base_cfg, dev_config_vector &conf_entries, smart_device_list &scanned_devs, const smart_devtype_list &types) |
static int | ReadOrMakeConfigEntries (dev_config_vector &conf_entries, smart_device_list &scanned_devs) |
static bool | register_device (dev_config &cfg, dev_state &state, smart_device_auto_ptr &dev, const dev_config_vector *prev_cfgs) |
static bool | register_devices (const dev_config_vector &conf_entries, smart_device_list &scanned_devs, dev_config_vector &configs, dev_state_vector &states, smart_device_list &devices) |
static int | main_worker (int argc, char **argv) |
int | main (int argc, char **argv) |
Variables | |
const char * | smartd_cpp_cvsid |
static const int | scsiLogRespLen = 252 |
static unsigned char | debugmode = 0 |
static constexpr int | default_checktime = 1800 |
static int | checktime = default_checktime |
static int | checktime_min = 0 |
static std::string | pid_file |
static std::string | state_path_prefix |
static std::string | attrlog_path_prefix |
static const char * | configfile |
static const char *const | configfile_stdin = "<stdin>" |
static std::string | configfile_alt |
static std::string | warning_script |
static quit_t | quit = QUIT_NODEV |
static bool | quit_nodev0 = false |
static int | facility =LOG_DAEMON |
static bool | do_fork =true |
unsigned char | failuretest_permissive = 0 |
static volatile int | caughtsigUSR1 =0 |
static volatile int | caughtsigHUP =0 |
static volatile int | caughtsigEXIT =0 |
static const int | SMARTD_NMAIL = 13 |
static const int | MAILTYPE_TEST = 0 |
const char * | fmt |
const char va_list | ap |
const bool | fix_swapped_id = false |
static const char | test_type_chars [] = "LncrSCO" |
static const unsigned | num_test_types = sizeof(test_type_chars)-1 |
static int | standby_disable_state = 0 |
#define __STDC_FORMAT_MACROS 1 |
Definition at line 13 of file smartd.cpp.
#define EBUFLEN 1024 |
Definition at line 1032 of file smartd.cpp.
#define EXIT_BADCMD 1 |
Definition at line 137 of file smartd.cpp.
#define EXIT_BADCODE 10 |
Definition at line 145 of file smartd.cpp.
#define EXIT_BADCONF 2 |
Definition at line 138 of file smartd.cpp.
#define EXIT_BADDEV 16 |
Definition at line 147 of file smartd.cpp.
#define EXIT_NOCONF 5 |
Definition at line 141 of file smartd.cpp.
#define EXIT_NODEV 17 |
Definition at line 148 of file smartd.cpp.
#define EXIT_NOMEM 8 |
Definition at line 144 of file smartd.cpp.
#define EXIT_PID 4 |
Definition at line 140 of file smartd.cpp.
#define EXIT_READCONF 6 |
Definition at line 142 of file smartd.cpp.
#define EXIT_SIGNAL 254 |
Definition at line 150 of file smartd.cpp.
#define EXIT_STARTUP 3 |
Definition at line 139 of file smartd.cpp.
#define SCANDIRECTIVE "DEVICESCAN" |
Definition at line 4814 of file smartd.cpp.
#define SELFTEST_ERRORCOUNT | ( | x | ) | (x & 0xff) |
Definition at line 1802 of file smartd.cpp.
#define SELFTEST_ERRORHOURS | ( | x | ) | ((x >> 8) & 0xffff) |
Definition at line 1803 of file smartd.cpp.
#define SIGQUIT_KEYNAME "CONTROL-\\" |
Definition at line 89 of file smartd.cpp.
typedef std::vector<dev_config> dev_config_vector |
Container for configuration info for each device.
Definition at line 569 of file smartd.cpp.
typedef std::vector<dev_state> dev_state_vector |
Container for state info for each device.
Definition at line 572 of file smartd.cpp.
typedef void(* signal_handler_type) (int) |
Definition at line 96 of file smartd.cpp.
anonymous enum |
Enumerator | |
---|---|
MONITOR_IGN_FAILUSE | |
MONITOR_IGNORE | |
MONITOR_RAW_PRINT | |
MONITOR_RAW | |
MONITOR_AS_CRIT | |
MONITOR_RAW_AS_CRIT |
Definition at line 356 of file smartd.cpp.
|
strong |
Enumerator | |
---|---|
unknown | |
once | |
always | |
daily | |
diminishing |
Definition at line 350 of file smartd.cpp.
enum quit_t |
Enumerator | |
---|---|
QUIT_NODEV | |
QUIT_NODEVSTARTUP | |
QUIT_NEVER | |
QUIT_ONECHECK | |
QUIT_SHOWTESTS | |
QUIT_ERRORS |
Definition at line 200 of file smartd.cpp.
__attribute_format_printf | ( | 2 | , |
0 | |||
) |
|
static |
scsi
Definition at line 3551 of file smartd.cpp.
|
static |
Definition at line 1950 of file smartd.cpp.
time_t calc_next_wakeuptime | ( | time_t | wakeuptime, |
time_t | timenow, | ||
int | ct | ||
) |
Definition at line 4097 of file smartd.cpp.
|
inlinestatic |
Definition at line 991 of file smartd.cpp.
|
inlinestatic |
Definition at line 992 of file smartd.cpp.
|
static |
Definition at line 5080 of file smartd.cpp.
|
static |
Definition at line 3454 of file smartd.cpp.
|
static |
lpo_sup
Definition at line 2685 of file smartd.cpp.
|
static |
Definition at line 3338 of file smartd.cpp.
|
static |
Definition at line 1869 of file smartd.cpp.
|
static |
Definition at line 4025 of file smartd.cpp.
|
static |
Definition at line 2920 of file smartd.cpp.
void checksumwarning | ( | const char * | string | ) |
Definition at line 1390 of file smartd.cpp.
|
static |
Definition at line 3380 of file smartd.cpp.
|
static |
Definition at line 1703 of file smartd.cpp.
|
static |
Definition at line 1422 of file smartd.cpp.
|
static |
Definition at line 1525 of file smartd.cpp.
|
static |
Definition at line 3978 of file smartd.cpp.
|
static |
Definition at line 3220 of file smartd.cpp.
|
static |
Definition at line 3161 of file smartd.cpp.
|
static |
Definition at line 4104 of file smartd.cpp.
|
static |
Definition at line 1893 of file smartd.cpp.
|
static |
Definition at line 3371 of file smartd.cpp.
for | ( | char * | p = buf , |
*q;p &&*p; | p = q |
||
) |
Definition at line 1316 of file smartd.cpp.
|
static |
Definition at line 1910 of file smartd.cpp.
|
static |
Definition at line 4271 of file smartd.cpp.
|
static |
Definition at line 4237 of file smartd.cpp.
|
static |
Definition at line 1573 of file smartd.cpp.
|
static |
Definition at line 935 of file smartd.cpp.
|
static |
Definition at line 3950 of file smartd.cpp.
|
static |
Definition at line 4054 of file smartd.cpp.
|
static |
Definition at line 1927 of file smartd.cpp.
|
inlinestatic |
Definition at line 1806 of file smartd.cpp.
|
inlinestatic |
Definition at line 1812 of file smartd.cpp.
|
static |
Definition at line 2660 of file smartd.cpp.
|
static |
Definition at line 1818 of file smartd.cpp.
|
static |
Definition at line 1841 of file smartd.cpp.
|
static |
Definition at line 1039 of file smartd.cpp.
int main | ( | int | argc, |
char ** | argv | ||
) |
Definition at line 5936 of file smartd.cpp.
|
static |
Definition at line 5737 of file smartd.cpp.
|
static |
Definition at line 5462 of file smartd.cpp.
|
static |
Definition at line 2984 of file smartd.cpp.
|
static |
Definition at line 1730 of file smartd.cpp.
|
inlinestatic |
Definition at line 343 of file smartd.cpp.
|
inlinestatic |
Definition at line 345 of file smartd.cpp.
|
inlinestatic |
Definition at line 341 of file smartd.cpp.
|
inlinestatic |
Definition at line 340 of file smartd.cpp.
|
inlinestatic |
Definition at line 342 of file smartd.cpp.
|
inlinestatic |
Definition at line 329 of file smartd.cpp.
|
inlinestatic |
Definition at line 344 of file smartd.cpp.
|
static |
Definition at line 2674 of file smartd.cpp.
|
static |
Definition at line 3877 of file smartd.cpp.
|
static |
Definition at line 2752 of file smartd.cpp.
|
static |
Definition at line 2857 of file smartd.cpp.
|
static |
Definition at line 622 of file smartd.cpp.
|
static |
Definition at line 5095 of file smartd.cpp.
|
static |
Definition at line 4931 of file smartd.cpp.
|
static |
Definition at line 4825 of file smartd.cpp.
|
static |
Definition at line 4326 of file smartd.cpp.
void pout | ( | const char * | fmt, |
... | |||
) |
Definition at line 1336 of file smartd.cpp.
|
static |
Definition at line 1519 of file smartd.cpp.
|
static |
Definition at line 1364 of file smartd.cpp.
|
static |
Definition at line 4192 of file smartd.cpp.
|
static |
Definition at line 3107 of file smartd.cpp.
|
static |
Definition at line 5066 of file smartd.cpp.
|
static |
Definition at line 1739 of file smartd.cpp.
|
static |
Definition at line 719 of file smartd.cpp.
|
static |
Definition at line 5506 of file smartd.cpp.
|
static |
Definition at line 5551 of file smartd.cpp.
|
static |
Definition at line 5636 of file smartd.cpp.
|
static |
Definition at line 1282 of file smartd.cpp.
|
static |
Definition at line 1714 of file smartd.cpp.
|
static |
Definition at line 3795 of file smartd.cpp.
|
static |
Definition at line 2398 of file smartd.cpp.
|
static |
Definition at line 1763 of file smartd.cpp.
|
static |
Definition at line 99 of file smartd.cpp.
|
static |
Definition at line 945 of file smartd.cpp.
|
static |
Definition at line 1611 of file smartd.cpp.
|
static |
Definition at line 917 of file smartd.cpp.
|
static |
Definition at line 1399 of file smartd.cpp.
|
static |
Definition at line 899 of file smartd.cpp.
|
static |
Definition at line 878 of file smartd.cpp.
|
static |
Definition at line 824 of file smartd.cpp.
|
static |
Definition at line 770 of file smartd.cpp.
|
static |
Definition at line 757 of file smartd.cpp.
|
static |
Definition at line 763 of file smartd.cpp.
|
static |
Definition at line 1495 of file smartd.cpp.
const char va_list ap |
Definition at line 1311 of file smartd.cpp.
|
static |
Definition at line 172 of file smartd.cpp.
|
static |
Definition at line 231 of file smartd.cpp.
|
static |
Definition at line 228 of file smartd.cpp.
|
static |
Definition at line 219 of file smartd.cpp.
|
static |
Definition at line 158 of file smartd.cpp.
|
static |
Definition at line 159 of file smartd.cpp.
|
static |
Definition at line 179 of file smartd.cpp.
|
static |
Definition at line 183 of file smartd.cpp.
|
static |
Definition at line 181 of file smartd.cpp.
|
static |
Definition at line 154 of file smartd.cpp.
|
staticconstexpr |
Definition at line 157 of file smartd.cpp.
|
static |
Definition at line 212 of file smartd.cpp.
|
static |
Definition at line 208 of file smartd.cpp.
unsigned char failuretest_permissive = 0 |
Definition at line 216 of file smartd.cpp.
const bool fix_swapped_id = false |
Definition at line 1947 of file smartd.cpp.
const char* fmt |
Definition at line 1311 of file smartd.cpp.
|
static |
Definition at line 459 of file smartd.cpp.
|
static |
Definition at line 2980 of file smartd.cpp.
|
static |
Definition at line 162 of file smartd.cpp.
|
static |
Definition at line 204 of file smartd.cpp.
|
static |
Definition at line 205 of file smartd.cpp.
|
static |
Definition at line 134 of file smartd.cpp.
const char* smartd_cpp_cvsid |
Definition at line 92 of file smartd.cpp.
|
static |
Definition at line 457 of file smartd.cpp.
|
static |
Definition at line 3948 of file smartd.cpp.
|
static |
Definition at line 165 of file smartd.cpp.
|
static |
Definition at line 2979 of file smartd.cpp.
|
static |
Definition at line 186 of file smartd.cpp.