blob: b9c6f69cdce1946af23eb68319a259ec26925b24 [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.
64 rc = ipmi_validate_fru_area(fruid, eeprom_file.c_str(), bus_type);
65 }
66
67 // Cleanup
68 sd_bus_unref(bus_type);
69
70 return (rc < 0 ? EXIT_FAILURE : EXIT_SUCCESS);
71}