5 /* (c) Copyright 1988 by the Massachusetts Institute of Technology. */
6 /* For copying and distribution information, please see the file */
7 /* <mit-copyright.h>. */
10 static char *rcsid_dispatch_c = "$Header$";
13 #include <mit-copyright.h>
20 #include <sys/ioctl.h>
23 extern int auth_001(), inst_001();
24 extern int xfer_002(), exec_002();
26 extern int sync_proc(), quit();
28 extern void gdb_debug();
29 extern int exit(), abort(), errno;
30 extern STRING instructions;
36 int have_authorization = 0;
38 int have_instructions = 0;
43 (_send_int=(n),send_object(conn,(char *)&_send_int,INTEGER_T))
49 } dispatch_table[] = {
50 { "INST_001", inst_001 },
51 { "AUTH_001", auth_001 },
52 { "XFER_002", xfer_002 },
53 { "EXEC_002", exec_002 },
55 { (char *)NULL, abort }
59 * general scratch space -- useful for building
60 * error messages et al...
67 sprintf(buf, fmt, error_message(code));
80 gdb_debug(GDB_NOFORK);
83 whoami = rindex(argv[0], '/');
89 /* interpret arguments here */
91 fprintf(stderr, "Usage: %s\n", whoami);
94 /* well, sort of... */
99 n = open("/dev/tty", O_RDWR|FNDELAY);
101 (void) ioctl(n, TIOCNOTTY, (char *)NULL);
107 initialize_sms_error_table();
108 initialize_krb_error_table();
109 mr_update_initialize();
111 /* wait for connection */
113 conn = create_forking_server(SERVICE_NAME, 0);
115 err(errno, "%s: can't get connection");
118 if (connection_status(conn) == CON_STOPPED) {
119 com_err(whoami, connection_errno(conn), ": can't get connection");
123 mr_log_info("got connection");
124 /* got a connection; loop forever */
127 code = receive_object(conn, (char *)&str, STRING_T);
129 err(connection_errno(conn), "%s: receiving command");
130 sever_connection(conn);
133 cp = index(STRING_DATA(str), ' ');
136 for (d = dispatch_table; d->str; d++) {
137 if (!strcmp(d->str, STRING_DATA(str))) {
141 printf("got request: %s\n", STRING_DATA(str));
143 (void)(d->proc)(STRING_DATA(str));
147 sprintf(buf, "unknown request received: %s\n", STRING_DATA(str));
149 code = send_int(MR_UNKNOWN_PROC);
151 err(connection_errno(conn), "%s: sending UNKNOWN_PROC");
162 return((code = send_object(conn, (char *)&zero, INTEGER_T)));
168 /* keep have_authorization around */
170 have_instructions = 0;
172 if (STRING_DATA(instructions) != (char *)NULL)
173 string_free(&instructions);
183 * any arguments are ignored
186 * closes connection from MR
196 sever_connection(conn);
197 mr_log_info("Closing connection.");
205 * put <msg> to log as error, break connection, and exit
211 sprintf(buf, "%s: %s", error_message(code), msg);
214 sever_connection(conn);
221 * send back (external) <code>; if error, punt big with <lose(msg)>
227 code = send_object(conn, (char *)&code, INTEGER_T);
229 code = connection_errno(conn);
237 * set (external) <code> to <c> and call <report_error>
244 report_error("call rejected");