* 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
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
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
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;
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],
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)
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");
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");
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
}
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;
}
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;
}
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];
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...
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),
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());
// 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;
}
{
// 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";
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();
}
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);
}
"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,