chiark / gitweb /
[PATCH] chassis_id: clean compilation and fix bad function parameter passing
authorkay.sievers@vrfy.org <kay.sievers@vrfy.org>
Sat, 5 Feb 2005 01:36:54 +0000 (02:36 +0100)
committerGreg KH <gregkh@suse.de>
Wed, 27 Apr 2005 06:24:19 +0000 (23:24 -0700)
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
extras/chassis_id/chassis_id.c
extras/chassis_id/chassis_id.h
extras/chassis_id/table.c

index 141d23c7b817c42aa38d40e5f643d55ab48ec9c0..ae5c95961c5aa6870a0c2c0168fa12cd56d765d8 100644 (file)
@@ -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)
+
index 3fdfa96018e9af4e31c33a81adfaed29853192b9..de86087921e9509487e812777181d1fdfc28255d 100644 (file)
@@ -18,7 +18,7 @@
  * Boston, MA 021110-1307, USA.
  *
  * Authors: Atul Sabharwal
- *          
+ *
  */
 
 #include <stdio.h>
 
 //#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;
-}
-
index 9937e3dfac7e284e653a8886323ecc4e000e13fc..1463bd22c7d52ce13d23f9762c45e0fa571b5616 100644 (file)
@@ -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
index f4689ae24361980af0c7f30d2db4b3939026d8c0..8d14cd1b592a6bbbd270673887ee0b82ebb6d195 100644 (file)
  * Boston, MA 021110-1307, USA.
  *
  * Authors: Atul Sabharwal
- *          
+ *
  */
 
 #include <stdio.h>
+#include <string.h>
+
+#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;
 }