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>
27 extern int auth_001(), inst_001();
28 extern int xfer_002(), exec_002();
30 extern int sync_proc(), quit();
32 extern void gdb_debug();
33 extern int exit(), abort(), errno;
34 extern STRING instructions;
40 int have_authorization = 0;
42 int have_instructions = 0;
47 (_send_int=(n),send_object(conn,(char *)&_send_int,INTEGER_T))
53 } dispatch_table[] = {
54 { "INST_001", inst_001 },
55 { "AUTH_001", auth_001 },
56 { "XFER_002", xfer_002 },
57 { "EXEC_002", exec_002 },
59 { (char *)NULL, abort }
63 * general scratch space -- useful for building
64 * error messages et al...
71 sprintf(buf, fmt, error_message(code));
84 gdb_debug(GDB_NOFORK);
87 whoami = rindex(argv[0], '/');
93 /* interpret arguments here */
95 fprintf(stderr, "Usage: %s\n", whoami);
98 /* well, sort of... */
103 n = open("/dev/tty", O_RDWR|O_NDELAY);
105 (void) ioctl(n, TIOCNOTTY, (char *)NULL);
113 sms_update_initialize();
115 /* wait for connection */
117 conn = create_forking_server(SERVICE_NAME, 0);
119 err(errno, "%s: can't get connection");
122 if (connection_status(conn) == CON_STOPPED) {
123 com_err(whoami, connection_errno(conn), ": can't get connection");
127 sms_log_info("got connection");
128 /* got a connection; loop forever */
131 code = receive_object(conn, (char *)&str, STRING_T);
133 err(connection_errno(conn), "%s: receiving command");
134 sever_connection(conn);
137 cp = index(STRING_DATA(str), ' ');
140 for (d = dispatch_table; d->str; d++) {
141 if (!strcmp(d->str, STRING_DATA(str))) {
145 printf("got request: %s\n", STRING_DATA(str));
147 (void)(d->proc)(STRING_DATA(str));
151 sprintf(buf, "unknown request received: %s\n", STRING_DATA(str));
153 code = send_int(SMS_UNKNOWN_PROC);
155 err(connection_errno(conn), "%s: sending UNKNOWN_PROC");
166 return((code = send_object(conn, (char *)&zero, INTEGER_T)));
172 /* keep have_authorization around */
174 have_instructions = 0;
176 if (STRING_DATA(instructions) != (char *)NULL)
177 string_free(&instructions);
187 * any arguments are ignored
190 * closes connection from SMS
200 sever_connection(conn);
201 sms_log_info("Closing connection.");
209 * put <msg> to log as error, break connection, and exit
215 sprintf(buf, "%s: %s", error_message(code), msg);
218 sever_connection(conn);
225 * send back (external) <code>; if error, punt big with <lose(msg)>
231 code = send_object(conn, (char *)&code, INTEGER_T);
233 code = connection_errno(conn);
241 * set (external) <code> to <c> and call <report_error>
248 report_error("call rejected");