XRootD
XrdFrmAdminMain.cc
Go to the documentation of this file.
1 /******************************************************************************/
2 /* */
3 /* X r d F r m A d m i n M a i n . c c */
4 /* */
5 /* (c) 2009 by the Board of Trustees of the Leland Stanford, Jr., University */
6 /* All Rights Reserved */
7 /* Produced by Andrew Hanushevsky for Stanford University under contract */
8 /* DE-AC02-76-SFO0515 with the Department of Energy */
9 /* */
10 /* This file is part of the XRootD software suite. */
11 /* */
12 /* XRootD is free software: you can redistribute it and/or modify it under */
13 /* the terms of the GNU Lesser General Public License as published by the */
14 /* Free Software Foundation, either version 3 of the License, or (at your */
15 /* option) any later version. */
16 /* */
17 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */
18 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
19 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
20 /* License for more details. */
21 /* */
22 /* You should have received a copy of the GNU Lesser General Public License */
23 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
24 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
25 /* */
26 /* The copyright holder's institutional names and contributor's names may not */
27 /* be used to endorse or promote products derived from this software without */
28 /* specific prior written permission of the institution or contributor. */
29 /******************************************************************************/
30 
31 /* This is the "main" part of the frm_PreStage command. Syntax is:
32 */
33 static const char *XrdFrmOpts = "c:dhn:v";
34 static const char *XrdFrmUsage =
35 
36  " [-c <cfgfile>] [-d] [-h] [-n name] [-v] [help | cmd & opts]\n";
37 /*
38 Where:
39 
40  -c The configuration file. The default is '/opt/xrootd/etc/xrootd.cf'
41 
42  -d Turns on debugging mode.
43 
44  -h Print helpful information (other options ignored).
45 
46  -n The instance name.
47 
48  cmd Specific commands, see the help information.
49 
50  opts Options specific to the command.
51 */
52 
53 /******************************************************************************/
54 /* i n c l u d e f i l e s */
55 /******************************************************************************/
56 
57 #include <unistd.h>
58 #include <cctype>
59 #include <cerrno>
60 #include <signal.h>
61 #include <cstdlib>
62 #include <cstring>
63 #include <strings.h>
64 #include <cstdio>
65 #include <sys/param.h>
66 
67 #ifdef HAVE_READLINE
68 #include <readline/readline.h>
69 #include <readline/history.h>
70 #endif
71 
72 #include "XrdFrc/XrdFrcTrace.hh"
73 #include "XrdFrm/XrdFrmAdmin.hh"
74 #include "XrdFrm/XrdFrmConfig.hh"
75 #include "XrdNet/XrdNetOpts.hh"
76 #include "XrdNet/XrdNetSocket.hh"
78 #include "XrdSys/XrdSysError.hh"
79 #include "XrdSys/XrdSysHeaders.hh"
80 #include "XrdSys/XrdSysLogger.hh"
81 
82 using namespace XrdFrc;
83 using namespace XrdFrm;
84 
85 /******************************************************************************/
86 /* G l o b a l V a r i a b l e s */
87 /******************************************************************************/
88 
91 
93 
94 // The following is needed to resolve symbols for objects included from xrootd
95 //
99 
100 /******************************************************************************/
101 /* r e a d l i n e */
102 /******************************************************************************/
103 
104 #ifndef HAVE_READLINE
105 
106 // replacement function for GNU readline
107 //
108 char *readline(const char *prompt)
109 {
110  char buff[4096];
111 
112  std::cout << prompt;
113  if (!fgets(buff, 4096, stdin) || *buff == '\n' || !strlen(buff)) return 0;
114  return strdup(buff);
115 }
116 
117 void add_history(const char *cLine) {}
118 void stifle_history(int hnum) {}
119 #endif
120 
121 /******************************************************************************/
122 /* m a i n */
123 /******************************************************************************/
124 
125 int main(int argc, char *argv[])
126 {
128  sigset_t myset;
129  XrdOucTokenizer Request(0);
130  char *cLine = 0, *pLine = 0, *Cmd = 0, *CmdArgs = 0;
131  int IMode;
132 
133 // Turn off sigpipe and host a variety of others before we start any threads
134 //
135  signal(SIGPIPE, SIG_IGN); // Solaris optimization
136  sigemptyset(&myset);
137  sigaddset(&myset, SIGPIPE);
138  sigaddset(&myset, SIGCHLD);
139  pthread_sigmask(SIG_BLOCK, &myset, NULL);
140 
141 // Perform configuration
142 //
143  Say.logger(&Logger);
144  XrdLog.logger(&Logger);
145  if (!Config.Configure(argc, argv, 0)) exit(4);
146 
147 // Fill out the dummy symbol to avoid crashes
148 //
150 
151 // We either have a command line or need to enter interactive mode
152 //
153  if (Config.nextArg >= argc) IMode = 1;
154  else {Cmd = argv[Config.nextArg++];
155  Admin.setArgs(argc-Config.nextArg, &argv[Config.nextArg]);
156  IMode = 0;
157  }
158 
159 // Set readline history list (keep only 256 lines, max)
160 //
161  if (IMode) stifle_history(256);
162 
163 // Process the request(s)
164 //
165  do {if (IMode)
166  {if (!(cLine = readline("frm_admin> "))) Admin.Quit();
167  if (!pLine || strcmp(pLine, cLine))
168  {add_history(cLine);
169  if (pLine) free(pLine);
170  pLine = strdup(cLine);
171  }
172  Request.Attach(cLine);
173  if (!Request.GetLine() || !(Cmd=Request.GetToken(&CmdArgs)))
174  Admin.Quit();
175  Admin.setArgs(CmdArgs);
176  }
177  Admin.xeqArgs(Cmd);
178  if (cLine) free(cLine);
179  } while(IMode);
180 
181 // All done
182 //
183  Admin.Quit();
184 }
int main(int argc, char *argv[])
XrdOucTrace * XrdXrootdTrace
XrdSysError XrdLog(0, "")
void stifle_history(int hnum)
void add_history(const char *cLine)
char * readline(const char *prompt)
static const char * XrdFrmUsage
static const char * XrdFrmOpts
char * GetToken(char **rest=0, int lowcase=0)
void Attach(char *bp)
XrdSysLogger * logger(XrdSysLogger *lp=0)
Definition: XrdSysError.hh:141
XrdCmsAdmin Admin
XrdCmsConfig Config
XrdSysError Say
XrdFrmConfig Config
XrdFrmAdmin Admin
XrdSysLogger Logger
Definition: XrdGlobals.cc:47
XrdSysTrace XrdTrace
Definition: XrdTrace.hh:56