void (*h_command_function) (void) )
{
struct ServiceFunctionHook *newfcn;
+ char message[256];
newfcn = (struct ServiceFunctionHook *)
mallok(sizeof(struct ServiceFunctionHook));
if (sockpath != NULL) {
newfcn->msock = ig_uds_server(sockpath, config.c_maxsessions);
+ sprintf(message, "Unix domain socket %s: ", sockpath);
}
- else if (tcp_port < 0) { /* port -1 to disable */
+ else if (tcp_port <= 0) { /* port -1 to disable */
lprintf(7, "Service has been manually disabled, skipping\n");
phree(newfcn);
return;
}
else {
newfcn->msock = ig_tcp_server(tcp_port, config.c_maxsessions);
+ sprintf(message, "TCP port %d: ", tcp_port);
}
- if (newfcn->msock >= 0) {
+ if (newfcn->msock > 0) {
ServiceHookTable = newfcn;
- lprintf(5, "Registered a new service (TCP port %d)\n",
- tcp_port);
+ strcat(message, "registered.");
+ lprintf(5, "%s\n", message);
}
else {
- lprintf(2, "ERROR: could not bind to TCP port %d.\n",
- tcp_port);
+ strcat(message, "FAILED.");
+ lprintf(2, "%s\n", message);
phree(newfcn);
}
}
{
struct sockaddr_un addr;
int s;
+ int i;
- unlink(sockpath);
+ i = unlink(sockpath);
+ if (i != 0) if (errno != ENOENT) {
+ lprintf(1, "citserver: can't unlink %s: %s\n",
+ sockpath, strerror(errno));
+ return(-1);
+ }
memset(&addr, 0, sizeof(addr));
addr.sun_family = AF_UNIX;
+/*
+ * Set up a fd_set containing all the master sockets to which we
+ * always listen. It's computationally less expensive to just copy
+ * this to a local fd_set when starting a new select() and then add
+ * the client sockets than it is to initialize a new one and then
+ * figure out what to put there.
+ */
+void init_master_fdset(void) {
+ struct ServiceFunctionHook *serviceptr;
+ int m;
+
+ lprintf(9, "Initializing master fdset\n");
+
+ FD_ZERO(&masterfds);
+ masterhighest = 0;
+ lprintf(9, "Will listen on rescan pipe %d\n", rescan[0]);
+ FD_SET(rescan[0], &masterfds);
+ if (rescan[0] > masterhighest) masterhighest = rescan[0];
+
+ for (serviceptr = ServiceHookTable; serviceptr != NULL;
+ serviceptr = serviceptr->next ) {
+ m = serviceptr->msock;
+ lprintf(9, "Will listen on master socket %d\n", m);
+ FD_SET(m, &masterfds);
+ if (m > masterhighest) {
+ masterhighest = m;
+ }
+ }
+ lprintf(9, "masterhighest = %d\n", masterhighest);
+}
+
+
+
/*
* Here's where it all begins.
*/
struct passwd *pw;
int drop_root_perms = 1;
char *moddir;
- struct ServiceFunctionHook *serviceptr;
/* specify default port name and trace file */
strcpy(tracefile, "");
exit(errno);
}
- /*
- * Set up a fd_set containing all the master sockets to which we
- * always listen. It's computationally less expensive to just copy
- * this to a local fd_set when starting a new select() and then add
- * the client sockets than it is to initialize a new one and then
- * figure out what to put there.
- */
- FD_ZERO(&masterfds);
- masterhighest = 0;
- FD_SET(rescan[0], &masterfds);
- if (rescan[0] > masterhighest) masterhighest = rescan[0];
-
- for (serviceptr = ServiceHookTable; serviceptr != NULL;
- serviceptr = serviceptr->next ) {
- lprintf(9, "Will listen on master socket %d\n",
- serviceptr->msock);
- FD_SET(serviceptr->msock, &masterfds);
- if (serviceptr->msock > masterhighest) {
- masterhighest = serviceptr->msock;
- }
- }
-
+ init_master_fdset();
/*
* Now that we've bound the sockets, change to the BBS user id and its