From 1d88ccc4be4faa6ecb4b7a6820fdfa5abbbb8849 Mon Sep 17 00:00:00 2001 From: Michael Narigon Date: Tue, 2 Feb 2021 13:12:08 +0100 Subject: [PATCH] Remove deprecated sbrk in macOS and Windows. This patch adds a new functions to manage heap size allocation reporting in macOS and Windows systems. It will be used as a generic heap applocation reporting in Bacula. This is a port of the work from Michael Narigon . --- bacula/src/baconfig.h | 2 -- bacula/src/dird/bdirjson.c | 1 - bacula/src/dird/dird.c | 3 +- bacula/src/dird/ua_collect.c | 5 +-- bacula/src/dird/ua_status.c | 3 +- bacula/src/filed/accurate.c | 4 +-- bacula/src/filed/fdcollect.c | 3 +- bacula/src/filed/filed.c | 3 +- bacula/src/filed/status.c | 4 +-- bacula/src/lib/bsys.c | 53 ++++++++++++++++++++++++++---- bacula/src/lib/protos.h | 2 ++ bacula/src/lib/workq.c | 4 +-- bacula/src/stored/bcopy.c | 1 - bacula/src/stored/bextract.c | 1 - bacula/src/stored/bls.c | 1 - bacula/src/stored/bscan.c | 1 - bacula/src/stored/btape.c | 1 - bacula/src/stored/cloud_parts.c | 4 +-- bacula/src/stored/cloud_test.c | 1 - bacula/src/stored/generic_driver.c | 46 +++++++++++++------------- bacula/src/stored/sdcollect.c | 3 +- bacula/src/stored/status.c | 3 +- bacula/src/stored/stored.c | 3 +- 23 files changed, 83 insertions(+), 69 deletions(-) diff --git a/bacula/src/baconfig.h b/bacula/src/baconfig.h index 7310f8ad9..b7f7c29d3 100644 --- a/bacula/src/baconfig.h +++ b/bacula/src/baconfig.h @@ -121,8 +121,6 @@ void InitWinAPIWrapper(); #define OSDependentInit() InitWinAPIWrapper() -#define sbrk(x) 0 - #define clear_thread_id(x) memset(&(x), 0, sizeof(x)) #if defined(BUILDING_DLL) diff --git a/bacula/src/dird/bdirjson.c b/bacula/src/dird/bdirjson.c index f37d06ed1..91ffe8ce8 100644 --- a/bacula/src/dird/bdirjson.c +++ b/bacula/src/dird/bdirjson.c @@ -37,7 +37,6 @@ DIRRES *director; /* Director resource */ int FDConnectTimeout; int SDConnectTimeout; char *configfile = NULL; -void *start_heap; /* Globals Imported */ extern RES_ITEM job_items[]; diff --git a/bacula/src/dird/dird.c b/bacula/src/dird/dird.c index 7dd43d8ca..5e37b6030 100644 --- a/bacula/src/dird/dird.c +++ b/bacula/src/dird/dird.c @@ -73,7 +73,6 @@ DIRRES *director; /* Director resource */ int FDConnectTimeout; int SDConnectTimeout; char *configfile = NULL; -void *start_heap; utime_t last_reload_time = 0; bstatcollect *statcollector = NULL; dirdstatmetrics_t dirstatmetrics; @@ -259,7 +258,7 @@ int main (int argc, char *argv[]) /* DELETE ME when bugs in MA1512, MA1632 MA1639 are fixed */ MA1512_reload_job_end_cb = reload_job_end_cb; - start_heap = sbrk(0); + mark_heap(); setlocale(LC_ALL, ""); bindtextdomain("bacula", LOCALEDIR); textdomain("bacula"); diff --git a/bacula/src/dird/ua_collect.c b/bacula/src/dird/ua_collect.c index 716060fa7..92765e786 100644 --- a/bacula/src/dird/ua_collect.c +++ b/bacula/src/dird/ua_collect.c @@ -30,9 +30,6 @@ #include "bacula.h" #include "dird.h" -/* imported variables */ -extern void *start_heap; - /* imported variables */ static bool collector_threads_started = false; @@ -75,7 +72,7 @@ bool update_permanent_stats(void *data) memused = get_memory_info(NULL, 0); statcollector->set_value_int64(dirstatmetrics.bacula_dir_memory_heap, memused); #else - statcollector->set_value_int64(dirstatmetrics.bacula_dir_memory_heap, (char *)sbrk(0)-(char *)start_heap); + statcollector->set_value_int64(dirstatmetrics.bacula_dir_memory_heap, heap_used()); #endif statcollector->set_value_int64(dirstatmetrics.bacula_dir_memory_maxbufs, sm_max_buffers); statcollector->set_value_int64(dirstatmetrics.bacula_dir_memory_maxbytes, sm_max_bytes); diff --git a/bacula/src/dird/ua_status.c b/bacula/src/dird/ua_status.c index d11e05afb..b13304c49 100644 --- a/bacula/src/dird/ua_status.c +++ b/bacula/src/dird/ua_status.c @@ -28,7 +28,6 @@ #include "bacula.h" #include "dird.h" -extern void *start_heap; extern utime_t last_reload_time; static void list_scheduled_jobs(UAContext *ua); @@ -489,7 +488,7 @@ void list_dir_status_header(UAContext *ua) ua->send_msg(_(" Crypto: fips=%s crypto=%s\n"), crypto_get_fips_enabled(), crypto_get_version()); ua->send_msg(_(" Heap: heap=%s smbytes=%s max_bytes=%s bufs=%s max_bufs=%s\n"), - edit_uint64_with_commas((char *)sbrk(0)-(char *)start_heap, b1), + edit_uint64_with_commas(heap_used(), b1), edit_uint64_with_commas(sm_bytes, b2), edit_uint64_with_commas(sm_max_bytes, b3), edit_uint64_with_commas(sm_buffers, b4), diff --git a/bacula/src/filed/accurate.c b/bacula/src/filed/accurate.c index 1951d5a1f..ec61254a9 100644 --- a/bacula/src/filed/accurate.c +++ b/bacula/src/filed/accurate.c @@ -636,11 +636,9 @@ int accurate_cmd(JCR *jcr) } #ifdef DEBUG - extern void *start_heap; - char b1[50], b2[50], b3[50], b4[50], b5[50]; Dmsg5(dbglvl," Heap: heap=%s smbytes=%s max_bytes=%s bufs=%s max_bufs=%s\n", - edit_uint64_with_commas((char *)sbrk(0)-(char *)start_heap, b1), + edit_uint64_with_commas(heap_used(), b1), edit_uint64_with_commas(sm_bytes, b2), edit_uint64_with_commas(sm_max_bytes, b3), edit_uint64_with_commas(sm_buffers, b4), diff --git a/bacula/src/filed/fdcollect.c b/bacula/src/filed/fdcollect.c index 75ad4ce19..2b5e706cc 100644 --- a/bacula/src/filed/fdcollect.c +++ b/bacula/src/filed/fdcollect.c @@ -29,7 +29,6 @@ #include "filed.h" /* imported functions and variables */ -extern void *start_heap; extern const char collect_all_cmd[]; extern const char collect_metrics_cmd[]; @@ -83,7 +82,7 @@ bool update_permanent_stats(void *data) memused = get_memory_info(NULL, 0); statcollector->set_value_int64(fdstatmetrics.bacula_client_memory_heap, memused); #else - statcollector->set_value_int64(fdstatmetrics.bacula_client_memory_heap, (char *)sbrk(0)-(char *)start_heap); + statcollector->set_value_int64(fdstatmetrics.bacula_client_memory_heap, heap_used()); #endif statcollector->set_value_int64(fdstatmetrics.bacula_client_memory_maxbufs, sm_max_buffers); statcollector->set_value_int64(fdstatmetrics.bacula_client_memory_maxbytes, sm_max_bytes); diff --git a/bacula/src/filed/filed.c b/bacula/src/filed/filed.c index fd171d01b..0b045779c 100644 --- a/bacula/src/filed/filed.c +++ b/bacula/src/filed/filed.c @@ -36,7 +36,6 @@ static bool check_resources(); /* Exported variables */ CLIENT *me; /* my resource */ bool no_signals = false; -void *start_heap; extern struct s_cmds cmds[]; bstatcollect *statcollector = NULL; fdstatmetrics_t fdstatmetrics; @@ -95,7 +94,7 @@ int main (int argc, char *argv[]) char *uid = NULL; char *gid = NULL; - start_heap = sbrk(0); + mark_heap(); setlocale(LC_ALL, ""); bindtextdomain("bacula", LOCALEDIR); textdomain("bacula"); diff --git a/bacula/src/filed/status.c b/bacula/src/filed/status.c index 04087ab9e..91895f0d4 100644 --- a/bacula/src/filed/status.c +++ b/bacula/src/filed/status.c @@ -27,8 +27,6 @@ #include "filed.h" #include "lib/status.h" -extern void *start_heap; - extern bool GetWindowsVersionString(char *buf, int maxsiz); @@ -134,7 +132,7 @@ static void list_status_header(STATUS_PKT *sp) { POOL_MEM msg(PM_MESSAGE); char b1[32], b2[32], b3[32], b4[32], b5[35]; - int64_t memused = (char *)sbrk(0)-(char *)start_heap; + int64_t memused = heap_used(); int len; char dt[MAX_TIME_LENGTH]; diff --git a/bacula/src/lib/bsys.c b/bacula/src/lib/bsys.c index 97bf72980..a0c86edd4 100644 --- a/bacula/src/lib/bsys.c +++ b/bacula/src/lib/bsys.c @@ -1191,7 +1191,46 @@ int fs_get_free_space(const char *path, int64_t *freeval, int64_t *totalval) return -1; } -/* This function is used after a fork, the memory manager is not be initialized +#if defined(HAVE_DARWIN_OS) +#include +#endif + +/* + * Determine the amount of heap used + * macOS - sbrk(0) is deprecated, use malloc info + * Windows - not implemented + * others - use sbrk(0) + */ + +/* the initial heap value */ +static int64_t start_heap = 0; + +void mark_heap() +{ +#if defined(HAVE_WIN32) + start_heap = 0; +#elif defined(HAVE_DARWIN_OS) + struct mstats ms = mstats(); + start_heap = (int64_t) ms.bytes_used; +#else + start_heap = (int64_t) sbrk(0); +#endif +} + +int64_t heap_used() +{ +#if defined(HAVE_WIN32) + return get_memory_info(NULL, 0); +#elif defined(HAVE_DARWIN_OS) + struct mstats ms = mstats(); + return (int64_t) ms.bytes_used - start_heap; +#else + return (int64_t) sbrk(0) - start_heap; +#endif +} + +/* + * This function is used after a fork, the memory manager is not be initialized * properly, so we must stay simple. */ void setup_env(char *envp[]) @@ -1470,7 +1509,7 @@ uint64_t bget_max_mlock(int64_t value) if (value < 0) { Dmsg0(50, "Limit incorrect set, use the maximum for mlock_max\n"); /* Request to keep 2GB, we have only 1GB, something is incorrect, so - * we take the maximum + * we take the maximum */ value = sys; } @@ -1541,7 +1580,7 @@ static int init_size=1024; static int dbglevel=500; /* alist(100, owned_by_alist) */ -/* return 0: ok, -1: error, 1: not found +/* return 0: ok, -1: error, 1: not found * Will return a list of users for a group. We look for /etc/groups * and in /etc/passwd */ @@ -1574,7 +1613,7 @@ again: } else if (ret == EINTR) { goto again; - + } else if (ret != 0) { berrno be; Dmsg1(dbglevel, "Got error for getgrnam_r %s\n", be.bstrerror(ret)); @@ -1656,7 +1695,7 @@ int get_user_home_directory(const char *user, POOLMEM *&home) struct passwd pw, *ppw; int size = init_size; char *buf = (char *)malloc(size); - + again: errno = 0; ret = getpwnam_r(user, &pw, buf, size, &ppw); @@ -1901,7 +1940,7 @@ int main(int argc, char **argv) POOL_MEM home; char *name; int ret; - + ret = get_group_members("bin", &a); ok(ret == 0, "get_group_members()"); ok(a.size() > 0, "get_group_members() size"); @@ -1919,7 +1958,7 @@ int main(int argc, char **argv) } ok(get_user_home_directory("root", home.addr()) == 0, "get_user_home_directory()"); - + return report(); } #endif diff --git a/bacula/src/lib/protos.h b/bacula/src/lib/protos.h index 6d5c56708..4ebbb2194 100644 --- a/bacula/src/lib/protos.h +++ b/bacula/src/lib/protos.h @@ -125,6 +125,8 @@ void gdb_print_local(int level); int safer_unlink(const char *pathname, const char *regex); int fs_get_free_space(const char *path, int64_t *freeval, int64_t *totalval); +void mark_heap(); +int64_t heap_used(); /* bnet.c */ bool bnet_tls_server (TLS_CONTEXT *ctx, BSOCK *bsock, diff --git a/bacula/src/lib/workq.c b/bacula/src/lib/workq.c index 232c8a291..09a6c7cdf 100644 --- a/bacula/src/lib/workq.c +++ b/bacula/src/lib/workq.c @@ -448,9 +448,7 @@ int main (int argc, char *argv[]) { pthread_attr_t attr; - void * start_heap = sbrk(0); - (void)start_heap; - + mark_heap(); setlocale(LC_ALL, ""); bindtextdomain("bacula", LOCALEDIR); textdomain("bacula"); diff --git a/bacula/src/stored/bcopy.c b/bacula/src/stored/bcopy.c index a86087022..573db3dbb 100644 --- a/bacula/src/stored/bcopy.c +++ b/bacula/src/stored/bcopy.c @@ -50,7 +50,6 @@ static SESSION_LABEL sessrec; static CONFIG *config; #define CONFIG_FILE "bacula-sd.conf" -void *start_heap; char *configfile = NULL; static void usage() diff --git a/bacula/src/stored/bextract.c b/bacula/src/stored/bextract.c index ff5aa758b..b898bb3d3 100644 --- a/bacula/src/stored/bextract.c +++ b/bacula/src/stored/bextract.c @@ -67,7 +67,6 @@ static uint64_t fileAddr = 0; /* file write address */ static CONFIG *config; #define CONFIG_FILE "bacula-sd.conf" -void *start_heap; char *configfile = NULL; bool skip_extract = false; diff --git a/bacula/src/stored/bls.c b/bacula/src/stored/bls.c index ec44c08c2..41b9f6373 100644 --- a/bacula/src/stored/bls.c +++ b/bacula/src/stored/bls.c @@ -53,7 +53,6 @@ static CONFIG *config; bool filter = false; /* any filter set ? */ bool dedup = false; /* decode dedup reference */ -void *start_heap; #define CONFIG_FILE "bacula-sd.conf" char *configfile = NULL; bool detect_errors = false; diff --git a/bacula/src/stored/bscan.c b/bacula/src/stored/bscan.c index 69bdbf82e..7617220e8 100644 --- a/bacula/src/stored/bscan.c +++ b/bacula/src/stored/bscan.c @@ -97,7 +97,6 @@ static int num_plugin_objects = 0; static CONFIG *config; #define CONFIG_FILE "bacula-sd.conf" -void *start_heap; char *configfile = NULL; static void usage() diff --git a/bacula/src/stored/btape.c b/bacula/src/stored/btape.c index 5c8def1ef..359c5d5e9 100644 --- a/bacula/src/stored/btape.c +++ b/bacula/src/stored/btape.c @@ -42,7 +42,6 @@ extern bool parse_sd_config(CONFIG *config, const char *configfile, int exit_cod extern void free_config_resources(); /* Exported variables */ -void *start_heap; int quit = 0; char buf[100000]; int bsize = TAPE_BSIZE; diff --git a/bacula/src/stored/cloud_parts.c b/bacula/src/stored/cloud_parts.c index c279ac0ad..cab9a4d58 100644 --- a/bacula/src/stored/cloud_parts.c +++ b/bacula/src/stored/cloud_parts.c @@ -335,9 +335,7 @@ int main (int argc, char *argv[]) { pthread_attr_t attr; - void * start_heap = sbrk(0); - (void)start_heap; - + mark_heap(); setlocale(LC_ALL, ""); bindtextdomain("bacula", LOCALEDIR); textdomain("bacula"); diff --git a/bacula/src/stored/cloud_test.c b/bacula/src/stored/cloud_test.c index 7972611e4..7662ac51e 100644 --- a/bacula/src/stored/cloud_test.c +++ b/bacula/src/stored/cloud_test.c @@ -24,7 +24,6 @@ extern bool parse_sd_config(CONFIG *config, const char *configfile, int exit_cod static CONFIG *config; -void *start_heap; #define CONFIG_FILE "bacula-sd.conf" char *configfile = NULL; bool detect_errors = false; diff --git a/bacula/src/stored/generic_driver.c b/bacula/src/stored/generic_driver.c index 160a8dfcd..f977e7983 100644 --- a/bacula/src/stored/generic_driver.c +++ b/bacula/src/stored/generic_driver.c @@ -47,7 +47,7 @@ cloud_driver *BaculaCloudDriver() } #endif /* taken from plugins */ -static ssize_t full_write(FILE *fp, char *ptr, int32_t nbytes, cancel_callback *cancel_cb=NULL) +static ssize_t full_write(FILE *fp, char *ptr, int32_t nbytes, cancel_callback *cancel_cb=NULL) { int fd = fileno(fp); int32_t nleft, nwritten; @@ -157,9 +157,9 @@ bool generic_driver::init(CLOUD *cloud, POOLMEM *&err) { max_concurrent_downloads = cloud->max_concurrent_downloads; upload_limit.set_bwlimit(cloud->upload_limit); download_limit.set_bwlimit(cloud->download_limit); - + driver_command = cloud->driver_command; - + pm_strcpy(host_env, "CLOUD_HOST="); pm_strcat(host_env, NPRTB(host_name)); @@ -214,7 +214,7 @@ bool generic_driver::init(CLOUD *cloud, POOLMEM *&err) { pm_strcpy(max_concurrent_uploads_env, "CLOUD_MAX_CONCURRENT_UPLOADS="); pm_strcat(max_concurrent_uploads_env, b); envs[12] = max_concurrent_uploads_env; - + sprintf(b, "%d", max_concurrent_downloads); pm_strcpy(max_concurrent_downloads_env, "CLOUD_MAX_CONCURRENT_DOWNLOADS="); pm_strcat(max_concurrent_downloads_env, b); @@ -224,12 +224,12 @@ bool generic_driver::init(CLOUD *cloud, POOLMEM *&err) { pm_strcpy(upload_limit_env, "CLOUD_UPLOAD_LIMIT="); pm_strcat(upload_limit_env, b); envs[14] = upload_limit_env; - + sprintf(b, "%lld", (long long) cloud->download_limit); pm_strcpy(download_limit_env, "CLOUD_DOWNLOAD_LIMIT="); pm_strcat(download_limit_env, b); envs[15] = download_limit_env; - + pm_strcpy(debug_env, "CLOUD_DEBUG="); if (chk_dbglvl(dbglvl)) pm_strcat(debug_env, "TRUE"); envs[16] = debug_env; @@ -331,21 +331,21 @@ int handle_error(int stat, POOLMEM *&err) /* Main contact point with the script. The script is always called with the following parameters -in this exact order : -fct_name, -volume_name, -cache_name, -partname ("part.x"). +in this exact order : +fct_name, +volume_name, +cache_name, +partname ("part.x"). Depending on fct_name, some parameters can be NULL ("*None*"). call_fct Control I/Os with the script and calls read_cb and write_cb in return. -read_cb : is called when data from the script is available for read. First argument is the data buffer ready +read_cb : is called when data from the script is available for read. First argument is the data buffer ready for read. Second argument is the size of the data. The last argument is the arg parameter that's been passed at cb creation. A typical read_cb function will parse the data buffer for some information/error message or copy the data buffer to file. -write_cb : is called when the script is ready to write data. First argument is the data buffer to fill with data. +write_cb : is called when the script is ready to write data. First argument is the data buffer to fill with data. Second argument is the max size of the data. The last argument is the arg parameter that's been passed at cb creation. The write_cb function must return the actual written size in the data buffer within the write_cb function, 0 if the file is to be closed (eof) or -1 in case of error (in this case, data buffer contains the error text). @@ -365,10 +365,10 @@ int generic_driver::call_fct(const char* fct_name, { POOL_MEM cmd(PM_FNAME); if (cache_path_name) { - Mmsg(cmd, "%s %s %s part.%d %s", + Mmsg(cmd, "%s %s %s part.%d %s", driver_command, fct_name, NPRT(volume_name), part_number, cache_path_name); } else { - Mmsg(cmd, "%s %s %s part.%d", + Mmsg(cmd, "%s %s %s part.%d", driver_command, fct_name, NPRT(volume_name), part_number); } @@ -384,7 +384,7 @@ int generic_driver::call_fct(const char* fct_name, POOLMEM *&err) { POOL_MEM cmd(PM_FNAME); - Mmsg(cmd, "%s %s %s %s", + Mmsg(cmd, "%s %s %s %s", driver_command, fct_name, NPRT(volume_name), NPRT(part_name)); return call_fct(cmd.addr(), read_cb, write_cb, cancel_cb, err); @@ -423,7 +423,7 @@ int generic_driver::call_fct(char* cmd, } cancel = (cancel_cb && cancel_cb->fct && cancel_cb->fct(cancel_cb->arg)); - + while(!cancel) { int rfd = bpipe->rfd ? fileno(bpipe->rfd):-1; int wfd = bpipe->wfd ? fileno(bpipe->wfd):-1; @@ -594,7 +594,7 @@ size_t copy_cache_part_to_cloud_write_cb(char *res, size_t block_size, void* arg if (_arg->xfer) { _arg->xfer->increment_processed_size(ret); } - } + } } } return ret; @@ -654,7 +654,7 @@ bool generic_driver::copy_cache_part_to_cloud(transfer *xfer) if (retry < max_upload_retries) { if (xfer->m_message) { Dmsg3(dbglvl, "%s retry #%d err=%d\n", xfer->m_message, (max_upload_retries-retry), ret); - } else { + } else { Dmsg3(dbglvl, "generic_driver::copy_cache_part_to_cloud part.%d retry #%d err=%d\n", xfer->m_part, (max_upload_retries-retry), ret); } /* And we clean the cloud part, in case the cloud target is a mess */ @@ -680,7 +680,7 @@ bool generic_driver::copy_cache_part_to_cloud(transfer *xfer) free(fname); return (ret==0); - } else { + } else { uint32_t retry = max_upload_retries; int ret=-1; while ((ret!=0) && (retry>0)) { @@ -690,7 +690,7 @@ bool generic_driver::copy_cache_part_to_cloud(transfer *xfer) if (retry < max_upload_retries) { if (xfer->m_message) { Dmsg3(dbglvl, "%s retry #%d err=%d\n", xfer->m_message, (max_upload_retries-retry), ret); - } else { + } else { Dmsg3(dbglvl, "generic_driver::copy_cache_part_to_cloud part.%d retry #%d err=%d\n", xfer->m_part, (max_upload_retries-retry), ret); } /* And we clean the cloud part, in case the cloud target is a mess */ @@ -904,7 +904,7 @@ int generic_driver::copy_cloud_part_to_cache(transfer *xfer) } bool generic_driver::restore_cloud_object(transfer *xfer, const char *cloud_fname) -{ +{ (void) (xfer); (void) (cloud_fname); /* not implemented */ @@ -1153,7 +1153,7 @@ size_t get_cloud_volumes_list_read_cb(char* res, size_t size, void *arg) volumes = _arg->volumes; remain = _arg->remain; } - + if (volumes) { /* do the actual process */ char * pch = strtok (res,"\n"); diff --git a/bacula/src/stored/sdcollect.c b/bacula/src/stored/sdcollect.c index 7480206fa..f790616da 100644 --- a/bacula/src/stored/sdcollect.c +++ b/bacula/src/stored/sdcollect.c @@ -29,7 +29,6 @@ #include "stored.h" /* imported functions and variables */ -extern void *start_heap; extern const char collect_all_cmd[]; extern const char collect_metrics_cmd[]; extern bool init_done; @@ -104,7 +103,7 @@ bool update_permanent_stats(void *data) memused = get_memory_info(NULL, 0); statcollector->set_value_int64(sdstatmetrics.bacula_storage_memory_heap, memused); #else - statcollector->set_value_int64(sdstatmetrics.bacula_storage_memory_heap, (char *)sbrk(0)-(char *)start_heap); + statcollector->set_value_int64(sdstatmetrics.bacula_storage_memory_heap, heap_used()); #endif statcollector->set_value_int64(sdstatmetrics.bacula_storage_memory_maxbufs, sm_max_buffers); statcollector->set_value_int64(sdstatmetrics.bacula_storage_memory_maxbytes, sm_max_bytes); diff --git a/bacula/src/stored/status.c b/bacula/src/stored/status.c index 86e583e42..16a1e063f 100644 --- a/bacula/src/stored/status.c +++ b/bacula/src/stored/status.c @@ -34,7 +34,6 @@ extern void dbg_print_plugin(FILE *fp); /* Imported variables */ extern BSOCK *filed_chan; -extern void *start_heap; /* Static variables */ static char OKqstatus[] = "3000 OK .status\n"; @@ -598,7 +597,7 @@ static void list_status_header(STATUS_PKT *sp) list_resource_limits(sp, nofile_l, memlock_l); len = Mmsg(msg, _(" Heap: heap=%s smbytes=%s max_bytes=%s bufs=%s max_bufs=%s\n"), - edit_uint64_with_commas((char *)sbrk(0)-(char *)start_heap, b1), + edit_uint64_with_commas(heap_used(), b1), edit_uint64_with_commas(sm_bytes, b2), edit_uint64_with_commas(sm_max_bytes, b3), edit_uint64_with_commas(sm_buffers, b4), diff --git a/bacula/src/stored/stored.c b/bacula/src/stored/stored.c index 4bad8a7d4..91c4e68d0 100644 --- a/bacula/src/stored/stored.c +++ b/bacula/src/stored/stored.c @@ -52,7 +52,6 @@ extern "C" void *device_initialization(void *arg); /* Global variables exported */ char OK_msg[] = "3000 OK\n"; char TERM_msg[] = "3999 Terminate\n"; -void *start_heap; static bool test_config = false; bstatcollect *statcollector = NULL; sdstatmetrics_t sdstatmetrics; @@ -132,7 +131,7 @@ int main (int argc, char *argv[]) device_default_open_mode = omd_write; - start_heap = sbrk(0); + mark_heap(); setlocale(LC_ALL, ""); bindtextdomain("bacula", LOCALEDIR); textdomain("bacula"); -- 2.47.3