]> arthur.barton.de Git - netatalk.git/commitdiff
use open and fchdir rather than getcwd in catsearch
authordidg <didg>
Wed, 27 Jan 2010 12:36:42 +0000 (12:36 +0000)
committerdidg <didg>
Wed, 27 Jan 2010 12:36:42 +0000 (12:36 +0000)
etc/afpd/catsearch.c

index 59b0227b98e3a3440a0acff25c0aa74c4aefe26f..ccbdd80fbcb7b82671422e7c3c7201f7a02d215a 100644 (file)
@@ -495,13 +495,12 @@ static int catsearch(struct vol *vol, struct dir *dir,
        int result = AFP_OK;
        int ccr;
     struct path path;
-       char *orig_dir = NULL;
-       int orig_dir_len = 128;
        char *vpath = vol->v_path;
        char *rrbuf = rbuf;
     time_t start_time;
     int num_rounds = NUM_ROUNDS;
     int cached;
+    int cwd = -1;
         
        if (*pos != 0 && *pos != cur_pos) {
                result = AFPERR_CATCHNG;
@@ -529,15 +528,10 @@ static int catsearch(struct vol *vol, struct dir *dir,
        }
 
        /* Save current path */
-       orig_dir = (char*)malloc(orig_dir_len);
-       while (getcwd(orig_dir, orig_dir_len-1)==NULL) {
-               if (errno != ERANGE) {
-                       result = AFPERR_MISC;
-                       goto catsearch_end;
-               }
-               orig_dir_len += 128; 
-               orig_dir = realloc(orig_dir, orig_dir_len);
-       } /* while() */
+    if ((cwd = open(".", O_RDONLY)) < 0) {
+        result = AFPERR_MISC;
+        goto catsearch_end;
+    }
        
        while ((cidx = reducestack()) != -1) {
                cached = 1;
@@ -658,10 +652,12 @@ catsearch_pause:
 
 catsearch_end: /* Exiting catsearch: error condition */
        *rsize = rrbuf - rbuf;
-       if (orig_dir != NULL) {
-               chdir(orig_dir);
-               free(orig_dir);
-       }
+    if (cwd != -1) {
+        if ((fchdir(cwd)) != 0) {
+            LOG(log_debug, logtype_afpd, "error chdiring back: %s", strerror(errno));        
+        }
+        close(cwd);
+    }
        return result;
 } /* catsearch() */