Home | History | Annotate | Download | only in fchdir
      1 /*
      2  *
      3  *   Copyright (c) International Business Machines  Corp., 2001
      4  *
      5  *   This program is free software;  you can redistribute it and/or modify
      6  *   it under the terms of the GNU General Public License as published by
      7  *   the Free Software Foundation; either version 2 of the License, or
      8  *   (at your option) any later version.
      9  *
     10  *   This program is distributed in the hope that it will be useful,
     11  *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
     12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
     13  *   the GNU General Public License for more details.
     14  *
     15  *   You should have received a copy of the GNU General Public License
     16  *   along with this program;  if not, write to the Free Software
     17  *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
     18  */
     19 
     20 /*
     21  * NAME
     22  *	fchdir02.c
     23  *
     24  * DESCRIPTION
     25  *	fchdir02 - try to cd into a bad directory (bad fd).
     26  *
     27  * CALLS
     28  *	fchdir()
     29  *
     30  * ALGORITHM
     31  *	loop if that option was specified
     32  *	call fchdir() with an invalid file descriptor
     33  *	check the errno value
     34  *	  issue a PASS message if we get EBADF - errno 9
     35  *	otherwise, the tests fails
     36  *	  issue a FAIL message
     37  *	  break any remaining tests
     38  *	  call cleanup
     39  *
     40  * USAGE:  <for command-line>
     41  *  fchdir02 [-c n] [-e] [-i n] [-I x] [-P x] [-t]
     42  *     where,  -c n : Run n copies concurrently.
     43  *             -e   : Turn on errno logging.
     44  *	       -i n : Execute test n times.
     45  *	       -I x : Execute test for x seconds.
     46  *	       -P x : Pause for x seconds between iterations.
     47  *	       -t   : Turn on syscall timing.
     48  *
     49  * HISTORY
     50  *	03/2001 - Written by Wayne Boyer
     51  *
     52  * RESTRICTIONS
     53  *	none
     54  */
     55 
     56 #include "test.h"
     57 
     58 #include <errno.h>
     59 #include <sys/stat.h>
     60 #include <fcntl.h>
     61 
     62 void cleanup(void);
     63 void setup(void);
     64 
     65 char *TCID = "fchdir02";
     66 int TST_TOTAL = 1;
     67 
     68 int main(int ac, char **av)
     69 {
     70 	const int bad_fd = -5;
     71 	int lc;
     72 
     73 	tst_parse_opts(ac, av, NULL, NULL);
     74 
     75 	setup();		/* global setup */
     76 
     77 	for (lc = 0; TEST_LOOPING(lc); lc++) {
     78 		tst_count = 0;
     79 
     80 		TEST(fchdir(bad_fd));
     81 
     82 		if (TEST_RETURN != -1)
     83 			tst_brkm(TFAIL, cleanup, "call succeeded unexpectedly");
     84 
     85 		if (TEST_ERRNO == EBADF)
     86 			tst_resm(TPASS, "failed as expected with EBADF");
     87 		else
     88 			tst_brkm(TFAIL | TTERRNO, cleanup,
     89 				 "call failed unexpectedly");
     90 	}
     91 
     92 	cleanup();
     93 
     94 	tst_exit();
     95 }
     96 
     97 void setup(void)
     98 {
     99 
    100 	tst_sig(NOFORK, DEF_HANDLER, cleanup);
    101 
    102 	TEST_PAUSE;
    103 
    104 	tst_tmpdir();
    105 }
    106 
    107 void cleanup(void)
    108 {
    109 	tst_rmdir();
    110 }
    111