Hi Waldemar,

I'm enclosing a testcase.  When run from an unpatched uclibc-ng system, we see:

Processing f2 in working dir /tmp/stest_dir/d1
Processing d1 in working dir /tmp/stest_dir/d1
Oops...relative path does not exist in current directory: No such file or 
directory
Processing f1 in working dir /tmp/stest_dir
Processing stest_dir in working dir /tmp/stest_dir
Oops...relative path does not exist in current directory: No such file or 
directory

When run from a patched system, we see:

Processing f2 in working dir /tmp/stest_dir/d1
Processing d1 in working dir /tmp/stest_dir
Processing f1 in working dir /tmp/stest_dir
Processing stest_dir in working dir /tmp

Let me know if you need anything else...

Take care,
---- 
John Ata, CISSP
Senior Principal Software Engineer
Electronics Systems
STOP Operating System Software Development

T 703-563-8115 | F 703-668-4359 | john....@baesystems.com
http://www.baesystems.com/csp

-----Original Message-----
From: Waldemar Brodkorb [mailto:w...@uclibc-ng.org] 
Sent: Tuesday, October 18, 2016 12:17 PM
To: Ata, John (US) <john....@baesystems.com>
Cc: devel@uclibc-ng.org
Subject: Re: [uclibc-ng-devel] PATCH] Fix ntfw when called with FTW_CHDIR and 
FTW_DEPTH to change directory back to the parent before processing the 
directory (after the contents have already been processed).

*** WARNING ***
EXTERNAL EMAIL -- This message originates from outside our organization.


Hi John,
Ata, John  (US) wrote,

> Hi all,
> 
>  
> 
> In using ftw/nftw, I’ve discovered a bug when using FTW_CHDIR and FTW_DEPTH.  
> After changing the working directory to a subdirectory, nftw would process the
> contents fine.  However, it would then try and process the directory itself
> while still in that directory and then switch back to the parent.  This would
> result in an error (ENOENT).  This patch will change working directories to 
> the
> parent before processing the directory itself.

Thanks for the report.
Are you able to provide a small test-case showing the issue?

best regards
 Waldemar
#define _XOPEN_SOURCE 500 
#define _GNU_SOURCE
#include <ftw.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>

static int process_one_entry(const char *fpath, const struct stat *sb,
                             int typeflag, struct FTW *ftwbuf)
{
    
    struct stat buf;
    const char *rel_path = fpath+ftwbuf->base;

    printf("Processing %s in working dir %s\n",
           rel_path, get_current_dir_name());
    if (stat(rel_path, &buf) < 0)
        perror("Oops...relative path does not exist in current directory");
    return 0;
    
}

int main (int argc, char **argv)
{
    char *path = "/tmp/stest_dir";
    char *subpath = "/tmp/stest_dir/d1";
    char *filepath = "/tmp/stest_dir/f1";
    char *filesubpath = "/tmp/stest_dir/d1/f2";
    
    if ((mkdir(path, 0700)) < 0)
        perror("Creating path");
    if ((mkdir(subpath, 0700)) < 0)
        perror("Creating subpath");
    if ((open(filepath, O_CREAT)) < 0)
        perror("Opening filepath");
    if ((open(filesubpath, O_CREAT)) < 0)
        perror("Opening filesubpath");

    if (nftw(path, process_one_entry, 100, (FTW_CHDIR|FTW_DEPTH|FTW_PHYS)) < 0)
        perror("ntfw");

    unlink(filesubpath);
    unlink(filepath);
    rmdir(subpath);
    rmdir(path);

    return 0;
}
_______________________________________________
devel mailing list
devel@uclibc-ng.org
http://mailman.uclibc-ng.org/cgi-bin/mailman/listinfo/devel

Reply via email to