You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

nvo_cmd.c 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #include <stdint.h>
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include <string.h>
  5. #include <errno.h>
  6. #include <getopt.h>
  7. #include <gpxe/settings.h>
  8. #include <gpxe/command.h>
  9. static int show_exec ( int argc, char **argv ) {
  10. char buf[256];
  11. int rc;
  12. if ( argc != 2 ) {
  13. printf ( "Syntax: %s <identifier>\n", argv[0] );
  14. return 1;
  15. }
  16. if ( ( rc = fetchf_named_setting ( argv[1], buf,
  17. sizeof ( buf ) ) ) < 0 ){
  18. printf ( "Could not find \"%s\": %s\n",
  19. argv[1], strerror ( rc ) );
  20. return 1;
  21. }
  22. printf ( "%s = %s\n", argv[1], buf );
  23. return 0;
  24. }
  25. static int set_exec ( int argc, char **argv ) {
  26. int rc;
  27. if ( argc != 3 ) {
  28. printf ( "Syntax: %s <identifier> <value>\n", argv[0] );
  29. return 1;
  30. }
  31. if ( ( rc = storef_named_setting ( argv[1], argv[2] ) ) != 0 ) {
  32. printf ( "Could not set \"%s\"=\"%s\": %s\n",
  33. argv[1], argv[2], strerror ( rc ) );
  34. return 1;
  35. }
  36. return 0;
  37. }
  38. static int clear_exec ( int argc, char **argv ) {
  39. int rc;
  40. if ( argc != 2 ) {
  41. printf ( "Syntax: %s <identifier>\n", argv[0] );
  42. return 1;
  43. }
  44. if ( ( rc = delete_named_setting ( argv[1] ) ) != 0 ) {
  45. printf ( "Could not clear \"%s\": %s\n",
  46. argv[1], strerror ( rc ) );
  47. return 1;
  48. }
  49. return 0;
  50. }
  51. struct command nvo_commands[] __command = {
  52. {
  53. .name = "show",
  54. .exec = show_exec,
  55. },
  56. {
  57. .name = "set",
  58. .exec = set_exec,
  59. },
  60. {
  61. .name = "clear",
  62. .exec = clear_exec,
  63. },
  64. };