source: rtems/c/src/librdbg/src/rdbg.c @ 2977f24c

4.104.114.84.95
Last change on this file since 2977f24c was 718f981, checked in by Ralf Corsepius <ralf.corsepius@…>, on 07/18/03 at 05:19:20

2003-07-18 Ralf Corsepius <corsepiu@…>

  • src/rdbg.c: Use memset instead of bzero (deprecated).
  • src/servtsp.c: Ditto.
  • Property mode set to 100644
File size: 3.1 KB
Line 
1/*
2 **************************************************************************
3 *
4 * Component =   
5 *
6 * Synopsis  =   rdbg.c
7 *
8 * $Id$
9 *
10 **************************************************************************
11 */
12
13#include <assert.h>
14#include <errno.h>
15#include <rtems.h>
16#include <rtems/error.h>
17#include <rdbg/rdbg.h>
18#include <rdbg/servrpc.h>
19#include <rtems/rtems_bsdnet.h>
20#include <rpc/pmap_clnt.h>
21#include <sys/socket.h>
22#include <netinet/in.h>
23#include <rtems/bspIo.h>
24
25u_short rtemsPort = RTEMS_PORT;
26int BackPort = RTEMS_BACK_PORT;
27int rtemsActive = 0;
28SVCXPRT *rtemsXprt;
29int rtemsSock;
30char taskName[] = "RTEMS rdbg daemon";
31volatile int ExitForSingleStep = 0;
32volatile int Continue;
33volatile int justSaveContext;
34volatile Objects_Id currentTargetThread;
35volatile int CannotRestart = 0;
36volatile int TotalReboot = 0;
37int CONN_LIST_INC = 3;
38int PID_LIST_INC = 1;
39int TSP_RETRIES = 10;
40
41  int
42getId ()
43{
44  rtems_id id;
45
46  rtems_task_ident (RTEMS_SELF, RTEMS_SEARCH_ALL_NODES, &id);
47  return (int) (id);
48}
49
50  static int
51rdbgInit (void)
52{
53  int sock;
54  struct sockaddr_in addr;
55
56  sock = socket (AF_INET, SOCK_DGRAM, IPPROTO_UDP);
57  if (sock == -1) {
58    printf ("%s: rdbgInit: cannot allocate socket\n", taskName);
59    return -1;
60  }
61
62  memset ((void *) &addr, 0, sizeof (struct sockaddr_in));
63  addr.sin_port = htons (rtemsPort);
64  if ((bind (sock, (struct sockaddr *) &addr, sizeof (addr))) == -1) {
65    printf ("%s: rdbgInit: cannot bind socket\n", taskName);
66    return -2;
67  }
68  rtemsXprt = svcudp_create (sock);
69  if (svcudp_enablecache (rtemsXprt, 1) == 0) {
70    printf ("%s: rdbgInit: cannot enable rpc cache\n", taskName);
71    return -3;
72  }
73  rtemsSock = sock;
74  if (!svc_register (rtemsXprt, REMOTEDEB, REMOTEVERS, remotedeb_2, 0)) {
75    fprintf (stderr, "unable to register (REMOTEDEB, REMOTEVERS, udp).");
76    return -4;
77  }
78  connect_rdbg_exception ();
79
80  return 0;
81}
82
83  rtems_task
84rdbgDaemon (rtems_task_argument argument)
85{
86  svc_run ();
87}
88
89  void
90rtems_rdbg_initialize (void)
91{
92  rtems_name task_name;
93  rtems_id tid;
94  rtems_status_code status;
95
96#ifdef DDEBUG
97  rdb_debug = 1;                /* DPRINTF now will display */
98#endif
99
100  DPRINTF (("%s init starting\n", taskName));
101
102  /*
103   * Print version string
104   */
105#ifdef DDEBUG
106  printk ("RDBG v.%d built on [%s %s]\n", SERVER_VERS, __DATE__, __TIME__);
107#else
108  printk ("RDBG v.%d\n", SERVER_VERS);
109#endif
110
111  /*
112   * Create socket and init UDP RPC server
113   */
114  if (rdbgInit () != 0)
115    goto error;
116
117  Continue = 1;
118  justSaveContext = 0;
119  currentTargetThread = 0;
120
121  task_name = rtems_build_name ('R', 'D', 'B', 'G');
122  if ((status = rtems_task_create (task_name, 5, 24576,
123                                   RTEMS_INTERRUPT_LEVEL (0),
124                                   RTEMS_DEFAULT_ATTRIBUTES |
125                                   RTEMS_SYSTEM_TASK, &tid))
126      != RTEMS_SUCCESSFUL) {
127    printf ("status = %d\n", status);
128    rtems_panic ("Can't create task.\n");
129  }
130
131  status = rtems_task_start (tid, rdbgDaemon, 0);
132
133  return;
134
135error:
136  printf ("initialization failed.\n");
137}
138
139  void
140setErrno (int error)
141{
142  errno = error;
143}
144
145  int
146getErrno ()
147{
148  return errno;
149}
Note: See TracBrowser for help on using the repository browser.