source: ada-examples/shell/shell_init.c @ 789d0e8

ada-examples-4-10-branch
Last change on this file since 789d0e8 was f421fee, checked in by Joel Sherrill <joel.sherrill@…>, on 09/15/09 at 21:11:42

2009-09-15 Joel Sherrill <joel.sherrill@…>

  • .cvsignore, ChangeLog?, Makefile, README, commands.adb, commands.ads, config.h, main.adb, rtems_shell.ads, shell_init.c: New files.
  • Property mode set to 100644
File size: 3.2 KB
Line 
1/*
2 *  This is a derived from the init.c file in the telnetd demo.
3 *
4 *  $Id$
5 */
6
7#include <bsp.h>
8
9#include <errno.h>
10#include <time.h>
11
12#include <stdio.h>
13#include <rtems/rtems_bsdnet.h>
14#include <rtems/telnetd.h>
15#include <rtems/shell.h>
16
17#include <rtems/error.h>
18#include <rpc/rpc.h>
19#include <netinet/in.h>
20#include <time.h>
21
22#include <arpa/inet.h>
23#include <sys/socket.h>
24#include "../networkconfig.h"
25
26// I'm not sure why this is necessary
27#include <rtems/bdbuf.h>
28const rtems_bdbuf_config rtems_bdbuf_configuration;
29
30typedef char * (* prompt_function_t)(void);
31
32static prompt_function_t prompt_function = NULL;
33
34extern void set_prompt_function(prompt_function_t f)
35{
36  prompt_function = f;
37}
38
39extern char * get_prompt(void);
40void rtems_shell_get_prompt(
41  rtems_shell_env_t *shell_env,
42  char              *prompt,
43  size_t             size
44)
45{
46  char curdir[256];
47
48  if (prompt_function == NULL)
49  {
50    getcwd(curdir,sizeof(curdir));
51    snprintf(prompt, size - 1, "%s%s[%s] %c ",
52            ((shell_env->taskname) ? shell_env->taskname : ""),
53            ((shell_env->taskname) ? " " : ""),
54            curdir,
55            geteuid()?'$':'#');
56
57  }
58  else
59    snprintf(prompt, size - 1, prompt_function());
60}
61
62/*
63 *  If true, listen on socket(s).
64 *  If false, remain on console.
65 */
66/* #define REMAIN_ON_CONSOLE */
67bool remain_on_console = false;
68
69#include <rtems/shell.h>
70
71#define SHELL_HELP_MSG \
72  "Starting rtemsShell via telnetd -- default account is rtems w/no password\n"
73
74#define CONFIGURE_SHELL_COMMANDS_ALL_NETWORKING
75#define CONFIGURE_SHELL_COMMANDS_ALL
76
77#define CONFIGURE_SHELL_COMMANDS_INIT
78#include <rtems/shellconfig.h>
79
80
81static void rtemsShell(
82  char *pty_name,
83  void *cmd_arg
84)
85{
86  rtems_shell_env_t env = rtems_global_shell_env;
87 
88  env.devname = pty_name;
89  env.taskname = "TLNT";
90  env.login_check = rtems_shell_login_check;
91
92  if ( !remain_on_console )
93    printk("============== Starting Shell ==============\n");
94
95  rtems_shell_main_loop( &env );
96
97  if ( !remain_on_console )
98    printk("============== Exiting Shell ==============\n");
99}
100
101#define SHELL_ENTRY rtemsShell
102
103/*
104 *  Telnet demon configuration
105 */
106rtems_telnetd_config_table rtems_telnetd_config = {
107  .command = SHELL_ENTRY,
108  .arg = NULL,
109  .priority = 1, /* We feel important today */
110  .stack_size = 20 * RTEMS_MINIMUM_STACK_SIZE, /* Shell needs a large stack */
111  .login_check = NULL, /* Shell asks for user and password */
112  .keep_stdio = false
113};
114
115/*
116 *  Initialization Aid
117 */
118void init_telnet_daemon(void)
119{
120  fprintf(stderr, "\n\n*** Telnetd Server Test ***\n\r" );
121
122  fprintf(stderr, "============== Initializing Network ==============\n");
123  rtems_bsdnet_initialize_network ();
124
125  fprintf(stderr, "============== Add Route ==============\n");
126  rtems_bsdnet_show_inet_routes ();
127
128  fprintf(stderr, "============== Start Telnetd ==============\n");
129
130  printk( SHELL_HELP_MSG );
131
132  #if defined(REMAIN_ON_CONSOLE)
133    remain_on_console = true;
134  #endif
135
136  rtems_global_shell_env.login_check = rtems_shell_login_check;
137  rtems_telnetd_config.keep_stdio = remain_on_console;
138 
139  rtems_telnetd_initialize();
140}
141
142
143#include <stdlib.h>
144#include <rtems.h>
145#include <rtems/telnetd.h>
146
147/* Helper for Ada */
148void invoke_rtems_shell(void)
149{
150  rtemsShell("console", NULL);
151}
152
Note: See TracBrowser for help on using the repository browser.