XRootD
Loading...
Searching...
No Matches
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*/
33static const char *XrdFrmOpts = "c:dhn:v";
34static const char *XrdFrmUsage =
35
36 " [-c <cfgfile>] [-d] [-h] [-n name] [-v] [help | cmd & opts]\n";
37/*
38Where:
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"
75#include "XrdNet/XrdNetOpts.hh"
78#include "XrdSys/XrdSysError.hh"
81
82using namespace XrdFrc;
83using 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//
97 XrdOucTrace XrdTrace(&Say);
98
99/******************************************************************************/
100/* r e a d l i n e */
101/******************************************************************************/
102
103#ifndef HAVE_READLINE
104
105// replacement function for GNU readline
106//
107char *readline(const char *prompt)
108{
109 char buff[4096];
110
111 std::cout << prompt;
112 if (!fgets(buff, 4096, stdin) || *buff == '\n' || !strlen(buff)) return 0;
113 return strdup(buff);
114}
115
116void add_history(const char *cLine) {}
117void stifle_history(int hnum) {}
118#endif
119
120/******************************************************************************/
121/* m a i n */
122/******************************************************************************/
123
124int main(int argc, char *argv[])
125{
127 sigset_t myset;
128 XrdOucTokenizer Request(0);
129 char *cLine = 0, *pLine = 0, *Cmd = 0, *CmdArgs = 0;
130 int IMode;
131
132// Turn off sigpipe and host a variety of others before we start any threads
133//
134 signal(SIGPIPE, SIG_IGN); // Solaris optimization
135 sigemptyset(&myset);
136 sigaddset(&myset, SIGPIPE);
137 sigaddset(&myset, SIGCHLD);
138 pthread_sigmask(SIG_BLOCK, &myset, NULL);
139
140// Perform configuration
141//
142 Say.logger(&Logger);
143 XrdLog.logger(&Logger);
144 if (!Config.Configure(argc, argv, 0)) exit(4);
145
146// We either have a command line or need to enter interactive mode
147//
148 if (Config.nextArg >= argc) IMode = 1;
149 else {Cmd = argv[Config.nextArg++];
150 Admin.setArgs(argc-Config.nextArg, &argv[Config.nextArg]);
151 IMode = 0;
152 }
153
154// Set readline history list (keep only 256 lines, max)
155//
156 if (IMode) stifle_history(256);
157
158// Process the request(s)
159//
160 do {if (IMode)
161 {if (!(cLine = readline("frm_admin> "))) Admin.Quit();
162 if (!pLine || strcmp(pLine, cLine))
163 {add_history(cLine);
164 if (pLine) free(pLine);
165 pLine = strdup(cLine);
166 }
167 Request.Attach(cLine);
168 if (!Request.GetLine() || !(Cmd=Request.GetToken(&CmdArgs)))
169 Admin.Quit();
170 Admin.setArgs(CmdArgs);
171 }
172 Admin.xeqArgs(Cmd);
173 if (cLine) free(cLine);
174 } while(IMode);
175
176// All done
177//
178 Admin.Quit();
179}
XrdOucPup XrdCmsParser::Pup & Say
static XrdSysLogger Logger
int main(int argc, char *argv[])
XrdSysError XrdLog(0, "")
void stifle_history(int hnum)
char * readline(const char *prompt)
void add_history(const char *cLine)
static const char * XrdFrmUsage
static const char * XrdFrmOpts
char * GetToken(char **rest=0, int lowcase=0)
void Attach(char *bp)
XrdFrmConfig Config
XrdFrmAdmin Admin