2 * $Id: dsi_getsess.c,v 1.3 2001-06-29 14:14:46 rufustfirefly Exp $
4 * Copyright (c) 1997 Adrian Sun (asun@zoology.washington.edu)
5 * All rights reserved. See COPYRIGHT.
10 #endif /* HAVE_CONFIG_H */
17 #endif /* HAVE_UNISTD_H */
18 #include <sys/types.h>
24 #include <atalk/dsi.h>
25 #include <atalk/server_child.h>
27 static server_child *children = NULL;
29 void dsi_kill(int sig)
32 server_child_kill(children, CHILD_DSIFORK, sig);
35 /* hand off the command. return child connection to the main program */
36 DSI *dsi_getsession(DSI *dsi, server_child *serv_children,
41 /* do a couple things on first entry */
43 if (!(children = serv_children))
48 switch (pid = dsi->proto_open(dsi)) {
50 /* if we fail, just return. it might work later */
51 syslog(LOG_ERR, "dsi_getsess: %m");
54 case 0: /* child. mostly handled below. */
59 /* using SIGQUIT is hokey, but the child might not have
60 * re-established its signal handler for SIGTERM yet. */
61 if (server_child_add(children, CHILD_DSIFORK, pid) < 0) {
62 syslog(LOG_ERR, "dsi_getsess: %m");
63 dsi->header.dsi_flags = DSIFL_REPLY;
64 dsi->header.dsi_code = DSIERR_SERVBUSY;
66 dsi->header.dsi_code = DSIERR_OK;
70 dsi->proto_close(dsi);
74 /* child: check number of open connections. this is one off the
76 if ((children->count >= children->nsessions) &&
77 (dsi->header.dsi_command == DSIFUNC_OPEN)) {
78 syslog(LOG_INFO, "dsi_getsess: too many connections");
79 dsi->header.dsi_flags = DSIFL_REPLY;
80 dsi->header.dsi_code = DSIERR_TOOMANY;
85 /* get rid of some stuff */
86 close(dsi->serversock);
87 server_child_free(children);
90 switch (dsi->header.dsi_command) {
91 case DSIFUNC_STAT: /* send off status and return */
93 /* OpenTransport 1.1.2 bug workaround:
95 * OT code doesn't currently handle close sockets well. urk.
96 * the workaround: wait for the client to close its
97 * side. timeouts prevent indefinite resource use.
100 static struct timeval timeout = {120, 0};
106 FD_SET(dsi->socket, &readfds);
108 select(FD_SETSIZE, &readfds, NULL, NULL, &timeout);
113 case DSIFUNC_OPEN: /* setup session */
114 /* set up the tickle timer */
115 dsi->timer.it_interval.tv_sec = dsi->timer.it_value.tv_sec = tickleval;
116 dsi->timer.it_interval.tv_usec = dsi->timer.it_value.tv_usec = 0;
117 signal(SIGPIPE, SIG_IGN); /* we catch these ourselves */
118 dsi_opensession(dsi);
122 default: /* just close */
123 syslog(LOG_INFO, "DSIUnknown %d", dsi->header.dsi_command);
124 dsi->proto_close(dsi);