#define OSDependentInit() InitWinAPIWrapper()
-#define sbrk(x) 0
-
#define clear_thread_id(x) memset(&(x), 0, sizeof(x))
#if defined(BUILDING_DLL)
int FDConnectTimeout;
int SDConnectTimeout;
char *configfile = NULL;
-void *start_heap;
/* Globals Imported */
extern RES_ITEM job_items[];
int FDConnectTimeout;
int SDConnectTimeout;
char *configfile = NULL;
-void *start_heap;
utime_t last_reload_time = 0;
bstatcollect *statcollector = NULL;
dirdstatmetrics_t dirstatmetrics;
/* 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");
#include "bacula.h"
#include "dird.h"
-/* imported variables */
-extern void *start_heap;
-
/* imported variables */
static bool collector_threads_started = false;
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);
#include "bacula.h"
#include "dird.h"
-extern void *start_heap;
extern utime_t last_reload_time;
static void list_scheduled_jobs(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),
}
#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),
#include "filed.h"
/* imported functions and variables */
-extern void *start_heap;
extern const char collect_all_cmd[];
extern const char collect_metrics_cmd[];
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);
/* Exported variables */
CLIENT *me; /* my resource */
bool no_signals = false;
-void *start_heap;
extern struct s_cmds cmds[];
bstatcollect *statcollector = NULL;
fdstatmetrics_t fdstatmetrics;
char *uid = NULL;
char *gid = NULL;
- start_heap = sbrk(0);
+ mark_heap();
setlocale(LC_ALL, "");
bindtextdomain("bacula", LOCALEDIR);
textdomain("bacula");
#include "filed.h"
#include "lib/status.h"
-extern void *start_heap;
-
extern bool GetWindowsVersionString(char *buf, int maxsiz);
{
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];
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[])
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;
}
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
*/
} else if (ret == EINTR) {
goto again;
-
+
} else if (ret != 0) {
berrno be;
Dmsg1(dbglevel, "Got error for getgrnam_r %s\n", be.bstrerror(ret));
struct passwd pw, *ppw;
int size = init_size;
char *buf = (char *)malloc(size);
-
+
again:
errno = 0;
ret = getpwnam_r(user, &pw, buf, size, &ppw);
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");
}
ok(get_user_home_directory("root", home.addr()) == 0, "get_user_home_directory()");
-
+
return report();
}
#endif
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,
{
pthread_attr_t attr;
- void * start_heap = sbrk(0);
- (void)start_heap;
-
+ mark_heap();
setlocale(LC_ALL, "");
bindtextdomain("bacula", LOCALEDIR);
textdomain("bacula");
static CONFIG *config;
#define CONFIG_FILE "bacula-sd.conf"
-void *start_heap;
char *configfile = NULL;
static void usage()
static CONFIG *config;
#define CONFIG_FILE "bacula-sd.conf"
-void *start_heap;
char *configfile = NULL;
bool skip_extract = false;
static bool filter = false; /* any filter set ? */
static bool dedup = false; /* decode dedup reference */
-void *start_heap;
#define CONFIG_FILE "bacula-sd.conf"
char *configfile = NULL;
bool detect_errors = false;
static CONFIG *config;
#define CONFIG_FILE "bacula-sd.conf"
-void *start_heap;
char *configfile = NULL;
static void usage()
extern void free_config_resources();
/* Exported variables */
-void *start_heap;
int quit = 0;
char buf[100000];
int bsize = TAPE_BSIZE;
{
pthread_attr_t attr;
- void * start_heap = sbrk(0);
- (void)start_heap;
-
+ mark_heap();
setlocale(LC_ALL, "");
bindtextdomain("bacula", LOCALEDIR);
textdomain("bacula");
static CONFIG *config;
-void *start_heap;
#define CONFIG_FILE "bacula-sd.conf"
char *configfile = NULL;
bool detect_errors = false;
#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;
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);
/* Imported variables */
extern BSOCK *filed_chan;
-extern void *start_heap;
/* Static variables */
static char OKqstatus[] = "3000 OK .status\n";
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),
/* 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;
device_default_open_mode = omd_write;
- start_heap = sbrk(0);
+ mark_heap();
setlocale(LC_ALL, "");
bindtextdomain("bacula", LOCALEDIR);
textdomain("bacula");