use one talloc context for entire vty code
This commit is contained in:
parent
2477d93c6e
commit
0224e4d051
|
@ -147,5 +147,5 @@ int vty_shell (struct vty *);
|
|||
int vty_shell_serv (struct vty *);
|
||||
void vty_hello (struct vty *);
|
||||
|
||||
|
||||
void *tall_vty_ctx;
|
||||
#endif
|
||||
|
|
|
@ -32,8 +32,6 @@
|
|||
#include <vty/buffer.h>
|
||||
#include <vty/vty.h>
|
||||
|
||||
static void *tall_vbuf_ctx;
|
||||
|
||||
/* Buffer master. */
|
||||
struct buffer {
|
||||
/* Data list. */
|
||||
|
@ -71,7 +69,7 @@ struct buffer *buffer_new(size_t size)
|
|||
{
|
||||
struct buffer *b;
|
||||
|
||||
b = talloc_zero(tall_vbuf_ctx, struct buffer);
|
||||
b = talloc_zero(tall_vty_ctx, struct buffer);
|
||||
|
||||
if (size)
|
||||
b->size = size;
|
||||
|
@ -105,7 +103,7 @@ char *buffer_getstr(struct buffer *b)
|
|||
|
||||
for (data = b->head; data; data = data->next)
|
||||
totlen += data->cp - data->sp;
|
||||
if (!(s = _talloc_zero(tall_vbuf_ctx, (totlen + 1), "buffer_getstr")))
|
||||
if (!(s = _talloc_zero(tall_vty_ctx, (totlen + 1), "buffer_getstr")))
|
||||
return NULL;
|
||||
p = s;
|
||||
for (data = b->head; data; data = data->next) {
|
||||
|
@ -140,7 +138,7 @@ static struct buffer_data *buffer_add(struct buffer *b)
|
|||
{
|
||||
struct buffer_data *d;
|
||||
|
||||
d = _talloc_zero(tall_vbuf_ctx,
|
||||
d = _talloc_zero(tall_vty_ctx,
|
||||
offsetof(struct buffer_data, data[b->size]),
|
||||
"buffer_add");
|
||||
if (!d)
|
||||
|
@ -463,8 +461,3 @@ buffer_write(struct buffer * b, int fd, const void *p, size_t size)
|
|||
}
|
||||
return b->head ? BUFFER_PENDING : BUFFER_EMPTY;
|
||||
}
|
||||
|
||||
static __attribute__((constructor)) void on_dso_load_vty_buf(void)
|
||||
{
|
||||
tall_vbuf_ctx = talloc_named_const(NULL, 1, "vty_buffer");
|
||||
}
|
||||
|
|
|
@ -49,8 +49,6 @@ Boston, MA 02111-1307, USA. */
|
|||
#include <openbsc/gsm_subscriber.h>
|
||||
#include <openbsc/talloc.h>
|
||||
|
||||
static void *tall_vcmd_ctx;
|
||||
|
||||
/* Command vector which includes some level of command lists. Normally
|
||||
each daemon maintains each own cmdvec. */
|
||||
vector cmdvec;
|
||||
|
@ -175,7 +173,7 @@ char *argv_concat(const char **argv, int argc, int shift)
|
|||
len += strlen(argv[i]) + 1;
|
||||
if (!len)
|
||||
return NULL;
|
||||
p = str = _talloc_zero(tall_vcmd_ctx, len, "arvg_concat");
|
||||
p = str = _talloc_zero(tall_vty_ctx, len, "arvg_concat");
|
||||
for (i = shift; i < argc; i++) {
|
||||
size_t arglen;
|
||||
memcpy(p, argv[i], (arglen = strlen(argv[i])));
|
||||
|
@ -277,7 +275,7 @@ vector cmd_make_strvec(const char *string)
|
|||
*cp != '\0')
|
||||
cp++;
|
||||
strlen = cp - start;
|
||||
token = _talloc_zero(tall_vcmd_ctx, strlen + 1, "make_strvec");
|
||||
token = _talloc_zero(tall_vty_ctx, strlen + 1, "make_strvec");
|
||||
memcpy(token, start, strlen);
|
||||
*(token + strlen) = '\0';
|
||||
vector_set(strvec, token);
|
||||
|
@ -333,7 +331,7 @@ static char *cmd_desc_str(const char **string)
|
|||
cp++;
|
||||
|
||||
strlen = cp - start;
|
||||
token = _talloc_zero(tall_vcmd_ctx, strlen + 1, "cmd_desc_str");
|
||||
token = _talloc_zero(tall_vty_ctx, strlen + 1, "cmd_desc_str");
|
||||
memcpy(token, start, strlen);
|
||||
*(token + strlen) = '\0';
|
||||
|
||||
|
@ -404,11 +402,11 @@ static vector cmd_make_descvec(const char *string, const char *descstr)
|
|||
|
||||
len = cp - sp;
|
||||
|
||||
token = _talloc_zero(tall_vcmd_ctx, len + 1, "cmd_make_descvec");
|
||||
token = _talloc_zero(tall_vty_ctx, len + 1, "cmd_make_descvec");
|
||||
memcpy(token, sp, len);
|
||||
*(token + len) = '\0';
|
||||
|
||||
desc = talloc_zero(tall_vcmd_ctx, struct desc);
|
||||
desc = talloc_zero(tall_vty_ctx, struct desc);
|
||||
desc->cmd = token;
|
||||
desc->str = cmd_desc_str(&dp);
|
||||
|
||||
|
@ -1855,7 +1853,7 @@ static char **cmd_complete_command_real(vector vline, struct vty *vty,
|
|||
if (len < lcd) {
|
||||
char *lcdstr;
|
||||
|
||||
lcdstr = _talloc_zero(tall_vcmd_ctx, lcd + 1,
|
||||
lcdstr = _talloc_zero(tall_vty_ctx, lcd + 1,
|
||||
"complete-lcdstr");
|
||||
memcpy(lcdstr, matchvec->index[0], lcd);
|
||||
lcdstr[lcd] = '\0';
|
||||
|
@ -2476,13 +2474,13 @@ DEFUN(config_write_file,
|
|||
config_file = host.config;
|
||||
|
||||
config_file_sav =
|
||||
_talloc_zero(tall_vcmd_ctx,
|
||||
_talloc_zero(tall_vty_ctx,
|
||||
strlen(config_file) + strlen(CONF_BACKUP_EXT) + 1,
|
||||
"config_file_sav");
|
||||
strcpy(config_file_sav, config_file);
|
||||
strcat(config_file_sav, CONF_BACKUP_EXT);
|
||||
|
||||
config_file_tmp = _talloc_zero(tall_vcmd_ctx, strlen(config_file) + 8,
|
||||
config_file_tmp = _talloc_zero(tall_vty_ctx, strlen(config_file) + 8,
|
||||
"config_file_tmp");
|
||||
sprintf(config_file_tmp, "%s.XXXXXX", config_file);
|
||||
|
||||
|
@ -3421,8 +3419,3 @@ void cmd_init(int terminal)
|
|||
}
|
||||
srand(time(NULL));
|
||||
}
|
||||
|
||||
static __attribute__((constructor)) void on_dso_load_vty_command(void)
|
||||
{
|
||||
tall_vcmd_ctx = talloc_named_const(NULL, 1, "vty_command");
|
||||
}
|
||||
|
|
|
@ -23,15 +23,14 @@
|
|||
#include <unistd.h>
|
||||
|
||||
#include <vty/vector.h>
|
||||
#include <vty/vty.h>
|
||||
#include <openbsc/talloc.h>
|
||||
#include <memory.h>
|
||||
|
||||
static void *tall_vvec_ctx;
|
||||
|
||||
/* Initialize vector : allocate memory and return vector. */
|
||||
vector vector_init(unsigned int size)
|
||||
{
|
||||
vector v = talloc_zero(tall_vvec_ctx, struct _vector);
|
||||
vector v = talloc_zero(tall_vty_ctx, struct _vector);
|
||||
if (!v)
|
||||
return NULL;
|
||||
|
||||
|
@ -41,7 +40,7 @@ vector vector_init(unsigned int size)
|
|||
|
||||
v->alloced = size;
|
||||
v->active = 0;
|
||||
v->index = _talloc_zero(tall_vvec_ctx, sizeof(void *) * size,
|
||||
v->index = _talloc_zero(tall_vty_ctx, sizeof(void *) * size,
|
||||
"vector_init:index");
|
||||
if (!v->index) {
|
||||
talloc_free(v);
|
||||
|
@ -69,7 +68,7 @@ void vector_free(vector v)
|
|||
vector vector_copy(vector v)
|
||||
{
|
||||
unsigned int size;
|
||||
vector new = talloc_zero(tall_vvec_ctx, struct _vector);
|
||||
vector new = talloc_zero(tall_vty_ctx, struct _vector);
|
||||
if (!new)
|
||||
return NULL;
|
||||
|
||||
|
@ -77,7 +76,7 @@ vector vector_copy(vector v)
|
|||
new->alloced = v->alloced;
|
||||
|
||||
size = sizeof(void *) * (v->alloced);
|
||||
new->index = _talloc_zero(tall_vvec_ctx, size, "vector_copy:index");
|
||||
new->index = _talloc_zero(tall_vty_ctx, size, "vector_copy:index");
|
||||
if (!new->index) {
|
||||
talloc_free(new);
|
||||
return NULL;
|
||||
|
@ -93,7 +92,7 @@ void vector_ensure(vector v, unsigned int num)
|
|||
if (v->alloced > num)
|
||||
return;
|
||||
|
||||
v->index = talloc_realloc_size(tall_vvec_ctx, v->index,
|
||||
v->index = talloc_realloc_size(tall_vty_ctx, v->index,
|
||||
sizeof(void *) * (v->alloced * 2));
|
||||
memset(&v->index[v->alloced], 0, sizeof(void *) * v->alloced);
|
||||
v->alloced *= 2;
|
||||
|
@ -189,8 +188,3 @@ unsigned int vector_count(vector v)
|
|||
|
||||
return count;
|
||||
}
|
||||
|
||||
static __attribute__((constructor)) void on_dso_load_vty_vec(void)
|
||||
{
|
||||
tall_vvec_ctx = talloc_named_const(NULL, 1, "vty_vector");
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ static int vty_config;
|
|||
|
||||
static int no_password_check = 1;
|
||||
|
||||
static void *tall_vty_ctx;
|
||||
void *tall_vty_ctx;
|
||||
|
||||
static void vty_clear_buf(struct vty *vty)
|
||||
{
|
||||
|
@ -1616,14 +1616,15 @@ void vty_init_vtysh()
|
|||
vtyvec = vector_init(VECTOR_MIN_SIZE);
|
||||
}
|
||||
|
||||
extern void *tall_bsc_ctx;
|
||||
/* Install vty's own commands like `who' command. */
|
||||
void vty_init()
|
||||
{
|
||||
tall_vty_ctx = talloc_named_const(tall_bsc_ctx, 1, "vty");
|
||||
|
||||
/* For further configuration read, preserve current directory. */
|
||||
vty_save_cwd();
|
||||
|
||||
host.config = "openbsc.cfg";
|
||||
|
||||
vtyvec = vector_init(VECTOR_MIN_SIZE);
|
||||
|
||||
/* Install bgp top node. */
|
||||
|
|
Loading…
Reference in New Issue