nfs-ganesha 1.4
Defines | Functions | Variables

shell.c File Reference

Internal routines for the shell. More...

#include "shell.h"
#include "shell_utils.h"
#include "shell_vars.h"
#include "log.h"
#include "commands.h"
#include "cmd_tools.h"
#include "abstract_mem.h"
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include <pthread.h>
#include <sys/time.h>

Go to the source code of this file.

Defines

#define MAX_OUTPUT_LEN   (1024*1024)
#define TRACEBUFFSIZE   1024
#define PROMPTSIZE   64
#define P_shell(_mutex_)   pthread_mutex_lock( &_mutex_ )
#define V_shell(_mutex_)   pthread_mutex_unlock( &_mutex_ )

Functions

int shell_BarrierInit (int nb_threads)
int shell_Init (int verbose, char *input_file, char *prompt, int shell_index)
int shell_Launch ()
int shell_ParseLine (char *in_out_line, char **out_arglist, int *p_argcount)
int shell_SolveArgs (int argc, char **in_out_argv, int *out_allocated)
void shell_CleanArgs (int argc, char **in_out_argv, int *in_allocated)
int shell_Execute (int argc, char **argv, FILE *output)
void shell_PrintError (shell_state_t *context, char *error_msg)
void shell_PrintTrace (shell_state_t *context, char *msg)
int shell_SetLayer (shell_state_t *context, char *layer_name)
layer_def_tshell_GetLayer (shell_state_t *context)
int shell_SetStatus (shell_state_t *context, int returned_status)
int shell_GetStatus (shell_state_t *context)
int shell_SetVerbose (shell_state_t *context, char *str_verbose)
int shell_GetVerbose (shell_state_t *context)
int shell_SetDbgLvl (shell_state_t *context, char *str_debug_level)
int shell_GetDbgLvl (shell_state_t *context)
int shell_SetInput (shell_state_t *context, char *file_name)
FILE * shell_GetInputStream (shell_state_t *context)
int shell_SetPrompt (shell_state_t *context, char *str_prompt)
char * shell_GetPrompt (shell_state_t *context)
int shell_SetShellId (shell_state_t *context, int shell_index)
int shell_SetLine (shell_state_t *context, int lineno)
int shell_GetLine (shell_state_t *context)
int shellcmd_help (int argc, char **argv, FILE *output)
int shellcmd_if (int argc, char **argv, FILE *output)
int shellcmd_interactive (int argc, char **argv, FILE *output)
int shellcmd_set (int argc, char **argv, FILE *output)
int shellcmd_unset (int argc, char **argv, FILE *output)
int shellcmd_print (int argc, char **argv, FILE *output)
int shellcmd_varlist (int argc, char **argv, FILE *output)
int shellcmd_time (int argc, char **argv, FILE *output)
int shellcmd_quit (int argc, char **argv, FILE *output)
int shellcmd_barrier (int argc, char **argv, FILE *output)

Variables

layer_def_t layer_list []
char * shell_special_vars []
command_def_t shell_utils []

Detailed Description

Internal routines for the shell.

Author:
Author:
leibovic
Date:
Date:
2006/02/24 08:33:44
Version:
Revision:
1.20
Log:
shell.c,v

Revision 1.20 2006/02/24 08:33:44 leibovic shellid is read only.

Revision 1.19 2006/02/23 07:42:53 leibovic Adding -n option to shell.

Revision 1.18 2006/02/08 12:50:00 leibovic changing NIV_EVNMT to NIV_EVENT.

Revision 1.17 2006/01/17 14:56:22 leibovic Adaptation de HPSS 6.2.

Revision 1.15 2005/09/27 09:30:16 leibovic Removing non-thread safe trace buffer.

Revision 1.14 2005/09/27 08:15:13 leibovic Adding traces and changhing readexport prototype.

Revision 1.13 2005/08/12 12:15:33 leibovic Erreur d'init.

Revision 1.12 2005/08/12 11:21:27 leibovic Now, set cat concatenate strings.

Revision 1.11 2005/08/05 07:59:21 leibovic Better help printing.

Revision 1.10 2005/07/29 13:34:28 leibovic Changing _FULL_DEBUG to _DEBUG_SHELL

Revision 1.9 2005/07/26 12:54:47 leibovic Multi-thread shell with synchronisation routines.

Revision 1.8 2005/07/25 12:50:45 leibovic Adding thr_create and thr_join commands.

Revision 1.7 2005/05/11 15:53:37 leibovic Adding time function.

Revision 1.6 2005/05/11 07:25:58 leibovic Escaped char support.

Revision 1.5 2005/05/10 14:02:27 leibovic Fixed bug in log management.

Revision 1.4 2005/05/10 11:38:07 leibovic Adding log initialization.

Revision 1.3 2005/05/10 11:07:21 leibovic Adapting to ganeshell v2.

Revision 1.2 2005/05/09 14:54:59 leibovic Adding if.

Revision 1.1 2005/05/09 12:23:55 leibovic Version 2 of ganeshell.

Definition in file shell.c.


Define Documentation

#define MAX_OUTPUT_LEN   (1024*1024)

Definition at line 124 of file shell.c.

#define P_shell (   _mutex_)    pthread_mutex_lock( &_mutex_ )

Definition at line 181 of file shell.c.

#define PROMPTSIZE   64

Definition at line 128 of file shell.c.

#define TRACEBUFFSIZE   1024

Definition at line 126 of file shell.c.

#define V_shell (   _mutex_)    pthread_mutex_unlock( &_mutex_ )

Definition at line 182 of file shell.c.


Function Documentation

int shell_BarrierInit ( int  nb_threads)

Initialize the barrier for shell synchronization routines. The number of threads to wait for is given as parameter.

Definition at line 202 of file shell.c.

void shell_CleanArgs ( int  argc,
char **  in_out_argv,
int *  in_allocated 
)

shell_CleanArgs: Free allocated arguments.

Parameters:
argcThe number of command line tokens.
in_out_argvThe list of command line tokens (modified).
in_allocatedIndicates which tokens must be freed.

Definition at line 1045 of file shell.c.

int shell_Execute ( int  argc,
char **  argv,
FILE *  output 
)

shell_Execute: Commands dispatcher.

Parameters:
argcThe number of arguments of this command.
argvThe arguments for this command.
outputThe output stream of this command.
Returns:
The returned status of this command.

Definition at line 1076 of file shell.c.

int shell_GetDbgLvl ( shell_state_t context)

shell_GetDbgLvl Get the special variable $DEBUG_LEVEL and $DBG_LVL (internal use).

Definition at line 1478 of file shell.c.

FILE* shell_GetInputStream ( shell_state_t context)

shell_GetInputStream Get the input stream for reading commands (internal use).

Definition at line 1600 of file shell.c.

layer_def_t* shell_GetLayer ( shell_state_t context)

shell_GetLayer: Retrieves the current active layer (internal use).

Definition at line 1302 of file shell.c.

int shell_GetLine ( shell_state_t context)

shell_GetLine Get the special variable $LINE

Definition at line 1691 of file shell.c.

char* shell_GetPrompt ( shell_state_t context)

shell_GetPrompt Get the special variable $PROMPT

Definition at line 1631 of file shell.c.

int shell_GetStatus ( shell_state_t context)

shell_GetStatus Get the special variables $? or $STATUS (internal use).

Definition at line 1349 of file shell.c.

int shell_GetVerbose ( shell_state_t context)

shell_GetVerbose Get the special variable $VERBOSE (internal use).

Definition at line 1414 of file shell.c.

int shell_Init ( int  verbose,
char *  input_file,
char *  prompt,
int  shell_index 
)

Initialize the shell. The command line for the shell is given as parameter.

Parameters:
input_filethe file to read from (NULL if stdin).

Definition at line 344 of file shell.c.

int shell_Launch ( )

Run the interpreter.

Definition at line 486 of file shell.c.

int shell_ParseLine ( char *  in_out_line,
char **  out_arglist,
int *  p_argcount 
)

shell_ParseLine: Extract an arglist from a command line.

Parameters:
in_out_lineThe command line (modified).
out_arglistThe list of command line tokens.
p_argcountThe number of command line tokens.
Returns:
0 if no errors.

Definition at line 664 of file shell.c.

void shell_PrintError ( shell_state_t context,
char *  error_msg 
)

shell_PrintError: Prints an error.

Definition at line 1207 of file shell.c.

void shell_PrintTrace ( shell_state_t context,
char *  msg 
)

shell_PrintTrace: Prints a verbose trace.

Definition at line 1221 of file shell.c.

int shell_SetDbgLvl ( shell_state_t context,
char *  str_debug_level 
)

shell_SetDbgLvl Set the special variables $DEBUG_LEVEL and $DBG_LVL

Definition at line 1423 of file shell.c.

int shell_SetInput ( shell_state_t context,
char *  file_name 
)

shell_SetInput Set the input for reading commands and set the value of $INPUT and $INTERACTIVE.

Parameters:
file_name,:a script file or NULL for reading from stdin.

Definition at line 1491 of file shell.c.

int shell_SetLayer ( shell_state_t context,
char *  layer_name 
)

shell_SetLayer: Set the current active layer.

Returns:
0 if OK. else, an error code.

Definition at line 1246 of file shell.c.

int shell_SetLine ( shell_state_t context,
int  lineno 
)

shell_SetLine Set the special variable $LINE

Definition at line 1664 of file shell.c.

int shell_SetPrompt ( shell_state_t context,
char *  str_prompt 
)

shell_SetPrompt Set the special variable $PROMPT

Definition at line 1612 of file shell.c.

int shell_SetShellId ( shell_state_t context,
int  shell_index 
)

shell_SetShellId Set the special variable $SHELLID

Definition at line 1640 of file shell.c.

int shell_SetStatus ( shell_state_t context,
int  returned_status 
)

shell_SetStatus Set the special variables $? and $STATUS.

Definition at line 1313 of file shell.c.

int shell_SetVerbose ( shell_state_t context,
char *  str_verbose 
)

shell_SetVerbose Set the special variable $VERBOSE.

Definition at line 1358 of file shell.c.

int shell_SolveArgs ( int  argc,
char **  in_out_argv,
int *  out_allocated 
)

shell_SolveArgs: Interprets arguments if they are vars or commands.

Parameters:
argcThe number of command line tokens.
in_out_argvThe list of command line tokens (modified).
out_allocatedIndicates which tokens must be freed.
Returns:
0 if no errors.

Definition at line 768 of file shell.c.

int shellcmd_barrier ( int  argc,
char **  argv,
FILE *  output 
)

Definition at line 2166 of file shell.c.

int shellcmd_help ( int  argc,
char **  argv,
FILE *  output 
)

Definition at line 1700 of file shell.c.

int shellcmd_if ( int  argc,
char **  argv,
FILE *  output 
)

Definition at line 1771 of file shell.c.

int shellcmd_interactive ( int  argc,
char **  argv,
FILE *  output 
)

Definition at line 1861 of file shell.c.

int shellcmd_print ( int  argc,
char **  argv,
FILE *  output 
)

Definition at line 2052 of file shell.c.

int shellcmd_quit ( int  argc,
char **  argv,
FILE *  output 
)

Definition at line 2141 of file shell.c.

int shellcmd_set ( int  argc,
char **  argv,
FILE *  output 
)

Definition at line 1887 of file shell.c.

int shellcmd_time ( int  argc,
char **  argv,
FILE *  output 
)

Definition at line 2096 of file shell.c.

int shellcmd_unset ( int  argc,
char **  argv,
FILE *  output 
)

Definition at line 1994 of file shell.c.

int shellcmd_varlist ( int  argc,
char **  argv,
FILE *  output 
)

Definition at line 2070 of file shell.c.


Variable Documentation

Initial value:
 {
  {"FSAL", commands_FSAL, "File system abstraction layer", fsal_layer_SetLogLevel}
  ,
  {"Cache_inode", commands_Cache_inode, "Cache inode layer", Cache_inode_layer_SetLogLevel}
  ,
  {"NFS", commands_NFS,
   "NFSv2, NFSv3, MNTv1, MNTv3 protocols (direct calls, not through RPCs)",
   nfs_layer_SetLogLevel}
  ,
  {"NFS_remote", commands_NFS_remote,
   "NFSv2, NFSv3, MNTv1, MNTv3 protocols (calls through RPCs)",
   nfs_remote_layer_SetLogLevel}
  ,
  {NULL, NULL, NULL, NULL}      
}

Layer list.

Definition at line 130 of file shell.c.

Initial value:
 {
  "INPUT",                      
  "INTERACTIVE",                
  "LAYER",                      
  "STATUS",                     
  "?",                          
  "VERBOSE",                    
  "DEBUG_LEVEL",                
  "DBG_LVL",                    
  "PROMPT",                     
  "LINE",                       

  
  NULL
}

List of the shell special variables

Definition at line 146 of file shell.c.

Initial value:
 {
  {"chomp", util_chomp, "removes final newline character"},
  {"cmp", util_cmp, "compares two expressions"},
  {"diff", util_diff, "lists differences between two expressions"},
  {"eq", util_cmp, "test if two expressions are equal"},
  {"meminfo", util_meminfo, "prints information about memory use"},
  {"ne", util_cmp, "test if two expressions are different"},
  {"shell", util_shell, "executes a real shell command"},
  {"sleep", util_sleep, "suspends script execution for some time"},
  {"timer", util_timer, "timer management command"},
  {"wc", util_wc, "counts the number of char/words/lines in a string"},

  {NULL, NULL, NULL}            
}

Definition at line 162 of file shell.c.