smartmontools SVN Rev 5643
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"
#include "sg_unaligned.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 | 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 | check_ata_self_test_log (ata_device *device, const char *name, firmwarebug_defs firmwarebugs, unsigned &hour) |
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 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 | report_self_test_log_changes (const dev_config &cfg, dev_state &state, int errcnt, uint64_t hour) |
static char | next_scheduled_test (const dev_config &cfg, dev_state &state, 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 void | log_nvme_self_test_exec_status (const char *name, dev_state &state, bool firstpass, const nvme_self_test_log &self_test_log) |
static int | check_nvme_self_test_log (uint32_t nsid, const nvme_self_test_log &self_test_log, uint64_t &hour) |
static int | start_nvme_self_test (const dev_config &cfg, dev_state &state, nvme_device *device, char testtype, const nvme_self_test_log &self_test_log) |
static int | NVMeCheckDevice (const dev_config &cfg, dev_state &state, nvme_device *nvmedev, bool firstpass, bool allow_selftests) |
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 1043 of file smartd.cpp.
#define EXIT_BADCMD 1 |
Definition at line 138 of file smartd.cpp.
#define EXIT_BADCODE 10 |
Definition at line 146 of file smartd.cpp.
#define EXIT_BADCONF 2 |
Definition at line 139 of file smartd.cpp.
#define EXIT_BADDEV 16 |
Definition at line 148 of file smartd.cpp.
#define EXIT_NOCONF 5 |
Definition at line 142 of file smartd.cpp.
#define EXIT_NODEV 17 |
Definition at line 149 of file smartd.cpp.
#define EXIT_NOMEM 8 |
Definition at line 145 of file smartd.cpp.
#define EXIT_PID 4 |
Definition at line 141 of file smartd.cpp.
#define EXIT_READCONF 6 |
Definition at line 143 of file smartd.cpp.
#define EXIT_SIGNAL 254 |
Definition at line 151 of file smartd.cpp.
#define EXIT_STARTUP 3 |
Definition at line 140 of file smartd.cpp.
#define SCANDIRECTIVE "DEVICESCAN" |
Definition at line 5035 of file smartd.cpp.
#define SIGQUIT_KEYNAME "CONTROL-\\" |
Definition at line 90 of file smartd.cpp.
typedef std::vector<dev_config> dev_config_vector |
Container for configuration info for each device.
Definition at line 580 of file smartd.cpp.
typedef std::vector<dev_state> dev_state_vector |
Container for state info for each device.
Definition at line 583 of file smartd.cpp.
typedef void(* signal_handler_type) (int) |
Definition at line 97 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 359 of file smartd.cpp.
|
strong |
Enumerator | |
---|---|
unknown | |
once | |
always | |
daily | |
diminishing |
Definition at line 353 of file smartd.cpp.
enum quit_t |
Enumerator | |
---|---|
QUIT_NODEV | |
QUIT_NODEVSTARTUP | |
QUIT_NEVER | |
QUIT_ONECHECK | |
QUIT_SHOWTESTS | |
QUIT_ERRORS |
Definition at line 201 of file smartd.cpp.
__attribute_format_printf | ( | 2 | , |
0 | |||
) |
|
static |
scsi
Definition at line 3594 of file smartd.cpp.
|
static |
Definition at line 1971 of file smartd.cpp.
time_t calc_next_wakeuptime | ( | time_t | wakeuptime, |
time_t | timenow, | ||
int | ct | ||
) |
Definition at line 4318 of file smartd.cpp.
|
inlinestatic |
Definition at line 1002 of file smartd.cpp.
|
inlinestatic |
Definition at line 1003 of file smartd.cpp.
|
static |
Definition at line 5301 of file smartd.cpp.
|
static |
Definition at line 1782 of file smartd.cpp.
|
static |
Definition at line 3497 of file smartd.cpp.
|
static |
lpo_sup
Definition at line 2699 of file smartd.cpp.
|
static |
Definition at line 3989 of file smartd.cpp.
|
static |
Definition at line 3381 of file smartd.cpp.
|
static |
Definition at line 1887 of file smartd.cpp.
|
static |
Definition at line 4246 of file smartd.cpp.
void checksumwarning | ( | const char * | string | ) |
Definition at line 1401 of file smartd.cpp.
|
static |
Definition at line 3423 of file smartd.cpp.
|
static |
Definition at line 1722 of file smartd.cpp.
|
static |
Definition at line 1433 of file smartd.cpp.
|
static |
Definition at line 1544 of file smartd.cpp.
|
static |
Definition at line 4199 of file smartd.cpp.
|
static |
Definition at line 3262 of file smartd.cpp.
|
static |
Definition at line 3203 of file smartd.cpp.
|
static |
Definition at line 4325 of file smartd.cpp.
|
static |
Definition at line 1911 of file smartd.cpp.
|
static |
Definition at line 3414 of file smartd.cpp.
for | ( | char * | p = buf , |
*q;p &&*p; | p = q |
||
) |
Definition at line 1327 of file smartd.cpp.
|
static |
Definition at line 1928 of file smartd.cpp.
|
static |
Definition at line 4492 of file smartd.cpp.
|
static |
Definition at line 4458 of file smartd.cpp.
|
static |
Definition at line 1592 of file smartd.cpp.
|
static |
Definition at line 946 of file smartd.cpp.
|
static |
Definition at line 4171 of file smartd.cpp.
|
static |
Definition at line 4275 of file smartd.cpp.
|
static |
Definition at line 1945 of file smartd.cpp.
|
inlinestatic |
Definition at line 1824 of file smartd.cpp.
|
inlinestatic |
Definition at line 1830 of file smartd.cpp.
|
static |
Definition at line 2685 of file smartd.cpp.
|
static |
Definition at line 3923 of file smartd.cpp.
|
static |
Definition at line 1836 of file smartd.cpp.
|
static |
Definition at line 1859 of file smartd.cpp.
|
static |
Definition at line 1050 of file smartd.cpp.
int main | ( | int | argc, |
char ** | argv | ||
) |
Definition at line 6155 of file smartd.cpp.
|
static |
Definition at line 5959 of file smartd.cpp.
|
static |
Definition at line 5684 of file smartd.cpp.
|
static |
Definition at line 3026 of file smartd.cpp.
|
static |
Definition at line 1749 of file smartd.cpp.
|
inlinestatic |
Definition at line 346 of file smartd.cpp.
|
inlinestatic |
Definition at line 348 of file smartd.cpp.
|
inlinestatic |
Definition at line 344 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 332 of file smartd.cpp.
|
inlinestatic |
Definition at line 347 of file smartd.cpp.
|
static |
Definition at line 4062 of file smartd.cpp.
|
static |
Definition at line 2766 of file smartd.cpp.
|
static |
Definition at line 2907 of file smartd.cpp.
|
static |
Definition at line 633 of file smartd.cpp.
|
static |
Definition at line 5316 of file smartd.cpp.
|
static |
Definition at line 5152 of file smartd.cpp.
|
static |
Definition at line 5046 of file smartd.cpp.
|
static |
Definition at line 4547 of file smartd.cpp.
void pout | ( | const char * | fmt, |
... | |||
) |
Definition at line 1347 of file smartd.cpp.
|
static |
Definition at line 1538 of file smartd.cpp.
|
static |
Definition at line 1375 of file smartd.cpp.
|
static |
Definition at line 4413 of file smartd.cpp.
|
static |
Definition at line 3149 of file smartd.cpp.
|
static |
Definition at line 5287 of file smartd.cpp.
|
static |
Definition at line 1758 of file smartd.cpp.
|
static |
Definition at line 730 of file smartd.cpp.
|
static |
Definition at line 5728 of file smartd.cpp.
|
static |
Definition at line 5773 of file smartd.cpp.
|
static |
Definition at line 5858 of file smartd.cpp.
|
static |
Definition at line 2970 of file smartd.cpp.
|
static |
Definition at line 1293 of file smartd.cpp.
|
static |
Definition at line 1733 of file smartd.cpp.
|
static |
Definition at line 3838 of file smartd.cpp.
|
static |
Definition at line 2419 of file smartd.cpp.
|
static |
Definition at line 100 of file smartd.cpp.
|
static |
Definition at line 956 of file smartd.cpp.
|
static |
Definition at line 4024 of file smartd.cpp.
|
static |
Definition at line 1630 of file smartd.cpp.
|
static |
Definition at line 928 of file smartd.cpp.
|
static |
Definition at line 1410 of file smartd.cpp.
|
static |
Definition at line 910 of file smartd.cpp.
|
static |
Definition at line 889 of file smartd.cpp.
|
static |
Definition at line 835 of file smartd.cpp.
|
static |
Definition at line 781 of file smartd.cpp.
|
static |
Definition at line 768 of file smartd.cpp.
|
static |
Definition at line 774 of file smartd.cpp.
|
static |
Definition at line 1514 of file smartd.cpp.
const char va_list ap |
Definition at line 1322 of file smartd.cpp.
|
static |
Definition at line 173 of file smartd.cpp.
|
static |
Definition at line 232 of file smartd.cpp.
|
static |
Definition at line 229 of file smartd.cpp.
|
static |
Definition at line 220 of file smartd.cpp.
|
static |
Definition at line 159 of file smartd.cpp.
|
static |
Definition at line 160 of file smartd.cpp.
|
static |
Definition at line 180 of file smartd.cpp.
|
static |
Definition at line 184 of file smartd.cpp.
|
static |
Definition at line 182 of file smartd.cpp.
|
static |
Definition at line 155 of file smartd.cpp.
|
staticconstexpr |
Definition at line 158 of file smartd.cpp.
|
static |
Definition at line 213 of file smartd.cpp.
|
static |
Definition at line 209 of file smartd.cpp.
unsigned char failuretest_permissive = 0 |
Definition at line 217 of file smartd.cpp.
const bool fix_swapped_id = false |
Definition at line 1968 of file smartd.cpp.
const char* fmt |
Definition at line 1322 of file smartd.cpp.
|
static |
Definition at line 463 of file smartd.cpp.
|
static |
Definition at line 3022 of file smartd.cpp.
|
static |
Definition at line 163 of file smartd.cpp.
|
static |
Definition at line 205 of file smartd.cpp.
|
static |
Definition at line 206 of file smartd.cpp.
|
static |
Definition at line 135 of file smartd.cpp.
const char* smartd_cpp_cvsid |
Definition at line 93 of file smartd.cpp.
|
static |
Definition at line 461 of file smartd.cpp.
|
static |
Definition at line 4169 of file smartd.cpp.
|
static |
Definition at line 166 of file smartd.cpp.
|
static |
Definition at line 3021 of file smartd.cpp.
|
static |
Definition at line 187 of file smartd.cpp.