From 98e31d287346cb11e42f3115b70629afefc3e1e6 Mon Sep 17 00:00:00 2001 From: ballen4705 <ballen4705@4ea69e1a-61f1-4043-bf83-b5c94c648137> Date: Sun, 26 Oct 2003 02:20:41 +0000 Subject: [PATCH] added memory allocation tracking to solaris code. Fixed solaris signal handling (reset handler to default after first call to handler) by using sigset. Added HAVE_SIGSET to configure.in git-svn-id: https://smartmontools.svn.sourceforge.net/svnroot/smartmontools/trunk@1164 4ea69e1a-61f1-4043-bf83-b5c94c648137 --- sm5/CHANGELOG | 7 ++++++- sm5/configure.in | 5 +++-- sm5/os_solaris.c | 30 +++++++++++++++++++++--------- sm5/os_solaris.cpp | 30 +++++++++++++++++++++--------- sm5/os_solaris.h | 2 +- sm5/smartd.c | 35 +++++++++++++++++++++-------------- sm5/smartd.cpp | 35 +++++++++++++++++++++-------------- sm5/smartd.h | 10 +++++++++- 8 files changed, 103 insertions(+), 51 deletions(-) diff --git a/sm5/CHANGELOG b/sm5/CHANGELOG index f21060da9..f200c93ea 100644 --- a/sm5/CHANGELOG +++ b/sm5/CHANGELOG @@ -1,6 +1,6 @@ CHANGELOG for smartmontools -$Id: CHANGELOG,v 1.224 2003/10/26 02:12:33 ballen4705 Exp $ +$Id: CHANGELOG,v 1.225 2003/10/26 02:20:40 ballen4705 Exp $ Maintainers / Developers Key: [BA] Bruce Allen @@ -23,6 +23,11 @@ CURRENT DEVELOPMENT VERSION (see VERSION file in this directory): <ADDITIONS TO THE CHANGE LOG SHOULD BE ADDED HERE, PLEASE> + [BA] added memory allocation tracking to solaris code. + Fixed solaris signal handling (reset handler to default + after first call to handler) by using sigset. Added + HAVE_SIGSET to configure.in + [CD] solaris port: added SCSI functionality to solaris stubs. diff --git a/sm5/configure.in b/sm5/configure.in index d337bd32a..5fdd802f8 100644 --- a/sm5/configure.in +++ b/sm5/configure.in @@ -1,5 +1,5 @@ # -# $Id: configure.in,v 1.30 2003/10/20 14:11:55 ballen4705 Exp $ +# $Id: configure.in,v 1.31 2003/10/26 02:20:40 ballen4705 Exp $ # dnl Process this file with autoconf to produce a configure script. AC_PREREQ(2.50) @@ -7,7 +7,7 @@ AC_INIT(smartmontools, 5.22, smartmontools-support@lists.sourceforge.net) AC_CONFIG_SRCDIR(smartctl.c) smartmontools_configure_date=`date -u +"%Y/%m/%d %T %Z"` -smartmontools_cvs_tag=`echo '$Id: configure.in,v 1.30 2003/10/20 14:11:55 ballen4705 Exp $'` +smartmontools_cvs_tag=`echo '$Id: configure.in,v 1.31 2003/10/26 02:20:40 ballen4705 Exp $'` AC_DEFINE_UNQUOTED(SMARTMONTOOLS_CONFIGURE_ARGS, "$ac_configure_args", [smartmontools Configure Arguments]) AC_DEFINE_UNQUOTED(SMARTMONTOOLS_CONFIGURE_DATE, "$smartmontools_configure_date", [smartmontools Configure Date]) @@ -36,6 +36,7 @@ dnl Checks for library functions. AC_CHECK_FUNCS([getopt]) AC_CHECK_FUNCS([getopt_long]) AC_CHECK_FUNCS([getdomainname]) +AC_CHECK_FUNCS([sigset]) AC_SUBST(CPPFLAGS) AC_SUBST(LDFLAGS) diff --git a/sm5/os_solaris.c b/sm5/os_solaris.c index d7913bf9a..eb7730528 100644 --- a/sm5/os_solaris.c +++ b/sm5/os_solaris.c @@ -38,6 +38,7 @@ #include <sys/param.h> // These are needed to define prototypes for the functions defined below +#include "config.h" #include "atacmds.h" #include "scsicmds.h" #include "utility.h" @@ -45,8 +46,10 @@ // This is to include whatever prototypes you define in os_solaris.h #include "os_solaris.h" -const char *os_XXXX_c_cvsid="$Id: os_solaris.c,v 1.7 2003/10/26 02:12:33 ballen4705 Exp $" \ -ATACMDS_H_CVSID OS_XXXX_H_CVSID SCSICMDS_H_CVSID UTILITY_H_CVSID; +extern long long bytes; + +const char *os_XXXX_c_cvsid="$Id: os_solaris.c,v 1.8 2003/10/26 02:20:40 ballen4705 Exp $" \ +ATACMDS_H_CVSID CONFIG_H_CVSID OS_XXXX_H_CVSID SCSICMDS_H_CVSID UTILITY_H_CVSID; // The printwarning() function warns about unimplemented functions int printedout[2]; @@ -67,7 +70,7 @@ int printwarning(int which){ pout("\n" "#######################################################################\n" "%s NOT IMPLEMENTED under Solaris.\n" - "Please contact smartmontools-support@lists.sourceforge.net if\n" + "Please contact " PACKAGE_BUGREPORT " if\n" "you want to help in porting smartmontools to Solaris.\n" "#######################################################################\n" "\n", @@ -143,12 +146,12 @@ addpath(const char *path, struct pathlist *res) { if (++res->nnames > res->maxnames) { res->maxnames += 16; - res->names = realloc(res->names, - res->maxnames * sizeof (char *)); + res->names = realloc(res->names, res->maxnames * sizeof (char *)); if (res->names == NULL) return -1; + bytes += 16*sizeof(char *); } - if ((res->names[res->nnames-1] = strdup(path)) == NULL) + if (!(res->names[res->nnames-1] = CustomStrDup((char *)path, 1, __LINE__, __FILE__))) return -1; return 0; } @@ -187,7 +190,7 @@ grokdir(const char *dir, struct pathlist *res, int testfun(const char *)) } else { /* Tape drive represented by the all-digit device */ for (p = de->d_name; *p; p++) - if (!isdigit(*p)) + if (!isdigit((int)(*p))) break; if (*p != '\0') continue; @@ -214,12 +217,21 @@ int make_device_names (char*** devlist, const char* name) { res.names = NULL; if (strcmp(name, "SCSI") == 0) { if (grokdir("/dev/rdsk", &res, isscsidev) == -1) - return (-1); + return -1; if (grokdir("/dev/rmt", &res, isscsidev) == -1) - return (-1); + return -1; + + // shrink array to min possible size + res.names = realloc(res.names, res.nnames * sizeof (char *)); + bytes -= sizeof(char *)*(res.maxnames-res.nnames); + + // pass list back *devlist = res.names; return res.nnames; } + + // ATA case not implemented + *devlist=NULL; return 0; } diff --git a/sm5/os_solaris.cpp b/sm5/os_solaris.cpp index e88e1c969..f22bbfc98 100644 --- a/sm5/os_solaris.cpp +++ b/sm5/os_solaris.cpp @@ -38,6 +38,7 @@ #include <sys/param.h> // These are needed to define prototypes for the functions defined below +#include "config.h" #include "atacmds.h" #include "scsicmds.h" #include "utility.h" @@ -45,8 +46,10 @@ // This is to include whatever prototypes you define in os_solaris.h #include "os_solaris.h" -const char *os_XXXX_c_cvsid="$Id: os_solaris.cpp,v 1.7 2003/10/26 02:12:33 ballen4705 Exp $" \ -ATACMDS_H_CVSID OS_XXXX_H_CVSID SCSICMDS_H_CVSID UTILITY_H_CVSID; +extern long long bytes; + +const char *os_XXXX_c_cvsid="$Id: os_solaris.cpp,v 1.8 2003/10/26 02:20:40 ballen4705 Exp $" \ +ATACMDS_H_CVSID CONFIG_H_CVSID OS_XXXX_H_CVSID SCSICMDS_H_CVSID UTILITY_H_CVSID; // The printwarning() function warns about unimplemented functions int printedout[2]; @@ -67,7 +70,7 @@ int printwarning(int which){ pout("\n" "#######################################################################\n" "%s NOT IMPLEMENTED under Solaris.\n" - "Please contact smartmontools-support@lists.sourceforge.net if\n" + "Please contact " PACKAGE_BUGREPORT " if\n" "you want to help in porting smartmontools to Solaris.\n" "#######################################################################\n" "\n", @@ -143,12 +146,12 @@ addpath(const char *path, struct pathlist *res) { if (++res->nnames > res->maxnames) { res->maxnames += 16; - res->names = realloc(res->names, - res->maxnames * sizeof (char *)); + res->names = realloc(res->names, res->maxnames * sizeof (char *)); if (res->names == NULL) return -1; + bytes += 16*sizeof(char *); } - if ((res->names[res->nnames-1] = strdup(path)) == NULL) + if (!(res->names[res->nnames-1] = CustomStrDup((char *)path, 1, __LINE__, __FILE__))) return -1; return 0; } @@ -187,7 +190,7 @@ grokdir(const char *dir, struct pathlist *res, int testfun(const char *)) } else { /* Tape drive represented by the all-digit device */ for (p = de->d_name; *p; p++) - if (!isdigit(*p)) + if (!isdigit((int)(*p))) break; if (*p != '\0') continue; @@ -214,12 +217,21 @@ int make_device_names (char*** devlist, const char* name) { res.names = NULL; if (strcmp(name, "SCSI") == 0) { if (grokdir("/dev/rdsk", &res, isscsidev) == -1) - return (-1); + return -1; if (grokdir("/dev/rmt", &res, isscsidev) == -1) - return (-1); + return -1; + + // shrink array to min possible size + res.names = realloc(res.names, res.nnames * sizeof (char *)); + bytes -= sizeof(char *)*(res.maxnames-res.nnames); + + // pass list back *devlist = res.names; return res.nnames; } + + // ATA case not implemented + *devlist=NULL; return 0; } diff --git a/sm5/os_solaris.h b/sm5/os_solaris.h index f5b33a242..dfcb27dc3 100644 --- a/sm5/os_solaris.h +++ b/sm5/os_solaris.h @@ -24,7 +24,7 @@ #ifndef OS_SOLARIS_H_ #define OS_SOLARIS_H_ -#define OS_XXXX_H_CVSID "$Id: os_solaris.h,v 1.5 2003/10/26 02:12:33 ballen4705 Exp $\n" +#define OS_XXXX_H_CVSID "$Id: os_solaris.h,v 1.6 2003/10/26 02:20:40 ballen4705 Exp $\n" // Additional material should start here. Note: to keep the '-V' CVS // reporting option working as intended, you should only #include diff --git a/sm5/smartd.c b/sm5/smartd.c index 2acd3526c..85e460d1d 100644 --- a/sm5/smartd.c +++ b/sm5/smartd.c @@ -65,7 +65,7 @@ extern const char *atacmdnames_c_cvsid, *atacmds_c_cvsid, *ataprint_c_cvsid, *escalade_c_cvsid, *knowndrives_c_cvsid, *os_XXXX_c_cvsid, *scsicmds_c_cvsid, *utility_c_cvsid; -const char *smartd_c_cvsid="$Id: smartd.c,v 1.222 2003/10/25 13:03:26 ballen4705 Exp $" +const char *smartd_c_cvsid="$Id: smartd.c,v 1.223 2003/10/26 02:20:40 ballen4705 Exp $" ATACMDS_H_CVSID ATAPRINT_H_CVSID CONFIG_H_CVSID EXTERN_H_CVSID KNOWNDRIVES_H_CVSID SCSICMDS_H_CVSID SMARTD_H_CVSID UTILITY_H_CVSID; @@ -1461,23 +1461,25 @@ void Initialize(time_t *wakeuptime){ if (!debugmode) WritePidFile(); - // install signal handlers: + // install signal handlers. On Solaris, can't use signal() because + // it resets the handler to SIG_DFL after each call. So use sigset() + // instead. So SIGNALFN()==signal() or SIGNALFN()==sigset(). // normal and abnormal exit - if (signal(SIGTERM, sighandler)==SIG_IGN) - signal(SIGTERM, SIG_IGN); - if (signal(SIGQUIT, sighandler)==SIG_IGN) - signal(SIGQUIT, SIG_IGN); + if (SIGNALFN(SIGTERM, sighandler)==SIG_IGN) + SIGNALFN(SIGTERM, SIG_IGN); + if (SIGNALFN(SIGQUIT, sighandler)==SIG_IGN) + SIGNALFN(SIGQUIT, SIG_IGN); // in debug mode, <CONTROL-C> ==> HUP - if (signal(SIGINT, debugmode?HUPhandler:sighandler)==SIG_IGN) - signal(SIGINT, SIG_IGN); + if (SIGNALFN(SIGINT, debugmode?HUPhandler:sighandler)==SIG_IGN) + SIGNALFN(SIGINT, SIG_IGN); // Catch HUP and USR1 - if (signal(SIGHUP, HUPhandler)==SIG_IGN) - signal(SIGHUP, SIG_IGN); - if (signal(SIGUSR1, USR1handler)==SIG_IGN) - signal(SIGUSR1, SIG_IGN); + if (SIGNALFN(SIGHUP, HUPhandler)==SIG_IGN) + SIGNALFN(SIGHUP, SIG_IGN); + if (SIGNALFN(SIGUSR1, USR1handler)==SIG_IGN) + SIGNALFN(SIGUSR1, SIG_IGN); // initialize wakeup time to CURRENT time *wakeuptime=time(NULL); @@ -2461,6 +2463,10 @@ int MakeConfigEntries(const char *type, int start){ EXIT(EXIT_NOMEM); } + // if nothing on list, we are finished! + if (!num) + return num; + // check that we still have space for entries if (MAXENTRIES<(start+num)){ PrintOut(LOG_CRIT,"Error: simulated config file can have no more than MAXENTRIES=%d entries\n",(int)MAXENTRIES); @@ -2490,7 +2496,8 @@ int MakeConfigEntries(const char *type, int start){ cfg->name=devlist[i]; } - // free memory used for devlist: pointers now in cfgentries[]->names + // If needed, free memory used for devlist: pointers now in + // cfgentries[]->names devlist = FreeNonZero(devlist,(sizeof (char*) * num),__LINE__,__FILE__); return num; @@ -2590,7 +2597,7 @@ void RegisterDevices(int scanning){ // then register SCSI devices if (ent->tryscsi){ - int retscsi; + int retscsi=0; struct sigaction alarmAction, defaultaction; // Set up an alarm handler to catch USB devices that hang on diff --git a/sm5/smartd.cpp b/sm5/smartd.cpp index 9a7072af4..9cd30d1bc 100644 --- a/sm5/smartd.cpp +++ b/sm5/smartd.cpp @@ -65,7 +65,7 @@ extern const char *atacmdnames_c_cvsid, *atacmds_c_cvsid, *ataprint_c_cvsid, *escalade_c_cvsid, *knowndrives_c_cvsid, *os_XXXX_c_cvsid, *scsicmds_c_cvsid, *utility_c_cvsid; -const char *smartd_c_cvsid="$Id: smartd.cpp,v 1.222 2003/10/25 13:03:26 ballen4705 Exp $" +const char *smartd_c_cvsid="$Id: smartd.cpp,v 1.223 2003/10/26 02:20:40 ballen4705 Exp $" ATACMDS_H_CVSID ATAPRINT_H_CVSID CONFIG_H_CVSID EXTERN_H_CVSID KNOWNDRIVES_H_CVSID SCSICMDS_H_CVSID SMARTD_H_CVSID UTILITY_H_CVSID; @@ -1461,23 +1461,25 @@ void Initialize(time_t *wakeuptime){ if (!debugmode) WritePidFile(); - // install signal handlers: + // install signal handlers. On Solaris, can't use signal() because + // it resets the handler to SIG_DFL after each call. So use sigset() + // instead. So SIGNALFN()==signal() or SIGNALFN()==sigset(). // normal and abnormal exit - if (signal(SIGTERM, sighandler)==SIG_IGN) - signal(SIGTERM, SIG_IGN); - if (signal(SIGQUIT, sighandler)==SIG_IGN) - signal(SIGQUIT, SIG_IGN); + if (SIGNALFN(SIGTERM, sighandler)==SIG_IGN) + SIGNALFN(SIGTERM, SIG_IGN); + if (SIGNALFN(SIGQUIT, sighandler)==SIG_IGN) + SIGNALFN(SIGQUIT, SIG_IGN); // in debug mode, <CONTROL-C> ==> HUP - if (signal(SIGINT, debugmode?HUPhandler:sighandler)==SIG_IGN) - signal(SIGINT, SIG_IGN); + if (SIGNALFN(SIGINT, debugmode?HUPhandler:sighandler)==SIG_IGN) + SIGNALFN(SIGINT, SIG_IGN); // Catch HUP and USR1 - if (signal(SIGHUP, HUPhandler)==SIG_IGN) - signal(SIGHUP, SIG_IGN); - if (signal(SIGUSR1, USR1handler)==SIG_IGN) - signal(SIGUSR1, SIG_IGN); + if (SIGNALFN(SIGHUP, HUPhandler)==SIG_IGN) + SIGNALFN(SIGHUP, SIG_IGN); + if (SIGNALFN(SIGUSR1, USR1handler)==SIG_IGN) + SIGNALFN(SIGUSR1, SIG_IGN); // initialize wakeup time to CURRENT time *wakeuptime=time(NULL); @@ -2461,6 +2463,10 @@ int MakeConfigEntries(const char *type, int start){ EXIT(EXIT_NOMEM); } + // if nothing on list, we are finished! + if (!num) + return num; + // check that we still have space for entries if (MAXENTRIES<(start+num)){ PrintOut(LOG_CRIT,"Error: simulated config file can have no more than MAXENTRIES=%d entries\n",(int)MAXENTRIES); @@ -2490,7 +2496,8 @@ int MakeConfigEntries(const char *type, int start){ cfg->name=devlist[i]; } - // free memory used for devlist: pointers now in cfgentries[]->names + // If needed, free memory used for devlist: pointers now in + // cfgentries[]->names devlist = FreeNonZero(devlist,(sizeof (char*) * num),__LINE__,__FILE__); return num; @@ -2590,7 +2597,7 @@ void RegisterDevices(int scanning){ // then register SCSI devices if (ent->tryscsi){ - int retscsi; + int retscsi=0; struct sigaction alarmAction, defaultaction; // Set up an alarm handler to catch USB devices that hang on diff --git a/sm5/smartd.h b/sm5/smartd.h index cbe4ca3f9..3ba9432cc 100644 --- a/sm5/smartd.h +++ b/sm5/smartd.h @@ -27,7 +27,7 @@ #ifndef SMARTD_H_CVSID -#define SMARTD_H_CVSID "$Id: smartd.h,v 1.51 2003/10/25 13:03:26 ballen4705 Exp $\n" +#define SMARTD_H_CVSID "$Id: smartd.h,v 1.52 2003/10/26 02:20:41 ballen4705 Exp $\n" #endif // Configuration file @@ -236,4 +236,12 @@ export NJAMD_TRACE_LIBS=1 // time expires without sucess or failure, then treat it as failure. #define SCSITIMEOUT 7 +// This is for solaris, where signal() resets the handler to SIG_DFL +// after the first signal is caught. +#ifdef HAVE_SIGSET +#define SIGNALFN sigset +#else +#define SIGNALFN signal +#endif + #endif -- GitLab