plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * Copyright (c) International Business Machines Corp., 2001 |
Cyril Hrubis | dbec150 | 2012-11-28 12:59:23 +0100 | [diff] [blame] | 4 | * Copyright (c) 2012 Cyril Hrubis <chrubis@suse.cz> |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 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 |
Wanlong Gao | 4548c6c | 2012-10-19 18:03:36 +0800 | [diff] [blame] | 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 19 | */ |
| 20 | |
Cyril Hrubis | dbec150 | 2012-11-28 12:59:23 +0100 | [diff] [blame] | 21 | /* |
| 22 | * wait402 - check for ECHILD errno when using an illegal pid value |
| 23 | */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 24 | |
| 25 | #include "test.h" |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 26 | |
| 27 | #include <errno.h> |
| 28 | #define _USE_BSD |
| 29 | #include <sys/types.h> |
| 30 | #include <sys/resource.h> |
| 31 | #include <sys/wait.h> |
robbiew | 5832f9b | 2002-08-12 14:57:23 +0000 | [diff] [blame] | 32 | #include <stdlib.h> |
| 33 | #include <string.h> |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 34 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 35 | char *TCID = "wait402"; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 36 | int TST_TOTAL = 1; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 37 | |
Cyril Hrubis | dbec150 | 2012-11-28 12:59:23 +0100 | [diff] [blame] | 38 | static void cleanup(void); |
| 39 | static void setup(void); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 40 | |
Cyril Hrubis | dbec150 | 2012-11-28 12:59:23 +0100 | [diff] [blame] | 41 | static long get_pid_max(void) |
vapier | 6c53d8e | 2006-08-06 04:34:47 +0000 | [diff] [blame] | 42 | { |
Cyril Hrubis | dbec150 | 2012-11-28 12:59:23 +0100 | [diff] [blame] | 43 | long pid_max; |
vapier | 6c53d8e | 2006-08-06 04:34:47 +0000 | [diff] [blame] | 44 | |
Cyril Hrubis | dbec150 | 2012-11-28 12:59:23 +0100 | [diff] [blame] | 45 | SAFE_FILE_SCANF(NULL, "/proc/sys/kernel/pid_max", "%ld", &pid_max); |
vapier | 6c53d8e | 2006-08-06 04:34:47 +0000 | [diff] [blame] | 46 | |
Cyril Hrubis | dbec150 | 2012-11-28 12:59:23 +0100 | [diff] [blame] | 47 | return pid_max; |
vapier | 6c53d8e | 2006-08-06 04:34:47 +0000 | [diff] [blame] | 48 | } |
| 49 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 50 | int main(int ac, char **av) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 51 | { |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 52 | int lc; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 53 | const char *msg; |
vapier | 6c53d8e | 2006-08-06 04:34:47 +0000 | [diff] [blame] | 54 | pid_t epid = get_pid_max() + 1; |
robbiew | eda1cbd | 2003-03-24 20:55:05 +0000 | [diff] [blame] | 55 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 56 | int status = 1; |
Cyril Hrubis | dbec150 | 2012-11-28 12:59:23 +0100 | [diff] [blame] | 57 | struct rusage rusage; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 58 | |
Cyril Hrubis | dbec150 | 2012-11-28 12:59:23 +0100 | [diff] [blame] | 59 | if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 60 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 61 | |
Cyril Hrubis | dbec150 | 2012-11-28 12:59:23 +0100 | [diff] [blame] | 62 | setup(); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 63 | |
| 64 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 65 | tst_count = 0; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 66 | |
Cyril Hrubis | dbec150 | 2012-11-28 12:59:23 +0100 | [diff] [blame] | 67 | TEST(wait4(epid, &status, 0, &rusage)); |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 68 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 69 | if (TEST_RETURN == 0) { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 70 | tst_brkm(TFAIL, cleanup, |
| 71 | "call failed to produce expected error - errno = %d - %s", |
| 72 | TEST_ERRNO, strerror(TEST_ERRNO)); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 73 | } |
| 74 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 75 | switch (TEST_ERRNO) { |
| 76 | case ECHILD: |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 77 | tst_resm(TPASS, |
| 78 | "received expected failure - errno = %d - %s", |
| 79 | TEST_ERRNO, strerror(TEST_ERRNO)); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 80 | break; |
| 81 | default: |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 82 | tst_brkm(TFAIL, cleanup, |
| 83 | "call failed to produce expected " |
| 84 | "error - errno = %d - %s", TEST_ERRNO, |
| 85 | strerror(TEST_ERRNO)); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 86 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | cleanup(); |
Garrett Cooper | 7d0a4a5 | 2010-12-16 10:05:08 -0800 | [diff] [blame] | 90 | tst_exit(); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 91 | } |
| 92 | |
Cyril Hrubis | dbec150 | 2012-11-28 12:59:23 +0100 | [diff] [blame] | 93 | static void setup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 94 | { |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 95 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 96 | tst_sig(FORK, DEF_HANDLER, cleanup); |
| 97 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 98 | TEST_PAUSE; |
| 99 | } |
| 100 | |
Cyril Hrubis | dbec150 | 2012-11-28 12:59:23 +0100 | [diff] [blame] | 101 | static void cleanup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 102 | { |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 103 | } |