mirror of
https://github.com/samba-team/samba.git
synced 2024-12-22 13:34:15 +03:00
ctdb: Use sys_read() and sys_write() to ensure correct signal interaction
... and avoid compiler warnings in some cases. Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Amitay Isaacs <amitay@gmail.com>
This commit is contained in:
parent
fcd6ee1eac
commit
c1558adeaa
@ -196,7 +196,9 @@ static void queue_io_read(struct ctdb_queue *queue)
|
||||
}
|
||||
|
||||
if (num_ready > 0) {
|
||||
nread = read(queue->fd, queue->buffer.data + queue->buffer.length, num_ready);
|
||||
nread = sys_read(queue->fd,
|
||||
queue->buffer.data + queue->buffer.length,
|
||||
num_ready);
|
||||
if (nread <= 0) {
|
||||
DEBUG(DEBUG_ERR, ("read error nread=%d\n", (int)nread));
|
||||
goto failed;
|
||||
@ -230,9 +232,9 @@ static void queue_io_write(struct ctdb_queue *queue)
|
||||
struct ctdb_queue_pkt *pkt = queue->out_queue;
|
||||
ssize_t n;
|
||||
if (queue->ctdb->flags & CTDB_FLAG_TORTURE) {
|
||||
n = write(queue->fd, pkt->data, 1);
|
||||
n = sys_write(queue->fd, pkt->data, 1);
|
||||
} else {
|
||||
n = write(queue->fd, pkt->data, pkt->length);
|
||||
n = sys_write(queue->fd, pkt->data, pkt->length);
|
||||
}
|
||||
|
||||
if (n == -1 && errno != EAGAIN && errno != EWOULDBLOCK) {
|
||||
@ -308,7 +310,7 @@ int ctdb_queue_send(struct ctdb_queue *queue, uint8_t *data, uint32_t length)
|
||||
queue overhead. This relies on non-blocking sockets */
|
||||
if (queue->out_queue == NULL && queue->fd != -1 &&
|
||||
!(queue->ctdb->flags & CTDB_FLAG_TORTURE)) {
|
||||
ssize_t n = write(queue->fd, data, length2);
|
||||
ssize_t n = sys_write(queue->fd, data, length2);
|
||||
if (n == -1 && errno != EAGAIN && errno != EWOULDBLOCK) {
|
||||
talloc_free(queue->fde);
|
||||
queue->fde = NULL;
|
||||
|
@ -1457,7 +1457,7 @@ static void revokechild_handler(struct event_context *ev, struct fd_event *fde,
|
||||
int ret;
|
||||
char c;
|
||||
|
||||
ret = read(rc->fd[0], &c, 1);
|
||||
ret = sys_read(rc->fd[0], &c, 1);
|
||||
if (ret != 1) {
|
||||
DEBUG(DEBUG_ERR,("Failed to read status from revokechild. errno:%d\n", errno));
|
||||
rc->status = -1;
|
||||
@ -1675,7 +1675,7 @@ int ctdb_start_revoke_ro_record(struct ctdb_context *ctdb, struct ctdb_db_contex
|
||||
c = ctdb_revoke_all_delegations(ctdb, ctdb_db, tdata, key, header, data);
|
||||
|
||||
child_finished:
|
||||
write(rc->fd[1], &c, 1);
|
||||
sys_write(rc->fd[1], &c, 1);
|
||||
/* make sure we die when our parent dies */
|
||||
while (ctdb_kill(ctdb, parent, 0) == 0 || errno != ESRCH) {
|
||||
sleep(5);
|
||||
|
@ -123,7 +123,7 @@ int main(int argc, char *argv[])
|
||||
if (output == ENOENT || output == ENOEXEC) {
|
||||
output = -output;
|
||||
}
|
||||
write(write_fd, &output, sizeof(output));
|
||||
sys_write(write_fd, &output, sizeof(output));
|
||||
exit(output);
|
||||
}
|
||||
|
||||
|
@ -443,7 +443,7 @@ static void ctdb_lock_handler(struct tevent_context *ev,
|
||||
}
|
||||
|
||||
/* Read the status from the child process */
|
||||
if (read(lock_ctx->fd[0], &c, 1) != 1) {
|
||||
if (sys_read(lock_ctx->fd[0], &c, 1) != 1) {
|
||||
locked = false;
|
||||
} else {
|
||||
locked = (c == 0 ? true : false);
|
||||
|
@ -26,7 +26,7 @@ static char *progname = NULL;
|
||||
|
||||
static void send_result(int fd, char result)
|
||||
{
|
||||
write(fd, &result, 1);
|
||||
sys_write(fd, &result, 1);
|
||||
if (result == 1) {
|
||||
exit(1);
|
||||
}
|
||||
|
@ -129,7 +129,7 @@ int start_syslog_daemon(struct ctdb_context *ctdb)
|
||||
set_close_on_exec(state->fd[0]);
|
||||
|
||||
close(startup_fd[1]);
|
||||
n = read(startup_fd[0], &dummy, sizeof(dummy));
|
||||
n = sys_read(startup_fd[0], &dummy, sizeof(dummy));
|
||||
close(startup_fd[0]);
|
||||
if (n < sizeof(dummy)) {
|
||||
return -1;
|
||||
@ -182,7 +182,7 @@ int start_syslog_daemon(struct ctdb_context *ctdb)
|
||||
|
||||
/* Tell parent that we're up */
|
||||
ret = 0;
|
||||
write(startup_fd[1], &ret, sizeof(ret));
|
||||
sys_write(startup_fd[1], &ret, sizeof(ret));
|
||||
close(startup_fd[1]);
|
||||
|
||||
event_loop_wait(ctdb->ev);
|
||||
@ -304,7 +304,7 @@ static void ctdb_logfile_log(const char *format, va_list ap)
|
||||
if (ret == -1) {
|
||||
const char *errstr = "vasprintf failed\n";
|
||||
|
||||
write(log_state->fd, errstr, strlen(errstr));
|
||||
sys_write(log_state->fd, errstr, strlen(errstr));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -319,11 +319,11 @@ static void ctdb_logfile_log(const char *format, va_list ap)
|
||||
free(s);
|
||||
if (ret == -1) {
|
||||
const char *errstr = "asprintf failed\n";
|
||||
write(log_state->fd, errstr, strlen(errstr));
|
||||
sys_write(log_state->fd, errstr, strlen(errstr));
|
||||
return;
|
||||
}
|
||||
if (s2) {
|
||||
write(log_state->fd, s2, strlen(s2));
|
||||
sys_write(log_state->fd, s2, strlen(s2));
|
||||
free(s2);
|
||||
}
|
||||
}
|
||||
@ -337,12 +337,12 @@ static void ctdb_logfile_log_add(const char *format, va_list ap)
|
||||
if (ret == -1) {
|
||||
const char *errstr = "vasprintf failed\n";
|
||||
|
||||
write(log_state->fd, errstr, strlen(errstr));
|
||||
sys_write(log_state->fd, errstr, strlen(errstr));
|
||||
return;
|
||||
}
|
||||
|
||||
if (s) {
|
||||
write(log_state->fd, s, strlen(s));
|
||||
sys_write(log_state->fd, s, strlen(s));
|
||||
free(s);
|
||||
}
|
||||
}
|
||||
@ -424,7 +424,7 @@ static void ctdb_log_handler(struct event_context *ev, struct fd_event *fde,
|
||||
return;
|
||||
}
|
||||
|
||||
n = read(log->pfd, &log->buf[log->buf_used],
|
||||
n = sys_read(log->pfd, &log->buf[log->buf_used],
|
||||
sizeof(log->buf) - log->buf_used);
|
||||
if (n > 0) {
|
||||
log->buf_used += n;
|
||||
|
@ -534,7 +534,7 @@ static void set_recmode_handler(struct event_context *ev, struct fd_event *fde,
|
||||
the file which at this time SHOULD be locked by the recovery
|
||||
daemon on the recmaster
|
||||
*/
|
||||
ret = read(state->fd[0], &c, 1);
|
||||
ret = sys_read(state->fd[0], &c, 1);
|
||||
if (ret != 1 || c != 0) {
|
||||
ctdb_request_control_reply(state->ctdb, state->c, NULL, -1, "managed to lock reclock file from inside daemon");
|
||||
talloc_free(state);
|
||||
@ -679,11 +679,11 @@ int32_t ctdb_control_set_recmode(struct ctdb_context *ctdb,
|
||||
cc = 1;
|
||||
}
|
||||
|
||||
write(state->fd[1], &cc, 1);
|
||||
sys_write(state->fd[1], &cc, 1);
|
||||
/* make sure we die when our parent dies */
|
||||
while (ctdb_kill(ctdb, parent, 0) == 0 || errno != ESRCH) {
|
||||
sleep(5);
|
||||
write(state->fd[1], &cc, 1);
|
||||
sys_write(state->fd[1], &cc, 1);
|
||||
}
|
||||
_exit(0);
|
||||
}
|
||||
|
@ -3383,7 +3383,7 @@ static void reclock_child_handler(struct event_context *ev, struct fd_event *fde
|
||||
talloc_free(state->te);
|
||||
state->te = NULL;
|
||||
|
||||
ret = read(state->fd[0], &c, 1);
|
||||
ret = sys_read(state->fd[0], &c, 1);
|
||||
if (ret != 1 || c != RECLOCK_OK) {
|
||||
DEBUG(DEBUG_ERR,(__location__ " reclock child process returned error %d\n", c));
|
||||
state->status = RECLOCK_FAILED;
|
||||
@ -3445,7 +3445,7 @@ static int check_recovery_lock(struct ctdb_context *ctdb)
|
||||
cc = RECLOCK_FAILED;
|
||||
}
|
||||
|
||||
write(state->fd[1], &cc, 1);
|
||||
sys_write(state->fd[1], &cc, 1);
|
||||
/* make sure we die when our parent dies */
|
||||
while (ctdb_kill(ctdb, parent, 0) == 0 || errno != ESRCH) {
|
||||
sleep(5);
|
||||
|
@ -4471,7 +4471,7 @@ static void ctdb_reloadips_child_handler(struct event_context *ev, struct fd_eve
|
||||
char res;
|
||||
int ret;
|
||||
|
||||
ret = read(h->fd[0], &res, 1);
|
||||
ret = sys_read(h->fd[0], &res, 1);
|
||||
if (ret < 1 || res != 0) {
|
||||
DEBUG(DEBUG_ERR, (__location__ " Reloadips child process returned error\n"));
|
||||
res = 1;
|
||||
@ -4708,7 +4708,7 @@ int32_t ctdb_control_reload_public_ips(struct ctdb_context *ctdb, struct ctdb_re
|
||||
}
|
||||
}
|
||||
|
||||
write(h->fd[1], &res, 1);
|
||||
sys_write(h->fd[1], &res, 1);
|
||||
/* make sure we die when our parent dies */
|
||||
while (ctdb_kill(ctdb, parent, 0) == 0 || errno != ESRCH) {
|
||||
sleep(5);
|
||||
|
@ -62,7 +62,7 @@ static void ctdb_traverse_child_handler(struct tevent_context *ev, struct tevent
|
||||
ssize_t n;
|
||||
|
||||
/* Read the number of records sent by traverse child */
|
||||
n = read(h->fd[0], &res, sizeof(res));
|
||||
n = sys_read(h->fd[0], &res, sizeof(res));
|
||||
if (n < 0 || n != sizeof(res)) {
|
||||
/* Traverse child failed */
|
||||
DEBUG(DEBUG_ERR, ("Local traverse failed db:%s reqid:%d\n",
|
||||
@ -213,7 +213,7 @@ static struct ctdb_traverse_local_handle *ctdb_traverse_local(struct ctdb_db_con
|
||||
d = ctdb_marshall_record(h, h->reqid, tdb_null, NULL, tdb_null);
|
||||
if (d == NULL) {
|
||||
res = 0;
|
||||
write(h->fd[1], &res, sizeof(int));
|
||||
sys_write(h->fd[1], &res, sizeof(int));
|
||||
_exit(0);
|
||||
}
|
||||
|
||||
@ -243,7 +243,7 @@ static struct ctdb_traverse_local_handle *ctdb_traverse_local(struct ctdb_db_con
|
||||
}
|
||||
}
|
||||
|
||||
write(h->fd[1], &res, sizeof(res));
|
||||
sys_write(h->fd[1], &res, sizeof(res));
|
||||
|
||||
while (ctdb_kill(ctdb, parent, 0) == 0 || errno != ESRCH) {
|
||||
sleep(5);
|
||||
|
@ -191,7 +191,7 @@ static void childwrite_handler(struct event_context *ev, struct fd_event *fde,
|
||||
|
||||
talloc_set_destructor(h, NULL);
|
||||
|
||||
ret = read(h->fd[0], &c, 1);
|
||||
ret = sys_read(h->fd[0], &c, 1);
|
||||
if (ret < 1) {
|
||||
DEBUG(DEBUG_ERR, (__location__ " Read returned %d. Childwrite failed\n", ret));
|
||||
c = 1;
|
||||
@ -258,7 +258,7 @@ static struct childwrite_handle *ctdb_childwrite(
|
||||
c = 1;
|
||||
}
|
||||
|
||||
write(result->fd[1], &c, 1);
|
||||
sys_write(result->fd[1], &c, 1);
|
||||
|
||||
/* make sure we die when our parent dies */
|
||||
while (ctdb_kill(ctdb_db->ctdb, parent, 0) == 0 || errno != ESRCH) {
|
||||
|
@ -1411,7 +1411,7 @@ static void vacuum_child_handler(struct event_context *ev, struct fd_event *fde,
|
||||
DEBUG(DEBUG_INFO,("Vacuuming child process %d finished for db %s\n", child_ctx->child_pid, child_ctx->vacuum_handle->ctdb_db->db_name));
|
||||
child_ctx->child_pid = -1;
|
||||
|
||||
ret = read(child_ctx->fd[0], &c, 1);
|
||||
ret = sys_read(child_ctx->fd[0], &c, 1);
|
||||
if (ret != 1 || c != 0) {
|
||||
child_ctx->status = VACUUM_ERROR;
|
||||
DEBUG(DEBUG_ERR, ("A vacuum child process failed with an error for database %s. ret=%d c=%d\n", child_ctx->vacuum_handle->ctdb_db->db_name, ret, c));
|
||||
@ -1503,7 +1503,7 @@ ctdb_vacuum_event(struct event_context *ev, struct timed_event *te,
|
||||
}
|
||||
cc = ctdb_vacuum_and_repack_db(ctdb_db, full_vacuum_run);
|
||||
|
||||
write(child_ctx->fd[1], &cc, 1);
|
||||
sys_write(child_ctx->fd[1], &cc, 1);
|
||||
_exit(0);
|
||||
}
|
||||
|
||||
|
@ -364,7 +364,7 @@ static void ctdb_event_script_handler(struct event_context *ev, struct fd_event
|
||||
return;
|
||||
}
|
||||
|
||||
r = read(state->fd[0], ¤t->status, sizeof(current->status));
|
||||
r = sys_read(state->fd[0], ¤t->status, sizeof(current->status));
|
||||
if (r < 0) {
|
||||
current->status = -errno;
|
||||
} else if (r != sizeof(current->status)) {
|
||||
|
@ -141,7 +141,7 @@ static int socket_client_connect(void)
|
||||
|
||||
static int socket_client_write(int client)
|
||||
{
|
||||
if (write(client, "\0", 1) == -1) {
|
||||
if (sys_write(client, "\0", 1) == -1) {
|
||||
DEBUG(DEBUG_CRIT,("Unable to write to client socket: %s\n", strerror(errno)));
|
||||
return -1;
|
||||
}
|
||||
|
@ -3983,10 +3983,10 @@ static int control_pfetch(struct ctdb_context *ctdb, int argc, const char **argv
|
||||
talloc_free(tmp_ctx);
|
||||
return -1;
|
||||
}
|
||||
write(fd, data.dptr, data.dsize);
|
||||
sys_write(fd, data.dptr, data.dsize);
|
||||
close(fd);
|
||||
} else {
|
||||
write(1, data.dptr, data.dsize);
|
||||
sys_write(1, data.dptr, data.dsize);
|
||||
}
|
||||
|
||||
/* abort the transaction */
|
||||
@ -4047,16 +4047,16 @@ static int control_tfetch(struct ctdb_context *ctdb, int argc, const char **argv
|
||||
return -1;
|
||||
}
|
||||
if (options.verbose){
|
||||
write(fd, data.dptr, data.dsize);
|
||||
sys_write(fd, data.dptr, data.dsize);
|
||||
} else {
|
||||
write(fd, data.dptr+sizeof(struct ctdb_ltdb_header), data.dsize-sizeof(struct ctdb_ltdb_header));
|
||||
sys_write(fd, data.dptr+sizeof(struct ctdb_ltdb_header), data.dsize-sizeof(struct ctdb_ltdb_header));
|
||||
}
|
||||
close(fd);
|
||||
} else {
|
||||
if (options.verbose){
|
||||
write(1, data.dptr, data.dsize);
|
||||
sys_write(1, data.dptr, data.dsize);
|
||||
} else {
|
||||
write(1, data.dptr+sizeof(struct ctdb_ltdb_header), data.dsize-sizeof(struct ctdb_ltdb_header));
|
||||
sys_write(1, data.dptr+sizeof(struct ctdb_ltdb_header), data.dsize-sizeof(struct ctdb_ltdb_header));
|
||||
}
|
||||
}
|
||||
|
||||
@ -4193,7 +4193,7 @@ static int control_pstore(struct ctdb_context *ctdb, int argc, const char **argv
|
||||
talloc_free(tmp_ctx);
|
||||
return -1;
|
||||
}
|
||||
ret = read(fd, data.dptr, data.dsize);
|
||||
ret = sys_read(fd, data.dptr, data.dsize);
|
||||
if (ret != data.dsize) {
|
||||
DEBUG(DEBUG_ERR,("Failed to read %d bytes of record data\n", (int)data.dsize));
|
||||
close(fd);
|
||||
@ -5638,12 +5638,12 @@ static int control_backupdb(struct ctdb_context *ctdb, int argc, const char **ar
|
||||
goto done;
|
||||
}
|
||||
strncpy(discard_const(dbhdr.name), argv[0], MAX_DB_NAME-1);
|
||||
ret = write(fh, &dbhdr, sizeof(dbhdr));
|
||||
ret = sys_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);
|
||||
ret = sys_write(fh, bd->records, bd->len);
|
||||
if (ret == -1) {
|
||||
DEBUG(DEBUG_ERR,("write failed: %s\n", strerror(errno)));
|
||||
goto done;
|
||||
@ -5699,7 +5699,7 @@ static int control_restoredb(struct ctdb_context *ctdb, int argc, const char **a
|
||||
return -1;
|
||||
}
|
||||
|
||||
read(fh, &dbhdr, sizeof(dbhdr));
|
||||
sys_read(fh, &dbhdr, sizeof(dbhdr));
|
||||
if (dbhdr.version != DB_VERSION) {
|
||||
DEBUG(DEBUG_ERR,("Invalid version of database dump. File is version %lu but expected version was %u\n", dbhdr.version, DB_VERSION));
|
||||
close(fh);
|
||||
@ -5720,7 +5720,7 @@ static int control_restoredb(struct ctdb_context *ctdb, int argc, const char **a
|
||||
talloc_free(tmp_ctx);
|
||||
return -1;
|
||||
}
|
||||
read(fh, outdata.dptr, outdata.dsize);
|
||||
sys_read(fh, outdata.dptr, outdata.dsize);
|
||||
close(fh);
|
||||
|
||||
tm = localtime(&dbhdr.timestamp);
|
||||
@ -5895,7 +5895,7 @@ static int control_dumpdbbackup(struct ctdb_context *ctdb, int argc, const char
|
||||
return -1;
|
||||
}
|
||||
|
||||
read(fh, &dbhdr, sizeof(dbhdr));
|
||||
sys_read(fh, &dbhdr, sizeof(dbhdr));
|
||||
if (dbhdr.version != DB_VERSION) {
|
||||
DEBUG(DEBUG_ERR,("Invalid version of database dump. File is version %lu but expected version was %u\n", dbhdr.version, DB_VERSION));
|
||||
close(fh);
|
||||
@ -5911,7 +5911,7 @@ static int control_dumpdbbackup(struct ctdb_context *ctdb, int argc, const char
|
||||
talloc_free(tmp_ctx);
|
||||
return -1;
|
||||
}
|
||||
read(fh, outdata.dptr, outdata.dsize);
|
||||
sys_read(fh, outdata.dptr, outdata.dsize);
|
||||
close(fh);
|
||||
m = (struct ctdb_marshall_buffer *)outdata.dptr;
|
||||
|
||||
@ -6122,7 +6122,7 @@ static int control_dumpmemory(struct ctdb_context *ctdb, int argc, const char **
|
||||
talloc_free(tmp_ctx);
|
||||
return -1;
|
||||
}
|
||||
write(1, data.dptr, data.dsize);
|
||||
sys_write(1, data.dptr, data.dsize);
|
||||
talloc_free(tmp_ctx);
|
||||
return 0;
|
||||
}
|
||||
@ -6133,7 +6133,7 @@ static int control_dumpmemory(struct ctdb_context *ctdb, int argc, const char **
|
||||
static void mem_dump_handler(struct ctdb_context *ctdb, uint64_t srvid,
|
||||
TDB_DATA data, void *private_data)
|
||||
{
|
||||
write(1, data.dptr, data.dsize);
|
||||
sys_write(1, data.dptr, data.dsize);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user