Home | History | Annotate | Download | only in wait4
      1 /*
      2  *
      3  *   Copyright (c) International Business Machines  Corp., 2001
      4  *   Copyright (c) 2012 Cyril Hrubis <chrubis (at) suse.cz>
      5  *
      6  *   This program is free software;  you can redistribute it and/or modify
      7  *   it under the terms of the GNU General Public License as published by
      8  *   the Free Software Foundation; either version 2 of the License, or
      9  *   (at your option) any later version.
     10  *
     11  *   This program is distributed in the hope that it will be useful,
     12  *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
     13  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
     14  *   the GNU General Public License for more details.
     15  *
     16  *   You should have received a copy of the GNU General Public License
     17  *   along with this program;  if not, write to the Free Software
     18  *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
     19  */
     20 
     21  /*
     22   * wait402 - check for ECHILD errno when using an illegal pid value
     23   */
     24 
     25 #include "test.h"
     26 
     27 #include <errno.h>
     28 #define _USE_BSD
     29 #include <sys/types.h>
     30 #include <sys/resource.h>
     31 #include <sys/wait.h>
     32 #include <stdlib.h>
     33 #include <string.h>
     34 
     35 char *TCID = "wait402";
     36 int TST_TOTAL = 1;
     37 
     38 static void cleanup(void);
     39 static void setup(void);
     40 
     41 static long get_pid_max(void)
     42 {
     43 	long pid_max;
     44 
     45 	SAFE_FILE_SCANF(NULL, "/proc/sys/kernel/pid_max", "%ld", &pid_max);
     46 
     47 	return pid_max;
     48 }
     49 
     50 int main(int ac, char **av)
     51 {
     52 	int lc;
     53 	pid_t epid = get_pid_max() + 1;
     54 
     55 	int status = 1;
     56 	struct rusage rusage;
     57 
     58 	tst_parse_opts(ac, av, NULL, NULL);
     59 
     60 	setup();
     61 
     62 	for (lc = 0; TEST_LOOPING(lc); lc++) {
     63 		tst_count = 0;
     64 
     65 		TEST(wait4(epid, &status, 0, &rusage));
     66 
     67 		if (TEST_RETURN == 0) {
     68 			tst_brkm(TFAIL, cleanup,
     69 				 "call failed to produce expected error - errno = %d - %s",
     70 				 TEST_ERRNO, strerror(TEST_ERRNO));
     71 		}
     72 
     73 		switch (TEST_ERRNO) {
     74 		case ECHILD:
     75 			tst_resm(TPASS,
     76 				 "received expected failure - errno = %d - %s",
     77 				 TEST_ERRNO, strerror(TEST_ERRNO));
     78 			break;
     79 		default:
     80 			tst_brkm(TFAIL, cleanup,
     81 				 "call failed to produce expected "
     82 				 "error - errno = %d - %s", TEST_ERRNO,
     83 				 strerror(TEST_ERRNO));
     84 		}
     85 	}
     86 
     87 	cleanup();
     88 	tst_exit();
     89 }
     90 
     91 static void setup(void)
     92 {
     93 
     94 	tst_sig(FORK, DEF_HANDLER, cleanup);
     95 
     96 	TEST_PAUSE;
     97 }
     98 
     99 static void cleanup(void)
    100 {
    101 }
    102