source: rtems/cpukit/libdl/rap-shell.c @ ae5fe7e6

4.115
Last change on this file since ae5fe7e6 was ae5fe7e6, checked in by Chris Johns <chrisj@…>, on 10/27/14 at 01:09:41

cpukit: Add libdl with the Runtime Loader (RTL) code.

This is a merge of the RTL project.

  • Property mode set to 100644
File size: 2.1 KB
Line 
1/*
2 *  COPYRIGHT (c) 2013 Chris Johns <chrisj@rtems.org>
3 *
4 *  The license and distribution terms for this file may be
5 *  found in the file LICENSE in this distribution or at
6 *  http://www.rtems.com/license/LICENSE.
7 */
8/**
9 * @file
10 *
11 * @ingroup rtems_rtld
12 *
13 * @brief RTEMS Application Loader.
14 *
15 * Shell command wrappers for the RTEMS Application loader.
16 */
17
18#if HAVE_CONFIG_H
19#include "config.h"
20#endif
21
22#include <stdbool.h>
23#include <stdio.h>
24#include <stdlib.h>
25#include <string.h>
26
27#include <rtems/rtl/rap.h>
28#include <rtems/rtl/rap-shell.h>
29
30static void
31shell_rap_command_help (void)
32{
33  printf ("usage: rap [cmd] [arg]\n" \
34          "Commands and options:\n" \
35          "ls:   List the loaded applications (also list)\n" \
36          "ld:   Load an application (also load)\n" \
37          "un:   Unload an application (also unload)\n");
38}
39
40static void
41shell_rap_get_error (const char* what)
42{
43  char message[64];
44  int  error;
45  error = rtems_rap_get_error (message, sizeof (message));
46  printf ("error: %s: (%d) %s\n", what, error, message);
47}
48
49static bool
50shell_rap_list_handler (void* handle)
51{
52  printf (" %-10p %-10p %-s\n",
53          handle, rtems_rap_dl_handle (handle), rtems_rap_name (handle));
54  return true;
55}
56
57static int
58shell_rap_list (int argc, char* argv[])
59{
60  printf (" App        DL Handle  Name\n");
61  return rtems_rap_iterate (shell_rap_list_handler) ? 0 : 1;
62}
63
64static int
65shell_rap_load (int argc, char* argv[])
66{
67  int r = 0;
68  if (argc == 0)
69  {
70    printf ("error: no application name\n");
71    return 0;
72  }
73  if (rtems_rap_load (argv[0], 0, argc - 1, (const char**) (argv + 1)))
74    printf ("%s loaded\n", argv[0]);
75  else
76  {
77    r = 1;
78    shell_rap_get_error ("loading");
79  }
80  return r;
81}
82
83int
84shell_rap (int argc, char* argv[])
85{
86  if (argc == 1)
87  {
88    shell_rap_command_help ();
89    return 0;
90  }
91
92  if ((strcmp (argv[1], "ls") == 0) ||
93      (strcmp (argv[1], "list") == 0))
94  {
95    return shell_rap_list (argc - 2, argv + 2);
96  }
97  else if ((strcmp (argv[1], "ld") == 0) ||
98           (strcmp (argv[1], "load") == 0))
99  {
100    return shell_rap_load (argc - 2, argv + 2);
101  }
102
103  printf ("error: invalid command: %s\n", argv[1]);
104  return 0;
105}
106
Note: See TracBrowser for help on using the repository browser.