XrdFrmAdminMain.cc

Go to the documentation of this file.
00001 /******************************************************************************/
00002 /*                                                                            */
00003 /*                    X r d F r m A d m i n M a i n . c c                     */
00004 /*                                                                            */
00005 /* (c) 2009 by the Board of Trustees of the Leland Stanford, Jr., University  */
00006 /*                            All Rights Reserved                             */
00007 /*   Produced by Andrew Hanushevsky for Stanford University under contract    */
00008 /*              DE-AC02-76-SFO0515 with the Department of Energy              */
00009 /******************************************************************************/
00010 
00011 //           $Id: XrdFrmAdminMain.cc 34000 2010-06-21 06:49:56Z ganis $
00012 
00013 const char *XrdFrmAdminMainCVSID = "$Id: XrdFrmAdminMain.cc 34000 2010-06-21 06:49:56Z ganis $";
00014 
00015 /* This is the "main" part of the frm_PreStage command. Syntax is:
00016 */
00017 static const char *XrdFrmOpts  = "c:dhn:v";
00018 static const char *XrdFrmUsage =
00019 
00020   " [-c <cfgfile>] [-d] [-h] [-n name] [-v] [help | cmd & opts]\n";
00021 /*
00022 Where:
00023 
00024    -c     The configuration file. The default is '/opt/xrootd/etc/xrootd.cf'
00025 
00026    -d     Turns on debugging mode.
00027 
00028    -h     Print helpful information (other options ignored).
00029 
00030    -n     The instance name.
00031 
00032    cmd    Specific commands, see the help information.
00033 
00034    opts   Options specific to the command.
00035 */
00036 
00037 /******************************************************************************/
00038 /*                         i n c l u d e   f i l e s                          */
00039 /******************************************************************************/
00040   
00041 #include <unistd.h>
00042 #include <ctype.h>
00043 #include <errno.h>
00044 #include <signal.h>
00045 #include <stdlib.h>
00046 #include <string.h>
00047 #include <strings.h>
00048 #include <stdio.h>
00049 #include <sys/param.h>
00050 
00051 #ifdef HAVE_READLINE
00052 #include <readline/readline.h>
00053 #include <readline/history.h>
00054 #endif
00055 
00056 #include "XrdFrm/XrdFrmAdmin.hh"
00057 #include "XrdFrm/XrdFrmConfig.hh"
00058 #include "XrdFrm/XrdFrmTrace.hh"
00059 #include "XrdNet/XrdNetOpts.hh"
00060 #include "XrdNet/XrdNetSocket.hh"
00061 #include "XrdOuc/XrdOucTokenizer.hh"
00062 #include "XrdSys/XrdSysError.hh"
00063 #include "XrdSys/XrdSysHeaders.hh"
00064 #include "XrdSys/XrdSysLogger.hh"
00065 
00066 using namespace XrdFrm;
00067   
00068 /******************************************************************************/
00069 /*                      G l o b a l   V a r i a b l e s                       */
00070 /******************************************************************************/
00071 
00072        XrdFrmConfig       XrdFrm::Config(XrdFrmConfig::ssAdmin,
00073                                          XrdFrmOpts, XrdFrmUsage);
00074 
00075        XrdFrmAdmin        XrdFrm::Admin;
00076 
00077 // The following is needed to resolve symbols for objects included from xrootd
00078 //
00079        XrdOucTrace       *XrdXrootdTrace;
00080        XrdSysError        XrdLog(0, "");
00081        XrdOucTrace        XrdTrace(&Say);
00082 
00083 /******************************************************************************/
00084 /*                              r e a d l i n e                               */
00085 /******************************************************************************/
00086 
00087 #ifndef HAVE_READLINE
00088 
00089 // replacement function for GNU readline
00090 //
00091 char *readline(const char *prompt)
00092 {
00093    char buff[4096];
00094   
00095    cout << prompt;
00096    if (!fgets(buff, 4096, stdin) || *buff == '\n' || !strlen(buff)) return 0;
00097    return strdup(buff);
00098 }
00099 
00100 void    add_history(const char *cLine) {}
00101 void stifle_history(int hnum) {}
00102 #endif
00103 
00104 /******************************************************************************/
00105 /*                                  m a i n                                   */
00106 /******************************************************************************/
00107   
00108 int main(int argc, char *argv[])
00109 {
00110    XrdSysLogger Logger;
00111    sigset_t myset;
00112    XrdOucTokenizer Request(0);
00113    char *cLine = 0, *pLine = 0, *Cmd = 0, *CmdArgs;
00114    int IMode;
00115 
00116 // Turn off sigpipe and host a variety of others before we start any threads
00117 //
00118    signal(SIGPIPE, SIG_IGN);  // Solaris optimization
00119    sigemptyset(&myset);
00120    sigaddset(&myset, SIGPIPE);
00121    sigaddset(&myset, SIGCHLD);
00122    pthread_sigmask(SIG_BLOCK, &myset, NULL);
00123 
00124 // Perform configuration
00125 //
00126    Say.logger(&Logger);
00127    XrdLog.logger(&Logger);
00128    if (!Config.Configure(argc, argv, 0)) exit(4);
00129 
00130 // Fill out the dummy symbol to avoid crashes
00131 //
00132    XrdXrootdTrace = new XrdOucTrace(&Say);
00133 
00134 // We either have a command line or need to enter interactive mode
00135 //
00136    if (Config.nextArg >= argc) IMode = 1;
00137       else {Cmd = argv[Config.nextArg++];
00138             Admin.setArgs(argc-Config.nextArg, &argv[Config.nextArg]);
00139             IMode = 0;
00140            }
00141 
00142 // Set readline history list (keep only 256 lines, max)
00143 //
00144    if (IMode) stifle_history(256);
00145 
00146 // Process the request(s)
00147 //
00148    do {if (IMode)
00149           {if (!(cLine = readline("frm_admin> "))) Admin.Quit();
00150            if (!pLine || strcmp(pLine, cLine))
00151               {add_history(cLine);
00152                if (pLine) free(pLine);
00153                pLine = strdup(cLine);
00154               }
00155            Request.Attach(cLine);
00156            if (!Request.GetLine() || !(Cmd=Request.GetToken(&CmdArgs)))
00157               Admin.Quit();
00158            Admin.setArgs(CmdArgs);
00159           }
00160        Admin.xeqArgs(Cmd);
00161        if (cLine) free(cLine);
00162       } while(IMode);
00163 
00164 // All done
00165 //
00166    Admin.Quit();
00167 }

Generated on Tue Jul 5 14:46:35 2011 for ROOT_528-00b_version by  doxygen 1.5.1