config.c (2322B)
1 /* 2 * 3 * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file. 4 * 5 * Copyright 2007-2019 Broadcom Inc. All rights reserved. 6 * 7 * System configuration command. 8 */ 9 10 #include <appl/diag/shell.h> 11 #include <appl/diag/system.h> 12 #include <kconfig.h> 13 14 char sh_config_usage[] = 15 "Parameters: show | refresh | save | [add] [<var>=<value>] | delete <var>\n\t" 16 "If no parameters are given, displays the current config vars.\n\t" 17 " show display current config vars\n\t" 18 " <var>=<value> change the value of a config var\n\t" 19 " add <var>=<value> create a new config var\n\t" 20 " delete <var> deletes a config var\n\t" 21 " = prompt for new value for each config var\n\t" 22 "NOTE: changes are not retained permanently unless saved\n"; 23 24 cmd_result_t 25 sh_config(int u, args_t *a) 26 /* 27 * Function: sh_config 28 * Purpose: Configure switch management information. 29 * Parameters: 30 * Returns: 31 */ 32 { 33 int rv, add; 34 char *name, *value, *c = ARG_CUR(a); 35 36 rv = CMD_OK; 37 38 if (c == NULL || !sal_strcasecmp(c, "show")) { 39 name = NULL; 40 while (kconfig_get_next(&name, &value) >= 0) { 41 sal_printf("\t%s=%s\n", name, value); 42 } 43 if (NULL != c) { 44 ARG_NEXT(a); 45 } 46 return CMD_OK; 47 } 48 49 if (!sal_strcasecmp(c, "delete")) { 50 ARG_NEXT(a); 51 while ((c = ARG_GET(a)) != NULL) { 52 if (kconfig_set(c, 0) != 0) { 53 printk("%s: Variable not found: %s\n", ARG_CMD(a), c); 54 rv = CMD_FAIL; 55 } 56 } 57 return rv; 58 } 59 60 if (!sal_strcasecmp(c, "add")) { 61 ARG_NEXT(a); 62 add = 1; 63 } else { 64 add = 0; 65 } 66 67 if (ARG_CNT(a)) { 68 while ((c = ARG_GET(a)) != NULL) { 69 char *s; 70 s = strchr(c, '='); 71 if (s == NULL) { 72 printk("%s: Invalid assignment: %s\n", ARG_CMD(a), c); 73 rv = CMD_FAIL; 74 } else { 75 *s++ = 0; 76 if (!add && kconfig_get(c) == NULL) { 77 printk("%s: Must use 'add' to create new variable: %s\n", 78 ARG_CMD(a), c); 79 rv = CMD_FAIL; 80 } else { 81 if (kconfig_set(c, s) < 0) { 82 rv = CMD_FAIL; 83 } 84 } 85 } 86 } 87 } 88 89 return rv; 90 }