struct ctdb_context *ctdb = talloc_get_type(state->ctdb, struct ctdb_context);
int ret;
TDB_DATA outdata;
- int32_t res;
+ int32_t res = -1;
uint32_t destnode = state->c->hdr.destnode;
/* one more node has responded with recmode data */
tm = localtime(&log_entries[tmp_entry].t.tv_sec);
strftime(tbuf, sizeof(tbuf)-1,"%Y/%m/%d %H:%M:%S", tm);
- if (log_entries[tmp_entry].message) {
+ if (log_entries[tmp_entry].message[0] != '\0') {
count += fprintf(f, "%s:%s %s", tbuf, get_debug_by_level(log_entries[tmp_entry].level), log_entries[tmp_entry].message);
}
}
fsize = ftell(f);
+ if (fsize < 0) {
+ fclose(f);
+ DEBUG(DEBUG_ERR,("Cannot get current file position\n"));
+ return;
+ }
rewind(f);
data.dptr = talloc_size(NULL, fsize);
- CTDB_NO_MEMORY_VOID(ctdb, data.dptr);
+ if (data.dptr == NULL) {
+ fclose(f);
+ CTDB_NO_MEMORY_VOID(ctdb, data.dptr);
+ }
data.dsize = fread(data.dptr, 1, fsize, f);
fclose(f);
fde = event_add_fd(ctdb->ev, ctdb, ctdb->daemon.sd,
EVENT_FD_READ|EVENT_FD_AUTOCLOSE,
ctdb_accept_client, ctdb);
+ if (fde == NULL) {
+ DEBUG(DEBUG_CRIT,("Failed to add daemon socket to event loop\n"));
+ exit(1);
+ }
/* release any IPs we hold from previous runs of the daemon */
ctdb_release_all_ips(ctdb);
/* We'll fail if stderr/stdout not already open; it's simpler. */
old_stdout = dup(STDOUT_FILENO);
old_stderr = dup(STDERR_FILENO);
+ if (old_stdout < 0 || old_stderr < 0) {
+ DEBUG(DEBUG_ERR,(__location__ " Failed to copy files descriptors\n"));
+ return -1;
+ }
if (dup2(p[1], STDOUT_FILENO) < 0 || dup2(p[1], STDERR_FILENO) < 0) {
int saved_errno = errno;
dup2(old_stdout, STDOUT_FILENO);
int invalid_name = 0;
s = talloc_strdup(ctdb, de->d_name);
- CTDB_NO_MEMORY(ctdb, s);
+ if (s == NULL) {
+ closedir(d);
+ CTDB_NO_MEMORY(ctdb, s);
+ }
/* only accept names ending in .tdb */
p = strstr(s, ".tdb.");
}
params->recdata = talloc_realloc_size(NULL, params->recdata, rec->length + params->len);
if (params->recdata == NULL) {
- DEBUG(DEBUG_CRIT,(__location__ " Failed to expand recdata to %u (%u records)\n",
- rec->length + params->len, params->recdata->count));
+ DEBUG(DEBUG_CRIT,(__location__ " Failed to expand recdata to %u\n",
+ rec->length + params->len));
params->failed = true;
return -1;
}
tree_item = talloc(tree, struct ctdb_script_tree_item);
if (tree_item == NULL) {
DEBUG(DEBUG_ERR, (__location__ " Failed to allocate new tree item\n"));
+ closedir(dir);
talloc_free(tmp_ctx);
return NULL;
}
tree_item->name = talloc_strdup(tree_item, de->d_name);
if (tree_item->name == NULL) {
DEBUG(DEBUG_ERR,(__location__ " Failed to allocate script name.\n"));
+ closedir(dir);
talloc_free(tmp_ctx);
return NULL;
}
va_start(ap, fmt);
ret = ctdb_event_script_callback_v(ctdb,
event_script_callback, &status, false, call, fmt, ap);
+ va_end(ap);
if (ret != 0) {
return ret;
}
- va_end(ap);
status.status = -1;
status.done = false;
}
tnode->fd = socket(sock_out.sa.sa_family, SOCK_STREAM, IPPROTO_TCP);
+ if (tnode->fd == -1) {
+ DEBUG(DEBUG_ERR, (__location__ " Failed to create socket.\n"));
+ return;
+ }
set_nonblocking(tnode->fd);
set_close_on_exec(tnode->fd);
sock_in.ip.sin_len = sockin_size;
sock_out.ip.sin_len = sockout_size;
#endif
- bind(tnode->fd, (struct sockaddr *)&sock_in, sockin_size);
+ if (bind(tnode->fd, (struct sockaddr *)&sock_in, sockin_size) != 0) {
+ DEBUG(DEBUG_ERR,(__location__ " Failed to bind() to socket. %s(%d)\n", strerror(errno), errno));
+ close(tnode->fd);
+ return;
+ }
if (connect(tnode->fd, (struct sockaddr *)&sock_out, sockout_size) != 0 &&
errno != EINPROGRESS) {
data.dptr = (uint8_t *)talloc_asprintf_append((char *)data.dptr,
"msg_count=%d on node %d\n",
msg_count, ctdb_get_pnn(ctdb));
+ if (data.dptr == NULL) {
+ printf("Failed to create record\n");
+ talloc_free(tmp_ctx);
+ return;
+ }
data.dsize = strlen((const char *)data.dptr)+1;
ret = ctdb_record_store(h, data);