From 2099cc875a4d20ab1bb12b1c33da16c95968e202 Mon Sep 17 00:00:00 2001 From: "Kaleb S. KEITHLEY" Date: Thu, 1 Oct 2015 16:28:58 -0400 Subject: core: use syscall wrappers instead of direct syscalls - libglusterfs 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: Ieeca2d36adbc884e4cfa0026dba40df70310d40b BUG: 1267967 Signed-off-by: Kaleb S. KEITHLEY Reviewed-on: http://review.gluster.org/12275 Tested-by: NetBSD Build System Tested-by: Gluster Build System Reviewed-by: Jeff Darcy --- libglusterfs/src/common-utils.c | 44 ++++++++++++++++++++--------------------- libglusterfs/src/compat.c | 3 ++- libglusterfs/src/event-epoll.c | 5 +++-- libglusterfs/src/event-poll.c | 21 ++++++++++---------- libglusterfs/src/event.c | 9 +++++---- libglusterfs/src/graph.c | 5 +++-- libglusterfs/src/logging.c | 14 +++++++------ libglusterfs/src/run.c | 35 ++++++++++++++++---------------- libglusterfs/src/statedump.c | 15 +++++++------- libglusterfs/src/store.c | 33 +++++++++++++++++-------------- 10 files changed, 98 insertions(+), 86 deletions(-) (limited to 'libglusterfs') diff --git a/libglusterfs/src/common-utils.c b/libglusterfs/src/common-utils.c index a89e120c0fb..5852ae29c8a 100644 --- a/libglusterfs/src/common-utils.c +++ b/libglusterfs/src/common-utils.c @@ -90,7 +90,7 @@ mkdir_p (char *path, mode_t mode, gf_boolean_t allow_symlinks) continue; dir[i] = '\0'; - ret = mkdir (dir, mode); + ret = sys_mkdir (dir, mode); if (ret && errno != EEXIST) { gf_msg ("", GF_LOG_ERROR, errno, LG_MSG_DIR_OP_FAILED, "Failed due to reason"); @@ -98,7 +98,7 @@ mkdir_p (char *path, mode_t mode, gf_boolean_t allow_symlinks) } if (ret && errno == EEXIST && !allow_symlinks) { - ret = lstat (dir, &stbuf); + ret = sys_lstat (dir, &stbuf); if (ret) goto out; @@ -114,7 +114,7 @@ mkdir_p (char *path, mode_t mode, gf_boolean_t allow_symlinks) } while (path[i++] != '\0'); - ret = stat (dir, &stbuf); + ret = sys_stat (dir, &stbuf); if (ret || !S_ISDIR (stbuf.st_mode)) { if (ret == 0) errno = 0; @@ -1898,16 +1898,16 @@ get_checksum_for_file (int fd, uint32_t *checksum) char buf[GF_CHECKSUM_BUF_SIZE] = {0,}; /* goto first place */ - lseek (fd, 0L, SEEK_SET); + sys_lseek (fd, 0L, SEEK_SET); do { - ret = read (fd, &buf, GF_CHECKSUM_BUF_SIZE); + ret = sys_read (fd, &buf, GF_CHECKSUM_BUF_SIZE); if (ret > 0) compute_checksum (buf, GF_CHECKSUM_BUF_SIZE, checksum); } while (ret > 0); /* set it back */ - lseek (fd, 0L, SEEK_SET); + sys_lseek (fd, 0L, SEEK_SET); return ret; } @@ -1934,7 +1934,7 @@ get_checksum_for_path (char *path, uint32_t *checksum) out: if (fd != -1) - close (fd); + sys_close (fd); return ret; } @@ -1957,7 +1957,7 @@ get_file_mtime (const char *path, time_t *stamp) GF_VALIDATE_OR_GOTO (THIS->name, path, out); GF_VALIDATE_OR_GOTO (THIS->name, stamp, out); - ret = stat (path, &f_stat); + ret = sys_stat (path, &f_stat); if (ret < 0) { gf_msg (THIS->name, GF_LOG_ERROR, errno, LG_MSG_FILE_STAT_FAILED, "failed to stat %s", @@ -2902,7 +2902,7 @@ gf_get_reserved_ports () goto out; } - ret = read (proc_fd, buffer, sizeof (buffer)); + ret = sys_read (proc_fd, buffer, sizeof (buffer)); if (ret < 0) { gf_msg ("glusterfs", GF_LOG_WARNING, errno, LG_MSG_FILE_OP_FAILED, "could not read the file %s for" @@ -2913,7 +2913,7 @@ gf_get_reserved_ports () out: if (proc_fd != -1) - close (proc_fd); + sys_close (proc_fd); #endif /* GF_LINUX_HOST_OS */ return ports_info; } @@ -3477,7 +3477,7 @@ gf_skip_header_section (int fd, int header_len) { int ret = -1; - ret = lseek (fd, header_len, SEEK_SET); + ret = sys_lseek (fd, header_len, SEEK_SET); if (ret == (off_t) -1) { gf_msg ("", GF_LOG_ERROR, 0, LG_MSG_SKIP_HEADER_FAILED, "Failed to skip header section"); @@ -3637,7 +3637,7 @@ gf_set_timestamp (const char *src, const char* dest) GF_ASSERT (src); GF_ASSERT (dest); - ret = stat (src, &sb); + ret = sys_stat (src, &sb); if (ret) { gf_msg (this->name, GF_LOG_ERROR, errno, LG_MSG_FILE_STAT_FAILED, "stat on %s", src); @@ -3653,7 +3653,7 @@ gf_set_timestamp (const char *src, const char* dest) * requiremnt. Hence using 'utimes'. This can be updated * to 'utimensat' if we need timestamp in nanoseconds. */ - ret = utimes (dest, new_time); + ret = sys_utimes (dest, new_time); if (ret) { gf_msg (this->name, GF_LOG_ERROR, errno, LG_MSG_UTIMES_FAILED, "utimes on %s", dest); @@ -3719,7 +3719,7 @@ gf_backtrace_fillframes (char *buf) fp = fdopen (fd, "r"); if (!fp) { - close (fd); + sys_close (fd); ret = -1; goto out; } @@ -3744,7 +3744,7 @@ out: if (fp) fclose (fp); - unlink (tmpl); + sys_unlink (tmpl); return (idx > 0)? 0: -1; @@ -3968,7 +3968,7 @@ recursive_rmdir (const char *delete_path) GF_ASSERT (this); GF_VALIDATE_OR_GOTO (this->name, delete_path, out); - dir = opendir (delete_path); + dir = sys_opendir (delete_path); if (!dir) { gf_msg_debug (this->name, 0, "Failed to open directory %s. " "Reason : %s", delete_path, strerror (errno)); @@ -3979,7 +3979,7 @@ recursive_rmdir (const char *delete_path) GF_FOR_EACH_ENTRY_IN_DIR (entry, dir); while (entry) { snprintf (path, PATH_MAX, "%s/%s", delete_path, entry->d_name); - ret = lstat (path, &st); + ret = sys_lstat (path, &st); if (ret == -1) { gf_msg_debug (this->name, 0, "Failed to stat entry %s :" " %s", path, strerror (errno)); @@ -3989,7 +3989,7 @@ recursive_rmdir (const char *delete_path) if (S_ISDIR (st.st_mode)) ret = recursive_rmdir (path); else - ret = unlink (path); + ret = sys_unlink (path); if (ret) { gf_msg_debug (this->name, 0, " Failed to remove %s. " @@ -4002,13 +4002,13 @@ recursive_rmdir (const char *delete_path) GF_FOR_EACH_ENTRY_IN_DIR (entry, dir); } - ret = closedir (dir); + ret = sys_closedir (dir); if (ret) { gf_msg_debug (this->name, 0, "Failed to close dir %s. Reason :" " %s", delete_path, strerror (errno)); } - ret = rmdir (delete_path); + ret = sys_rmdir (delete_path); if (ret) { gf_msg_debug (this->name, 0, "Failed to rmdir: %s,err: %s", delete_path, strerror (errno)); @@ -4094,7 +4094,7 @@ gf_nread (int fd, void *buf, size_t count) ssize_t read_bytes = 0; for (read_bytes = 0; read_bytes < count; read_bytes += ret) { - ret = read (fd, buf + read_bytes, count - read_bytes); + ret = sys_read (fd, buf + read_bytes, count - read_bytes); if (ret == 0) { break; } else if (ret < 0) { @@ -4117,7 +4117,7 @@ gf_nwrite (int fd, const void *buf, size_t count) ssize_t written = 0; for (written = 0; written != count; written += ret) { - ret = write (fd, buf + written, count - written); + ret = sys_write (fd, buf + written, count - written); if (ret < 0) { if (errno == EINTR) ret = 0; diff --git a/libglusterfs/src/compat.c b/libglusterfs/src/compat.c index e50f27bff90..621ff5f54c9 100644 --- a/libglusterfs/src/compat.c +++ b/libglusterfs/src/compat.c @@ -24,6 +24,7 @@ #include "common-utils.h" #include "iatt.h" #include "inode.h" +#include "syscall.h" #include "run.h" #include "libglusterfs-messages.h" @@ -570,7 +571,7 @@ gf_umount_lazy (char *xlname, char *path, int rmdir_flag) #ifdef GF_LINUX_HOST_OS if (!ret && rmdir_flag) { - ret = rmdir (path); + ret = sys_rmdir (path); if (ret) gf_msg (xlname, GF_LOG_WARNING, errno, LG_MSG_DIR_OP_FAILED, "rmdir %s", path); diff --git a/libglusterfs/src/event-epoll.c b/libglusterfs/src/event-epoll.c index 78eff9398a6..3fd580d9d1a 100644 --- a/libglusterfs/src/event-epoll.c +++ b/libglusterfs/src/event-epoll.c @@ -20,6 +20,7 @@ #include "event.h" #include "mem-pool.h" #include "common-utils.h" +#include "syscall.h" #include "libglusterfs-messages.h" @@ -227,7 +228,7 @@ event_slot_unref (struct event_pool *event_pool, struct event_slot_epoll *slot, event_slot_dealloc (event_pool, idx); if (do_close) - close (fd); + sys_close (fd); done: return; } @@ -866,7 +867,7 @@ event_pool_destroy_epoll (struct event_pool *event_pool) int ret = 0, i = 0, j = 0; struct event_slot_epoll *table = NULL; - ret = close (event_pool->fd); + ret = sys_close (event_pool->fd); for (i = 0; i < EVENT_EPOLL_TABLES; i++) { if (event_pool->ereg[i]) { diff --git a/libglusterfs/src/event-poll.c b/libglusterfs/src/event-poll.c index 51c0cf1f4e7..2006e33d33b 100644 --- a/libglusterfs/src/event-poll.c +++ b/libglusterfs/src/event-poll.c @@ -20,6 +20,7 @@ #include "event.h" #include "mem-pool.h" #include "common-utils.h" +#include "syscall.h" #include "libglusterfs-messages.h" @@ -49,7 +50,7 @@ __flush_fd (int fd, int idx, void *data, return ret; do { - ret = read (fd, buf, 64); + ret = sys_read (fd, buf, 64); if (ret == -1 && errno != EAGAIN) { gf_msg ("poll", GF_LOG_ERROR, errno, LG_MSG_FILE_OP_FAILED, "read on %d returned " @@ -128,8 +129,8 @@ event_pool_new_poll (int count, int eventthreadcount) if (ret == -1) { gf_msg ("poll", GF_LOG_ERROR, errno, LG_MSG_SET_PIPE_FAILED, "could not set pipe to non blocking mode"); - close (event_pool->breaker[0]); - close (event_pool->breaker[1]); + sys_close (event_pool->breaker[0]); + sys_close (event_pool->breaker[1]); event_pool->breaker[0] = event_pool->breaker[1] = -1; GF_FREE (event_pool->reg); @@ -142,8 +143,8 @@ event_pool_new_poll (int count, int eventthreadcount) gf_msg ("poll", GF_LOG_ERROR, errno, LG_MSG_SET_PIPE_FAILED, "could not set pipe to non blocking mode"); - close (event_pool->breaker[0]); - close (event_pool->breaker[1]); + sys_close (event_pool->breaker[0]); + sys_close (event_pool->breaker[1]); event_pool->breaker[0] = event_pool->breaker[1] = -1; GF_FREE (event_pool->reg); @@ -156,8 +157,8 @@ event_pool_new_poll (int count, int eventthreadcount) if (ret == -1) { gf_msg ("poll", GF_LOG_ERROR, 0, LG_MSG_REGISTER_PIPE_FAILED, "could not register pipe fd with poll event loop"); - close (event_pool->breaker[0]); - close (event_pool->breaker[1]); + sys_close (event_pool->breaker[0]); + sys_close (event_pool->breaker[1]); event_pool->breaker[0] = event_pool->breaker[1] = -1; GF_FREE (event_pool->reg); @@ -288,7 +289,7 @@ event_unregister_close_poll (struct event_pool *event_pool, int fd, ret = event_unregister_poll (event_pool, fd, idx_hint); - close (fd); + sys_close (fd); return ret; } @@ -506,11 +507,11 @@ event_pool_destroy_poll (struct event_pool *event_pool) { int ret = 0; - ret = close (event_pool->breaker[0]); + ret = sys_close (event_pool->breaker[0]); if (ret) return ret; - ret = close (event_pool->breaker[1]); + ret = sys_close (event_pool->breaker[1]); if (ret) return ret; diff --git a/libglusterfs/src/event.c b/libglusterfs/src/event.c index aeef67107f5..09ecce1599d 100644 --- a/libglusterfs/src/event.c +++ b/libglusterfs/src/event.c @@ -21,6 +21,7 @@ #include "mem-pool.h" #include "common-utils.h" #include "libglusterfs-messages.h" +#include "syscall.h" @@ -177,7 +178,7 @@ poller_destroy_handler (int fd, int idx, void *data, if (readfd < 0) return -1; - while (read (readfd, &buf, 1) > 0) { + while (sys_read (readfd, &buf, 1) > 0) { } return 0; } @@ -254,7 +255,7 @@ event_dispatch_destroy (struct event_pool *event_pool) int retry = 0; while (event_pool->activethreadcount > 0 && retry++ < 10) { - if (write (fd[1], "dummy", 6) == -1) + if (sys_write (fd[1], "dummy", 6) == -1) break; sleep_till.tv_sec = time (NULL) + 1; ret = pthread_cond_timedwait (&event_pool->cond, @@ -268,9 +269,9 @@ event_dispatch_destroy (struct event_pool *event_pool) out: if (fd[0] != -1) - close (fd[0]); + sys_close (fd[0]); if (fd[1] != -1) - close (fd[1]); + sys_close (fd[1]); return ret; } diff --git a/libglusterfs/src/graph.c b/libglusterfs/src/graph.c index ed12b1c0e7f..2e290bb20a1 100644 --- a/libglusterfs/src/graph.c +++ b/libglusterfs/src/graph.c @@ -15,6 +15,7 @@ #include #include "defaults.h" #include +#include "syscall.h" #include "libglusterfs-messages.h" @@ -834,13 +835,13 @@ glusterfs_volfile_reconfigure (int oldvollen, FILE *newvolfile_fp, /*Calling unlink so that when the file is closed or program *terminates the tempfile is deleted. */ - u_ret = unlink(temp_file); + u_ret = sys_unlink(temp_file); if (u_ret < 0) { gf_msg ("glusterfsd-mgmt", GF_LOG_ERROR, errno, LG_MSG_TMPFILE_DELETE_FAILED, "Temporary file" " delete failed."); - close (file_desc); + sys_close (file_desc); goto out; } diff --git a/libglusterfs/src/logging.c b/libglusterfs/src/logging.c index 7081b184de9..03f5ff89733 100644 --- a/libglusterfs/src/logging.c +++ b/libglusterfs/src/logging.c @@ -26,6 +26,8 @@ #include +#include "syscall.h" + #define GF_JSON_MSG_LENGTH 8192 #define GF_SYSLOG_CEE_FORMAT \ "@cee: {\"msg\": \"%s\", \"gf_code\": \"%u\", \"gf_message\": \"%s\"}" @@ -369,7 +371,7 @@ gf_log_rotate(glusterfs_ctx_t *ctx) "logfile"); return; } - close (fd); + sys_close (fd); new_logfile = fopen (ctx->log.filename, "a"); if (!new_logfile) { @@ -689,7 +691,7 @@ gf_log_init (void *data, const char *file, const char *ident) gf_openlog (NULL, -1, LOG_DAEMON); } /* TODO: make FACILITY configurable than LOG_DAEMON */ - if (stat (GF_LOG_CONTROL_FILE, &buf) == 0) { + if (sys_stat (GF_LOG_CONTROL_FILE, &buf) == 0) { /* use syslog logging */ ctx->log.log_control_file_found = 1; } else { @@ -741,7 +743,7 @@ gf_log_init (void *data, const char *file, const char *ident) " \"%s\" (%s)\n", file, strerror (errno)); return -1; } - close (fd); + sys_close (fd); ctx->log.logfile = fopen (file, "a"); if (!ctx->log.logfile) { @@ -1234,7 +1236,7 @@ _gf_msg_nomem (const char *domain, const char *file, /* write directly to the fd to prevent out of order * message and stack */ - ret = write (fd, msg, wlen); + ret = sys_write (fd, msg, wlen); if (ret == -1) { pthread_mutex_unlock (&ctx->log.logfile_mutex); goto out; @@ -2179,7 +2181,7 @@ _gf_log (const char *domain, const char *file, const char *function, int line, "failed to open logfile"); return -1; } - close (fd); + sys_close (fd); new_logfile = fopen (ctx->log.filename, "a"); if (!new_logfile) { @@ -2353,7 +2355,7 @@ gf_cmd_log_init (const char *filename) LG_MSG_FILE_OP_FAILED, "failed to open cmd_log_file"); return -1; } - close (fd); + sys_close (fd); ctx->log.cmdlogfile = fopen (ctx->log.cmd_log_filename, "a"); if (!ctx->log.cmdlogfile){ diff --git a/libglusterfs/src/run.c b/libglusterfs/src/run.c index 6018a58ad5f..cb709546637 100644 --- a/libglusterfs/src/run.c +++ b/libglusterfs/src/run.c @@ -24,6 +24,7 @@ #include #include #include +#include "syscall.h" #ifdef RUN_STANDALONE #define GF_CALLOC(n, s, t) calloc(n, s) @@ -241,18 +242,18 @@ runner_start (runner_t *runner) switch (runner->chpid) { case -1: errno_priv = errno; - close (xpi[0]); - close (xpi[1]); + sys_close (xpi[0]); + sys_close (xpi[1]); for (i = 0; i < 3; i++) { - close (pi[i][0]); - close (pi[i][1]); + sys_close (pi[i][0]); + sys_close (pi[i][1]); } errno = errno_priv; return -1; case 0: for (i = 0; i < 3; i++) - close (pi[i][i ? 0 : 1]); - close (xpi[0]); + sys_close (pi[i][i ? 0 : 1]); + sys_close (xpi[0]); ret = 0; for (i = 0; i < 3; i++) { @@ -278,15 +279,15 @@ runner_start (runner_t *runner) struct dirent *de = NULL; char *e = NULL; - d = opendir ("/proc/self/fd"); + d = sys_opendir ("/proc/self/fd"); if (d) { - while ((de = readdir (d))) { + while ((de = sys_readdir (d))) { i = strtoul (de->d_name, &e, 10); if (*e == '\0' && i > 2 && i != dirfd (d) && i != xpi[1]) - close (i); + sys_close (i); } - closedir (d); + sys_closedir (d); } else ret = -1; #else /* !GF_LINUX_HOST_OS */ @@ -296,7 +297,7 @@ runner_start (runner_t *runner) for (i = 3; i < rl.rlim_cur; i++) { if (i != xpi[1]) - close (i); + sys_close (i); } #endif /* !GF_LINUX_HOST_OS */ } @@ -308,14 +309,14 @@ runner_start (runner_t *runner) execvp (runner->argv[0], runner->argv); } - ret = write (xpi[1], &errno, sizeof (errno)); + ret = sys_write (xpi[1], &errno, sizeof (errno)); _exit (1); } errno_priv = errno; for (i = 0; i < 3; i++) - close (pi[i][i ? 1 : 0]); - close (xpi[1]); + sys_close (pi[i][i ? 1 : 0]); + sys_close (xpi[1]); if (ret == -1) { for (i = 0; i < 3; i++) { if (runner->chio[i]) { @@ -324,8 +325,8 @@ runner_start (runner_t *runner) } } } else { - ret = read (xpi[0], (char *)&errno_priv, sizeof (errno_priv)); - close (xpi[0]); + ret = sys_read (xpi[0], (char *)&errno_priv, sizeof (errno_priv)); + sys_close (xpi[0]); if (ret <= 0) return 0; GF_ASSERT (ret == sizeof (errno_priv)); @@ -371,7 +372,7 @@ runner_end (runner_t *runner) GF_FREE (runner->argv); } for (i = 0; i < 3; i++) - close (runner->chfd[i]); + sys_close (runner->chfd[i]); return ret; } diff --git a/libglusterfs/src/statedump.c b/libglusterfs/src/statedump.c index fc66421be2f..caf228a8b01 100644 --- a/libglusterfs/src/statedump.c +++ b/libglusterfs/src/statedump.c @@ -15,6 +15,7 @@ #include "statedump.h" #include "stack.h" #include "common-utils.h" +#include "syscall.h" #ifdef HAVE_MALLOC_H @@ -73,7 +74,7 @@ gf_proc_dump_open (char *tmpname) static void gf_proc_dump_close (void) { - close (gf_dump_fd); + sys_close (gf_dump_fd); gf_dump_fd = -1; } @@ -131,7 +132,7 @@ gf_proc_dump_add_section_fd (char *key, va_list ap) GF_DUMP_MAX_BUF_LEN - strlen (buf), key, ap); snprintf (buf + strlen(buf), GF_DUMP_MAX_BUF_LEN - strlen (buf), "]\n"); - return write (gf_dump_fd, buf, strlen (buf)); + return sys_write (gf_dump_fd, buf, strlen (buf)); } @@ -184,7 +185,7 @@ gf_proc_dump_write_fd (char *key, char *value, va_list ap) offset = strlen (buf); snprintf (buf + offset, GF_DUMP_MAX_BUF_LEN - offset, "\n"); - return write (gf_dump_fd, buf, strlen (buf)); + return sys_write (gf_dump_fd, buf, strlen (buf)); } @@ -668,7 +669,7 @@ gf_proc_dump_parse_set_option (char *key, char *value) //None of dump options match the key, return back snprintf (buf, sizeof (buf), "[Warning]:None of the options " "matched key : %s\n", key); - ret = write (gf_dump_fd, buf, strlen (buf)); + ret = sys_write (gf_dump_fd, buf, strlen (buf)); if (ret >= 0) ret = -1; @@ -810,7 +811,7 @@ gf_proc_dump_info (int signum, glusterfs_ctx_t *ctx) timestr); //swallow the errors of write for start and end marker - ret = write (gf_dump_fd, sign_string, strlen (sign_string)); + ret = sys_write (gf_dump_fd, sign_string, strlen (sign_string)); memset (sign_string, 0, sizeof (sign_string)); memset (timestr, 0, sizeof (timestr)); @@ -857,12 +858,12 @@ gf_proc_dump_info (int signum, glusterfs_ctx_t *ctx) snprintf (sign_string, sizeof (sign_string), "\nDUMP-END-TIME: %s", timestr); - ret = write (gf_dump_fd, sign_string, strlen (sign_string)); + ret = sys_write (gf_dump_fd, sign_string, strlen (sign_string)); out: if (gf_dump_fd != -1) gf_proc_dump_close (); - rename (tmp_dump_name, path); + sys_rename (tmp_dump_name, path); GF_FREE (dump_options.dump_path); dump_options.dump_path = NULL; gf_proc_dump_unlock (); diff --git a/libglusterfs/src/store.c b/libglusterfs/src/store.c index b44ee0a12d6..1591627b741 100644 --- a/libglusterfs/src/store.c +++ b/libglusterfs/src/store.c @@ -15,13 +15,16 @@ #include "store.h" #include "dict.h" #include "xlator.h" +#include "syscall.h" #include "libglusterfs-messages.h" + + int32_t gf_store_mkdir (char *path) { int32_t ret = -1; - ret = mkdir (path, 0777); + ret = sys_mkdir (path, 0777); if ((-1 == ret) && (EEXIST != errno)) { gf_msg ("", GF_LOG_ERROR, errno, LG_MSG_DIR_OP_FAILED, "mkdir()" @@ -93,7 +96,7 @@ gf_store_sync_direntry (char *path) goto out; } - ret = fsync (dirfd); + ret = sys_fsync (dirfd); if (ret) { gf_msg (this->name, GF_LOG_ERROR, errno, LG_MSG_DIR_OP_FAILED, "Failed to fsync %s.", pdir); @@ -103,7 +106,7 @@ gf_store_sync_direntry (char *path) ret = 0; out: if (dirfd >= 0) { - ret = close (dirfd); + ret = sys_close (dirfd); if (ret) { gf_msg (this->name, GF_LOG_ERROR, errno, LG_MSG_DIR_OP_FAILED, "Failed to close %s", pdir); @@ -125,14 +128,14 @@ gf_store_rename_tmppath (gf_store_handle_t *shandle) GF_VALIDATE_OR_GOTO ("store", shandle, out); GF_VALIDATE_OR_GOTO ("store", shandle->path, out); - ret = fsync (shandle->tmp_fd); + ret = sys_fsync (shandle->tmp_fd); if (ret) { gf_msg (THIS->name, GF_LOG_ERROR, errno, LG_MSG_FILE_OP_FAILED, "Failed to fsync %s", shandle->path); goto out; } snprintf (tmppath, sizeof (tmppath), "%s.tmp", shandle->path); - ret = rename (tmppath, shandle->path); + ret = sys_rename (tmppath, shandle->path); if (ret) { gf_msg (THIS->name, GF_LOG_ERROR, errno, LG_MSG_FILE_OP_FAILED, "Failed to rename %s to %s", tmppath, @@ -143,7 +146,7 @@ gf_store_rename_tmppath (gf_store_handle_t *shandle) ret = gf_store_sync_direntry (tmppath); out: if (shandle && shandle->tmp_fd >= 0) { - close (shandle->tmp_fd); + sys_close (shandle->tmp_fd); shandle->tmp_fd = -1; } return ret; @@ -159,7 +162,7 @@ gf_store_unlink_tmppath (gf_store_handle_t *shandle) GF_VALIDATE_OR_GOTO ("store", shandle->path, out); snprintf (tmppath, sizeof (tmppath), "%s.tmp", shandle->path); - ret = unlink (tmppath); + ret = sys_unlink (tmppath); if (ret && (errno != ENOENT)) { gf_msg ("", GF_LOG_ERROR, errno, LG_MSG_FILE_OP_FAILED, "Failed to mv %s to %s", tmppath, @@ -169,7 +172,7 @@ gf_store_unlink_tmppath (gf_store_handle_t *shandle) } out: if (shandle && shandle->tmp_fd >= 0) { - close (shandle->tmp_fd); + sys_close (shandle->tmp_fd); shandle->tmp_fd = -1; } return ret; @@ -243,7 +246,7 @@ gf_store_retrieve_value (gf_store_handle_t *handle, char *key, char **value) handle->fd = open (handle->path, O_RDWR); else /* handle->fd is valid already, kept open for lockf() */ - lseek (handle->fd, 0, SEEK_SET); + sys_lseek (handle->fd, 0, SEEK_SET); if (handle->fd == -1) { gf_msg ("", GF_LOG_ERROR, errno, LG_MSG_FILE_OP_FAILED, @@ -261,7 +264,7 @@ gf_store_retrieve_value (gf_store_handle_t *handle, char *key, char **value) goto out; } - ret = fstat (handle->fd, &st); + ret = sys_fstat (handle->fd, &st); if (ret < 0) { gf_msg ("", GF_LOG_WARNING, errno, LG_MSG_FILE_OP_FAILED, "stat on file %s failed", handle->path); @@ -315,7 +318,7 @@ out: if (handle->fd > 0 && handle->locked == F_ULOCK) { /* only invalidate handle->fd if not locked */ - close (handle->fd); + sys_close (handle->fd); } GF_FREE (free_str); @@ -407,7 +410,7 @@ gf_store_handle_new (const char *path, gf_store_handle_t **handle) ret = 0; out: if (fd >= 0) - close (fd); + sys_close (fd); if (ret == -1) { GF_FREE (spath); @@ -424,7 +427,7 @@ gf_store_handle_retrieve (char *path, gf_store_handle_t **handle) int32_t ret = -1; struct stat statbuf = {0}; - ret = stat (path, &statbuf); + ret = sys_stat (path, &statbuf); if (ret) { gf_msg ("", GF_LOG_ERROR, errno, LG_MSG_PATH_NOT_FOUND, "Path " "corresponding to %s.", path); @@ -548,7 +551,7 @@ gf_store_iter_get_next (gf_store_iter_t *iter, char **key, char **value, GF_ASSERT (key); GF_ASSERT (value); - ret = stat (iter->filepath, &st); + ret = sys_stat (iter->filepath, &st); if (ret < 0) { gf_msg ("", GF_LOG_WARNING, errno, LG_MSG_FILE_OP_FAILED, "stat on file failed"); @@ -717,7 +720,7 @@ gf_store_unlock (gf_store_handle_t *sh) gf_msg ("", GF_LOG_ERROR, errno, LG_MSG_UNLOCK_FAILED, "Failed to release lock on '%s'", sh->path); - close (sh->fd); + sys_close (sh->fd); } int -- cgit