diff --git a/ctdb/common/ctdb_io.c b/ctdb/common/ctdb_io.c index b5f8a7274c4..467ec9a0fa5 100644 --- a/ctdb/common/ctdb_io.c +++ b/ctdb/common/ctdb_io.c @@ -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; diff --git a/ctdb/server/ctdb_call.c b/ctdb/server/ctdb_call.c index a4fa03d8778..54c6d770e14 100644 --- a/ctdb/server/ctdb_call.c +++ b/ctdb/server/ctdb_call.c @@ -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); diff --git a/ctdb/server/ctdb_event_helper.c b/ctdb/server/ctdb_event_helper.c index 238103a02bb..9ff763c538a 100644 --- a/ctdb/server/ctdb_event_helper.c +++ b/ctdb/server/ctdb_event_helper.c @@ -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); } diff --git a/ctdb/server/ctdb_lock.c b/ctdb/server/ctdb_lock.c index 72352af8466..93137df65f1 100644 --- a/ctdb/server/ctdb_lock.c +++ b/ctdb/server/ctdb_lock.c @@ -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); diff --git a/ctdb/server/ctdb_lock_helper.c b/ctdb/server/ctdb_lock_helper.c index 709130cf61f..d831a2d39b3 100644 --- a/ctdb/server/ctdb_lock_helper.c +++ b/ctdb/server/ctdb_lock_helper.c @@ -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); } diff --git a/ctdb/server/ctdb_logging.c b/ctdb/server/ctdb_logging.c index f22c9f30ee9..9f6f3b52dd4 100644 --- a/ctdb/server/ctdb_logging.c +++ b/ctdb/server/ctdb_logging.c @@ -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; diff --git a/ctdb/server/ctdb_recover.c b/ctdb/server/ctdb_recover.c index ecf3aba3019..d45b7f6c5b5 100644 --- a/ctdb/server/ctdb_recover.c +++ b/ctdb/server/ctdb_recover.c @@ -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); } diff --git a/ctdb/server/ctdb_recoverd.c b/ctdb/server/ctdb_recoverd.c index 50709a637dc..9b553b7ba36 100644 --- a/ctdb/server/ctdb_recoverd.c +++ b/ctdb/server/ctdb_recoverd.c @@ -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); diff --git a/ctdb/server/ctdb_takeover.c b/ctdb/server/ctdb_takeover.c index 8449288d36b..a3b95926892 100644 --- a/ctdb/server/ctdb_takeover.c +++ b/ctdb/server/ctdb_takeover.c @@ -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); diff --git a/ctdb/server/ctdb_traverse.c b/ctdb/server/ctdb_traverse.c index 99e7e8f3e0d..64f25306b5d 100644 --- a/ctdb/server/ctdb_traverse.c +++ b/ctdb/server/ctdb_traverse.c @@ -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); diff --git a/ctdb/server/ctdb_update_record.c b/ctdb/server/ctdb_update_record.c index 7bfa08ac8b4..81e36253c73 100644 --- a/ctdb/server/ctdb_update_record.c +++ b/ctdb/server/ctdb_update_record.c @@ -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) { diff --git a/ctdb/server/ctdb_vacuum.c b/ctdb/server/ctdb_vacuum.c index c3054bfbbff..5013339c23f 100644 --- a/ctdb/server/ctdb_vacuum.c +++ b/ctdb/server/ctdb_vacuum.c @@ -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); } diff --git a/ctdb/server/eventscript.c b/ctdb/server/eventscript.c index 604b8de44b5..447a83c9645 100644 --- a/ctdb/server/eventscript.c +++ b/ctdb/server/eventscript.c @@ -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)) { diff --git a/ctdb/tests/src/ctdb_porting_tests.c b/ctdb/tests/src/ctdb_porting_tests.c index 063c6daf544..6752f84cbea 100644 --- a/ctdb/tests/src/ctdb_porting_tests.c +++ b/ctdb/tests/src/ctdb_porting_tests.c @@ -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; } diff --git a/ctdb/tools/ctdb.c b/ctdb/tools/ctdb.c index 549c1aa1bd2..ca79363d173 100644 --- a/ctdb/tools/ctdb.c +++ b/ctdb/tools/ctdb.c @@ -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); }