source: rtems/c/src/librdbg/src/servcon.c @ 7a97f26

4.104.114.84.95
Last change on this file since 7a97f26 was 40cf43ea, checked in by Joel Sherrill <joel.sherrill@…>, on 02/01/02 at 17:00:01
  • So many patches have been posted recently on the mailing list and because we were unable to find correct solution to compile on various linux distros (due to rpcgen incompatibilities), and because the coding style of rdbg was rather inconsistant among various pieces of code, I decided to:

1) make some cleaning regarding global coding style (using

indent + manual edits),

2) incorporate/review the paches send by various people

(S. Holford, T. Strauman),

3) Fix the bug due to varying rpcgen code generation

in remdeb_svc.c,

4) Remove some dead code,
5) Apply a patches enabling to call enterRdbg imediately

after rdbg initialization is done,

NB : the paches is huge but it is mainly due to coding styke chnages.
Only few lines of codes have been really changed and they do not impact
rdbg functionnality (AFAIKT).

  • include/rdbg/servrpc.h, include/rdbg/i386/rdbg_f.h, include/rdbg/m68k/rdbg_f.h, include/rdbg/powerpc/rdbg_f.h, src/_servtgt.c, src/awk.svc, src/excep.c, src/ptrace.c, src/rdbg.c, src/remdeb.x, src/servbkpt.c, src/servcon.c, src/servrpc.c, src/servtgt.c, src/servtsp.c, src/servutil.c, src/i386/excep_f.c, src/i386/rdbg_f.c, src/i386/any/Makefile.am, src/i386/any/remdeb.h, src/i386/any/remdeb_svc.c, src/i386/any/remdeb_xdr.c, src/m68k/excep_f.c, src/m68k/rdbg_f.c, src/m68k/any/Makefile.am, src/m68k/any/remdeb.h, src/m68k/any/remdeb_svc.c, src/m68k/any/remdeb_xdr.c, src/powerpc/excep_f.c, src/powerpc/rdbg_f.c, src/powerpc/new_exception_processing/Makefile.am, src/powerpc/new_exception_processing/remdeb.h, src/powerpc/new_exception_processing/remdeb_svc.c, src/powerpc/new_exception_processing/remdeb_xdr.c: Modified.
  • Property mode set to 100644
File size: 4.1 KB
Line 
1/*
2 **************************************************************************
3 *
4 *  Component:  RDBG
5 *  Module:     servcon.c
6 *
7 *  Synopsis:   Management of RPC client connections.
8 *
9 * $Id$
10 *
11 **************************************************************************
12 */
13
14#include <sys/errno.h>
15#include <rdbg/rdbg.h>
16#include <rdbg/servrpc.h>
17
18    /*
19     *  ConnCreate - create a new connection entry for a client.
20     *
21     *  This function finds an empty entry in the connection array
22     *  or makes space. It fills in the fields that are passed to it.
23     *  It does not do any validation on net addresses nor does it
24     *  start a validation cycle on other clients. This is done by
25     *  the caller.
26     */
27
28  int
29ConnCreate (struct svc_req *rqstp, open_in * in)
30{
31  NET_OPAQUE sender;
32  int idx;
33  CONN_LIST *clst;
34
35  setErrno (0);
36
37  /*
38   * Convert to valid Net address
39   */
40  if (!TspTranslateRpcAddr (rqstp, &sender)) {
41    DPRINTF (("ConnCreate: TspTranslateRpcAddr failed\n"));
42    return -1;
43  }
44  if (!TspValidateAddr ((NET_OPAQUE *) in->back_port, &sender)) {
45    DPRINTF (("ConnCreate: TspValidateAddr failed\n"));
46    return -1;                  /* errno now setup with error */
47  }
48
49  /*
50   * look for an empty connection entry
51   */
52  for (idx = 0; idx < conn_list_cnt; idx++) {
53    if (!conn_list[idx].in_use)
54      break;                    /* an empty one found */
55  }
56
57  if (idx >= conn_list_cnt) {   /* no empties, create space */
58    CONN_LIST *tmp_conn_list = conn_list;
59
60    conn_list_cnt += CONN_LIST_INC;
61    if (conn_list) {
62      conn_list = (CONN_LIST *) Realloc (conn_list, /* extend */
63                                         conn_list_cnt * sizeof (CONN_LIST));
64    } else {
65      conn_list = (CONN_LIST *) Malloc (conn_list_cnt * sizeof (CONN_LIST));
66    }
67
68    if (!conn_list) {           /* unable to get space */
69      if ((conn_list_cnt -= CONN_LIST_INC)) {
70        /*
71         * was realloc, restore space
72         */
73        conn_list = tmp_conn_list;
74      }
75      return -1;                /* errno set by failed alloc */
76    }
77    /*
78     * clear newly created memory
79     */
80    memset (conn_list + idx, 0, CONN_LIST_INC * sizeof (CONN_LIST));
81  } else {                      /* clear new entry */
82    memset (conn_list + idx, 0, sizeof (CONN_LIST));
83  }
84  clst = conn_list + idx;
85
86  clst->in_use = True;          /* now in use */
87  clst->sender = sender;
88  memcpy (&clst->back_port, &in->back_port, sizeof (NET_OPAQUE));
89  memcpy (&clst->route, &in->destination, sizeof (NET_OPAQUE));
90  clst->debug_type = (UCHAR) in->debug_type;
91  clst->flags = in->flags;
92  strncpy (clst->user_name, in->user_name, NAMEMAX - 1);
93  clst->user_name[NAMEMAX - 1] = 0;
94
95  return idx;
96}
97
98    /*
99     *  ConnDelete - remove connection entry when shutdown.
100     *
101     */
102
103  void
104ConnDelete (int conn, struct svc_req *rqstp, close_control control)
105{
106  CONN_LIST *clst = conn_list + conn;
107  int idx;
108  Boolean prim;
109
110  if (!clst->in_use)
111    return;                     /* not active */
112
113  for (idx = 0; idx < pid_list_cnt; idx++) {
114    PID_LIST *plst = pid_list + idx;
115
116    if (!PIDMAP_TEST (conn, idx))
117      continue;
118
119    /*
120     * found a controlled pid
121     */
122    prim = (plst->primary_conn == conn) ? True : False;
123    TgtDetachCon (conn, idx, True);
124
125    /*
126     * if still running or alive, we use close control on it
127     */
128    if (!plst->pid)
129      continue;                 /* entry gone */
130
131    if (prim && control == CLOSE_KILL) {
132      /*
133       * kill off process
134       */
135      TgtKillAndDelete (plst, rqstp, True);
136    } else if (!plst->owners) {
137      /*
138       * no owners left
139       */
140      if (control == CLOSE_DETACH) {
141        TgtKillAndDelete (plst, rqstp, False);
142      }
143      if (control == CLOSE_DETACH || PROC_TERMINATED (plst)) {
144        TgtDelete (plst, conn, (control == CLOSE_DETACH) ? BMSG_DETACH : 0);
145      }
146    }
147  }
148  if (clst->list) {
149    Free (clst->list);          /* free allocated memory */
150  }
151  DPRINTF (("ConnDelete: Connection closed for port %u\n",
152            HL_W (*((UINT16 *) & clst->back_port.c[2]))));
153
154  clst->in_use = False;         /* free it back */
155}
Note: See TracBrowser for help on using the repository browser.