Hi,

On 07/28/2014 09:50 PM, [email protected] wrote:
> Hi!
>> ---
>>  
>> -     */
>> -    if (chdir(parent_dir) != 0) {
>> -            tst_resm(TWARN | TERRNO,
>> -                     "%s: chdir(%s) failed\nAttempting to remove temp dir "
>> -                     "anyway", __func__, parent_dir);
>> +            parent_dir = dirname(parent_dir);
>> +            if (parent_dir == NULL) {
>> +                    tst_resm(TWARN | TERRNO,
>> +                             "%s: dirname failed", __func__);
>> +                    return;
>> +            }
>> +
>> +            /*
>> +             * Change directory to parent_dir (The dir above TESTDIR).
>> +             */
>> +            if (chdir(parent_dir) != 0) {
>> +                    tst_resm(TWARN | TERRNO, "%s: chdir(%s) failed\n"
>> +                             "Attempting to remove temp dir anyway",
>> +                             __func__, parent_dir);
>> +            }
>>      }
> 
> Good catch.
> 
> Can't we just do chdir(test_start_work_dir) in both cases and then the
> rmobj(TESTDIR, &errmsg)? That would really simplify the code for
> tst_rmdir().

Yeah, that would be better. But when i try to use chdir(test_start_work_dir) in 
both cases,
there are some other errors that occur. Please see below error message:
1. # apply the patch using chdir(test_start_work_dir) in both cases.
2. # cd testcases/kernel/syscalls/access
3. # mkdir testdir
4. # export TMPDIR=testdir
5. # chmod 777 testdir (access05 will do a setuid(), so change testdir's mode.)
6. # ./access05
Error message:
access05    1  TPASS  :  access failed as expected: TEST_ERRNO=EACCES(13): 
Permission denied                                                               
   
access05    2  TPASS  :  access failed as expected: TEST_ERRNO=EACCES(13): 
Permission denied
access05    3  TPASS  :  access failed as expected: TEST_ERRNO=EACCES(13): 
Permission denied
access05    4  TPASS  :  access failed as expected: TEST_ERRNO=EINVAL(22): 
Invalid argument
access05    5  TPASS  :  access failed as expected: TEST_ERRNO=EFAULT(14): Bad 
address
access05    6  TPASS  :  access failed as expected: TEST_ERRNO=EFAULT(14): Bad 
address
access05    7  TPASS  :  access failed as expected: TEST_ERRNO=ENOENT(2): No 
such file or directory
access05    8  TPASS  :  access failed as expected: 
TEST_ERRNO=ENAMETOOLONG(36): File name too long
access05    9  TPASS  :  access failed as expected: TEST_ERRNO=ENOTDIR(20): Not 
a directory
access05   10  TPASS  :  access failed as expected: TEST_ERRNO=ELOOP(40): Too 
many levels of symbolic links
access05    0  TWARN  :  tst_tmpdir.c:191: tst_rmdir: 
chdir(/home/lege/extern_stroage/ltp-dev/testcases/kernel/syscalls/access) failed
Attempting to remove temp dir anyway: errno=EACCES(13): Permission denied
access05    0  TWARN  :  tst_tmpdir.c:199: tst_rmdir: rmobj(testdir/accVCAXvs) 
failed: lstat(testdir/accVCAXvs) failed; errno=2: No such file or directory

Look at the getcwd(2)'s implementation in kernel, it does not have privilege 
check, so usually we can store current working directory in
test_start_work_dir correctly. But chdir(2) does it, if search permission is 
denied for one of the components of path, it will return EACCES. This
may occur when some test cases call setuid() change effective uid. In this 
case, lege directory's mode would be drwx--x---, so the chdir(2) operation 
failed.

Currently I don't find a better method to deal with this issue gracefully, and 
i recommend that we force environment variable
TMPDIR to use an absolute pathname. At least, if we don't have some privilege, 
we can fail fast in tst_tmpdir() and this will also
greatly simplify the code in tst_rmdir(). Please see my next patches, thanks!


Regards,
Xiaoguang Wang


------------------------------------------------------------------------------
Infragistics Professional
Build stunning WinForms apps today!
Reboot your WinForms applications with our WinForms controls. 
Build a bridge from your legacy apps to the future.
http://pubads.g.doubleclick.net/gampad/clk?id=153845071&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reply via email to