summaryrefslogtreecommitdiffstats
path: root/booster
diff options
context:
space:
mode:
authorRaghavendra G <raghavendra@gluster.com>2009-11-18 01:15:11 +0000
committerAnand V. Avati <avati@dev.gluster.com>2009-11-18 21:13:59 -0800
commit119b179fdc83d49e8242a93439fb043990eb74c9 (patch)
treef011ca233b1d395d8f5d732f3a5447fab3abc6d3 /booster
parent3940cf2fc26ed0d2417caef87ff25d17ec8d3bb4 (diff)
booster: implement chdir.
Signed-off-by: Raghavendra G <raghavendra@gluster.com> Signed-off-by: Anand V. Avati <avati@dev.gluster.com> BUG: 369 (Samba does not work with booster.) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=369
Diffstat (limited to 'booster')
-rw-r--r--booster/src/booster.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/booster/src/booster.c b/booster/src/booster.c
index 00352d6217f..6264695ab4e 100644
--- a/booster/src/booster.c
+++ b/booster/src/booster.c
@@ -49,6 +49,8 @@
#define GF_UNIT_KB 1024
#endif
+static pthread_mutex_t cwdlock = PTHREAD_MUTEX_INITIALIZER;
+
/* attr constructor registers this function with libc's
* _init function as a function that must be called before
* the main() of the program.
@@ -188,6 +190,7 @@ static ssize_t (*real_sendfile) (int out_fd, int in_fd, off_t *offset,
static ssize_t (*real_sendfile64) (int out_fd, int in_fd, off_t *offset,
size_t count);
static int (*real_fcntl) (int fd, int cmd, ...);
+static int (*real_chdir) (const char *path);
#define RESOLVE(sym) do { \
if (!real_##sym) \
@@ -2688,6 +2691,55 @@ out:
return ret;
}
+
+int
+chdir (const char *path)
+{
+ int ret = -1;
+ char cwd[PATH_MAX];
+ char *res = NULL;
+
+ gf_log ("booster", GF_LOG_TRACE, "chdir: path %s", path);
+
+ pthread_mutex_lock (&cwdlock);
+ {
+ res = glusterfs_getcwd (cwd, PATH_MAX);
+ if (res == NULL) {
+ gf_log ("booster", GF_LOG_ERROR, "getcwd failed: %s",
+ strerror (errno));
+ goto unlock;
+ }
+
+ ret = glusterfs_chdir (path);
+ if ((ret == -1) && (errno != ENODEV)) {
+ gf_log ("booster", GF_LOG_ERROR, "chdir failed: %s",
+ strerror (errno));
+ goto unlock;
+ }
+
+ if (ret == 0) {
+ gf_log ("booster", GF_LOG_TRACE, "chdir succeeded");
+ goto unlock;
+ }
+
+ if (real_chdir == NULL) {
+ errno = ENOSYS;
+ ret = -1;
+ goto unlock;
+ }
+
+ ret = real_chdir (path);
+ if (ret == -1) {
+ glusterfs_chdir (cwd);
+ }
+ }
+unlock:
+ pthread_mutex_unlock (&cwdlock);
+
+ return ret;
+}
+
+
void
booster_lib_init (void)
{
@@ -2765,6 +2817,7 @@ booster_lib_init (void)
RESOLVE (readdir_r);
RESOLVE (readdir64_r);
RESOLVE (fcntl);
+ RESOLVE (chdir);
/* This must be called after resolving real functions
* above so that the socket based IO calls in libglusterfsclient