blob: 561aba45bfc03695d70db837df9b6afa37b97d30 [file] [log] [blame]
vishwa13555bd2015-11-10 12:10:38 -06001#include <iostream>
2#include <memory>
3#include "argument.H"
4#include "writefrudata.H"
5
6static 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//--------------------------------------------------------------------------
17int 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 (eeprom_file == 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.
vishwaf3ca3522015-12-02 10:35:13 -060064 bool set_present = true;
65 rc = ipmi_validate_fru_area(fruid, eeprom_file.c_str(), bus_type, set_present);
vishwa13555bd2015-11-10 12:10:38 -060066 }
67
68 // Cleanup
69 sd_bus_unref(bus_type);
70
71 return (rc < 0 ? EXIT_FAILURE : EXIT_SUCCESS);
72}