]> git.proxmox.com Git - mirror_smartmontools-debian.git/blobdiff - smartd.cpp
apply wrap-and-sort
[mirror_smartmontools-debian.git] / smartd.cpp
index fec123552e8cbcbf0676f90a348bfba878068156..98c8ca4d00d5178504f893919654cddce7765be7 100644 (file)
@@ -4,7 +4,7 @@
  * Copyright (C) 2002-11 Bruce Allen <smartmontools-support@lists.sourceforge.net>
  * Copyright (C) 2000    Michael Cornwell <cornwell@acm.org>
  * Copyright (C) 2008    Oliver Bock <brevilo@users.sourceforge.net>
- * Copyright (C) 2008-13 Christian Franke <smartmontools-support@lists.sourceforge.net>
+ * Copyright (C) 2008-15 Christian Franke <smartmontools-support@lists.sourceforge.net>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -106,7 +106,7 @@ typedef int pid_t;
 extern "C" int getdomainname(char *, int); // no declaration in header files!
 #endif
 
-const char * smartd_cpp_cvsid = "$Id: smartd.cpp 3802 2013-03-24 18:36:21Z chrfranke $"
+const char * smartd_cpp_cvsid = "$Id: smartd.cpp 4059 2015-04-18 17:01:31Z chrfranke $"
   CONFIG_H_CVSID;
 
 // smartd exit codes
@@ -676,13 +676,13 @@ 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)
 {
   if (val)
-    fprintf(f, "%s = %"PRIu64"\n", name, val);
+    fprintf(f, "%s = %" PRIu64 "\n", name, val);
 }
 
 static void write_dev_state_line(FILE * f, const char * name1, int id, const char * name2, uint64_t val)
 {
   if (val)
-    fprintf(f, "%s.%d.%s = %"PRIu64"\n", name1, id, name2, val);
+    fprintf(f, "%s.%d.%s = %" PRIu64 "\n", name1, id, name2, val);
 }
 
 // Write a state file
@@ -757,7 +757,7 @@ static bool write_dev_attrlog(const char * path, const dev_state & state)
     const persistent_dev_state::ata_attribute & pa = state.ata_attributes[i];
     if (!pa.id)
       continue;
-    fprintf(f, "\t%d;%d;%"PRIu64";", pa.id, pa.val, pa.raw);
+    fprintf(f, "\t%d;%d;%" PRIu64 ";", pa.id, pa.val, pa.raw);
   }
   // SCSI ONLY
   const struct scsiErrorCounter * ecp;
@@ -765,13 +765,13 @@ static bool write_dev_attrlog(const char * path, const dev_state & state)
   for (int k = 0; k < 3; ++k) {
     if ( !state.scsi_error_counters[k].found ) continue;
     ecp = &state.scsi_error_counters[k].errCounter;
-     fprintf(f, "\t%s-corr-by-ecc-fast;%"PRIu64";"
-       "\t%s-corr-by-ecc-delayed;%"PRIu64";"
-       "\t%s-corr-by-retry;%"PRIu64";"
-       "\t%s-total-err-corrected;%"PRIu64";"
-       "\t%s-corr-algorithm-invocations;%"PRIu64";"
+     fprintf(f, "\t%s-corr-by-ecc-fast;%" PRIu64 ";"
+       "\t%s-corr-by-ecc-delayed;%" PRIu64 ";"
+       "\t%s-corr-by-retry;%" PRIu64 ";"
+       "\t%s-total-err-corrected;%" PRIu64 ";"
+       "\t%s-corr-algorithm-invocations;%" PRIu64 ";"
        "\t%s-gb-processed;%.3f;"
-       "\t%s-total-unc-errors;%"PRIu64";",
+       "\t%s-total-unc-errors;%" PRIu64 ";",
        pageNames[k], ecp->counter[0],
        pageNames[k], ecp->counter[1],
        pageNames[k], ecp->counter[2],
@@ -781,7 +781,7 @@ static bool write_dev_attrlog(const char * path, const dev_state & state)
        pageNames[k], ecp->counter[6]);
   }
   if(state.scsi_nonmedium_error.found && state.scsi_nonmedium_error.nme.gotPC0) {
-    fprintf(f, "\tnon-medium-errors;%"PRIu64";", state.scsi_nonmedium_error.nme.counterPC0);
+    fprintf(f, "\tnon-medium-errors;%" PRIu64 ";", state.scsi_nonmedium_error.nme.counterPC0);
   }
   // write SCSI current temperature if it is monitored
   if(state.TempPageSupported && state.temperature)
@@ -1491,7 +1491,7 @@ static void Usage()
   PrintOut(LOG_INFO,"  -A PREFIX, --attributelog=PREFIX\n");
   PrintOut(LOG_INFO,"        Log ATA attribute information to {PREFIX}MODEL-SERIAL.ata.csv\n");
 #ifdef SMARTMONTOOLS_ATTRIBUTELOG
-  PrintOut(LOG_INFO,"        [default is "SMARTMONTOOLS_ATTRIBUTELOG"MODEL-SERIAL.ata.csv]\n");
+  PrintOut(LOG_INFO,"        [default is " SMARTMONTOOLS_ATTRIBUTELOG "MODEL-SERIAL.ata.csv]\n");
 #endif
   PrintOut(LOG_INFO,"\n");
   PrintOut(LOG_INFO,"  -B [+]FILE, --drivedb=[+]FILE\n");
@@ -1507,7 +1507,7 @@ static void Usage()
   PrintOut(LOG_INFO,"        [default is %s]\n\n", configfile);
 #ifdef HAVE_LIBCAP_NG
   PrintOut(LOG_INFO,"  -C, --capabilities\n");
-  PrintOut(LOG_INFO,"        Use capabilities.\n"
+  PrintOut(LOG_INFO,"        Drop unneeded Linux process capabilities.\n"
                     "        Warning: Mail notification does not work when used.\n\n");
 #endif
   PrintOut(LOG_INFO,"  -d, --debug\n");
@@ -1537,13 +1537,13 @@ static void Usage()
   PrintOut(LOG_INFO,"  -s PREFIX, --savestates=PREFIX\n");
   PrintOut(LOG_INFO,"        Save disk states to {PREFIX}MODEL-SERIAL.TYPE.state\n");
 #ifdef SMARTMONTOOLS_SAVESTATES
-  PrintOut(LOG_INFO,"        [default is "SMARTMONTOOLS_SAVESTATES"MODEL-SERIAL.TYPE.state]\n");
+  PrintOut(LOG_INFO,"        [default is " SMARTMONTOOLS_SAVESTATES "MODEL-SERIAL.TYPE.state]\n");
 #endif
   PrintOut(LOG_INFO,"\n");
   PrintOut(LOG_INFO,"  -w NAME, --warnexec=NAME\n");
   PrintOut(LOG_INFO,"        Run executable NAME on warnings\n");
 #ifndef _WIN32
-  PrintOut(LOG_INFO,"        [default is "SMARTMONTOOLS_SYSCONFDIR"/smartd_warning.sh]\n\n");
+  PrintOut(LOG_INFO,"        [default is " SMARTMONTOOLS_SMARTDSCRIPTDIR "/smartd_warning.sh]\n\n");
 #else
   PrintOut(LOG_INFO,"        [default is %s/smartd_warning.cmd]\n\n", get_exe_dir().c_str());
 #endif
@@ -1591,7 +1591,7 @@ static int read_ata_error_count(ata_device * device, const char * name,
   }
   else {
     ata_smart_exterrlog logx;
-    if (!ataReadExtErrorLog(device, &logx, 1 /*first sector only*/, firmwarebugs)) {
+    if (!ataReadExtErrorLog(device, &logx, 0, 1 /*first sector only*/, firmwarebugs)) {
       PrintOut(LOG_INFO,"Device: %s, Read Extended Comprehensive SMART Error Log failed\n",name);
       return -1;
     }
@@ -1698,7 +1698,7 @@ static bool check_pending_id(const dev_config & cfg, const dev_state & state,
   uint64_t rawval = ata_get_attr_raw_value(state.smartval.vendor_attributes[i],
     cfg.attribute_defs);
   if (rawval >= (state.num_sectors ? state.num_sectors : 0xffffffffULL)) {
-    PrintOut(LOG_INFO, "Device: %s, ignoring %s count - bogus Attribute %d value %"PRIu64" (0x%"PRIx64")\n",
+    PrintOut(LOG_INFO, "Device: %s, ignoring %s count - bogus Attribute %d value %" PRIu64 " (0x%" PRIx64 ")\n",
              cfg.name.c_str(), msg, id, rawval, rawval);
     return false;
   }
@@ -1781,7 +1781,7 @@ static int ATADeviceScan(dev_config & cfg, dev_state & state, ata_device * atade
   unsigned oui = 0; uint64_t unique_id = 0;
   int naa = ata_get_wwn(&drive, oui, unique_id);
   if (naa >= 0)
-    snprintf(wwn, sizeof(wwn), "WWN:%x-%06x-%09"PRIx64", ", naa, oui, unique_id);
+    snprintf(wwn, sizeof(wwn), "WWN:%x-%06x-%09" PRIx64 ", ", naa, oui, unique_id);
 
   // Format device id string for warning emails
   char cap[32];
@@ -1849,8 +1849,12 @@ static int ATADeviceScan(dev_config & cfg, dev_state & state, ata_device * atade
   if (ataEnableSmart(atadev)) {
     // Enable SMART command has failed
     PrintOut(LOG_INFO,"Device: %s, could not enable SMART capability\n",name);
-    CloseDevice(atadev, name);
-    return 2; 
+
+    if (ataIsSmartEnabled(&drive) <= 0) {
+      CloseDevice(atadev, name);
+      return 2;
+    }
+    PrintOut(LOG_INFO, "Device: %s, proceeding since SMART is already enabled\n", name);
   }
   
   // disable device attribute autosave...
@@ -2749,7 +2753,7 @@ static int DoATASelfTest(const dev_config & cfg, dev_state & state, ata_device *
       return 1;
     }
     uint64_t start = selargs.span[0].start, end = selargs.span[0].end;
-    PrintOut(LOG_INFO, "Device: %s, %s test span at LBA %"PRIu64" - %"PRIu64" (%"PRIu64" sectors, %u%% - %u%% of disk).\n",
+    PrintOut(LOG_INFO, "Device: %s, %s test span at LBA %" PRIu64 " - %" PRIu64 " (%" PRIu64 " sectors, %u%% - %u%% of disk).\n",
       name, (selargs.span[0].mode == SEL_NEXT ? "next" : "redo"),
       start, end, end - start + 1,
       (unsigned)((100 * start + state.num_sectors/2) / state.num_sectors),
@@ -2800,9 +2804,9 @@ static void check_pending(const dev_config & cfg, dev_state & state,
     return;
 
   // Format message.
-  std::string s = strprintf("Device: %s, %"PRId64" %s", cfg.name.c_str(), rawval, msg);
+  std::string s = strprintf("Device: %s, %" PRId64 " %s", cfg.name.c_str(), rawval, msg);
   if (prev_rawval > 0 && rawval != prev_rawval)
-    s += strprintf(" (changed %+"PRId64")", rawval - prev_rawval);
+    s += strprintf(" (changed %+" PRId64 ")", rawval - prev_rawval);
 
   PrintOut(LOG_CRIT, "%s\n", s.c_str());
   MailWarning(cfg, state, mailtype, "%s", s.c_str());
@@ -4254,10 +4258,10 @@ static int ParseConfigFile(dev_config_vector & conf_entries)
   // No configuration file found -- use fake one
   int entry = 0;
   if (!f) {
-    char fakeconfig[] = SCANDIRECTIVE" -a"; // TODO: Remove this hack, build cfg_entry.
+    char fakeconfig[] = SCANDIRECTIVE " -a"; // TODO: Remove this hack, build cfg_entry.
 
     if (ParseConfigLine(conf_entries, default_conf, 0, fakeconfig) != -1)
-      throw std::logic_error("Internal error parsing "SCANDIRECTIVE);
+      throw std::logic_error("Internal error parsing " SCANDIRECTIVE);
     return 0;
   }
 
@@ -4395,8 +4399,8 @@ static void ParseOpts(int argc, char **argv)
 {
   // Init default path names
 #ifndef _WIN32
-  configfile = SMARTMONTOOLS_SYSCONFDIR"/smartd.conf";
-  warning_script = SMARTMONTOOLS_SYSCONFDIR"/smartd_warning.sh";
+  configfile = SMARTMONTOOLS_SYSCONFDIR "/smartd.conf";
+  warning_script = SMARTMONTOOLS_SMARTDSCRIPTDIR "/smartd_warning.sh";
 #else
   std::string exedir = get_exe_dir();
   static std::string configfile_str = exedir + "/smartd.conf";
@@ -4789,7 +4793,7 @@ static int ReadOrMakeConfigEntries(dev_config_vector & conf_entries, smart_devic
       PrintOut(LOG_CRIT,"In the system's table of devices NO devices found to scan\n");
   } 
   else
-    PrintOut(LOG_CRIT,"Configuration file %s parsed but has no entries (like /dev/hda)\n",configfile);
+    PrintOut(LOG_CRIT, "Configuration file %s parsed but has no entries\n", configfile);
   
   return conf_entries.size();
 }
@@ -5028,7 +5032,7 @@ static int main_worker(int argc, char **argv)
         PrintOut(LOG_INFO,
                  caughtsigHUP==1?
                  "Signal HUP - rereading configuration file %s\n":
-                 "\a\nSignal INT - rereading configuration file %s ("SIGQUIT_KEYNAME" quits)\n\n",
+                 "\a\nSignal INT - rereading configuration file %s (" SIGQUIT_KEYNAME " quits)\n\n",
                  configfile);
       }
 
@@ -5178,9 +5182,9 @@ int main(int argc, char **argv){
     "smartd", "SmartD Service", // servicename, displayname
     // description
     "Controls and monitors storage devices using the Self-Monitoring, "
-    "Analysis and Reporting Technology System (S.M.A.R.T.) "
-    "built into ATA and SCSI Hard Drives. "
-    PACKAGE_HOMEPAGE
+    "Analysis and Reporting Technology System (SMART) built into "
+    "ATA/SATA and SCSI/SAS hard drives and solid-state drives. "
+    "www.smartmontools.org"
   };
   // daemon_main() handles daemon and service specific commands
   // and starts smartd_main() direct, from a new process,