]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/lib/bnet_server.c
Use the command line utility dropdb instead of the psql command
[bacula/bacula] / bacula / src / lib / bnet_server.c
index 9798fb6f7a6ad669ffc4268be0f58650a3e50d40..308ef2c87e0cb3be1606997b2ceb5c2476ff2f05 100644 (file)
@@ -25,6 +25,7 @@
   */
 
 #include "bacula.h"
+#undef DEV_BSIZE
 #include <netinet/in.h>
 #include <sys/socket.h>
 #include <arpa/inet.h>
@@ -36,6 +37,7 @@
 #include <resolv.h>
 #endif
 
+
 static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
 
 #ifdef HAVE_LIBWRAP
@@ -70,7 +72,7 @@ bnet_thread_server(char *bind_addr, int port, int max_clients, workq_t *client_w
         tlog = 60; 
          Emsg1(M_ERROR, 0, _("Cannot open stream socket: %s. Retrying ...\n"), strerror(errno));
       }
-      sleep(10);
+      bmicrosleep(10, 0);
    }
 
    /*
@@ -106,7 +108,7 @@ bnet_thread_server(char *bind_addr, int port, int max_clients, workq_t *client_w
         tlog = 2*60;                 /* Complain every 2 minutes */
          Emsg2(M_WARNING, 0, _("Cannot bind port %d: %s. Retrying ...\n"), port, strerror(errno));
       }
-      sleep(5);
+      bmicrosleep(5, 0);
       if (--tmax <= 0) {
          Emsg2(M_ABORT, 0, _("Cannot bind port %d: %s.\n"), port, strerror(errno));
       }
@@ -126,17 +128,23 @@ bnet_thread_server(char *bind_addr, int port, int max_clients, workq_t *client_w
        * Wait for a connection from a client process.
        */
       ready = sockset;
-      if ((stat = select(sockfd+1, &ready, NULL, NULL, NULL)) < 0) {
-        if (errno == EINTR || errno == EAGAIN) {
-           errno = 0;
-           continue;
-        }
+      do {
+        errno = 0;
+        stat = select(sockfd+1, &ready, NULL, NULL, NULL);       
+      } while(stat == -1 && (errno == EINTR || errno == EAGAIN));
+      if (stat < 0) {
         close(sockfd);
          Emsg1(M_FATAL, 0, _("Error in select: %s\n"), strerror(errno));
         break;
       }
-      clilen = sizeof(cli_addr);
-      newsockfd = accept(sockfd, (struct sockaddr *)&cli_addr, &clilen);
+      do {
+        clilen = sizeof(cli_addr);
+        errno = 0;
+        newsockfd = accept(sockfd, (struct sockaddr *)&cli_addr, &clilen);
+      } while (newsockfd < 0 && (errno == EINTR || errno == EAGAIN));
+      if (newsockfd < 0) {
+        continue;
+      }
 
 #ifdef HAVE_LIBWRAP
       P(mutex);                      /* hosts_access is not thread safe */
@@ -166,9 +174,13 @@ bnet_thread_server(char *bind_addr, int port, int max_clients, workq_t *client_w
          caller = "unknown client";
       }
 
+      BSOCK *bs = init_bsock(NULL, newsockfd, "client", caller, port);
+      if (bs == NULL) {
+         Jmsg0(NULL, M_ABORT, 0, _("Could not create client BSOCK.\n"));
+      }
+
       /* Queue client to be served */
-      if ((stat = workq_add(client_wq, 
-            (void *)init_bsock(NULL, newsockfd, "client", caller, port), NULL, 0)) != 0) {
+      if ((stat = workq_add(client_wq, (void *)bs, NULL, 0)) != 0) {
         V(mutex);
          Jmsg1(NULL, M_ABORT, 0, _("Could not add job to client queue: ERR=%s\n"), strerror(stat));
       }
@@ -194,11 +206,14 @@ bnet_bind(int port)
     * Open a TCP socket  
     */
    for (tlog=0; (sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0; tlog -= 10 ) {
+      if (errno == EINTR) {
+        continue;
+      }
       if (tlog <= 0) {
         tlog = 2*60; 
          Emsg1(M_ERROR, 0, _("Cannot open stream socket: %s\n"), strerror(errno));
       }
-      sleep(60);
+      bmicrosleep(60, 0);
    }
 
    /*
@@ -217,11 +232,14 @@ bnet_bind(int port)
    serv_addr.sin_port = htons(port);
 
    for (tlog=0; bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0; tlog -= 5 ) {
+      if (errno == EINTR) {
+        continue;
+      }
       if (tlog <= 0) {
         tlog = 2*60;
          Emsg2(M_WARNING, 0, _("Cannot bind port %d: %s: retrying ...\n"), port, strerror(errno));
       }
-      sleep(5);
+      bmicrosleep(5, 0);
    }
    listen(sockfd, 1);                /* tell system we are ready */
    return init_bsock(NULL, sockfd, _("Server socket"), _("client"), port);
@@ -264,9 +282,13 @@ bnet_accept(BSOCK *bsock, char *who)
         newsockfd = -1;
         break;
       }
-      clilen = sizeof(cli_addr);
-      newsockfd = accept(bsock->fd, (struct sockaddr *)&cli_addr, &clilen);
-      break;
+      do {
+        clilen = sizeof(cli_addr);
+        newsockfd = accept(bsock->fd, (struct sockaddr *)&cli_addr, &clilen);
+      } while (newsockfd < 0 && errno == EINTR);
+      if (newsockfd >= 0) {
+        break;
+      }
    }
 
 #ifdef HAVE_LIBWRAP