diff options
author | Kaleb S. KEITHLEY <kkeithle@redhat.com> | 2015-10-01 16:16:52 -0400 |
---|---|---|
committer | Jeff Darcy <jdarcy@redhat.com> | 2015-10-28 16:34:45 -0700 |
commit | 36ea43b93b8476595ac22da031bc42a807ccc852 (patch) | |
tree | 314c44d79bdaea5f8e91676d0996b9313b5a843b /xlators/features/changelog/lib/src | |
parent | 323e71617fee5020324540776d0d4469577f0afe (diff) |
core: use syscall wrappers instead of direct syscalls
various xlators and other components are invoking system calls
directly instead of using the libglusterfs/syscall.[ch] wrappers.
If not using the system call wrappers there should be a comment
in the source explaining why the wrapper isn't used.
Change-Id: I8ef94c48728666465abf126c778b70c9e5c00e47
BUG: 1267967
Signed-off-by: Kaleb S. KEITHLEY <kkeithle@redhat.com>
Reviewed-on: http://review.gluster.org/12273
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Jeff Darcy <jdarcy@redhat.com>
Diffstat (limited to 'xlators/features/changelog/lib/src')
5 files changed, 37 insertions, 30 deletions
diff --git a/xlators/features/changelog/lib/src/gf-changelog-api.c b/xlators/features/changelog/lib/src/gf-changelog-api.c index 63c0098d248..f41b505a749 100644 --- a/xlators/features/changelog/lib/src/gf-changelog-api.c +++ b/xlators/features/changelog/lib/src/gf-changelog-api.c @@ -11,6 +11,7 @@ #include "compat-uuid.h" #include "globals.h" #include "glusterfs.h" +#include "syscall.h" #include "gf-changelog-helpers.h" #include "gf-changelog-journal.h" @@ -52,7 +53,7 @@ gf_changelog_done (char *file) jnl->jnl_processed_dir, basename (buffer)); gf_msg_debug (this->name, 0, "moving %s to processed directory", file); - ret = rename (buffer, to_path); + ret = sys_rename (buffer, to_path); if (ret) { gf_msg (this->name, GF_LOG_ERROR, errno, CHANGELOG_LIB_MSG_RENAME_FAILED, diff --git a/xlators/features/changelog/lib/src/gf-changelog-helpers.c b/xlators/features/changelog/lib/src/gf-changelog-helpers.c index d6245743437..8b35f4e9416 100644 --- a/xlators/features/changelog/lib/src/gf-changelog-helpers.c +++ b/xlators/features/changelog/lib/src/gf-changelog-helpers.c @@ -11,10 +11,11 @@ #include "changelog-mem-types.h" #include "gf-changelog-helpers.h" #include "changelog-lib-messages.h" +#include "syscall.h" ssize_t gf_changelog_read_path (int fd, char *buffer, size_t bufsize) { - return read (fd, buffer, bufsize); + return sys_read (fd, buffer, bufsize); } size_t @@ -24,8 +25,7 @@ gf_changelog_write (int fd, char *buffer, size_t len) size_t written = 0; while (written < len) { - size = write (fd, - buffer + written, len - written); + size = sys_write (fd, buffer + written, len - written); if (size <= 0) break; @@ -81,7 +81,9 @@ static ssize_t my_read (read_line_t *tsd, int fd, char *ptr) { if (tsd->rl_cnt <= 0) { - if ( (tsd->rl_cnt = read (fd, tsd->rl_buf, MAXLINE)) < 0 ) + tsd->rl_cnt = sys_read (fd, tsd->rl_buf, MAXLINE); + + if (tsd->rl_cnt < 0) return -1; else if (tsd->rl_cnt == 0) return 0; @@ -154,7 +156,8 @@ gf_lseek (int fd, off_t offset, int whence) if (gf_readline_init_once (&tsd)) return -1; - if ( (off = lseek (fd, offset, whence)) == -1) + off = sys_lseek (fd, offset, whence); + if (off == -1) return -1; tsd->rl_cnt = 0; @@ -171,7 +174,7 @@ gf_ftruncate (int fd, off_t length) if (gf_readline_init_once (&tsd)) return -1; - if (ftruncate (fd, 0)) + if (sys_ftruncate (fd, 0)) return -1; tsd->rl_cnt = 0; diff --git a/xlators/features/changelog/lib/src/gf-changelog-journal-handler.c b/xlators/features/changelog/lib/src/gf-changelog-journal-handler.c index f04117298a9..6ea7cac88da 100644 --- a/xlators/features/changelog/lib/src/gf-changelog-journal-handler.c +++ b/xlators/features/changelog/lib/src/gf-changelog-journal-handler.c @@ -11,6 +11,7 @@ #include "compat-uuid.h" #include "globals.h" #include "glusterfs.h" +#include "syscall.h" #include "compat-errno.h" #include "gf-changelog-helpers.h" @@ -440,7 +441,7 @@ gf_changelog_copy (xlator_t *this, int from_fd, int to_fd) char buffer[COPY_BUFSIZE+1] = {0,}; while (1) { - size = read (from_fd, buffer, COPY_BUFSIZE); + size = sys_read (from_fd, buffer, COPY_BUFSIZE); if (size <= 0) break; @@ -500,7 +501,7 @@ gf_changelog_decode (xlator_t *this, gf_changelog_journal_t *jnl, /** * start processing after the header */ - lseek (from_fd, elen, SEEK_SET); + sys_lseek (from_fd, elen, SEEK_SET); switch (encoding) { case CHANGELOG_ENCODE_BINARY: @@ -539,7 +540,7 @@ gf_changelog_publish (xlator_t *this, jnl->jnl_current_dir, basename (from_path)); /* handle zerob file that wont exist in current */ - ret = stat (to_path, &stbuf); + ret = sys_stat (to_path, &stbuf); if (ret) { if (errno == ENOENT) ret = 0; @@ -549,7 +550,7 @@ gf_changelog_publish (xlator_t *this, (void) snprintf (dest, PATH_MAX, "%s%s", jnl->jnl_processing_dir, basename (from_path)); - ret = rename (to_path, dest); + ret = sys_rename (to_path, dest); if (ret) { gf_msg (this->name, GF_LOG_ERROR, errno, CHANGELOG_LIB_MSG_RENAME_FAILED, @@ -574,7 +575,7 @@ gf_changelog_consume (xlator_t *this, char dest[PATH_MAX] = {0,}; char to_path[PATH_MAX] = {0,}; - ret = stat (from_path, &stbuf); + ret = sys_stat (from_path, &stbuf); if (ret || !S_ISREG(stbuf.st_mode)) { ret = -1; gf_msg (this->name, GF_LOG_ERROR, errno, @@ -609,14 +610,14 @@ gf_changelog_consume (xlator_t *this, ret = gf_changelog_decode (this, jnl, fd1, fd2, &stbuf, &zerob); - close (fd2); + sys_close (fd2); if (!ret) { /* move it to processing on a successful decode */ if (no_publish == _gf_true) goto close_fd; - ret = rename (to_path, dest); + ret = sys_rename (to_path, dest); if (ret) gf_msg (this->name, GF_LOG_ERROR, errno, CHANGELOG_LIB_MSG_RENAME_FAILED, @@ -627,7 +628,7 @@ gf_changelog_consume (xlator_t *this, /* remove it from .current if it's an empty file */ if (zerob) { /* zerob changelogs must be unlinked */ - ret = unlink (to_path); + ret = sys_unlink (to_path); if (ret) gf_msg (this->name, GF_LOG_ERROR, errno, CHANGELOG_LIB_MSG_UNLINK_FAILED, @@ -637,7 +638,7 @@ gf_changelog_consume (xlator_t *this, } close_fd: - close (fd1); + sys_close (fd1); out: return ret; @@ -830,10 +831,10 @@ gf_changelog_cleanup_fds (gf_changelog_journal_t *jnl) { /* tracker fd */ if (jnl->jnl_fd != -1) - close (jnl->jnl_fd); + sys_close (jnl->jnl_fd); /* processing dir */ if (jnl->jnl_dir) - closedir (jnl->jnl_dir); + sys_closedir (jnl->jnl_dir); if (jnl->jnl_working_dir) free (jnl->jnl_working_dir); /* allocated by realpath */ @@ -888,7 +889,7 @@ gf_changelog_open_dirs (xlator_t *this, gf_changelog_journal_t *jnl) if (ret) goto out; - dir = opendir (jnl->jnl_processing_dir); + dir = sys_opendir (jnl->jnl_processing_dir); if (!dir) { gf_msg ("", GF_LOG_ERROR, errno, CHANGELOG_LIB_MSG_OPENDIR_ERROR, @@ -904,7 +905,7 @@ gf_changelog_open_dirs (xlator_t *this, gf_changelog_journal_t *jnl) tracker_fd = open (tracker_path, O_CREAT | O_APPEND | O_RDWR, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); if (tracker_fd < 0) { - closedir (jnl->jnl_dir); + sys_closedir (jnl->jnl_dir); ret = -1; goto out; } @@ -1007,7 +1008,7 @@ gf_changelog_journal_init (void *xl, struct gf_brick_spec *brick) if (!jnl) goto error_return; - if (stat (scratch_dir, &buf) && errno == ENOENT) { + if (sys_stat (scratch_dir, &buf) && errno == ENOENT) { ret = mkdir_p (scratch_dir, 0600, _gf_true); if (ret) goto dealloc_private; diff --git a/xlators/features/changelog/lib/src/gf-changelog-reborp.c b/xlators/features/changelog/lib/src/gf-changelog-reborp.c index 665a6d0a5da..4c49e9a533f 100644 --- a/xlators/features/changelog/lib/src/gf-changelog-reborp.c +++ b/xlators/features/changelog/lib/src/gf-changelog-reborp.c @@ -15,6 +15,8 @@ #include "changelog-rpc-common.h" #include "changelog-lib-messages.h" +#include "syscall.h" + /** * Reverse socket: actual data transfer handler. Connection * initiator is PROBER, data transfer is REBORP. @@ -113,7 +115,7 @@ gf_changelog_reborp_rpcsvc_notify (rpcsvc_t *rpc, void *mydata, switch (event) { case RPCSVC_EVENT_ACCEPT: - ret = unlink (RPC_SOCK(entry)); + ret = sys_unlink (RPC_SOCK(entry)); if (ret != 0) gf_msg (this->name, GF_LOG_WARNING, errno, CHANGELOG_LIB_MSG_UNLINK_FAILED, diff --git a/xlators/features/changelog/lib/src/gf-history-changelog.c b/xlators/features/changelog/lib/src/gf-history-changelog.c index fffe48780c1..f7b58f5a965 100644 --- a/xlators/features/changelog/lib/src/gf-history-changelog.c +++ b/xlators/features/changelog/lib/src/gf-history-changelog.c @@ -75,7 +75,7 @@ gf_history_changelog_done (char *file) hist_jnl->jnl_processed_dir, basename (buffer)); gf_msg_debug (this->name, 0, "moving %s to processed directory", file); - ret = rename (buffer, to_path); + ret = sys_rename (buffer, to_path); if (ret) { gf_msg (this->name, GF_LOG_ERROR, errno, CHANGELOG_LIB_MSG_RENAME_FAILED, @@ -678,7 +678,7 @@ gf_history_consume (void * data) out: if (fd != -1) - close (fd); + sys_close (fd); GF_FREE (hist_data); return NULL; } @@ -728,7 +728,7 @@ gf_changelog_extract_min_max (const char *dname, const char *htime_dir, iter = (htime_file + strlen (htime_file) - TIMESTAMP_LENGTH); sscanf (iter ,"%lu",min_ts); - ret = stat (htime_file, &stbuf); + ret = sys_stat (htime_file, &stbuf); if (ret) { ret = -1; gf_msg (this->name, GF_LOG_ERROR, errno, @@ -841,7 +841,7 @@ gf_history_changelog (char* changelog_dir, unsigned long start, CHANGELOG_FILL_HTIME_DIR (changelog_dir, htime_dir); - dirp = opendir (htime_dir); + dirp = sys_opendir (htime_dir); if (dirp == NULL) { gf_msg (this->name, GF_LOG_ERROR, errno, CHANGELOG_LIB_MSG_HTIME_ERROR, @@ -851,7 +851,7 @@ gf_history_changelog (char* changelog_dir, unsigned long start, goto out; } - while ((dp = readdir (dirp)) != NULL) { + while ((dp = sys_readdir (dirp)) != NULL) { ret = gf_changelog_extract_min_max (dp->d_name, htime_dir, &fd, &total_changelog, &min_ts, &max_ts); @@ -865,7 +865,7 @@ gf_history_changelog (char* changelog_dir, unsigned long start, /** * TODO: handle short reads later... */ - n_read = read (fd, buffer, PATH_MAX); + n_read = sys_read (fd, buffer, PATH_MAX); if (n_read < 0) { ret = -1; gf_msg (this->name, GF_LOG_ERROR, errno, @@ -968,11 +968,11 @@ gf_history_changelog (char* changelog_dir, unsigned long start, out: if (dirp != NULL) - closedir (dirp); + sys_closedir (dirp); if (ret < 0) { if (fd != -1) - close (fd); + sys_close (fd); GF_FREE (hist_data); (void) pthread_attr_destroy (&attr); |