1 // vim: ts=4 sw=4 noet:
3 --------------------------------------------------------------------------------
4 Copyright (c) 2018-2019 AT&T Intellectual Property.
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
10 http://www.apache.org/licenses/LICENSE-2.0
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
17 --------------------------------------------------------------------------------
21 Mnemonic: mc_listener.c
22 Abstract: This application (management campaign listener) will listen for
23 RMR based messages and write the payloads into FIFOs which
24 correspond to the message type.
27 /var/lib/mc/listener -- directory for FIFOs
30 -d <path> FIFO directory (default is /tmp/mcl/fifos)
31 -p <port> The port to set RMR listener on (default is 4560)
32 -r <seconds> The frequency that count reports are written to
33 stderr. 0 == 0ff; default is 60.
36 RMR based environment variables which might be needed:
37 RMR_SEED_RT -- path to the static routing table
38 RMR_RTG_SVC -- port to listen for RTG connections
41 Author: E. Scott Daniels
54 //---- support -----------------------------------------------------------------------------
56 static void bad_arg( char* what ) {
57 fprintf( stderr, "[ERR] option is unrecognised or isn't followed by meaningful data: %s\n", what );
60 static void usage( char* argv0 ) {
61 fprintf( stderr, "usage: %s [-d fifo-dir] [-e] [-p listen-port] [-q | -r report-freq]\n", argv0 );
62 fprintf( stderr, " -e disable extended header in buffers written to FIFOs\n" );
63 fprintf( stderr, "\n" );
64 fprintf( stderr, "The following environment variables may be set to affect operation:\n" );
65 fprintf( stderr, " MCL_RDC_STAGE: the directory where raw data capture files are staged. (/tmp/rdc/stage)\n" );
66 fprintf( stderr, " MCL_RDC_FINAL: the directory where raw data capture files are placed for export. (/tmp/rdc/final)\n" );
67 fprintf( stderr, " MCL_RDC_SUFFIX: the suffix written on each raw data capture file; must include '.'. (.rdc)\n" );
68 fprintf( stderr, " MCL_RDC_SOURCE: a short string used as source identification in rdc file names.\n" );
69 fprintf( stderr, " MCL_RDC_FREQ: the amount of time (seconds) that raw capture files are rolled. (300)\n" );
70 fprintf( stderr, "\nIf either final or staging directories are defined by environment vars, they MUST exist.\n" );
71 fprintf( stderr, "\n" );
74 //------------------------------------------------------------------------------------------
75 int main( int argc, char** argv ) {
76 void* ctx; // the mc listener library context
77 char* dname = "/tmp/mcl/fifos"; // default directory where we open fifos
78 char* port = "4560"; // default rmr port
79 char* siphon_dir = "/tmp/mci/siphon"; // where siphon files are placed
80 int siphon = 0; // percentage of messages to siphone off
81 int report_freq = 60; // report stats every n seconds
82 int pidx = 1; // parameter index
84 int long_hdrs = 1; // -e sets and causes extended headers to be written
86 while( pidx < argc && argv[pidx][0] == '-' ) { // simple argument parsing (-x or -x value)
87 switch( argv[pidx][1] ) {
90 dname = strdup( argv[pidx+1] );
93 bad_arg( argv[pidx] );
103 if( pidx+1 < argc ) {
104 port = strdup( argv[pidx+1] );
107 bad_arg( argv[pidx] );
117 if( pidx+1 < argc ) {
118 report_freq = atoi( argv[pidx+1] );
121 bad_arg( argv[pidx] );
133 bad_arg( argv[pidx] );
146 ctx = mcl_mk_context( dname ); // initialise the library context
148 fprintf( stderr, "[FAIL] couldn't initialise the mc listener environment\n" );
151 mcl_set_sigh(); // set signal handler(s)
153 mcl_start_listening( ctx, port, MCL_NOWAIT ); // start the listener, no waiting for rt since we don't send
154 mcl_fifo_fanout( ctx, report_freq, long_hdrs ); // listen and fanout messages to fifo; report to stdout every ~2sec
156 fprintf( stderr, "[INFO] mc listener is finished.\n" );