chiark / gitweb /
Makefile: cleanup install targets
[elogind.git] / extras / chassis_id / chassis_id.c
index 857707eac7efa5e3b2a5b4fd7e595b893595fad5..de86087921e9509487e812777181d1fdfc28255d 100644 (file)
@@ -1,15 +1,24 @@
-/* -*-c-*-: 
- **
- ** (C) 2003 Intel Corporation
- **          Atul Sabharwal <atul.sabharwal@intel.com>
- **
- ** Distributed under the terms of the GNU Public License, v2.0 or
- ** later.
- **
- ** Many parts heavily based on test-skeleton.c, by Ulrich Drepper;
- ** with his permission, they have been re-licensed GPL, and his
- ** copyright still applies on them
- **
+/* 
+ * chassis_id.c
+ *
+ * Copyright (C) 2004 Intel Corporation.  All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License v 2.0 as published by the Free Software Foundation; 
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * 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)
 {
-       int chassis_num, slot_num, retval, host_num;
-       char disk_snum[255], devpath[255];
-       char *ptr;
-       int disk_index;
+       FILE *fp;
+       char vendor[255], model[255], cmd[255];
+       int retval;
 
-       syslog( LOG_PID| LOG_DAEMON| LOG_ERR, "\n%s", "starting chassis_id" );
+       sprintf(cmd, "/sbin/scsi_id -s %s -p 0x80", devpath);
 
-#if 0
-       ptr = getenv("CHASSIS");
-       if (ptr == NULL)
-               return -ERROR_NO_CHASSIS;
+       fp = popen(cmd, "r");
 
-       sscanf(ptr, "%d", &chassis_num);
+       if (fp == NULL)
+               return -ERROR_BAD_SNUMBER;
+
+       fscanf(fp, "%s %s %s", vendor, model, snumber);
        #ifdef DEBUG
-       syslog(LOG_PID| LOG_DAEMON| LOG_ERR, "Chassis %d", chassis_num);
+       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;
+}
 
-       ptr = getenv("SLOT");
-       if (ptr== NULL)
-               return -ERROR_NO_SLOT;
+int main(int argc, char **argv, char **envp)
+{
+       int chassis_num, slot_num, retval;
+       char disk_snum[255], devpath[255];
+       char *ptr;
+       int disk_index;
+
+       syslog( LOG_PID| LOG_DAEMON| LOG_ERR, "\n%s", "starting chassis_id" );
 
-       sscanf(ptr, "%d", &slot_num);
-       #ifdef DEBUG
-       syslog( LOG_PID|LOG_DAEMON| LOG_ERR, "Slot %d", slot_num);
-       #endif
-#endif
        ptr = getenv("DEVPATH");
        if (ptr == NULL)
                return -ERROR_NO_DEVPATH;
@@ -65,7 +80,7 @@ int main(int argc, char **argv, char ** envp)
        getserial_number(devpath, disk_snum);
 
        /* Now we open the provisioning table t find actual entry for the serial number*/
-       disk_index =  table_find_disk(disk_snum, &host_num, &chassis_num, &slot_num);
+       disk_index =  table_find_disk(disk_snum, &chassis_num, &slot_num);
        if ( disk_index == -1 ) {
                // typical provisioning error
                return -ERROR_NO_DISK;
@@ -74,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;
-}
-