]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
Remove deprecated sbrk in macOS and Windows.
authorMichael Narigon <mnarigon@gmail.com>
Tue, 2 Feb 2021 12:12:08 +0000 (13:12 +0100)
committerEric Bollengier <eric@baculasystems.com>
Thu, 24 Mar 2022 08:02:58 +0000 (09:02 +0100)
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 <mnarigon@gmail.com>.

23 files changed:
bacula/src/baconfig.h
bacula/src/dird/bdirjson.c
bacula/src/dird/dird.c
bacula/src/dird/ua_collect.c
bacula/src/dird/ua_status.c
bacula/src/filed/accurate.c
bacula/src/filed/fdcollect.c
bacula/src/filed/filed.c
bacula/src/filed/status.c
bacula/src/lib/bsys.c
bacula/src/lib/protos.h
bacula/src/lib/workq.c
bacula/src/stored/bcopy.c
bacula/src/stored/bextract.c
bacula/src/stored/bls.c
bacula/src/stored/bscan.c
bacula/src/stored/btape.c
bacula/src/stored/cloud_parts.c
bacula/src/stored/cloud_test.c
bacula/src/stored/generic_driver.c
bacula/src/stored/sdcollect.c
bacula/src/stored/status.c
bacula/src/stored/stored.c

index 7310f8ad9d49762c280095d6ea8ff6df73acebe4..b7f7c29d32fc807bca1fe7c3563a848f23abb7c8 100644 (file)
@@ -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)
index f37d06ed1eb32dccaf590b054205ed5d70f4b48c..91ffe8ce8e64b4261d50c81da9fdd024d020a793 100644 (file)
@@ -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[];
index 7dd43d8ca5896bee7b0377b3490d0fb7f90aa0c6..5e37b6030c92336ae4d891756326471481d9234c 100644 (file)
@@ -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");
index 716060fa729ee4a0e83afebc9f5ff9297dc0feb4..92765e78627528b8dc32a889fb56440a69d0a503 100644 (file)
@@ -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);
index d11e05afb25e70349642ddb118ed4fae01ad2f4a..b13304c4951c265e956219fdebba22b58d35b898 100644 (file)
@@ -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),
index 1951d5a1f4e57cce3ebbbee90b1653dc695425b2..ec61254a9696d8ff3152e82594dea3c183d9229c 100644 (file)
@@ -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),
index 75ad4ce19eb6dba4fc9a2db472bdcec639ad71a0..2b5e706cc06fc08b6db6a6b002289960b8595933 100644 (file)
@@ -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);
index fd171d01b697e0c93018f460f7eb549dc9c5255e..0b045779cd64b78690e0678f176169ac1e6c80a0 100644 (file)
@@ -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");
index 04087ab9e8227d639078fa978e17e6c70caac284..91895f0d4b123032c7b0c141515cf35ac86db2d4 100644 (file)
@@ -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];
 
index 97bf72980f66fabdd6dba0f9726d2cf3d1812473..a0c86edd4c4cb444d0005116fb704510a43eae50 100644 (file)
@@ -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 <malloc/malloc.h>
+#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
index 6d5c567080f39fa029af0bf87461f6b6494b2d14..4ebbb2194f6e04ef586ea05e28cd2b1f5d4fc532 100644 (file)
@@ -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,
index 232c8a29108f645c6eb153557a50f3f8fa78ca41..09a6c7cdf486f3eb56ba32222e154e34d0a51dd2 100644 (file)
@@ -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");
index a86087022368ea7b23770fc2c9c871a1654ebadc..573db3dbb25ce33f2f2d5d65d53bbc296abb03e9 100644 (file)
@@ -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()
index ff5aa758bda3f7742a1b9df5ebad659159556874..b898bb3d33669c809925f2cd072626dd85eb819c 100644 (file)
@@ -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;
 
index ec44c08c27c89bcbc3eb89a6feee30d8def6cdb9..41b9f637392a164b49b4905b11bb55305274b0e2 100644 (file)
@@ -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;
index 69bdbf82ed1e64767c9812fce599f0a789fc0c75..7617220e86169ce7fa9635fba9be8396e5b3b5ad 100644 (file)
@@ -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()
index 5c8def1ef0fdf67ad32399251966b54a7f028fd2..359c5d5e96612d579e44d4daf531fff510b77f4d 100644 (file)
@@ -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;
index c279ac0ad3ed9cc75bd953fbffe96c3383a72b71..cab9a4d58d4617e27f5b56fa7b5212407dce1ccd 100644 (file)
@@ -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");
index 7972611e40e9da8f24e65459ddab04e2567f626a..7662ac51efd49483cc59844c92a229ba38c3daf9 100644 (file)
@@ -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;
index 160a8dfcd81367da3cf4c82515cb518c5aea3061..f977e7983260ebdef07de1b9102815d58a4e48ec 100644 (file)
@@ -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");
index 7480206faec55df8a6576f1a3538ca3c4f653f77..f790616da2a09a0a3ce1101f7b5260d3dc817658 100644 (file)
@@ -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);
index 86e583e42f3057881fa8735cf4616ab101f3edd5..16a1e063f5c93d8482d45871d60faabc3eb47f76 100644 (file)
@@ -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),
index 4bad8a7d4337cfd11549f310b3f6995d462688dc..91c4e68d042715b7a8b1780a376e2c789231de76 100644 (file)
@@ -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");