int num = r_last - r_first + 1;
RES **res_tab = reload_table[table].res_table;
if (!res_tab) {
- Dmsg1(000, "res_tab for table %d already released.\n", table);
+ Dmsg1(100, "res_tab for table %d already released.\n", table);
return;
}
- Dmsg1(000, "Freeing resources for table %d\n", table);
+ Dmsg1(100, "Freeing resources for table %d\n", table);
for (int j=0; j<num; j++) {
free_resource(res_tab[j], r_first + j);
}
static void reload_job_end_cb(JCR *jcr, void *ctx)
{
int reload_id = (int)ctx;
- Dmsg3(000, "reload job_end JobId=%d table=%d cnt=%d\n", jcr->JobId,
+ Dmsg3(100, "reload job_end JobId=%d table=%d cnt=%d\n", jcr->JobId,
reload_id, reload_table[reload_id].job_count);
lock_jcr_chain();
LockRes();
goto bail_out;
}
- Dmsg1(000, "Reload_config njobs=%d\n", njobs);
+ Dmsg1(100, "Reload_config njobs=%d\n", njobs);
reload_table[table].res_table = save_config_resources();
- Dmsg1(000, "Saved old config in table %d\n", table);
+ Dmsg1(100, "Saved old config in table %d\n", table);
- Dmsg0(000, "Calling parse config\n");
parse_config(configfile);
- Dmsg0(000, "Reloaded config file\n");
+ Dmsg0(100, "Reloaded config file\n");
if (!check_resources()) {
rtable = find_free_reload_table_entry(); /* save new, bad table */
if (rtable < 0) {
job->hdr.name, job_items[i].name, *def_svalue, i, offset);
svalue = (char **)((char *)job + offset);
if (*svalue) {
- Dmsg1(000, "Hey something is wrong. p=0x%lu\n", *svalue);
+ Pmsg1(000, "Hey something is wrong. p=0x%lu\n", *svalue);
}
*svalue = bstrdup(*def_svalue);
set_bit(i, job->hdr.item_present);
job->hdr.name, job_items[i].name, i, offset);
svalue = (char **)((char *)job + offset);
if (*svalue) {
- Dmsg1(000, "Hey something is wrong. p=0x%lu\n", *svalue);
+ Pmsg1(000, "Hey something is wrong. p=0x%lu\n", *svalue);
}
*svalue = *def_svalue;
set_bit(i, job->hdr.item_present);
}
return res;
}
+
+RES **new_res_head()
+{
+ int size = (r_last - r_first + 1) * sizeof(RES *);
+ RES **res = (RES **)malloc(size);
+ memset(res, 0, size);
+ return res;
+}
*/
-struct RES_ITEM; /* Declare forward referenced structure */
+struct RES_ITEM; /* Declare forward referenced structure */
typedef void (MSG_RES_HANDLER)(LEX *lc, RES_ITEM *item, int index, int pass);
/* This is the structure that defines
* tables.
*/
struct RES_ITEM {
- const char *name; /* Resource name i.e. Director, ... */
- MSG_RES_HANDLER *handler; /* Routine storing the resource item */
- void **value; /* Where to store the item */
- int code; /* item code/additional info */
- int flags; /* flags: default, required, ... */
- int default_value; /* default value */
+ const char *name; /* Resource name i.e. Director, ... */
+ MSG_RES_HANDLER *handler; /* Routine storing the resource item */
+ void **value; /* Where to store the item */
+ int code; /* item code/additional info */
+ int flags; /* flags: default, required, ... */
+ int default_value; /* default value */
};
/* For storing name_addr items in res_items table */
#define ITEM(x) ((void **)&res_all.x)
-#define MAX_RES_ITEMS 50 /* maximum resource items per RES */
+#define MAX_RES_ITEMS 50 /* maximum resource items per RES */
/* This is the universal header that is
* at the beginning of every resource
* record.
*/
struct RES {
- RES *next; /* pointer to next resource of this type */
- char *name; /* resource name */
- char *desc; /* resource description */
- int rcode; /* resource id or type */
- int refcnt; /* reference count for releasing */
+ RES *next; /* pointer to next resource of this type */
+ char *name; /* resource name */
+ char *desc; /* resource description */
+ int rcode; /* resource id or type */
+ int refcnt; /* reference count for releasing */
char item_present[MAX_RES_ITEMS]; /* set if item is present in conf file */
};
* This is the structure that defines the
* resources that are available to this daemon.
*/
-struct RES_TABLE {
- const char *name; /* resource name */
- RES_ITEM *items; /* list of resource keywords */
- int rcode; /* code if needed */
+struct RES_TABLE {
+ const char *name; /* resource name */
+ RES_ITEM *items; /* list of resource keywords */
+ int rcode; /* code if needed */
};
/* Common Resource definitions */
-#define MAX_RES_NAME_LENGTH MAX_NAME_LENGTH-1 /* maximum resource name length */
+#define MAX_RES_NAME_LENGTH MAX_NAME_LENGTH-1 /* maximum resource name length */
-#define ITEM_REQUIRED 0x1 /* item required */
-#define ITEM_DEFAULT 0x2 /* default supplied */
+#define ITEM_REQUIRED 0x1 /* item required */
+#define ITEM_DEFAULT 0x2 /* default supplied */
#define ITEM_NO_EQUALS 0x4 /* Don't scan = after name */
/* Message Resource */
struct MSGS {
- RES hdr;
- char *mail_cmd; /* mail command */
- char *operator_cmd; /* Operator command */
- DEST *dest_chain; /* chain of destinations */
+ RES hdr;
+ char *mail_cmd; /* mail command */
+ char *operator_cmd; /* Operator command */
+ DEST *dest_chain; /* chain of destinations */
char send_msg[nbytes_for_bits(M_MAX+1)]; /* bit array of types */
};
/* Configuration routines */
-int parse_config(const char *cf, int exit_on_error = 1);
-void free_config_resources(void);
+int parse_config(const char *cf, int exit_on_error = 1);
+void free_config_resources(void);
RES **save_config_resources(void);
+RES **new_res_head();
+
/* Resource routines */
RES *GetResWithName(int rcode, char *name);
#ifdef the_old_way
#define foreach_res(var, type) \
- for((var)=NULL; (((void *)(var))=GetNextRes((type), (RES *)var));)
+ for((var)=NULL; (((void *)(var))=GetNextRes((type), (RES *)var));)
#endif
&abqueue, &abqueue
};
+uint64_t sm_max_bytes = 0;
+uint64_t sm_bytes = 0;
+uint32_t sm_max_buffers = 0;
+uint32_t sm_buffers = 0;
+
static bool bufimode = false; /* Buffers not tracked when True */
#define HEAD_SIZE BALIGN(sizeof(struct abufhead))
nbytes += HEAD_SIZE + 1;
if ((buf = (char *)malloc(nbytes)) != NULL) {
+ struct abufhead *head = (struct abufhead *)buf;
P(mutex);
/* Enqueue buffer on allocated list */
qinsert(&abqueue, (struct b_queue *) buf);
- ((struct abufhead *) buf)->ablen = nbytes;
- ((struct abufhead *) buf)->abfname = bufimode ? NULL : fname;
- ((struct abufhead *) buf)->ablineno = (sm_ushort) lineno;
+ head->ablen = nbytes;
+ head->abfname = bufimode ? NULL : fname;
+ head->ablineno = (sm_ushort) lineno;
/* Emplace end-clobber detector at end of buffer */
buf[nbytes - 1] = (((long) buf) & 0xFF) ^ 0xC5;
buf += HEAD_SIZE; /* Increment to user data start */
+ if (++sm_buffers > sm_max_buffers) {
+ sm_max_buffers = sm_buffers;
+ }
+ sm_bytes += nbytes;
+ if (sm_bytes > sm_max_bytes) {
+ sm_max_bytes = sm_bytes;
+ }
V(mutex);
} else {
Emsg0(M_ABORT, 0, _("Out of memory\n"));
cp -= HEAD_SIZE;
qp = (struct b_queue *) cp;
+ struct abufhead *head = (struct abufhead *)cp;
P(mutex);
Dmsg4(1150, "sm_free %d at %x from %s:%d\n",
- ((struct abufhead *)cp)->ablen, fp,
- ((struct abufhead *)cp)->abfname, ((struct abufhead *)cp)->ablineno);
+ head->ablen, fp,
+ head->abfname, head->ablineno);
/* The following assertions will catch virtually every release
of an address which isn't an allocated buffer. */
allocated space in the buffer by comparing the end of buffer
checksum with the address of the buffer. */
- if (((unsigned char *) cp)[((struct abufhead *) cp)->ablen - 1] !=
- ((((long) cp) & 0xFF) ^ 0xC5)) {
+ if (((unsigned char *)cp)[head->ablen - 1] != ((((long) cp) & 0xFF) ^ 0xC5)) {
V(mutex);
Emsg2(M_ABORT, 0, "Buffer overrun called from %s:%d\n", file, line);
}
-
+ sm_buffers--;
+ sm_bytes -= head->ablen;
qdchain(qp);
V(mutex);
attempts to access data through a pointer into storage that's
been previously released. */
- memset(cp, 0xAA, (int) ((struct abufhead *) cp)->ablen);
+ memset(cp, 0xAA, (int) head->ablen);
free(cp);
}
return the buffer passed in. */
cp -= HEAD_SIZE;
- osize = ((struct abufhead *) cp)->ablen - (HEAD_SIZE + 1);
+ struct abufhead *head = (struct abufhead *)cp;
+ osize = head->ablen - (HEAD_SIZE + 1);
if (size == osize) {
return ptr;
}
return NULL from realloc() and leave the buffer in PTR
intact. */
+ sm_buffers--;
+ sm_bytes -= osize;
+
if ((buf = smalloc(fname, lineno, size)) != NULL) {
memcpy(buf, ptr, (int) sm_min(size, osize));
/* If the new buffer is larger than the old, fill the balance