Massively cleaned up #include's, so they're in a consistent
[freeradius.git] / src / modules / rlm_sql / sql.c
index b79700b..72c164b 100644 (file)
 #include <freeradius-devel/ident.h>
 RCSID("$Id$")
 
-#include       <freeradius-devel/autoconf.h>
+#include       <freeradius-devel/radiusd.h>
 
-#include       <sys/types.h>
-#include       <sys/socket.h>
-#include       <sys/time.h>
 #include       <sys/file.h>
-#include       <string.h>
 #include       <sys/stat.h>
-#include       <netinet/in.h>
 
-#include       <stdio.h>
-#include       <stdlib.h>
-#include       <netdb.h>
 #include       <pwd.h>
-#include       <time.h>
 #include       <ctype.h>
-#include       <unistd.h>
 #include       <signal.h>
-#include       <errno.h>
 #include       <sys/wait.h>
 
-#include       <freeradius-devel/radiusd.h>
 #include       "rlm_sql.h"
 
 #ifdef HAVE_PTHREAD_H
@@ -484,7 +472,9 @@ int rlm_sql_query(SQLSOCK *sqlsocket, SQL_INST *inst, char *query)
 
        if (ret == SQL_DOWN) {
                /* close the socket that failed */
-               (inst->module->sql_close)(sqlsocket, inst->config);
+               if (sqlsocket->state == sockconnected) {
+                       (inst->module->sql_close)(sqlsocket, inst->config);
+               }
 
                /* reconnect the socket */
                if (connect_single_socket(sqlsocket, inst) < 0) {
@@ -527,7 +517,9 @@ int rlm_sql_select_query(SQLSOCK *sqlsocket, SQL_INST *inst, char *query)
 
        if (ret == SQL_DOWN) {
                /* close the socket that failed */
-               (inst->module->sql_close)(sqlsocket, inst->config);
+               if (sqlsocket->state == sockconnected) {
+                       (inst->module->sql_close)(sqlsocket, inst->config);
+               }
 
                /* reconnect the socket */
                if (connect_single_socket(sqlsocket, inst) < 0) {