2 * $Id: dsi_getsess.c,v 1.4 2001-08-15 02:18:57 srittau Exp $
4 * Copyright (c) 1997 Adrian Sun (asun@zoology.washington.edu)
5 * All rights reserved. See COPYRIGHT.
10 #endif /* HAVE_CONFIG_H */
18 #endif /* HAVE_UNISTD_H */
19 #include <sys/types.h>
25 #include <atalk/dsi.h>
26 #include <atalk/server_child.h>
28 static server_child *children = NULL;
30 void dsi_kill(int sig)
33 server_child_kill(children, CHILD_DSIFORK, sig);
36 /* hand off the command. return child connection to the main program */
37 DSI *dsi_getsession(DSI *dsi, server_child *serv_children,
42 /* do a couple things on first entry */
44 if (!(children = serv_children))
49 switch (pid = dsi->proto_open(dsi)) {
51 /* if we fail, just return. it might work later */
52 syslog(LOG_ERR, "dsi_getsess: %s", strerror(errno));
55 case 0: /* child. mostly handled below. */
60 /* using SIGQUIT is hokey, but the child might not have
61 * re-established its signal handler for SIGTERM yet. */
62 if (server_child_add(children, CHILD_DSIFORK, pid) < 0) {
63 syslog(LOG_ERR, "dsi_getsess: %s", strerror(errno));
64 dsi->header.dsi_flags = DSIFL_REPLY;
65 dsi->header.dsi_code = DSIERR_SERVBUSY;
67 dsi->header.dsi_code = DSIERR_OK;
71 dsi->proto_close(dsi);
75 /* child: check number of open connections. this is one off the
77 if ((children->count >= children->nsessions) &&
78 (dsi->header.dsi_command == DSIFUNC_OPEN)) {
79 syslog(LOG_INFO, "dsi_getsess: too many connections");
80 dsi->header.dsi_flags = DSIFL_REPLY;
81 dsi->header.dsi_code = DSIERR_TOOMANY;
86 /* get rid of some stuff */
87 close(dsi->serversock);
88 server_child_free(children);
91 switch (dsi->header.dsi_command) {
92 case DSIFUNC_STAT: /* send off status and return */
94 /* OpenTransport 1.1.2 bug workaround:
96 * OT code doesn't currently handle close sockets well. urk.
97 * the workaround: wait for the client to close its
98 * side. timeouts prevent indefinite resource use.
101 static struct timeval timeout = {120, 0};
107 FD_SET(dsi->socket, &readfds);
109 select(FD_SETSIZE, &readfds, NULL, NULL, &timeout);
114 case DSIFUNC_OPEN: /* setup session */
115 /* set up the tickle timer */
116 dsi->timer.it_interval.tv_sec = dsi->timer.it_value.tv_sec = tickleval;
117 dsi->timer.it_interval.tv_usec = dsi->timer.it_value.tv_usec = 0;
118 signal(SIGPIPE, SIG_IGN); /* we catch these ourselves */
119 dsi_opensession(dsi);
123 default: /* just close */
124 syslog(LOG_INFO, "DSIUnknown %d", dsi->header.dsi_command);
125 dsi->proto_close(dsi);