/* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright 2005 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ #pragma ident "%Z%%M% %I% %E% SMI" /* * zonecfg is a lex/yacc based command interpreter used to manage zone * configurations. The lexer (see zonecfg_lex.l) builds up tokens, which * the grammar (see zonecfg_grammar.y) builds up into commands, some of * which takes resources and/or properties as arguments. See the block * comments near the end of zonecfg_grammar.y for how the data structures * which keep track of these resources and properties are built up. * * The resource/property data structures are inserted into a command * structure (see zonecfg.h), which also keeps track of command names, * miscellaneous arguments, and function handlers. The grammar selects * the appropriate function handler, each of which takes a pointer to a * command structure as its sole argument, and invokes it. The grammar * itself is "entered" (a la the Matrix) by yyparse(), which is called * from read_input(), our main driving function. That in turn is called * by one of do_interactive(), cmd_file() or one_command_at_a_time(), each * of which is called from main() depending on how the program was invoked. * * The rest of this module consists of the various function handlers and * their helper functions. Some of these functions, particularly the * X_to_str() functions, which maps command, resource and property numbers * to strings, are used quite liberally, as doing so results in a better * program w/rt I18N, reducing the need for translation notes. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "zonecfg.h" #if !defined(TEXT_DOMAIN) /* should be defined by cc -D */ #define TEXT_DOMAIN "SYS_TEST" /* Use this only if it wasn't */ #endif #define PAGER "/usr/bin/more" struct help { uint_t cmd_num; char *cmd_name; uint_t flags; char *short_usage; }; extern int yyparse(void); extern int lex_lineno; #define MAX_LINE_LEN 1024 #define MAX_CMD_HIST 1024 /* * Each SHELP_ should be a simple string. */ #define SHELP_ADD "add \n\t(global scope)\n" \ "add \n\t(resource scope)" #define SHELP_CANCEL "cancel" #define SHELP_COMMIT "commit" #define SHELP_CREATE "create [-F] [ -b | -t