1 #include <iostream> 2 #include <memory> 3 #include "argument.hpp" 4 #include "writefrudata.hpp" 5 6 static void exit_with_error(const char* err, char** argv) 7 { 8 ArgumentParser::usage(argv); 9 std::cerr << std::endl; 10 std::cerr << "ERROR: " << err << std::endl; 11 exit(-1); 12 } 13 14 //-------------------------------------------------------------------------- 15 // This gets called by udev monitor soon after seeing hog plugs for EEPROMS. 16 //-------------------------------------------------------------------------- 17 int main(int argc, char **argv) 18 { 19 int rc = 0; 20 uint8_t fruid = 0; 21 22 // Handle to per process system bus 23 sd_bus *bus_type = NULL; 24 25 // Read the arguments. 26 auto cli_options = std::make_unique<ArgumentParser>(argc, argv); 27 28 // Parse out each argument. 29 auto eeprom_file = (*cli_options)["eeprom"]; 30 if (eeprom_file == ArgumentParser::empty_string) 31 { 32 // User has not passed in the appropriate argument value 33 exit_with_error("eeprom data not found.", argv); 34 } 35 36 auto fruid_str = (*cli_options)["fruid"]; 37 if (fruid_str == ArgumentParser::empty_string) 38 { 39 // User has not passed in the appropriate argument value 40 exit_with_error("fruid data not found.", argv); 41 } 42 43 // Extract the fruid 44 fruid = strtol(fruid_str.c_str(), NULL, 16); 45 if(fruid == 0) 46 { 47 // User has not passed in the appropriate argument value 48 exit_with_error("Invalid fruid.", argv); 49 } 50 51 // Finished getting options out, so release the parser. 52 cli_options.release(); 53 54 // Get a handle to System Bus 55 rc = sd_bus_open_system(&bus_type); 56 if (rc < 0) 57 { 58 fprintf(stderr, "Failed to connect to system bus: %s\n",strerror(-rc)); 59 } 60 else 61 { 62 // Now that we have the file that contains the eeprom data, go read it and 63 // update the Inventory DB. 64 bool bmc_fru = true; 65 rc = ipmi_validate_fru_area(fruid, eeprom_file.c_str(), bus_type, bmc_fru); 66 } 67 68 // Cleanup 69 sd_bus_unref(bus_type); 70 71 return (rc < 0 ? EXIT_FAILURE : EXIT_SUCCESS); 72 } 73