From 9172c95c77e8f1377b6c8becc84995e6e28a61eb Mon Sep 17 00:00:00 2001 From: "kay.sievers@vrfy.org" Date: Sat, 5 Feb 2005 02:36:54 +0100 Subject: [PATCH 1/1] [PATCH] chassis_id: clean compilation and fix bad function parameter passing Adding prototypes for functions resulted in an error, cause: table_find_disk(disk_snum, &chassis_num, &slot_num); is called but the function is defined as: int table_find_disk(char *serialnumber , int *host_num, int *chassis_num, int *slot_num) which can obviously not work correctly. Using popen() is not klibc compatible, so skip the compilation if a klibc compile is requested. --- extras/chassis_id/Makefile | 24 ++++++++++---- extras/chassis_id/chassis_id.c | 58 ++++++++++++++++------------------ extras/chassis_id/chassis_id.h | 6 ++-- extras/chassis_id/table.c | 13 +++++--- 4 files changed, 58 insertions(+), 43 deletions(-) diff --git a/extras/chassis_id/Makefile b/extras/chassis_id/Makefile index 141d23c7b..ae5c95961 100644 --- a/extras/chassis_id/Makefile +++ b/extras/chassis_id/Makefile @@ -20,7 +20,7 @@ # * Authors: Atul Sabharwal # * # * -CFLAGS = -g + TARGET = chassis_id exec_prefix = ${prefix} @@ -28,14 +28,24 @@ sbindir = ${exec_prefix}/sbin INSTALL = /usr/bin/install -c INSTALL_PROGRAM = ${INSTALL} INSTALL_DATA = ${INSTALL} -m 644 -all: chassis_id +all: chassis_id +ifneq ($(strip $(USE_KLIBC)),true) chassis_id: chassis_id.c table.c - gcc -o $(TARGET) $(CFLAGS) chassis_id.c table.c - -clean: - rm -rf core a.out $(TARGET) + $(QUIET) $(CC) -o $(TARGET) $(CFLAGS) chassis_id.c table.c install: all $(INSTALL_PROGRAM) $(TARGET) $(DESTDIR)$(sbindir)/$(TARGET) - +else +chassis_id: + @echo + @echo "!!! chassis_id is incompatible with klibc !!!" + @echo + @exit 0 + +install: all +endif + +clean: + rm -rf core a.out $(TARGET) + diff --git a/extras/chassis_id/chassis_id.c b/extras/chassis_id/chassis_id.c index 3fdfa9601..de8608792 100644 --- a/extras/chassis_id/chassis_id.c +++ b/extras/chassis_id/chassis_id.c @@ -18,7 +18,7 @@ * Boston, MA 021110-1307, USA. * * Authors: Atul Sabharwal - * + * */ #include @@ -29,7 +29,33 @@ //#define DEBUG 1 -int main(int argc, char **argv, char ** envp) +/* Run SCSI id to find serial number of the device */ +static int getserial_number(char * devpath, char * snumber) +{ + FILE *fp; + char vendor[255], model[255], cmd[255]; + int retval; + + sprintf(cmd, "/sbin/scsi_id -s %s -p 0x80", devpath); + + fp = popen(cmd, "r"); + + if (fp == NULL) + return -ERROR_BAD_SNUMBER; + + fscanf(fp, "%s %s %s", vendor, model, snumber); + #ifdef DEBUG + syslog(LOG_PID| LOG_DAEMON| LOG_ERR, "\n%s", snumber ); + #endif + + retval = pclose(fp); + if (retval == -1) + return -ERROR_BAD_SNUMBER; + else + return NO_ERROR; +} + +int main(int argc, char **argv, char **envp) { int chassis_num, slot_num, retval; char disk_snum[255], devpath[255]; @@ -63,31 +89,3 @@ int main(int argc, char **argv, char ** envp) } return 0; } - - -/* Run SCSI id to find serial number of the device */ -int getserial_number( char * devpath, char * snumber ) -{ - FILE *fp; - char vendor[255], model[255], cmd[255]; - int retval; - - sprintf(cmd, "/sbin/scsi_id -s %s -p 0x80", devpath); - - fp = popen(cmd, "r"); - - if (fp == NULL) - return -ERROR_BAD_SNUMBER; - - fscanf(fp, "%s %s %s", vendor, model, snumber); - #ifdef DEBUG - syslog(LOG_PID| LOG_DAEMON| LOG_ERR, "\n%s", snumber ); - #endif - - retval = pclose(fp); - if (retval == -1) - return -ERROR_BAD_SNUMBER; - else - return NO_ERROR; -} - diff --git a/extras/chassis_id/chassis_id.h b/extras/chassis_id/chassis_id.h index 9937e3dfa..1463bd22c 100644 --- a/extras/chassis_id/chassis_id.h +++ b/extras/chassis_id/chassis_id.h @@ -18,7 +18,7 @@ * Boston, MA 021110-1307, USA. * * Authors: Atul Sabharwal - * + * */ #ifndef _CHASSIS_ID_H @@ -35,6 +35,8 @@ #define ERROR_BAD_SCAN 8 #define NO_ERROR 0 -extern int table_init(); +extern int table_init(void); +extern int table_find_disk(const char *serialnumber , int *chassis_num, int *slot_num); +extern int table_select_disk(int diskindex); #endif diff --git a/extras/chassis_id/table.c b/extras/chassis_id/table.c index f4689ae24..8d14cd1b5 100644 --- a/extras/chassis_id/table.c +++ b/extras/chassis_id/table.c @@ -18,10 +18,13 @@ * Boston, MA 021110-1307, USA. * * Authors: Atul Sabharwal - * + * */ #include +#include + +#include "chassis_id.h" #define TABLE_SIZE 100 #define PROVISION_DB "/usr/local/bin/provision.tbl" @@ -40,7 +43,7 @@ int ptable_size; /* Initialize the provisioning table by reading the data from special file provision.tbl * Return error if something does not work appropriately. */ -int table_init() +int table_init(void) { FILE *fp; char ptr[255]; @@ -70,7 +73,7 @@ int table_init() /* return -1 when no disk found. Otherwise return index of disk */ -int table_find_disk( char * serialnumber , int * host_num, int * chassis_num, int *slot_num) +int table_find_disk(const char *serialnumber , int *chassis_num, int *slot_num) { int i; @@ -92,10 +95,12 @@ int table_find_disk( char * serialnumber , int * host_num, int * chassis_num, in * so that it can create descriptive GDN for it. So, for that we need to output * this data to stdout. */ -int table_select_disk( int diskindex ) +int table_select_disk(int diskindex) { printf("%d ", ptable[diskindex].chassis_num); printf("%d ", ptable[diskindex].slot_num); printf("%s ", ptable[diskindex].name); + + return 0; } -- 2.30.2