#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;
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;
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;
}
#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;
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));
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);
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;
/*
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).
{
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);
}
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);
}
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;
if (_arg->xfer) {
_arg->xfer->increment_processed_size(ret);
}
- }
+ }
}
}
return ret;
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 */
free(fname);
return (ret==0);
- } else {
+ } else {
uint32_t retry = max_upload_retries;
int ret=-1;
while ((ret!=0) && (retry>0)) {
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 */
}
bool generic_driver::restore_cloud_object(transfer *xfer, const char *cloud_fname)
-{
+{
(void) (xfer);
(void) (cloud_fname);
/* not implemented */
volumes = _arg->volumes;
remain = _arg->remain;
}
-
+
if (volumes) {
/* do the actual process */
char * pch = strtok (res,"\n");
#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");