From bb827dbd7f8f7421aace966d6c29e42399d01fbd Mon Sep 17 00:00:00 2001 From: Meno Abels Date: Thu, 12 Aug 2004 22:13:51 +0000 Subject: [PATCH] !!! I didn't run the regression tests.!!! 1. Find and fix the memory leak (most likely in address_conf.c) in address_conf there was no memory leak-:) the parser calls my init_default_addresses but also resets the datastructurs by memset so allocated resource will be lost. I added the pass number to init_defaults so that i could call my init_default only once per server. 2. Find some why to have smartalloc work correctly with new. *Please* note, you cannot simply put everything on SMARTALLOC -- this will not work because some of the delete's *must* de-allocate all the items in the list. I.e. by default, my lists own the list items. There was a missing brace in the use of my new operator to write new(fname, line) Type in the define. And also there was some operator definitions in dlist,alist,htable which causes that trouble. I only added the SMARTALLOC to all classes these are generated by new and removed by delete. 3. I believe I've fixed the byte order problem by modifying get_port(). However, if you turn on the debug statement at the top of init_bnet() src/lib/bnet.c:917 by setting the 100 to 000, you will see that the host address is not correct in all cases. Kern and I decided to add get_port_net_order get_port_host_order get_first_port_net_order get_first_port_host_order to the code. 4. Eliminate the use of inet_addr() -- it is deprecated. Done 5. Check the SetIP command in src/dir/fd_cmds.c fixed mixup of sockaddr and in_addr 6. There is too much #ifdefing in the code to deal with IPv4 and IPv6 I don't mind it in bnet.c and bnet_server.c (too much), but we should try to eliminate it elsewhere. I cleaned it up. Is this too much yes it is but, we can't reach the heaven in one day-:) ./lib/address_conf.c:#ifdef HAVE_IPV6 ./lib/address_conf.c:#ifdef HAVE_IPV6 ./lib/address_conf.c:#ifdef HAVE_IPV6 ./lib/address_conf.c:#ifdef HAVE_IPV6 ./lib/address_conf.c:#ifdef HAVE_IPV6 ./lib/address_conf.c:#ifdef HAVE_IPV6 ./lib/address_conf.c:#ifdef HAVE_IPV6 ./lib/address_conf.c:#ifdef HAVE_IPV6 ./lib/address_conf.c:#ifdef HAVE_IPV6 ./lib/address_conf.c:#ifdef HAVE_IPV6 ./lib/address_conf.c:#if defined(HAVE_INET_NTOP) && defined(HAVE_IPV6) ./lib/address_conf.c:#ifdef HAVE_IPV6 ./lib/address_conf.c:#ifdef HAVE_INET_NTOP ./lib/address_conf.h:#ifdef HAVE_IPV6 ./lib/address_conf.h:#ifdef HAVE_IPV6 ./lib/address_conf.h:#ifdef HAVE_IPV6 ./lib/bnet.c:#ifdef HAVE_IPV6 ./lib/bnet.c:#ifdef HAVE_IPV6 ./lib/bnet.c:#ifdef HAVE_IPV6 ./lib/bnet.c:#ifdef HAVE_IPV6 ./lib/bnet.c:#ifdef HAVE_IPV6 ./lib/bnet_server.c:#ifndef HAVE_INET_NTOP ./lib/bnet_server.c:#ifdef HAVE_INET_NTOP git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@1517 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/dird/dird.c | 8 ++-- bacula/src/dird/dird_conf.c | 2 +- bacula/src/dird/ua_cmds.c | 14 ++----- bacula/src/filed/filed.c | 20 ++++------ bacula/src/filed/filed_conf.c | 3 +- bacula/src/lib/address_conf.c | 71 +++++++++++++++++++++++++-------- bacula/src/lib/address_conf.h | 16 ++++++-- bacula/src/lib/alist.h | 14 +------ bacula/src/lib/berrno.h | 2 +- bacula/src/lib/bnet.c | 16 ++++---- bacula/src/lib/bnet_server.c | 6 +-- bacula/src/lib/dlist.h | 20 +--------- bacula/src/lib/htable.h | 4 +- bacula/src/lib/parse_conf.c | 6 +-- bacula/src/lib/smartall.h | 3 +- bacula/src/stored/dev.c | 2 +- bacula/src/stored/read_record.c | 2 +- bacula/src/stored/stored.c | 8 ++-- bacula/src/stored/stored_conf.c | 8 ++-- 19 files changed, 111 insertions(+), 114 deletions(-) diff --git a/bacula/src/dird/dird.c b/bacula/src/dird/dird.c index 857701844a..be64a25307 100644 --- a/bacula/src/dird/dird.c +++ b/bacula/src/dird/dird.c @@ -214,8 +214,8 @@ int main (int argc, char *argv[]) } /* Create pid must come after we are a daemon -- so we have our final pid */ - create_pid_file(director->pid_directory, "bacula-dir", get_first_port(director->DIRaddrs)); - read_state_file(director->working_directory, "bacula-dir", get_first_port(director->DIRaddrs)); + create_pid_file(director->pid_directory, "bacula-dir", get_first_port_host_order(director->DIRaddrs)); + read_state_file(director->working_directory, "bacula-dir", get_first_port_host_order(director->DIRaddrs)); drop(uid, gid); /* reduce priveleges if requested */ @@ -257,8 +257,8 @@ static void terminate_dird(int sig) exit(1); } already_here = TRUE; - write_state_file(director->working_directory, "bacula-dir", get_first_port(director->DIRaddrs)); - delete_pid_file(director->pid_directory, "bacula-dir", get_first_port(director->DIRaddrs)); + write_state_file(director->working_directory, "bacula-dir", get_first_port_host_order(director->DIRaddrs)); + delete_pid_file(director->pid_directory, "bacula-dir", get_first_port_host_order(director->DIRaddrs)); // signal(SIGCHLD, SIG_IGN); /* don't worry about children now */ term_scheduler(); term_job_server(); diff --git a/bacula/src/dird/dird_conf.c b/bacula/src/dird/dird_conf.c index cf45f51fbc..4fe3b112ac 100644 --- a/bacula/src/dird/dird_conf.c +++ b/bacula/src/dird/dird_conf.c @@ -1207,7 +1207,7 @@ void store_acl(LEX *lc, RES_ITEM *item, int index, int pass) token = lex_get_token(lc, T_NAME); if (pass == 1) { if (((alist **)item->value)[item->code] == NULL) { - ((alist **)item->value)[item->code] = new alist(10, owned_by_alist); + ((alist **)item->value)[item->code] = New(alist(10, owned_by_alist)); // Dmsg1(900, "Defined new ACL alist at %d\n", item->code); } ((alist **)item->value)[item->code]->append(bstrdup(lc->str)); diff --git a/bacula/src/dird/ua_cmds.c b/bacula/src/dird/ua_cmds.c index f29f9d7a8b..6c46946015 100644 --- a/bacula/src/dird/ua_cmds.c +++ b/bacula/src/dird/ua_cmds.c @@ -564,8 +564,7 @@ static int create_cmd(UAContext *ua, const char *cmd) static int setip_cmd(UAContext *ua, const char *cmd) { CLIENT *client; - char mybuf[1024]; - char *buf = mybuf; + char buf[1024]; if (!ua->cons || !acl_access_ok(ua, Client_ACL, ua->cons->hdr.name)) { bsendmsg(ua, _("Illegal command from this console.\n")); return 1; @@ -580,15 +579,8 @@ static int setip_cmd(UAContext *ua, const char *cmd) if (client->address) { free(client->address); } -#ifdef HAVE_INET_NTOP - inet_ntop(ua->UA_sock->client_addr.sa_family, - &(ua->UA_sock->client_addr), buf, - ua->UA_sock->client_addr.sa_family == AF_INET ? - sizeof(sockaddr_in) : sizeof(sockaddr_in6)); -#else - buf = inet_ntoa(((struct sockaddr_in *)&(ua->UA_sock->client_addr))->sin_addr); -#endif - + /* MA Bug 6 remove ifdef */ + sockaddr_to_ascii(&(ua->UA_sock->client_addr), buf, sizeof(buf)); client->address = bstrdup(buf); bsendmsg(ua, _("Client \"%s\" address set to %s\n"), client->hdr.name, client->address); diff --git a/bacula/src/filed/filed.c b/bacula/src/filed/filed.c index 08131cc825..1223a9c5a0 100644 --- a/bacula/src/filed/filed.c +++ b/bacula/src/filed/filed.c @@ -220,8 +220,8 @@ Without that I don't know who I am :-(\n"), configfile); } /* Maximum 1 daemon at a time */ - create_pid_file(me->pid_directory, "bacula-fd", get_first_port(me->FDaddrs)); - read_state_file(me->working_directory, "bacula-fd", get_first_port(me->FDaddrs)); + create_pid_file(me->pid_directory, "bacula-fd", get_first_port_host_order(me->FDaddrs)); + read_state_file(me->working_directory, "bacula-fd", get_first_port_host_order(me->FDaddrs)); drop(uid, gid); @@ -243,14 +243,8 @@ Without that I don't know who I am :-(\n"), configfile); int port = -1; socklen_t client_addr_len = sizeof(client_addr); if (getsockname(0, &client_addr, &client_addr_len) == 0) { - if (client_addr.sa_family == AF_INET) { - port = ((struct sockaddr_in*)&client_addr)->sin_port; - } -#ifdef HAVE_IPV6 - else if (client_addr.sa_family == AF_INET6) { - port = ((struct sockaddr_in6*)&client_addr)->sin6_port; - } -#endif + /* MA BUG 6 remove ifdefs */ + port = sockaddr_get_port_net_order(&client_addr); } BSOCK *bs = init_bsock(NULL, 0, "client", "unknown client", port, &client_addr); handle_client_request((void *)bs); @@ -258,7 +252,7 @@ Without that I don't know who I am :-(\n"), configfile); /* Become server, and handle requests */ IPADDR *p; foreach_dlist(p, me->FDaddrs) { - Dmsg1(10, "filed: listening on port %d\n", ntohs(p->get_port())); + Dmsg1(10, "filed: listening on port %d\n", p->get_port_host_order()); } bnet_thread_server(me->FDaddrs, me->MaxConcurrentJobs, &dir_workq, handle_client_request); } @@ -270,8 +264,8 @@ Without that I don't know who I am :-(\n"), configfile); void terminate_filed(int sig) { bnet_stop_thread_server(server_tid); - write_state_file(me->working_directory, "bacula-fd", get_first_port(me->FDaddrs)); - delete_pid_file(me->pid_directory, "bacula-fd", get_first_port(me->FDaddrs)); + write_state_file(me->working_directory, "bacula-fd", get_first_port_host_order(me->FDaddrs)); + delete_pid_file(me->pid_directory, "bacula-fd", get_first_port_host_order(me->FDaddrs)); if (configfile != NULL) { free(configfile); } diff --git a/bacula/src/filed/filed_conf.c b/bacula/src/filed/filed_conf.c index 5e8d964c19..319eef943f 100644 --- a/bacula/src/filed/filed_conf.c +++ b/bacula/src/filed/filed_conf.c @@ -145,7 +145,7 @@ void dump_resource(int type, RES *reshdr, void sendit(void *sock, const char *fm break; case R_CLIENT: sendit(sock, "Client: name=%s FDport=%d\n", reshdr->name, - get_first_port(res->res_client.FDaddrs)); + get_first_port_host_order(res->res_client.FDaddrs)); break; case R_MSGS: sendit(sock, "Messages: name=%s\n", res->res_msgs.hdr.name); @@ -185,7 +185,6 @@ void free_resource(RES *sres, int type) if (res->res_dir.hdr.desc) { free(res->res_dir.hdr.desc); } - switch (type) { case R_DIRECTOR: if (res->res_dir.password) { diff --git a/bacula/src/lib/address_conf.c b/bacula/src/lib/address_conf.c index 443d37ed2b..884c8d3e74 100644 --- a/bacula/src/lib/address_conf.c +++ b/bacula/src/lib/address_conf.c @@ -81,7 +81,7 @@ IPADDR::i_type IPADDR::get_type() const return type; } -unsigned short IPADDR::get_port() const +unsigned short IPADDR::get_port_net_order() const { unsigned short port = 0; if (saddr->sa_family == AF_INET) { @@ -95,7 +95,7 @@ unsigned short IPADDR::get_port() const return port; } -void IPADDR::set_port(unsigned short port) +void IPADDR::set_port_net(unsigned short port) { if (saddr->sa_family == AF_INET) { saddr4->sin_port = port; @@ -185,7 +185,7 @@ const char *IPADDR::build_address_str(char *buf, int blen) char tmp[1024]; bsnprintf(buf, blen, "host[%s:%s:%hu] ", get_family() == AF_INET ? "ipv4" : "ipv6", - get_address(tmp, sizeof(tmp) - 1), ntohs(get_port())); + get_address(tmp, sizeof(tmp) - 1), get_port_host_order()); return buf; } @@ -213,9 +213,14 @@ const char *get_first_address(dlist * addrs, char *outputbuf, int outlen) return ((IPADDR *)(addrs->first()))->get_address(outputbuf, outlen); } -int get_first_port(dlist * addrs) +int get_first_port_net_order(dlist * addrs) { - return ntohs(((IPADDR *)(addrs->first()))->get_port()); + return ((IPADDR *)(addrs->first()))->get_port_net_order(); +} + +int get_first_port_host_order(dlist * addrs) +{ + return ((IPADDR *)(addrs->first()))->get_port_host_order(); } static int skip_to_next_not_eol(LEX * lc) @@ -307,14 +312,14 @@ static int add_address(dlist **out, IPADDR::i_type type, unsigned short defaultp if (addrs->size()) { addr = (IPADDR *)addrs->first(); } else { - addr = new IPADDR(family); + addr = New(IPADDR(family)); addr->set_type(type); - addr->set_port(defaultport); + addr->set_port_net(defaultport); addr->set_addr_any(); addrs->append(addr); } if (intype == IPADDR::R_SINGLE_PORT) { - addr->set_port(port); + addr->set_port_net(port); } if (intype == IPADDR::R_SINGLE_ADDR) { addr->copy_addr((IPADDR *) (hostaddrs->first())); @@ -331,9 +336,9 @@ static int add_address(dlist **out, IPADDR::i_type type, unsigned short defaultp goto skip; /* no price */ } } - clone = new IPADDR(*iaddr); + clone = New(IPADDR(*iaddr)); clone->set_type(type); - clone->set_port(port); + clone->set_port_net(port); addrs->append(clone); skip: continue; @@ -352,6 +357,8 @@ void store_addresses(LEX * lc, RES_ITEM * item, int index, int pass) char port_str[128]; int family = 0; + + /* * = { [[ip|ipv4|ipv6] = { [[addr|port] = [^ ]+[\n;]+] }]+ } * or my tests @@ -471,12 +478,12 @@ void store_addresses(LEX * lc, RES_ITEM * item, int index, int pass) } char *errstr; - if (!add_address((dlist **)(item->value), IPADDR::R_MULTIPLE, - htons(item->default_value), family, hostname_str, port_str, &errstr)) { - scan_err3(lc, _("Can't add hostname(%s) and port(%s) to addrlist (%s)"), + if (pass == 1 && !add_address((dlist **)(item->value), IPADDR::R_MULTIPLE, + htons(item->default_value), family, hostname_str, port_str, &errstr)) { + scan_err3(lc, _("Can't add hostname(%s) and port(%s) to addrlist (%s)"), hostname_str, port_str, errstr); - free(errstr); - } + free(errstr); + } token = skip_to_next_not_eol(lc); } while ((token == T_IDENTIFIER || token == T_UNQUOTED_STRING)); if (token != T_EOB) { @@ -486,12 +493,13 @@ void store_addresses(LEX * lc, RES_ITEM * item, int index, int pass) void store_addresses_address(LEX * lc, RES_ITEM * item, int index, int pass) { + int token = lex_get_token(lc, T_ALL); if (!(token == T_UNQUOTED_STRING || token == T_NUMBER || token == T_IDENTIFIER)) { scan_err1(lc, _("Expected a hostname or ipnummer, got: %s"), lc->str); } char *errstr; - if (!add_address((dlist **) (item->value), IPADDR::R_SINGLE_ADDR, + if (pass == 1 && !add_address((dlist **) (item->value), IPADDR::R_SINGLE_ADDR, htons(item->default_value), AF_INET, lc->str, 0, &errstr)) { scan_err2(lc, _("can't add port (%s) to (%s)"), lc->str, errstr); free(errstr); @@ -505,7 +513,7 @@ void store_addresses_port(LEX * lc, RES_ITEM * item, int index, int pass) scan_err1(lc, _("Expected a port nummer or string, got: %s"), lc->str); } char *errstr; - if (!add_address((dlist **)(item->value), IPADDR::R_SINGLE_PORT, + if (pass == 1 && !add_address((dlist **)(item->value), IPADDR::R_SINGLE_PORT, htons(item->default_value), AF_INET, 0, lc->str, &errstr)) { scan_err2(lc, _("can't add port (%s) to (%s)"), lc->str, errstr); free(errstr); @@ -521,3 +529,32 @@ void free_addresses(dlist * addrs) } delete addrs; } + +int sockaddr_get_port_net_order(const struct sockaddr *client_addr) +{ + /* MA BUG 6 remove ifdefs */ + if (client_addr->sa_family == AF_INET) { + return ((struct sockaddr_in *)client_addr)->sin_port; + } + else { + return ((struct sockaddr_in6 *)client_addr)->sin6_port; + } + return -1; +} + +int sockaddr_to_ascii(const struct sockaddr *sa, char *buf, int len) +{ +#ifdef HAVE_INET_NTOP + /* MA Bug 5 the problem was that i mixed up sockaddr and in_addr */ + inet_ntop(sa->sa_family, + sa->sa_family == AF_INET ? + (void*)&(((struct sockaddr_in*)sa)->sin_addr) : + (void*)&(((struct sockaddr_in6*)sa)->sin6_addr), + buf, + sa->sa_family == AF_INET ? sizeof(in_addr) : sizeof(in6_addr)); +#else + bstrncpy(buf, inet_ntoa(((struct sockaddr_in *)sa)->sin_addr), len); +#endif + return 1; +} + diff --git a/bacula/src/lib/address_conf.h b/bacula/src/lib/address_conf.h index 1e86c745a4..3741d37a23 100644 --- a/bacula/src/lib/address_conf.h +++ b/bacula/src/lib/address_conf.h @@ -26,7 +26,7 @@ */ -class IPADDR { +class IPADDR : public SMARTALLOC { public: typedef enum { R_SINGLE, R_SINGLE_PORT, R_SINGLE_ADDR, R_MULTIPLE, R_DEFAULT, R_EMPTY @@ -51,8 +51,12 @@ class IPADDR { public: void set_type(i_type o); i_type get_type() const; - unsigned short get_port() const; - void set_port(unsigned short port); + unsigned short get_port_net_order() const; + unsigned short get_port_host_order() const + { + return ntohs(get_port_net_order()); + } + void set_port_net(unsigned short port); int get_family() const; struct sockaddr *get_sockaddr(); int get_sockaddr_len(); @@ -77,6 +81,10 @@ extern void store_addresses_port(LEX * lc, RES_ITEM * item, int index, int pass) extern void init_default_addresses(dlist ** addr, int port); extern const char *get_first_address(dlist * addrs, char *outputbuf, int outlen); -extern int get_first_port(dlist * addrs); +extern int get_first_port_net_order(dlist * addrs); +extern int get_first_port_host_order(dlist * addrs); extern const char *build_addresses_str(dlist *addrs, char *buf, int blen); + +extern int sockaddr_get_port_net_order(const struct sockaddr *sa); +extern int sockaddr_to_ascii(const struct sockaddr *sa, char *buf, int len); diff --git a/bacula/src/lib/alist.h b/bacula/src/lib/alist.h index c65a17fbb7..2fb63827d8 100644 --- a/bacula/src/lib/alist.h +++ b/bacula/src/lib/alist.h @@ -50,7 +50,7 @@ enum { * Array list -- much like a simplified STL vector * array of pointers to inserted items */ -class alist { +class alist : public SMARTALLOC { void **items; int num_items; int max_items; @@ -74,8 +74,6 @@ public: int size() const; void destroy(); void grow(int num); - void * operator new(size_t); - void operator delete(void *); }; inline void * alist::operator [](int index) const { @@ -122,14 +120,4 @@ inline void alist::grow(int num) num_grow = num; } -inline void * alist::operator new(size_t) -{ - return malloc(sizeof(alist)); -} - -inline void alist::operator delete(void *item) -{ - ((alist *)item)->destroy(); - free(item); -} diff --git a/bacula/src/lib/berrno.h b/bacula/src/lib/berrno.h index 7efdeba61b..ccdc01791b 100644 --- a/bacula/src/lib/berrno.h +++ b/bacula/src/lib/berrno.h @@ -42,7 +42,7 @@ * must to a GetLastError() to get the error code for formatting. * If bit 29 in berrno_ is not set, then it is a Unix errno. */ -class berrno { +class berrno : public SMARTALLOC { POOLMEM *buf_; int berrno_; public: diff --git a/bacula/src/lib/bnet.c b/bacula/src/lib/bnet.c index fd35187248..9994facfac 100644 --- a/bacula/src/lib/bnet.c +++ b/bacula/src/lib/bnet.c @@ -543,7 +543,7 @@ static pthread_mutex_t ip_mutex = PTHREAD_MUTEX_INITIALIZER; static IPADDR *add_any(int family) { - IPADDR *addr = new IPADDR(family); + IPADDR *addr = New(IPADDR(family)); addr->set_type(IPADDR::R_MULTIPLE); addr->set_addr_any(); return addr; @@ -567,7 +567,7 @@ static int resolv_host(int family, const char *host, dlist * addr_list, } else { char **p; for (p = hp->h_addr_list; *p != 0; p++) { - IPADDR *addr = new IPADDR(hp->h_addrtype); + IPADDR *addr = New(IPADDR(hp->h_addrtype)); addr->set_type(IPADDR::R_MULTIPLE); if (addr->get_family() == AF_INET) { addr->set_addr4((struct in_addr*)*p); @@ -595,7 +595,7 @@ dlist *bnet_host2ipaddrs(const char *host, int family, const char **errstr) struct in6_addr inaddr6; #endif - dlist *addr_list = new dlist(addr, &addr->link); + dlist *addr_list = New(dlist(addr, &addr->link)); if (!host || host[0] == '\0') { if (family != 0) { addr_list->append(add_any(family)); @@ -605,15 +605,15 @@ dlist *bnet_host2ipaddrs(const char *host, int family, const char **errstr) addr_list->append(add_any(AF_INET6)); #endif } - } else if ((inaddr.s_addr = inet_addr(host)) != INADDR_NONE) { - addr = new IPADDR(AF_INET); + } else if (inet_aton(host, &inaddr)) { /* MA Bug 4 */ + addr = New(IPADDR(AF_INET)); addr->set_type(IPADDR::R_MULTIPLE); addr->set_addr4(&inaddr); addr_list->append(addr); } else #ifdef HAVE_IPV6 if (inet_pton(AF_INET6, host, &inaddr6) > 1) { - addr = new IPADDR(AF_INET6); + addr = New(IPADDR(AF_INET6)); addr->set_type(IPADDR::R_MULTIPLE); addr->set_addr6(&inaddr6); addr_list->append(addr); @@ -670,7 +670,7 @@ static BSOCK *bnet_open(JCR * jcr, const char *name, char *host, char *service, } foreach_dlist(ipaddr, addr_list) { - ipaddr->set_port(htons(port)); + ipaddr->set_port_net(htons(port)); char allbuf[256 * 10]; char curbuf[256]; Dmsg2(100, "Current %sAll %s\n", @@ -682,7 +682,7 @@ static BSOCK *bnet_open(JCR * jcr, const char *name, char *host, char *service, save_errno = errno; *fatal = 1; Pmsg3(000, "Socket open error. proto=%d port=%d. ERR=%s\n", - ipaddr->get_family(), ipaddr->get_port(), be.strerror()); + ipaddr->get_family(), ipaddr->get_port_host_order(), be.strerror()); continue; } /* diff --git a/bacula/src/lib/bnet_server.c b/bacula/src/lib/bnet_server.c index 773b202610..cf0ee907df 100644 --- a/bacula/src/lib/bnet_server.c +++ b/bacula/src/lib/bnet_server.c @@ -89,7 +89,7 @@ bnet_thread_server(dlist *addrs, int max_clients, workq_t *client_wq, foreach_dlist(p, addrs) { /* Allocate on stack frame -- no need to free */ fd_ptr = (s_sockfd *)alloca(sizeof(s_sockfd)); - fd_ptr->port = p->get_port(); + fd_ptr->port = p->get_port_net_order(); /* * Open a TCP socket */ @@ -121,11 +121,11 @@ bnet_thread_server(dlist *addrs, int max_clients, workq_t *client_wq, if (tlog <= 0) { tlog = 2 * 60; /* Complain every 2 minutes */ Emsg2(M_WARNING, 0, _("Cannot bind port %d: ERR=%s. Retrying ...\n"), - fd_ptr->port, be.strerror()); + ntohs(fd_ptr->port), be.strerror()); } bmicrosleep(5, 0); if (--tmax <= 0) { - Emsg2(M_ABORT, 0, _("Cannot bind port %d: ERR=%s.\n"), fd_ptr->port, + Emsg2(M_ABORT, 0, _("Cannot bind port %d: ERR=%s.\n"), ntohs(fd_ptr->port), be.strerror()); } } diff --git a/bacula/src/lib/dlist.h b/bacula/src/lib/dlist.h index 90200f5413..1bb1b3c140 100644 --- a/bacula/src/lib/dlist.h +++ b/bacula/src/lib/dlist.h @@ -29,8 +29,6 @@ */ #define M_ABORT 1 -#undef New -#define New(type) new type /* In case you want to specifically specify the offset to the link */ #define OFFSET(item, link) ((char *)(link) - (char *)(item)) @@ -55,7 +53,7 @@ struct dlink { void *prev; }; -class dlist { +class dlist : public SMARTALLOC { void *head; void *tail; int16_t loffset; @@ -79,13 +77,8 @@ public: void destroy(); void *first() const; void *last() const; - void * operator new(size_t); - void operator delete(void *); }; -dlist *new_dlist(); -dlist *new_dlist(void *item, dlink *link); - /* * This allows us to do explicit initialization, @@ -131,17 +124,6 @@ inline int dlist::size() const } -inline void * dlist::operator new(size_t) -{ - return malloc(sizeof(dlist)); -} - -inline void dlist::operator delete(void *item) -{ - ((dlist *)item)->destroy(); - free(item); -} - inline void * dlist::first() const { diff --git a/bacula/src/lib/htable.h b/bacula/src/lib/htable.h index b97cce3fab..c358d0e5a8 100644 --- a/bacula/src/lib/htable.h +++ b/bacula/src/lib/htable.h @@ -42,7 +42,7 @@ struct hlink { uint32_t hash; /* hash for this key */ }; -class htable { +class htable : public SMARTALLOC { hlink **table; /* hash table */ int loffset; /* link offset in item */ uint32_t num_items; /* current number of items */ @@ -66,6 +66,4 @@ public: void destroy(); void stats(); /* print stats about the table */ uint32_t size(); /* return size of table */ - void * operator new(size_t); - void operator delete(void *); }; diff --git a/bacula/src/lib/parse_conf.c b/bacula/src/lib/parse_conf.c index 448f45d26e..527b724149 100755 --- a/bacula/src/lib/parse_conf.c +++ b/bacula/src/lib/parse_conf.c @@ -155,7 +155,7 @@ const char *res_to_str(int rcode) * Initialize the static structure to zeros, then * apply all the default values. */ -void init_resource(int type, RES_ITEM *items) +void init_resource(int type, RES_ITEM *items, int pass) { int i; int rindex = type - r_first; @@ -188,7 +188,7 @@ void init_resource(int type, RES_ITEM *items) *(uint64_t *)(items[i].value) = (uint64_t)items[i].default_value; } else if (items[i].handler == store_time) { *(utime_t *)(items[i].value) = (utime_t)items[i].default_value; - } else if (items[i].handler == store_addresses) { + } else if (pass == 1 && items[i].handler == store_addresses) { init_default_addresses((dlist**)items[i].value, items[i].default_value); } } @@ -729,7 +729,7 @@ parse_config(const char *cf, int exit_on_error) state = p_resource; items = resources[i].items; res_type = resources[i].rcode; - init_resource(res_type, items); + init_resource(res_type, items, pass); break; } if (state == p_none) { diff --git a/bacula/src/lib/smartall.h b/bacula/src/lib/smartall.h index a319ec5260..bd0614c28c 100644 --- a/bacula/src/lib/smartall.h +++ b/bacula/src/lib/smartall.h @@ -89,7 +89,7 @@ extern void *b_malloc(); #ifdef SMARTALLOC -#define New(type) new(__FILE__, __LINE__ type +#define New(type) new(__FILE__, __LINE__) type /* BUG 2 brace is missing */ #undef SMARTALLOC #define SMARTALLOC SMARTALLOC @@ -125,7 +125,6 @@ void *operator new[](size_t s) throw() { return 0; } #else - #define New(type) new type class SMARTALLOC diff --git a/bacula/src/stored/dev.c b/bacula/src/stored/dev.c index a7141b2c26..3bb3d0c71e 100644 --- a/bacula/src/stored/dev.c +++ b/bacula/src/stored/dev.c @@ -204,7 +204,7 @@ init_dev(DEVICE *dev, DEVRES *device) } dev->fd = -1; - dev->attached_dcrs = new dlist(dcr, &dcr->dev_link); + dev->attached_dcrs = New(dlist(dcr, &dcr->dev_link)); Dmsg2(29, "init_dev: tape=%d dev_name=%s\n", dev_is_tape(dev), dev->dev_name); return dev; diff --git a/bacula/src/stored/read_record.c b/bacula/src/stored/read_record.c index ef8bc32ad3..5ecfdf7c4e 100644 --- a/bacula/src/stored/read_record.c +++ b/bacula/src/stored/read_record.c @@ -56,7 +56,7 @@ bool read_records(DCR *dcr, dlist *recs; /* linked list of rec packets open */ block = new_block(dev); - recs = new dlist(rec, &rec->link); + recs = New(dlist(rec, &rec->link)); position_to_first_file(jcr, dev); for ( ; ok && !done; ) { diff --git a/bacula/src/stored/stored.c b/bacula/src/stored/stored.c index cd1d03556c..e2133ee948 100644 --- a/bacula/src/stored/stored.c +++ b/bacula/src/stored/stored.c @@ -196,8 +196,8 @@ int main (int argc, char *argv[]) init_stack_dump(); /* pick up new pid */ } - create_pid_file(me->pid_directory, "bacula-sd", get_first_port(me->sdaddrs)); - read_state_file(me->working_directory, "bacula-sd", get_first_port(me->sdaddrs)); + create_pid_file(me->pid_directory, "bacula-sd", get_first_port_host_order(me->sdaddrs)); + read_state_file(me->working_directory, "bacula-sd", get_first_port_host_order(me->sdaddrs)); drop(uid, gid); @@ -392,8 +392,8 @@ void terminate_stored(int sig) bmicrosleep(0, 500000); /* give them 1/2 sec to clean up */ } - write_state_file(me->working_directory, "bacula-sd", get_first_port(me->sdaddrs)); - delete_pid_file(me->pid_directory, "bacula-sd", get_first_port(me->sdaddrs)); + write_state_file(me->working_directory, "bacula-sd", get_first_port_host_order(me->sdaddrs)); + delete_pid_file(me->pid_directory, "bacula-sd", get_first_port_host_order(me->sdaddrs)); Dmsg1(200, "In terminate_stored() sig=%d\n", sig); diff --git a/bacula/src/stored/stored_conf.c b/bacula/src/stored/stored_conf.c index 61e3323524..2e51bb2003 100644 --- a/bacula/src/stored/stored_conf.c +++ b/bacula/src/stored/stored_conf.c @@ -166,16 +166,16 @@ void dump_resource(int type, RES *reshdr, void sendit(void *sock, const char *fm sendit(sock, "Storage: name=%s SDaddr=%s SDport=%d SDDport=%d HB=%s\n", res->res_store.hdr.name, NPRT(get_first_address(res->res_store.sdaddrs, buf, sizeof(buf))), - get_first_port(res->res_store.sdaddrs), - get_first_port(res->res_store.sddaddrs), + get_first_port_host_order(res->res_store.sdaddrs), + get_first_port_host_order(res->res_store.sddaddrs), edit_utime(res->res_store.heartbeat_interval, buf, sizeof(buf))); foreach_dlist(p, res->res_store.sdaddrs) { sendit(sock, " SDaddr=%s SDport=%d\n", - p->get_address(buf, sizeof(buf)), p->get_port()); + p->get_address(buf, sizeof(buf)), p->get_port_host_order()); } foreach_dlist(p, res->res_store.sddaddrs) { sendit(sock, " SDDaddr=%s SDDport=%d\n", - p->get_address(buf, sizeof(buf)), p->get_port()); + p->get_address(buf, sizeof(buf)), p->get_port_host_order()); } break; case R_DEVICE: -- 2.39.2