[go: up one dir, main page]

Menu

[r406]: / clp / trunk / src / omcclpc.cpp  Maximize  Restore  History

Download this file

758 lines (664 with data), 23.4 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
/****************************************************************************
|
| Copyright (c) 2006 Novell, Inc.
| All Rights Reserved.
|
| This program is free software; you can redistribute it and/or
| modify it under the terms of version 2 of the GNU General Public License as
| published by the Free Software Foundation.
|
| This program is distributed in the hope that it will be useful,
| but WITHOUT ANY WARRANTY; without even the implied warranty of
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
| GNU General Public License for more details.
|
| You should have received a copy of the GNU General Public License
| along with this program; if not, contact Novell, Inc.
|
| To contact Novell about this file by physical or electronic mail,
| you may find current contact information at www.novell.com
|
|***************************************************************************
/**
@author Brad Nicholes
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "omcclpc.h"
#include "omcclpprogram.h"
#include "omcclpcommon.h"
#include "omcclptargetpath.h"
#include "omcclpdconfigopts.h"
#include "omcclpdsyslogappender.h"
#include <readline/readline.h>
#include <readline/history.h>
#include <openwbem/OW_Assertion.hpp>
#include <openwbem/OW_CmdLineParser.hpp>
#include <openwbem/OW_SocketAddress.hpp>
#include <openwbem/OW_Select.hpp>
#include <openwbem/OW_AppenderLogger.hpp>
#include <openwbem/OW_Format.hpp>
using namespace OMCClpdConfigOpts;
#ifdef OMCCLPCLIENT
void init_rl ();
enum tag_OPTIONS
{
E_CMDOPT_HELP,
E_CMDOPT_URL, // specify URL
E_CMDOPT_NS, // specify namespace
E_CMDOPT_CONFIG, // specify configuration file
E_CMDOPT_CMD, // specify a single command
};
CmdLineParser::Option g_options[] =
{
{E_CMDOPT_CMD, 'c', "command", CmdLineParser::E_REQUIRED_ARG, 0, "Execute a single command from the command line."},
{E_CMDOPT_CONFIG, 'f', "config", CmdLineParser::E_REQUIRED_ARG, 0, "Alternate configuration file. Default is omcclpc.conf."},
{E_CMDOPT_HELP, 'h', "help", CmdLineParser::E_NO_ARG, 0, "Show help about options."},
{E_CMDOPT_NS, 'n', "ns", CmdLineParser::E_REQUIRED_ARG, 0, "Alternate CIM namespace to be used in place of the namespace specified in the configuration file"},
{E_CMDOPT_URL, 'u', "url", CmdLineParser::E_REQUIRED_ARG, 0, "Alternate CIM URL to be used in place of the URL specified in the configuration file."},
{0, 0, 0, CmdLineParser::E_NO_ARG, 0, 0}
};
OMCCLPProgram *gclp = NULL; // global pointer to the main program object
static void usage()
{
cerr << PROG_NAME << " " << PROG_VERSION
<< " Server Management Command Line Protocol" << endl;
cerr << "Copyright (C) 2006 by Novell Inc." << endl;
cerr << "Usage: " << PROG_NAME << " [OPTIONS]" << endl;
cout << endl << CmdLineParser::getUsage(g_options) << endl;
}
static void printCmdLineParserExceptionMessage(CmdLineParserException& e)
{
switch (e.getErrorCode())
{
case CmdLineParser::E_INVALID_OPTION:
cerr << "unknown option: " << e.getMessage() << endl;
break;
case CmdLineParser::E_MISSING_ARGUMENT:
cerr << "missing argument for option: " << e.getMessage() << endl;
break;
case CmdLineParser::E_INVALID_NON_OPTION_ARG:
cerr << "invalid non-option argument: " << e.getMessage() << endl;
break;
case CmdLineParser::E_MISSING_OPTION:
cerr << "missing required option: " << e.getMessage() << endl;
break;
default:
cerr << "failed parsing command line options: " << e << endl;
break;
}
}
void sigtermHandler(int status)
{
((OMCCLPClient*)gclp)->writePipe (status);
}
void registerSignalHandler ()
{
struct sigaction sa;
sa.sa_handler = sigtermHandler;
sa.sa_flags = 0;
sa.sa_restorer = NULL;
sigaction(SIGTERM, &sa, NULL);
sigaction(SIGINT, &sa, NULL);
}
#endif
namespace OMCCLP
{
String OMCCLPClient::COMPONENT_NAME("omcclp.clpc");
bool OMCCLPClient::socketConnect()
{
/* If the socket is already connected,
disconnect the socket first. */
if (m_socket.isConnected())
m_socket.disconnect();
/* Get the listen port from the configuration file. */
String item = getConfigItem(OMCClpdConfigOpts::SERVER_PORT_opt,
OMCCLPD_DEFAULT_SERVER_PORT);
Int32 port = item.toInt32();
OW_LOG_ERROR(m_logger, Format("Connecting socket on port (%1) "
"in OMCCLPClient::socketConnect", port));
try {
m_socket.connect(SocketAddress::getAnyLocalHost(port));
} catch (...) {
OW_LOG_ERROR(m_logger, "OMCCLPClient::socketConnect: "
"Unable to connect to omcclpd. "
"The server may not to be running");
}
return m_socket.isConnected();
}
void OMCCLPClient::createLogger()
{
AppenderLogger* pLogger = 0;
StringArray additionalLogs = OMCClpdConfig::getMultiConfigItem(
OMCClpdConfigOpts::ADDITIONAL_CLIENT_LOGS_opt);
String logName, logClientType, logClientComponents;
String logClientCategories, logClientLevel, logClientFormat;
// this also gets set if clpd is run with -d
bool debugFlag = getConfigItem(OMCClpdConfigOpts::DEBUGFLAG_opt,
OMCCLPD_DEFAULT_DEBUGFLAG).equalsIgnoreCase("true");
if (debugFlag)
{
// stick it at the beginning as a possible slight logging performance optimization
additionalLogs.insert(additionalLogs.begin(), LOG_DEBUG_LOG_NAME);
}
for (size_t i = 0; i < additionalLogs.size(); ++i)
{
logName = additionalLogs[i];
logClientType = getConfigItem(Format(OMCClpdConfigOpts::LOG_1_TYPE_opt, logName),
OMCCLPD_DEFAULT_LOG_1_TYPE);
logClientComponents = getConfigItem(Format(OMCClpdConfigOpts::LOG_1_COMPONENTS_opt, logName),
OMCCLPD_DEFAULT_LOG_1_COMPONENTS);
logClientCategories = getConfigItem(Format(OMCClpdConfigOpts::LOG_1_CATEGORIES_opt, logName));
if (logClientCategories.empty())
{
// convert level into categories
logClientLevel = getConfigItem(Format(OMCClpdConfigOpts::LOG_1_LEVEL_opt, logName),
OMCCLPD_DEFAULT_LOG_1_LEVEL);
if (logClientLevel.equalsIgnoreCase(Logger::STR_DEBUG_CATEGORY))
{
logClientCategories = Logger::STR_DEBUG_CATEGORY + " " +
Logger::STR_INFO_CATEGORY + " " +
Logger::STR_ERROR_CATEGORY + " " +
Logger::STR_FATAL_CATEGORY;
}
else if (logClientLevel.equalsIgnoreCase(Logger::STR_INFO_CATEGORY))
{
logClientCategories = Logger::STR_INFO_CATEGORY + " " +
Logger::STR_ERROR_CATEGORY + " " +
Logger::STR_FATAL_CATEGORY;
}
else if (logClientLevel.equalsIgnoreCase(Logger::STR_ERROR_CATEGORY))
{
logClientCategories = Logger::STR_ERROR_CATEGORY + " " + Logger::STR_FATAL_CATEGORY;
}
else if (logClientLevel.equalsIgnoreCase(Logger::STR_FATAL_CATEGORY))
{
logClientCategories = Logger::STR_FATAL_CATEGORY;
}
}
logClientFormat = getConfigItem(Format(OMCClpdConfigOpts::LOG_1_FORMAT_opt, logName),
OMCCLPD_DEFAULT_LOG_1_FORMAT);
if (logClientType.equalsIgnoreCase("syslog"))
{
pLogger = new AppenderLogger(COMPONENT_NAME, E_ALL_LEVEL,
LogAppenderRef(new OMCClpdSyslogAppender(logClientComponents.tokenize(),
logClientCategories.tokenize(), logClientFormat)));
}
else
{
pLogger = new AppenderLogger(COMPONENT_NAME, E_ALL_LEVEL,
LogAppender::createLogAppender(logName, logClientComponents.tokenize(),
logClientCategories.tokenize(), logClientFormat, logClientType,
OMCClpdConfig::getLogAppenderConfig()));
}
}
// This one will eventually be handled the same as all other logs by just sticking
// "main" in the additionalLogs array but we need to handle deprecated options for
// now, so it needs special treatment.
logName = LOG_CLIENT_LOG_NAME;
logClientType = getConfigItem(Format(OMCClpdConfigOpts::LOG_1_TYPE_opt, logName));
logClientComponents = getConfigItem(Format(OMCClpdConfigOpts::LOG_1_COMPONENTS_opt, logName),
OMCCLPD_DEFAULT_LOG_1_COMPONENTS);
logClientCategories = getConfigItem(Format(OMCClpdConfigOpts::LOG_1_CATEGORIES_opt, logName));
logClientLevel = getConfigItem(Format(OMCClpdConfigOpts::LOG_1_LEVEL_opt, logName));
logClientFormat = getConfigItem(Format(OMCClpdConfigOpts::LOG_1_FORMAT_opt, logName),
OMCCLPD_DEFAULT_LOG_1_FORMAT);
// If logClientType not specified, use syslog
if (logClientType.empty())
{
logClientType = "syslog";
}
// If no logClientCategoreis and the main level not specifed
if (logClientCategories.empty() && logClientLevel.empty())
{
logClientLevel = OMCCLPD_DEFAULT_LOG_1_LEVEL;
}
// convert level into categories
if (logClientCategories.empty())
{
// convert level into categories
logClientLevel = getConfigItem(Format(OMCClpdConfigOpts::LOG_1_LEVEL_opt, logName),
OMCCLPD_DEFAULT_LOG_1_LEVEL);
if (logClientLevel.equalsIgnoreCase(Logger::STR_DEBUG_CATEGORY))
{
logClientCategories = Logger::STR_DEBUG_CATEGORY + " " +
Logger::STR_INFO_CATEGORY + " " + Logger::STR_ERROR_CATEGORY +
" " + Logger::STR_FATAL_CATEGORY;
}
else if (logClientLevel.equalsIgnoreCase(Logger::STR_INFO_CATEGORY))
{
logClientCategories = Logger::STR_INFO_CATEGORY + " " +
Logger::STR_ERROR_CATEGORY + " " + Logger::STR_FATAL_CATEGORY;
}
else if (logClientLevel.equalsIgnoreCase(Logger::STR_ERROR_CATEGORY))
{
logClientCategories = Logger::STR_ERROR_CATEGORY + " " + Logger::STR_FATAL_CATEGORY;
}
else if (logClientLevel.equalsIgnoreCase(Logger::STR_FATAL_CATEGORY))
{
logClientCategories = Logger::STR_FATAL_CATEGORY;
}
}
LogAppenderRef appender;
if (logClientType.equalsIgnoreCase("syslog"))
{
appender = LogAppenderRef(new OMCClpdSyslogAppender(logClientComponents.tokenize(),
logClientCategories.tokenize(), logClientFormat));
}
else
{
appender = LogAppender::createLogAppender(logName,
logClientComponents.tokenize(), logClientCategories.tokenize(),
logClientFormat, logClientType, OMCClpdConfig::getLogAppenderConfig());
}
if (pLogger)
{
pLogger->addLogAppender(appender);
}
else
{
pLogger = new AppenderLogger(COMPONENT_NAME, E_ALL_LEVEL, appender);
}
m_logger = LoggerRef(pLogger);
m_logger->setDefaultComponent(COMPONENT_NAME);
}
String OMCCLPClient::getServerPrompt()
{
char promptBuf[256];
String prompt;
int count = 0;
/* Wait for the prompt from the server */
while (!prompt.endsWith("-->") && (count < 10))
{
if (m_socket.waitForInput(1))
{
/* The select timed out waiting for a prompt.
Poke the server to try to get a prompt back. */
m_socket.write("\r\n", 2);;
count++;
continue;
}
memset(promptBuf, 0, sizeof(promptBuf));
m_socket.read(promptBuf, sizeof(promptBuf));
prompt = String(promptBuf);
}
return prompt;
}
bool OMCCLPClient::initializeCLPSession()
{
OMCCLPProgram::initializeCLPSession();
createLogger();
if (!socketConnect()) {
cout << "Unable to connect to the CLP service" << endl;
return false;
}
return true;
}
bool OMCCLPClient::createCLPSessionInfo(CIMClient *rch)
{
try
{
char lineBuf[1024];
bool done = false;
if (isValidPrompt(getServerPrompt()))
{
String UFiP(0);
/* We need to get the session UFiP from the CLP server.
Send the command to get the session UFiP */
String cmd = "show -o format=keyword session";
m_socket.write(cmd.c_str(), cmd.length());
m_socket.write("\r\n", 2);
/* Get the timout value from the configuration file. */
String item = getConfigItem(OMCClpdConfigOpts::SERVER_TIMEOUT_opt,
OMCCLPD_DEFAULT_SERVER_TIMEOUT);
Int32 timeout = item.toInt32();
do {
/* Wait for a response from the CLP server. If the
timeout period is exceeded then just bail out
with no connection. */
if (m_socket.waitForInput(timeout))
{
break;
}
/* Read the data from the socket and
parse it on carriage returns. */
memset(lineBuf, 0, sizeof(lineBuf));
m_socket.read(lineBuf, sizeof(lineBuf));
StringArray lines = String(lineBuf).tokenize("=\r\n");
/* Output each line to the screen while looking for
the server prompt. Once the server prompt
is found, assume that there is no more data. */
for (int i = 0; i < lines.size(); i++)
{
if (lines[i].equalsIgnoreCase("ufip"))
{
UFiP = lines[i+1];
}
/* Read the output until we hit "endoutput" */
if (lines[i].equalsIgnoreCase("endoutput"))
{
done = true;
break;
}
}
} while (!done);
if (UFiP.length())
{
setSession(getCIMObjectPathFromUFiP (this, UFiP));
return true;
}
}
}
catch (...)
{
}
return false;
}
void OMCCLPClient::doExit()
{
/* do all of the exit stuff plus
write to the sigpipe to interrupt
any pending operation. */
OMCCLPProgram::doExit();
m_sigPipe->writeInt(1);
}
void OMCCLPClient::shutdown()
{
if(!m_running)
{
return;
}
m_shuttingDown = true;
doExit();
// Wait for the client to shutdown
m_threadBarrier.wait();
}
int OMCCLPClient::run(String cmdScript)
{
char *cmd = NULL;
FILE *fscript = NULL;
bool runOnce = false;
String histFile = getenv ("HOME");
String prompt;
char lineBuf[1024];
/* Get the timout value from the configuration file. */
String item = getConfigItem(OMCClpdConfigOpts::SERVER_TIMEOUT_opt,
OMCCLPD_DEFAULT_SERVER_TIMEOUT);
Int32 timeout = item.toInt32();
/* Load the select array with the sigpipe and the socket.
The sigpipe will allow us to interupt a pending
operation. */
SelectTypeArray selArray;
selArray.push_back(m_sigPipe->getSelectObj());
selArray.push_back(m_socket.getSelectObj());
if (!cmdScript.empty())
{
fscript = fopen (cmdScript.c_str(), "r");
if (fscript)
{
rl_instream = fscript;
}
else
{
cerr << "Could not open the script file " << cmdScript << endl;
doExit();
}
}
/* Read in the command history file from the previous session.*/
if (!histFile.empty())
{
histFile += String(HIST_FILENAME);
read_history(histFile.c_str());
}
m_running = true;
/* If we got a runOnce command off of the command line, then
set the runOnce flag and allow the command to be executed. */
String execCmd = getExecCmd();
if (!execCmd.empty())
runOnce = true;
/* Continue prompting for a command until the user enters
the exit command */
while (!shouldExit())
{
/* Free any previously existing command line string */
if (cmd)
{
free (cmd);
cmd = NULL;
}
/* Get a valid prompt from the server so that
we know that the server is ready for input. */
if (!isValidPrompt(prompt))
prompt = getServerPrompt();
if (runOnce)
{
cmd = execCmd.allocateCString();
}
else
{
/* Call the readline library to prompt for the command and
specify the comand prompt */
cmd = readline (prompt.c_str());
}
/* If the command is NULL, the EOF was hit and we need to
exit. If the command is empty, go back to the readline
prompt. Otherwise add the command to the command
history and continue processing */
if (!cmd)
{
doExit();
continue;
}
if (String(cmd).startsWith("exit", String::E_CASE_INSENSITIVE))
{
doExit();
}
else if ((*cmd == '\0') || (String(cmd).trim().charAt(0) == '#'))
{
continue;
}
else
add_history(cmd);
/* Write the command to the server over the socket
interface. The erase the current prompt so that
we can detect the new server prompt after all of
the data has been recieved. */
m_socket.write(cmd, String(cmd).length());
m_socket.write("\r\n", 2);
prompt.erase();
do {
StringArray lines;
/* If the program is exiting, then see if there is
anything to display. If not then get out. */
if (shouldExit() && m_socket.waitForInput(1))
{
break;
}
else
{
int selType = Select::SELECT_INTERRUPTED;
do {
selType = Select::select(selArray, timeout * 1000); // *1000 to convert seconds to milliseconds
} while(selType == Select::SELECT_INTERRUPTED);
if (selType == Select::SELECT_ERROR)
{
/*XXX This is a rather brut force way of aborting and
probably needs to be cleaned up. */
cout << "Socket select error occured. "
"Aborting the request and attempting to reconnect." << endl;
socketConnect();
break;
}
if (selType == Select::SELECT_TIMEOUT)
{
cout << "Request timeout exceeded." << endl;
char *abortit = readline ("Would you like to abort the request? (y/n) ");
if (abortit[0] == 'y')
{
/*XXX This is a rather brut force way of aborting and
probably needs to be cleaned up. */
socketConnect();
break;
}
rl_on_new_line();
continue;
}
if (selType == 0) // Unnamed pipe/event selected
{
doExit();
continue;
}
}
/* Read the data from the socket and
parse it on carriage returns. */
memset(lineBuf, 0, sizeof(lineBuf));
int bytesRead = m_socket.read(lineBuf, sizeof(lineBuf));
/* If we got data back then process it. Otherwise consider it
to be an EOF and bail out. */
if (bytesRead) {
lines = String(lineBuf).tokenize("\r\n");
}
else {
String msg = "The socket connection to the server appears to be broken\n" \
" Exiting the omcclp application.";
cout << msg << endl;
OW_LOG_ERROR(m_logger, msg);
doExit();
continue;
}
/* Output each line to the screen while looking for
the server prompt. Once the server prompt
is found, assume that there is no more data. */
for (int i = 0; i < lines.size(); i++)
{
if (isValidPrompt(lines[i])) {
prompt = lines[i];
/* If runOnce is set then get out after the
command response has been output. */
if (runOnce)
doExit();
break;
}
cout << lines[i] << endl;
}
} while (prompt.empty() && !shouldExit());
}
if (fscript)
{
fclose (fscript);
}
/* Write out the command history file to the user's home directory */
if (!histFile.empty())
{
int err = write_history(histFile.c_str());
if (!err)
{
history_truncate_file(histFile.c_str(), 100);
}
}
/* If we are exiting due to a call to the shutdown
method, then wait on the sync thread barrier. */
if (m_shuttingDown)
m_threadBarrier.wait();
return 0;
}
}
#ifdef OMCCLPCLIENT
/**
* Main program starting point
*/
int main (int argc, char *argv[])
{
OMCCLPClient clp(cout);
int c;
// Set the global pointer to the program object so that
// it can be referenced by other objects.
gclp = &clp;
cout << "hello world" << endl;
/* Initialize the readline library */
init_rl();
registerSignalHandler ();
try
{
// parse command line, and build the urlList
CmdLineParser parser(argc, argv, g_options, CmdLineParser::E_NON_OPTION_ARGS_ALLOWED);
if (parser.isSet(E_CMDOPT_HELP))
{
usage();
return 0;
}
if (parser.isSet(E_CMDOPT_URL))
{
String val = parser.getOptionValue(E_CMDOPT_URL);
clp.setCIMURL(val);
}
if (parser.isSet(E_CMDOPT_NS))
{
String val = parser.getOptionValue(E_CMDOPT_NS);
clp.setCIMNamespace(val);
}
if (parser.isSet(E_CMDOPT_CONFIG))
{
String val = parser.getOptionValue(E_CMDOPT_CONFIG);
clp.setConfFilename(val);
}
else
clp.setConfFilename(OMCCLP_SYSCONF_DIR"/omcclpc.conf");
if (parser.isSet(E_CMDOPT_CMD))
{
String val = parser.getOptionValue(E_CMDOPT_CMD);
clp.setExecCmd(val);
}
clp.setScriptFilenames(parser.getNonOptionArgs());
}
catch (CmdLineParserException& e)
{
printCmdLineParserExceptionMessage(e);
usage();
}
catch (CIMException& e)
{
cerr << "ERROR: CIMException:" << e.getMessage() << endl;
}
catch (Exception& e)
{
cerr << "ERROR: Exception:" << e.getMessage() << endl;
}
catch (std::exception& e)
{
cerr << "ERROR: sdtException:" << e.what() << endl;
}
catch (...)
{
cerr << "ERROR: UnknownException." << endl;
}
try
{
if (clp.initializeCLPSession() &&
clp.createCLPSessionInfo(clp.getCIMClient()))
{
StringArray cmdScripts = clp.getScriptFilenames();
if (!cmdScripts.empty())
{
for (int i=0; i < cmdScripts.size(); i++)
clp.run(cmdScripts[i]);
}
else
{
clp.run();
}
return 0;
}
}
catch (AssertionException& a)
{
cerr << "Caught Assertion: " << a << endl;
}
catch (Exception& e)
{
cerr << e << endl;
}
return 1;
}
#endif