diff -Naur cpqarrayd-2.2/cciss_functions.c cpqarrayd-2.2.oden/cciss_functions.c --- cpqarrayd-2.2/cciss_functions.c 2003-09-24 18:05:25.000000000 +0200 +++ cpqarrayd-2.2.oden/cciss_functions.c 2005-10-24 11:16:00.000000000 +0200 @@ -67,7 +67,7 @@ { int result, outfile; IOCTL_Command_struct iocommand; - unsigned char *buffer; + unsigned char buffer[128]; iocommand.LUN_info.LunAddrBytes[0] = 0; iocommand.LUN_info.LunAddrBytes[1] = 0; @@ -98,7 +98,6 @@ iocommand.Request.CDB[10] = 0x0; /* reserved, leave 0 */ iocommand.Request.CDB[11] = 0x0; /* control ? */ - buffer = (unsigned char *) malloc (128); memset (buffer, 0x0, 128); iocommand.buf_size = 128; iocommand.buf = buffer; @@ -125,7 +124,7 @@ { int result, outfile; IOCTL_Command_struct iocommand; - unsigned char *buffer; + unsigned char buffer[512]; iocommand.LUN_info.LunAddrBytes[0] = 0; iocommand.LUN_info.LunAddrBytes[1] = 0; @@ -157,7 +156,6 @@ iocommand.Request.CDB[11] = 0x0; iocommand.Request.CDB[12] = 0x0; - buffer = (unsigned char *) malloc (512); memset (buffer, 0x0, 512); iocommand.buf_size = 512; iocommand.buf = buffer; diff -Naur cpqarrayd-2.2/configure.ac cpqarrayd-2.2.oden/configure.ac --- cpqarrayd-2.2/configure.ac 2005-07-28 16:33:41.000000000 +0200 +++ cpqarrayd-2.2.oden/configure.ac 2005-10-24 11:16:00.000000000 +0200 @@ -16,24 +16,32 @@ AC_HEADER_STDC AC_CHECK_HEADERS([arpa/inet.h fcntl.h netdb.h netinet/in.h stdlib.h string.h sys/ioctl.h sys/socket.h sys/time.h syslog.h unistd.h]) -dnl Check for pathed kernel sources with ida_ioctl.h -AC_MSG_CHECKING(for SmartArray header directories) -found_kernel_dir="" -for kernel_dir in /usr/src/linux /usr/src/linux-2.4 -do - if test -d $kernel_dir ; then - CFLAGS="$CFLAGS -I$kernel_dir/include -I$kernel_dir/drivers/block" - CPPFLAGS="$CPPFLAGS -I$kernel_dir/include -I$kernel_dir/drivers/block" - found_kernel_dir="$kernel_dir" +dnl Check for directory with kernel source... +AC_MSG_CHECKING(for directory with kernel source) +AC_ARG_WITH(kernel, + [ --with-kernel=dir give the directory with kernel sources] + [ [/usr/src/linux]], + kerneldir="$withval", + if test -d "/lib/modules/`uname -r`/build" -o -L "/lib/modules/`uname -r`/build"; then + kerneldir="/lib/modules/`uname -r`/build" + else + kerneldir="/usr/src/linux" fi -done - -if test "$found_kernel_dir" != "" ; then - AC_MSG_RESULT(found $found_kernel_dir ) +) +if test -d "$kerneldir" -o -L "$kerneldir"; then + AC_MSG_RESULT(found $kerneldir ) else - AC_MSG_ERROR(SmartArray header directory not found) + AC_MSG_ERROR(kernel source directory not found) fi +CONFIG_KERNEL_SOURCE="$kerneldir" +AC_SUBST(CONFIG_KERNEL_SOURCE) + +CPQARRAY_INC="-I$CONFIG_KERNEL_SOURCE/drivers/block -I$CONFIG_KERNEL_SOURCE/include" + +CFLAGS="$CFLAGS $CPQARRAY_INC" +CPPFLAGS="$CPPFLAGS $CPQARRAY_INC" + dnl Check for compile.h (2.6.x kernels only? AC_CHECK_HEADERS(linux/compiler.h) diff -Naur cpqarrayd-2.2/cpqarrayd.1 cpqarrayd-2.2.oden/cpqarrayd.1 --- cpqarrayd-2.2/cpqarrayd.1 2003-09-26 13:41:31.000000000 +0200 +++ cpqarrayd-2.2.oden/cpqarrayd.1 2005-10-24 11:16:00.000000000 +0200 @@ -26,6 +26,20 @@ \fB\-t\fR <host> Specify a host that should receive traps. You can specify this option at max ten times. The host is in the format host:port. +.SH "STATUS" +.LP +The following exit values are returned: +.LP +.TP +\fB0\fR +Successful startup. +.TP +\fB1\fR +An error occurred. +.TP +\fB2\fR +No supported controller detected. + .SH "BUGS" .LP .TP diff -Naur cpqarrayd-2.2/cpqarrayd.c cpqarrayd-2.2.oden/cpqarrayd.c --- cpqarrayd-2.2/cpqarrayd.c 2005-07-28 16:23:20.000000000 +0200 +++ cpqarrayd-2.2.oden/cpqarrayd.c 2005-10-24 11:16:00.000000000 +0200 @@ -49,6 +49,10 @@ #include <errno.h> +#ifndef HOST_NAME_MAX +#define HOST_NAME_MAX 255 +#endif + #include "cpqarrayd.h" #include "discover.h" #include "status.h" @@ -63,6 +67,14 @@ "/dev/ida/c5d0", "/dev/ida/c6d0", "/dev/ida/c7d0" + "/dev/ida/c0d0/disc", + "/dev/ida/c1d0/disc", + "/dev/ida/c2d0/disc", + "/dev/ida/c3d0/disc", + "/dev/ida/c4d0/disc", + "/dev/ida/c5d0/disc", + "/dev/ida/c6d0/disc", + "/dev/ida/c7d0/disc", }; const char *statusstr[] = { @@ -145,8 +157,7 @@ case 't': if (opts.nr_traphosts < 10) { /* strlen doesn't count terminating \0. Add one to fix that. */ - opts.traphosts[opts.nr_traphosts] = (char *)malloc(strlen(optarg)+1); - strncpy(opts.traphosts[opts.nr_traphosts], optarg, strlen(optarg)+1); + opts.traphosts[opts.nr_traphosts] = strdup(optarg); opts.nr_traphosts++; } else { @@ -169,7 +180,7 @@ printf(" None Found!\n\n"); fprintf(stderr, "You don't seem to have any controllers\n"); fprintf(stderr, "therefore it's rather senseless for me to run.\n\n"); - exit(1); + exit(2); } else { printf("Done\n"); @@ -181,8 +192,11 @@ } /* get ip of current machine for traps */ - buffer = (char *)malloc(50); - if (gethostname(buffer, 50) == 0) { + buffer = (char *)malloc(HOST_NAME_MAX + 1); + buffer[0] = '\0'; + if (gethostname(buffer, HOST_NAME_MAX + 1) == 0) { + /* It is unspecified whether a truncated hostname will be NUL-terminated. */ + buffer[HOST_NAME_MAX] = '\0'; myhost = gethostbyname(buffer); myip = ((unsigned char) myhost->h_addr_list[0][3] << 24) + ((unsigned char) myhost->h_addr_list[0][2] << 16) + @@ -191,6 +205,8 @@ } else { perror("gethostname"); + strncpy(buffer, "(none)", HOST_NAME_MAX); + buffer[HOST_NAME_MAX] = '\0'; } /* test for trap destinations */ @@ -242,11 +258,11 @@ /* END OF ADDITIONAL CODE */ } - buffer = (char *)malloc(1024); + /* buffer = (char *)malloc(1024); */ /* sprintf (buffer, "cpqarrayd[%d]\0", getpid); */ openlog ("cpqarrayd", LOG_CONS, LOG_USER); syslog(LOG_INFO, "Logging Enabled..."); - free(buffer); + /* free(buffer); */ while (keeprunning) { status_check(opts); diff -Naur cpqarrayd-2.2/discover.c cpqarrayd-2.2.oden/discover.c --- cpqarrayd-2.2/discover.c 2005-07-29 21:22:47.000000000 +0200 +++ cpqarrayd-2.2.oden/discover.c 2005-10-24 11:16:00.000000000 +0200 @@ -137,8 +137,11 @@ int cntr; - devicefd = open (devicefile, O_RDONLY); - /* no checks, did that before */ + /* check if device actually exists */ + if((devicefd = open (devicefile, O_RDONLY))==-1) + { + return 0; + } /* clear io */ memset (&io, 0, sizeof (io)); @@ -153,9 +156,7 @@ boardid2str (io.c.id_ctlr.board_id, buffer); - ctrls_found[ctrls_found_num].ctrl_devicename = (char *)malloc(strlen(buffer)+1); - strncpy (ctrls_found[ctrls_found_num].ctrl_devicename, - buffer, strlen(buffer)); + ctrls_found[ctrls_found_num].ctrl_devicename = strdup(buffer); ctrls_found[ctrls_found_num].ctrl_type = CTRLTYPE_IDA; @@ -172,8 +173,7 @@ if (opts.verbose) printf(" Found a %s (%d Logical drives)\n", buffer, ctrls_found[ctrls_found_num].num_logd_found); - ctrls_found[ctrls_found_num].devicefile = (char *)malloc(strlen(devicefile)); - strcpy(ctrls_found[ctrls_found_num].devicefile, devicefile); + ctrls_found[ctrls_found_num].devicefile = strdup(devicefile); close (devicefd); @@ -293,7 +293,11 @@ int listlength = 0; int result; - devicefd = open (devicefile, O_RDWR); + if((devicefd = open (devicefile, O_RDWR))==-1) + { + return 0; + } + result = cciss_get_logical_luns(devicefd, &logicalluns); if (result < 0) { if (opts.debug && (result == -1)) { @@ -307,12 +311,8 @@ listlength |= (0xff & (unsigned int)(logicalluns.LUNlist_len[2])) << 8; listlength |= (0xff & (unsigned int)(logicalluns.LUNlist_len[3])); - ctrls_found[ctrls_found_num].ctrl_devicename = (char *)malloc(17); - strncpy (ctrls_found[ctrls_found_num].ctrl_devicename, - "CCISS Controller", 16); - ctrls_found[ctrls_found_num].ctrl_devicename[16] = 0x0; - ctrls_found[ctrls_found_num].devicefile = (char *)malloc(strlen(devicefile)); - strcpy(ctrls_found[ctrls_found_num].devicefile, devicefile); + ctrls_found[ctrls_found_num].ctrl_devicename = strdup("CCISS Controller"); + ctrls_found[ctrls_found_num].devicefile = strdup(devicefile); ctrls_found[ctrls_found_num].ctrl_type = CTRLTYPE_CCISS; ctrls_found[ctrls_found_num].num_logd_found = listlength / 8; diff -Naur cpqarrayd-2.2/sendtrap.c cpqarrayd-2.2.oden/sendtrap.c --- cpqarrayd-2.2/sendtrap.c 2003-09-26 13:41:11.000000000 +0200 +++ cpqarrayd-2.2.oden/sendtrap.c 2005-10-24 11:16:00.000000000 +0200 @@ -52,7 +52,7 @@ #ifdef HAVE_SNMPTRAP struct snmp_session session, *ss; struct snmp_pdu *pdu; - char *statusmsg; + char statusmsg[16]; oid enterprise[] = {1,3,6,1,4,1,300}; oid statusoid[] = {1,3,6,1,4,1,300,1}; oid messageoid[] = {1,3,6,1,4,1,300,2}; @@ -65,11 +65,8 @@ snmp_sess_init( &session ); - /* strlen() doesn't count the terminating \0, so we do +1 in malloc. */ - session.peername = (char *)malloc(strlen(opts.traphosts[counter])+1); - strcpy (session.peername, opts.traphosts[counter]); - session.community = (char *)malloc(strlen(community)+1); - strcpy (session.community, community); + session.peername = strdup(opts.traphosts[counter]); + session.community = strdup(community); session.community_len = strlen(session.community); session.version = SNMP_VERSION_1; session.retries = 5; @@ -94,13 +91,11 @@ pdu->contextEngineID = 0x0; *pdu_in_addr_t = get_myaddr(); - statusmsg = (char *)malloc(12); sprintf(statusmsg, "%d", status); snmp_add_var (pdu, statusoid, sizeof(statusoid) / sizeof (oid), 'i', statusmsg); - messagebuf = (char *)malloc(strlen(message)+1); - strcpy(messagebuf,message); + messagebuf = strdup(message); snmp_add_var (pdu, messageoid, sizeof(messageoid) / sizeof (oid), 's', message); diff -Naur cpqarrayd-2.2/status.c cpqarrayd-2.2.oden/status.c --- cpqarrayd-2.2/status.c 2005-07-28 16:25:38.000000000 +0200 +++ cpqarrayd-2.2.oden/status.c 2005-10-24 11:16:00.000000000 +0200 @@ -54,7 +54,7 @@ ida_ioctl_t io, io2; int status, nr_blks, blks_tr, trap_stat; float pvalue; - char *statusmsg; + char statusmsg[1024]; int counter; @@ -130,7 +130,6 @@ ctrls_found[ctrl_cntr].log_disk[logd_cntr].status, status, pvalue); } - statusmsg = (char *)malloc(1024); sprintf(statusmsg, statusstr[status], ctrl_cntr, logd_cntr, pvalue); if (opts.debug) { printf("DEBUG: sending traps.\n"); @@ -160,7 +159,6 @@ ctrls_found[ctrl_cntr].log_disk[logd_cntr].pvalue, pvalue); } - statusmsg = (char *)malloc(1024); sprintf(statusmsg, statusstr[status], ctrl_cntr, logd_cntr, pvalue); if (opts.debug) { printf("DEBUG: sending traps.\n"); @@ -195,7 +193,7 @@ ida_ioctl_t io, io2; int status, nr_blks, blks_tr, trap_stat; float pvalue; - char *statusmsg; + char statusmsg[2048]; int counter; cciss_event_type event; @@ -208,7 +206,6 @@ } devicefd = open (ctrls_found[ctrl_cntr].devicefile, O_RDONLY); - statusmsg = (char *)malloc(2048); result = cciss_get_event(devicefd, 0, &event); while (!CompareEvent(event,0,0,0)) {