len = offsetof(struct ctdb_all_public_ips, ips) +
ipsv4->num*sizeof(struct ctdb_public_ip);
*ips = talloc_zero_size(mem_ctx, len);
+ CTDB_NO_MEMORY(ctdb, *ips);
(*ips)->num = ipsv4->num;
for (i=0; i<ipsv4->num; i++) {
(*ips)->ips[i].pnn = ipsv4->ips[i].pnn;
*/
struct ctdb_context *ctdb_init(struct event_context *ev)
{
+ int ret;
struct ctdb_context *ctdb;
ctdb = talloc_zero(ev, struct ctdb_context);
+ if (ctdb == NULL) {
+ DEBUG(DEBUG_ERR,(__location__ " talloc_zero failed.\n"));
+ return NULL;
+ }
ctdb->ev = ev;
ctdb->idr = idr_init(ctdb);
CTDB_NO_MEMORY_NULL(ctdb, ctdb->idr);
- ctdb_set_socketname(ctdb, CTDB_PATH);
+ ret = ctdb_set_socketname(ctdb, CTDB_PATH);
+ if (ret != 0) {
+ DEBUG(DEBUG_ERR,(__location__ " ctdb_set_socketname failed.\n"));
+ talloc_free(ctdb);
+ return NULL;
+ }
return ctdb;
}
int ctdb_set_socketname(struct ctdb_context *ctdb, const char *socketname)
{
ctdb->daemon.name = talloc_strdup(ctdb, socketname);
+ if (ctdb->daemon.name == NULL) return -1;
return 0;
}
/* tell ctdb the socket address */
socket_name = getenv("CTDB_SOCKET");
if (socket_name != NULL) {
- ctdb_set_socketname(ctdb, socket_name);
+ ret = ctdb_set_socketname(ctdb, socket_name);
+ if (ret == -1) {
+ printf("ctdb_set_socketname failed - %s\n",
+ ctdb_errstr(ctdb));
+ exit(1);
+ }
}
if (ctdb_cmdline.socketname != NULL) {
endservent();
address->address = talloc_strdup(mem_ctx, str);
+ if (address->address == NULL) return -1;
if (se == NULL) {
address->port = CTDB_PORT;
} else {
* and being reused for next receive
* noticed that HL requires talloc-ed memory to be stolen */
buf2 = talloc_zero_size(conn, n);
+ if (buf2 == NULL) return -1;
memcpy(buf2, buf, n);
ctdb->upcalls->recv_pkt(ctdb, (uint8_t *)buf2, (uint32_t)n);
rc = ctdb_ibw_send_pkt(cn->conn, data, length);
} else {
struct ctdb_ibw_msg *p = talloc_zero(cn, struct ctdb_ibw_msg);
+ if (p == NULL) {
+ DEBUG(DEBUG_ERR, ("talloc_zero failed.\n"));
+ return -1;
+ }
p->data = talloc_memdup(p, data, length);
+ if (p->data == NULL) {
+ DEBUG(DEBUG_ERR, ("talloc_memdup failed.\n"));
+ return -1;
+ }
p->length = length;
DLIST_ADD_AFTER(cn->queue, p, cn->queue_last);
}
if (part->to_read==0) {
- pctx->receive_func(conn, part->buf, part->len);
+ if(pctx->receive_func(conn, part->buf, part->len)) goto error;
part->len = 0; /* tells not having partial data (any more) */
if (ibw_wc_mem_threshold(pconn, part, pctx->opts.recv_threshold))
goto error;
/* mostly awaited case: */
if (msglen<=remain) {
- pctx->receive_func(conn, p, msglen);
+ if(pctx->receive_func(conn, p, msglen)) goto error;
p += msglen;
remain -= msglen;
} else {
char *tmp;
tmp = talloc_strdup(tcx, optarg);
+ if (tmp == NULL) return -1;
/* hack to reuse the above ibw_initattr parser */
if (ibwtest_parse_attrs(tcx, tmp, &attrs, &tcx->naddrs, op))
return -1;
break;
case 'o':
tcx->opts = talloc_strdup(tcx, optarg);
+ if (tcx->opts) goto cleanup;
if (ibwtest_parse_attrs(tcx, tcx->opts, &tcx->attrs,
&tcx->nattrs, op))
goto cleanup;
}
w->name = talloc_strdup(w, name);
+ if (w->name == NULL) {
+ talloc_free(w);
+ return NULL;
+ }
w->tdb = tdb_open_ex(name, hash_size, tdb_flags,
open_flags, mode, &log_ctx, NULL);
char *s = NULL;
struct tm *tm;
char tbuf[100];
-
- vasprintf(&s, format, ap);
+ int ret;
+
+ ret = vasprintf(&s, format, ap);
+ if (ret == -1) {
+ fprintf(stderr, "vasprintf failed in _do_debug_v, cannot print debug message.\n");
+ fflush(stderr);
+ return;
+ }
t = timeval_current();
tm = localtime(&t.tv_sec);
/* ensure the socket is deleted on exit of the daemon */
domain_socket_name = talloc_strdup(talloc_autofree_context(), ctdb->daemon.name);
+ if (domain_socket_name == NULL) {
+ DEBUG(DEBUG_ALERT,(__location__ " talloc_strdup failed.\n"));
+ exit(12);
+ }
talloc_set_destructor(domain_socket_name, unlink_destructor);
ctdb->ev = event_context_init(NULL);
struct tm *tm;
char tbuf[100];
char *s2 = NULL;
+ int ret;
- vasprintf(&s, format, ap);
+ ret = vasprintf(&s, format, ap);
+ if (ret == -1) {
+ write(log_state->fd, "vasprintf failed\n", strlen("vasprintf failed\n"));
+ return;
+ }
t = timeval_current();
tm = localtime(&t.tv_sec);
strftime(tbuf,sizeof(tbuf)-1,"%Y/%m/%d %H:%M:%S", tm);
- asprintf(&s2, "%s.%06u [%5u]: %s",
+ ret = asprintf(&s2, "%s.%06u [%5u]: %s",
tbuf, (unsigned)t.tv_usec, (unsigned)getpid(), s);
free(s);
+ if (ret == -1) {
+ write(log_state->fd, "asprintf failed\n", strlen("asprintf failed\n"));
+ return;
+ }
if (s2) {
write(log_state->fd, s2, strlen(s2));
- free(s2);
+ free(s2);
}
}
*/
int ctdb_set_logfile(struct ctdb_context *ctdb, const char *logfile, bool use_syslog)
{
+ int ret;
ctdb->log = talloc_zero(ctdb, struct ctdb_log_state);
if (ctdb->log == NULL) {
printf("talloc_zero failed\n");
do_debug_v = ctdb_logfile_log;
ctdb->log->fd = 1;
/* also catch stderr of subcommands to stdout */
- dup2(1, 2);
+ ret = dup2(1, 2);
+ if (ret == -1) {
+ printf("dup2 failed: %s\n", strerror(errno));
+ abort();
+ }
} else {
do_debug_v = ctdb_logfile_log;
int ctdb_set_child_logging(struct ctdb_context *ctdb)
{
int p[2];
+ int ret;
if (ctdb->log->fd == 1) {
/* not needed for stdout logging */
close(1);
close(2);
if (p[1] != 1) {
- dup2(p[1], 1);
+ ret = dup2(p[1], 1);
+ if (ret == -1) {
+ printf("dup2 failed: %s\n", strerror(errno));
+ return -1;
+ }
close(p[1]);
}
/* also catch stderr of subcommands to the log */
- dup2(1, 2);
+ ret = dup2(1, 2);
+ if (ret == -1) {
+ printf("dup2 failed: %s\n", strerror(errno));
+ return -1;
+ }
return 0;
}
int ctdb_set_transport(struct ctdb_context *ctdb, const char *transport)
{
ctdb->transport = talloc_strdup(ctdb, transport);
+ if (ctdb->transport == NULL) return -1;
return 0;
}
int ctdb_set_recovery_lock_file(struct ctdb_context *ctdb, const char *file)
{
ctdb->recovery_lock_file = talloc_strdup(ctdb, file);
+ if (ctdb->recovery_lock_file == NULL) return -1;
return 0;
}
that the cluster has been reconfigured and they should
release any sockets on this IP */
data.dptr = (uint8_t *)talloc_strdup(state, ctdb_addr_to_str(state->addr));
+ CTDB_NO_MEMORY_VOID(ctdb, data.dptr);
data.dsize = strlen((char *)data.dptr)+1;
DEBUG(DEBUG_INFO,(__location__ " sending RELEASE_IP for '%s'\n", data.dptr));
vnn = talloc_zero(ctdb, struct ctdb_vnn);
CTDB_NO_MEMORY_FATAL(ctdb, vnn);
vnn->iface = talloc_strdup(vnn, iface);
+ CTDB_NO_MEMORY(ctdb, vnn->iface);
vnn->public_address = *addr;
vnn->public_netmask_bits = mask;
vnn->pnn = -1;
script->next = monitoring_status->scripts;
script->name = talloc_strdup(script, name);
+ CTDB_NO_MEMORY(ctdb, script->name);
script->start = timeval_current();
monitoring_status->scripts = script;
char *script;
int count;
int is_monitor = 0;
+ char *d_name_dup;
if (!strcmp(options, "monitor")) {
is_monitor = 1;
/* store the event script in the tree */
- trbt_insert32(tree, (num<<16)|count++, talloc_strdup(tree, de->d_name));
+ d_name_dup = talloc_strdup(tree, de->d_name);
+ CTDB_NO_MEMORY(ctdb, d_name_dup);
+ trbt_insert32(tree, (num<<16)|count++, d_name_dup);
}
closedir(dir);
{
int i;
uint32_t *counters, *old_counters;
+ unsigned char *tmp_dptr;
counters = (uint32_t *)data.dptr;
old_counters = (uint32_t *)old_data.dptr;
if (old_data.dsize != data.dsize) {
old_data.dsize = data.dsize;
- old_data.dptr = talloc_realloc_size(ctdb, old_data.dptr, old_data.dsize);
+ tmp_dptr = talloc_realloc_size(ctdb, old_data.dptr, old_data.dsize);
+ if (tmp_dptr == NULL) {
+ printf("[%4u] ERROR: talloc_realloc_size failed.\n", getpid());
+ success = false;
+ return;
+ } else {
+ old_data.dptr = tmp_dptr;
+ }
}
memcpy(old_data.dptr, data.dptr, data.dsize);
pnn_node = talloc(mem_ctx, struct pnn_node);
pnn_node->pnn = pnn++;
pnn_node->addr = talloc_strdup(pnn_node, node);
+ CTDB_NO_MEMORY(ctdb, pnn_node->addr);
pnn_node->next = pnn_nodes;
pnn_nodes = pnn_node;
}
}
natgw_node = talloc(ctdb, struct natgw_node);
natgw_node->addr = talloc_strdup(natgw_node, node);
+ CTDB_NO_MEMORY(ctdb, natgw_node->addr);
natgw_node->next = natgw_nodes;
natgw_nodes = natgw_node;
}
struct db_file_header dbhdr;
struct ctdb_db_context *ctdb_db;
struct backup_data *bd;
- int fh;
+ int fh = -1;
+ int status = -1;
if (argc != 2) {
DEBUG(DEBUG_ERR,("Invalid arguments\n"));
ctdb_db = ctdb_attach(ctdb, argv[0], dbmap->dbs[i].persistent, 0);
if (ctdb_db == NULL) {
DEBUG(DEBUG_ERR,("Unable to attach to database '%s'\n", argv[0]));
+ talloc_free(tmp_ctx);
return -1;
}
dbhdr.size = bd->len;
if (strlen(argv[0]) >= MAX_DB_NAME) {
DEBUG(DEBUG_ERR,("Too long dbname\n"));
- talloc_free(tmp_ctx);
- return -1;
+ goto done;
}
strncpy(discard_const(dbhdr.name), argv[0], MAX_DB_NAME);
- write(fh, &dbhdr, sizeof(dbhdr));
- write(fh, bd->records, bd->len);
+ ret = write(fh, &dbhdr, sizeof(dbhdr));
+ if (ret == -1) {
+ DEBUG(DEBUG_ERR,("write failed: %s\n", strerror(errno)));
+ goto done;
+ }
+ ret = write(fh, bd->records, bd->len);
+ if (ret == -1) {
+ DEBUG(DEBUG_ERR,("write failed: %s\n", strerror(errno)));
+ goto done;
+ }
- close(fh);
+ status = 0;
+done:
+ if (fh != -1) {
+ ret = close(fh);
+ if (ret == -1) {
+ DEBUG(DEBUG_ERR,("close failed: %s\n", strerror(errno)));
+ }
+ }
talloc_free(tmp_ctx);
- return 0;
+ return status;
}
/*
unsigned char *val;
unsigned char incr=0, last_incr=0;
unsigned char *p = NULL;
+ int ret;
- ftruncate(fd, num_locks+1);
+ ret = ftruncate(fd, num_locks+1);
+ if (ret == -1) {
+ printf("ftruncate failed: %s\n", strerror(errno));
+ return;
+ }
if (use_mmap) {
p = mmap(NULL, num_locks+1, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
+ if (p == MAP_FAILED) {
+ printf("mmap failed: %s\n", strerror(errno));
+ return;
+ }
}
val = (unsigned char *)calloc(num_locks+1, sizeof(unsigned char));
+ if (val == NULL) {
+ printf("calloc failed\n");
+ return;
+ }
- start_timer();
+ start_timer();
lock_range(fd, 0, 1);
i = 0;