2 * Copyright (c) 1997 Adrian Sun (asun@zoology.washington.edu)
3 * All rights reserved. See COPYRIGHT.
10 #include <sys/types.h>
16 #include <atalk/dsi.h>
17 #include <atalk/server_child.h>
19 static server_child *children = NULL;
21 void dsi_kill(int sig)
24 server_child_kill(children, CHILD_DSIFORK, sig);
27 /* hand off the command. return child connection to the main program */
28 DSI *dsi_getsession(DSI *dsi, server_child *serv_children,
33 /* do a couple things on first entry */
35 if (!(children = serv_children))
40 switch (pid = dsi->proto_open(dsi)) {
42 /* if we fail, just return. it might work later */
43 syslog(LOG_ERR, "dsi_getsess: %m");
46 case 0: /* child. mostly handled below. */
51 /* using SIGQUIT is hokey, but the child might not have
52 * re-established its signal handler for SIGTERM yet. */
53 if (server_child_add(children, CHILD_DSIFORK, pid) < 0) {
54 syslog(LOG_ERR, "dsi_getsess: %m");
55 dsi->header.dsi_flags = DSIFL_REPLY;
56 dsi->header.dsi_code = DSIERR_SERVBUSY;
58 dsi->header.dsi_code = DSIERR_OK;
62 dsi->proto_close(dsi);
66 /* child: check number of open connections. this is one off the
68 if ((children->count >= children->nsessions) &&
69 (dsi->header.dsi_command == DSIFUNC_OPEN)) {
70 syslog(LOG_INFO, "dsi_getsess: too many connections");
71 dsi->header.dsi_flags = DSIFL_REPLY;
72 dsi->header.dsi_code = DSIERR_TOOMANY;
77 /* get rid of some stuff */
78 close(dsi->serversock);
79 server_child_free(children);
82 switch (dsi->header.dsi_command) {
83 case DSIFUNC_STAT: /* send off status and return */
85 /* OpenTransport 1.1.2 bug workaround:
87 * OT code doesn't currently handle close sockets well. urk.
88 * the workaround: wait for the client to close its
89 * side. timeouts prevent indefinite resource use.
92 static struct timeval timeout = {120, 0};
98 FD_SET(dsi->socket, &readfds);
100 select(FD_SETSIZE, &readfds, NULL, NULL, &timeout);
105 case DSIFUNC_OPEN: /* setup session */
106 /* set up the tickle timer */
107 dsi->timer.it_interval.tv_sec = dsi->timer.it_value.tv_sec = tickleval;
108 dsi->timer.it_interval.tv_usec = dsi->timer.it_value.tv_usec = 0;
109 signal(SIGPIPE, SIG_IGN); /* we catch these ourselves */
110 dsi_opensession(dsi);
114 default: /* just close */
115 syslog(LOG_INFO, "DSIUnknown %d", dsi->header.dsi_command);
116 dsi->proto_close(dsi);