]> arthur.barton.de Git - netatalk.git/commitdiff
Fix fd handling on Solaris
authorFrank Lahm <franklahm@googlemail.com>
Tue, 31 Jan 2012 06:11:02 +0000 (07:11 +0100)
committerFrank Lahm <franklahm@googlemail.com>
Tue, 31 Jan 2012 06:11:02 +0000 (07:11 +0100)
include/atalk/ea.h
libatalk/adouble/ad_lock.c
libatalk/adouble/ad_lock.h
libatalk/adouble/ad_open.c
libatalk/vfs/extattr.c

index 63534cdc9fb8972ab4d633ecca39392bacd4aaac..228970373a54567e6e35eec6935034938c5dffaf 100644 (file)
@@ -94,7 +94,7 @@ int sys_setxattr (const char *path, const char *name, const void *value, size_t
 int sys_lsetxattr (const char *path, const char *name, const void *value, size_t size, int flags);
 int sys_fsetxattr (int filedes, const char *name, const void *value, size_t size, int flags);
 int sys_copyxattr (const char *src, const char *dst);
-int sys_getxattrfd(const char *path, const char *uname, int oflag, ...);
+int sys_getxattrfd(int fd, const char *uname, int oflag, ...);
 
 /****************************************************************************************
  * Stuff for our implementation of storing EAs in files in .AppleDouble dirs
index b7b4722b176ba9c0b30ec09f3be2d3e812ba0194..6932b33d4bd5be187bae75c843d16af9752e5321 100644 (file)
@@ -63,8 +63,8 @@ static int set_lock(int fd, int cmd,  struct flock *lock)
 {
     EC_INIT;
 
-    LOG(log_debug, logtype_default, "set_lock(%s, %s, off: %jd (%s), len: %jd): BEGIN",
-        cmd == F_SETLK ? "F_SETLK" : "F_GETLK",
+    LOG(log_debug, logtype_default, "set_lock(fd: %d, %s, %s, off: %jd (%s), len: %jd): BEGIN",
+        fd, cmd == F_SETLK ? "F_SETLK" : "F_GETLK",
         lock->l_type == F_RDLCK ? "F_RDLCK" : lock->l_type == F_WRLCK ? "F_WRLCK" : "F_UNLCK",
         (intmax_t)lock->l_start,
         shmdstrfromoff(lock->l_start),
@@ -77,8 +77,7 @@ static int set_lock(int fd, int cmd,  struct flock *lock)
         return 0;
     }
 
-    EC_NEG1_LOGSTR( fcntl(fd, cmd, lock),
-                    "set_lock: %s", strerror(errno));
+    EC_NEG1_LOG( fcntl(fd, cmd, lock) );
 
 EC_CLEANUP:
     EC_EXIT;
index b08807ab2b7dace80fde77f19c75c3281e981e65..2d15da908bbab2d0673edebcfbb1f258750263f3 100644 (file)
@@ -3,8 +3,8 @@
 
 #include <atalk/adouble.h>
 
-/* this is so that we can keep lists of fds referencing the same file                                                                                                                                                                                                         
- * around. that way, we can honor locks created by the same process                                                                                                                                                                                                           
+/* this is so that we can keep lists of fds referencing the same file
+ * around. that way, we can honor locks created by the same process
  * with the same file. */
 
 #define adf_lock_init(a) do {   \
@@ -19,7 +19,8 @@
             break;                                            \
         for (i = 0; i < (a)->adf_lockcount; i++) {            \
             adf_lock_t *lock = (a)->adf_lock + i;             \
-            if (--(*lock->refcount) < 1)free(lock->refcount); \
+            if (--(*lock->refcount) < 1)                      \
+                free(lock->refcount);                         \
         }                                                     \
         free((a)->adf_lock);                                  \
         adf_lock_init(a);                                     \
index a799d3b760cd0b1dcf1760165d672512ade7dee7..3e6680828597c9abd10595ce30499110a87605cf 100644 (file)
@@ -1045,14 +1045,15 @@ static int ad_reso_size(const char *path, int adflags, struct adouble *ad)
     LOG(log_debug, logtype_default, "ad_reso_size(\"%s\")", path);
 
 #ifdef HAVE_EAFD
-    int opened = 0;
-    int eafd = ad_reso_fileno(ad);
-    if (eafd == -1) {
-        EC_NEG1( eafd = sys_getxattrfd(path, AD_EA_RESO, O_RDONLY) );
-        opened = 1;
-    }
-    EC_NEG1( fstat(eafd, &st) );
-    ad->ad_rlen = st.st_size;
+    ssize_t easz;
+    int eafd;
+
+    if ((eafd = ad_reso_fileno(ad)) == -1)
+        if ((eafd = ad_data_fileno(ad)) == -1)
+            EC_FAIL;
+
+    EC_NEG1( easz = sys_fgetxattr(eafd, AD_EA_RESO, NULL, 0) );
+    ad->ad_rlen = easz;
 #else
     const char *rfpath;
     EC_NULL_LOG( rfpath = ad->ad_ops->ad_path(path, adflags));
@@ -1066,10 +1067,6 @@ static int ad_reso_size(const char *path, int adflags, struct adouble *ad)
     LOG(log_debug, logtype_default, "ad_reso_size(\"%s\"): size: %zd", path, ad->ad_rlen);
 
 EC_CLEANUP:
-#ifdef HAVE_EAFD
-    if (opened)
-        close(eafd);
-#endif
     if (ret != 0)
         ad->ad_rlen = 0;
     EC_EXIT;
@@ -1114,11 +1111,16 @@ static int ad_open_rf(const char *path, int adflags, int mode, struct adouble *a
         goto EC_CLEANUP;
     }
 #ifdef HAVE_EAFD
-    if ((ad_reso_fileno(ad) = sys_getxattrfd(path, AD_EA_RESO, oflags)) == -1) {
-        if (!(adflags & ADFLAGS_CREATE))
+    if (ad_meta_fileno(ad) == -1)
+        EC_FAIL;
+    if ((ad_reso_fileno(ad) = sys_getxattrfd(ad_meta_fileno(ad), AD_EA_RESO, oflags)) == -1) {
+        if (!(adflags & ADFLAGS_CREATE)) {
+            errno = ENOENT;
             EC_FAIL;
+        }
         oflags |= O_CREAT;
-        EC_NEG1_LOG( ad_reso_fileno(ad) = sys_getxattrfd(path, AD_EA_RESO, oflags, 0666) ); 
+        EC_NEG1_LOG( ad_reso_fileno(ad) = sys_getxattrfd(ad_meta_fileno(ad),
+                                                         AD_EA_RESO, oflags, 0666) ); 
     }
 #else
     EC_NULL_LOG( rfpath = ad->ad_ops->ad_path(path, adflags) );
index 6336980c2bd6aeb27fc2d06ae4b24920c0edef52..66f0b8c0c5b644b4e926a3c887c3b15399a1147a 100644 (file)
@@ -88,12 +88,12 @@ static const char *prefix(const char *uname)
 #endif
 }
 
-int sys_getxattrfd(const char *path, const char *uname, int oflag, ...)
+int sys_getxattrfd(int fd, const char *uname, int oflag, ...)
 {
 #if defined HAVE_ATTROPEN
     int eafd;
     va_list args;
-    mode_t mode;
+    mode_t mode = 0;
 
     if (oflag & O_CREAT) {
         va_start(args, oflag);
@@ -102,9 +102,9 @@ int sys_getxattrfd(const char *path, const char *uname, int oflag, ...)
     }
 
     if (oflag & O_CREAT)
-        eafd = attropen(path, uname, oflag, mode);
+        eafd = solaris_openat(fd, uname, oflag | O_XATTR, mode);
     else
-        eafd = attropen(path, uname, oflag);
+        eafd = solaris_openat(fd, uname, oflag | O_XATTR, mode);
 
     return eafd;
 #else