FD.io VPP  v16.06
Vector Packet Processing
n1k_harness.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #include <dlfcn.h>
16 #include <vppinfra/format.h>
17 
18 void vlib_cli_output (void * vm, char * fmt, ...)
19 { clib_warning ("%s", fmt); }
20 
21 /*
22  * build system finesse hack
23  * since we can't build everything in one build system, this
24  * hack exists to make sure that the invoked program runs against
25  * the right libraries.
26  */
27 
28 int main (int argc, char ** argv)
29 {
30  void *handle, *main_handle;
31  int (*fp)(int argc, char **argv);
32  int rv;
33 
34  /* n1k_harness <plugin-name> <plugin args> */
35 
36  if (argc < 2) {
37  fformat (stderr, "usage: %s <plugin-name> [<plugin-args>...]\n",
38  argv[0]);
39  exit (1);
40  }
41 
42  handle = dlopen (argv[1], RTLD_LAZY);
43 
44  /*
45  * Note: this can happen if the plugin has an undefined symbol reference,
46  * so print a warning. Otherwise, the poor slob won't know what happened.
47  * Ask me how I know that...
48  */
49  if (handle == 0)
50  {
51  clib_warning ("%s", dlerror());
52  exit(1);
53  }
54 
55  main_handle = dlsym (handle, "plugin_main");
56  if (main_handle == 0) {
57  clib_warning ("plugin_main(int argc, char **argv) missing...\n");
58  exit(1);
59  }
60 
61  fp = main_handle;
62 
63  rv = (*fp)(argc-2, argv+2);
64 
65  return rv;
66 }
void vlib_cli_output(void *vm, char *fmt,...)
Definition: n1k_harness.c:18
int main(int argc, char **argv)
Definition: n1k_harness.c:28
#define clib_warning(format, args...)
Definition: error.h:59
word fformat(FILE *f, char *fmt,...)
Definition: format.c:437