Home | History | Annotate | Download | only in getsid
      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 #define _GNU_SOURCE 1
     22 
     23 #include "test.h"
     24 
     25 #include <errno.h>
     26 
     27 char *TCID = "getsid02";
     28 int TST_TOTAL = 1;
     29 
     30 static pid_t unused_pid;
     31 
     32 static void cleanup(void);
     33 static void setup(void);
     34 
     35 int main(int ac, char **av)
     36 {
     37 	int lc;
     38 
     39 	tst_parse_opts(ac, av, NULL, NULL);
     40 
     41 	setup();
     42 
     43 	for (lc = 0; TEST_LOOPING(lc); lc++) {
     44 		tst_count = 0;
     45 
     46 		TEST(getsid(unused_pid));
     47 
     48 		if (TEST_RETURN == 0) {
     49 			tst_resm(TFAIL, "call succeed when failure expected");
     50 			continue;
     51 		}
     52 
     53 		switch (TEST_ERRNO) {
     54 		case ESRCH:
     55 			tst_resm(TPASS, "expected failure - errno = %d - %s",
     56 				 TEST_ERRNO, strerror(TEST_ERRNO));
     57 			break;
     58 		default:
     59 			tst_resm(TFAIL, "call failed to produce "
     60 				 "expected error - errno = %d - %s",
     61 				 TEST_ERRNO, strerror(TEST_ERRNO));
     62 			break;
     63 		}
     64 	}
     65 
     66 	cleanup();
     67 	tst_exit();
     68 }
     69 
     70 void setup(void)
     71 {
     72 	unused_pid = tst_get_unused_pid(cleanup);
     73 
     74 	tst_sig(NOFORK, DEF_HANDLER, cleanup);
     75 
     76 	TEST_PAUSE;
     77 }
     78 
     79 void cleanup(void)
     80 {
     81 }
     82