]> code.citadel.org Git - citadel.git/blobdiff - citadel/serv_extensions.c
* if we're shutting down instantly close our server file descriptions
[citadel.git] / citadel / serv_extensions.c
index 0617cce0a750a0622258352736915230c5acdb35..54eaecd536a4233921a9ca72cefd15ad9b0be69f 100644 (file)
@@ -1,9 +1,6 @@
 /*
- * $Id$
- *
  * Citadel Dynamic Loading Module
  * Written by Brian Costello <btx@calyx.net>
- *
  */
 
 #include "sysdep.h"
@@ -727,12 +724,11 @@ void CtdlRegisterServiceHook(int tcp_port,
 {
        struct ServiceFunctionHook *newfcn;
        char *message;
-       char *error;
+       char error[SIZ];
 
-       error = NULL;
-       newfcn = (struct ServiceFunctionHook *)
-           malloc(sizeof(struct ServiceFunctionHook));
-       message = (char*) malloc (SIZ);
+       strcpy(error, "");
+       newfcn = (struct ServiceFunctionHook *) malloc(sizeof(struct ServiceFunctionHook));
+       message = (char*) malloc (SIZ + SIZ);
        
        newfcn->next = ServiceHookTable;
        newfcn->tcp_port = tcp_port;
@@ -743,7 +739,7 @@ void CtdlRegisterServiceHook(int tcp_port,
        newfcn->ServiceName = ServiceName;
 
        if (sockpath != NULL) {
-               newfcn->msock = ig_uds_server(sockpath, config.c_maxsessions, &error);
+               newfcn->msock = ctdl_uds_server(sockpath, config.c_maxsessions, error);
                snprintf(message, SIZ, "Unix domain socket '%s': ", sockpath);
        }
        else if (tcp_port <= 0) {       /* port -1 to disable */
@@ -753,10 +749,10 @@ void CtdlRegisterServiceHook(int tcp_port,
                return;
        }
        else {
-               newfcn->msock = ig_tcp_server(config.c_ip_addr,
+               newfcn->msock = ctdl_tcp_server(config.c_ip_addr,
                                              tcp_port,
                                              config.c_maxsessions, 
-                                             &error);
+                                             error);
                snprintf(message, SIZ, "TCP port %s:%d: (%s) ", 
                         config.c_ip_addr, tcp_port, ServiceName);
        }
@@ -785,7 +781,8 @@ void CtdlUnregisterServiceHook(int tcp_port, char *sockpath,
 {
        struct ServiceFunctionHook *cur, *p;
 
-       for (cur = ServiceHookTable; cur != NULL; cur = cur->next) {
+       cur = ServiceHookTable;
+       while (cur != NULL) {
                /* This will also remove duplicates if any */
                while (cur != NULL &&
                                !(sockpath && cur->sockpath &&
@@ -813,6 +810,32 @@ void CtdlUnregisterServiceHook(int tcp_port, char *sockpath,
        }
 }
 
+
+void CtdlShutdownServiceHooks(void)
+{
+       /* sort of a duplicate of close_masters() but called earlier */
+       struct ServiceFunctionHook *cur;
+
+       cur = ServiceHookTable;
+       while (cur != NULL) 
+       {
+               if (cur->msock != -1)
+               {
+                       close(cur->msock);
+                       cur->msock = -1;
+                       if (cur->sockpath != NULL){
+                               CtdlLogPrintf(CTDL_INFO, "[%s] Closed UNIX domain socket %s\n",
+                                             cur->ServiceName,
+                                             cur->sockpath);
+                       } else {
+                               CtdlLogPrintf(CTDL_INFO, "[%s] closing service\n", 
+                                             cur->ServiceName);
+                       }
+               }
+               cur = cur->next;
+       }
+}
+
 void CtdlDestroyServiceHook(void)
 {
        struct ServiceFunctionHook *cur, *p;