]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/lib/bnet.c
- Add user supplied patch to add inet_aton() of old Solaris
[bacula/bacula] / bacula / src / lib / bnet.c
index b1dc54e9ac4ef971dc606751f9906957fb783c26..bf8fe9d457bdfdad2db0d42423f30bc4e108a3f7 100644 (file)
@@ -54,6 +54,19 @@ extern time_t watchdog_time;
 #endif
 
 
+#ifdef HAVE_OLD_SOCKOPT
+int inet_aton(const char *cp, struct in_addr *inp)
+{
+   struct in_addr inaddr;
+
+   if((inaddr.s_addr = inet_addr(cp)) != INADDR_NONE) {
+      inp->s_addr = inaddr.s_addr;
+      return 1;
+   }
+   return 0;
+}
+#endif
+
 /*
  * Read a nbytes from the network.
  * It is possible that the total bytes require in several
@@ -95,9 +108,11 @@ static int32_t write_nbytes(BSOCK * bsock, char *ptr, int32_t nbytes)
       nwritten = fwrite(ptr, 1, nbytes, bsock->spool_fd);
       if (nwritten != nbytes) {
         berrno be;
+        bsock->b_errno = errno;
          Qmsg1(bsock->jcr, M_FATAL, 0, _("Attr spool write error. ERR=%s\n"),
               be.strerror());
          Dmsg2(400, "nwritten=%d nbytes=%d.\n", nwritten, nbytes);
+        errno = bsock->b_errno;
         return -1;
       }
       return nbytes;
@@ -160,6 +175,7 @@ int32_t bnet_recv(BSOCK * bsock)
 
    ASSERT(bsock != NULL);
    bsock->msg[0] = 0;
+   bsock->msglen = 0;
    if (bsock->errors || bsock->terminated) {
       return BNET_HARDEOF;
    }
@@ -334,8 +350,8 @@ int bnet_despool_to_bsock(BSOCK * bsock, void update_attr_spool_size(ssize_t siz
  * two network packets. The first is sends a 32 bit integer containing
  * the length of the data packet which follows.
  *
- * Returns: 0 on failure
- *         1 on success
+ * Returns: false on failure
+ *         true  on success
  */
 bool bnet_send(BSOCK * bsock)
 {
@@ -701,10 +717,9 @@ static BSOCK *bnet_open(JCR * jcr, const char *name, char *host, char *service,
         continue;
       }
       /*
-       * Receive notification when connection dies.
+       * Keep socket from timing out from inactivity
        */
-      if (setsockopt(sockfd, SOL_SOCKET, SO_KEEPALIVE, (sockopt_val_t) & turnon,
-          sizeof(turnon)) < 0) {
+      if (setsockopt(sockfd, SOL_SOCKET, SO_KEEPALIVE, (sockopt_val_t)&turnon, sizeof(turnon)) < 0) {
         berrno be;
          Qmsg1(jcr, M_WARNING, 0, _("Cannot set SO_KEEPALIVE on socket: %s\n"),
               be.strerror());
@@ -725,6 +740,15 @@ static BSOCK *bnet_open(JCR * jcr, const char *name, char *host, char *service,
       errno = save_errno;
       return NULL;
    }
+   /*
+    * Keep socket from timing out from inactivity
+    *  Do this a second time out of paranoia
+    */
+   if (setsockopt(sockfd, SOL_SOCKET, SO_KEEPALIVE, (sockopt_val_t)&turnon, sizeof(turnon)) < 0) {
+      berrno be;
+      Qmsg1(jcr, M_WARNING, 0, _("Cannot set SO_KEEPALIVE on socket: %s\n"),
+           be.strerror());
+   }
    BSOCK* ret =  init_bsock(jcr, sockfd, name, host, port, ipaddr->get_sockaddr());
    free_addresses(addr_list);
    return ret;
@@ -771,9 +795,14 @@ Retrying ...\n", name, host, port, be.strerror());
  * Return the string for the error that occurred
  * on the socket. Only the first error is retained.
  */
-char *bnet_strerror(BSOCK * bsock)
+const char *bnet_strerror(BSOCK * bsock)
 {
-   return strerror(bsock->b_errno);
+   berrno be;
+   if (bsock->errmsg == NULL) {
+      bsock->errmsg = get_pool_memory(PM_MESSAGE);
+   }
+   pm_strcpy(bsock->errmsg, be.strerror(bsock->b_errno));
+   return bsock->errmsg;
 }
 
 /*