t_tcsetpgrp.c revision 302408
11539Srgrimes/*	$NetBSD: t_tcsetpgrp.c,v 1.3 2012/03/18 07:14:08 jruoho Exp $ */
2156960Sume
3156960Sume/*-
41539Srgrimes * Copyright (c) 2011 The NetBSD Foundation, Inc.
5156960Sume * All rights reserved.
6156960Sume *
71539Srgrimes * This code is derived from software contributed to The NetBSD Foundation
81539Srgrimes * by Jukka Ruohonen.
91539Srgrimes *
101539Srgrimes * Redistribution and use in source and binary forms, with or without
111539Srgrimes * modification, are permitted provided that the following conditions
121539Srgrimes * are met:
131539Srgrimes * 1. Redistributions of source code must retain the above copyright
141539Srgrimes *    notice, this list of conditions and the following disclaimer.
15203965Simp * 2. Redistributions in binary form must reproduce the above copyright
161539Srgrimes *    notice, this list of conditions and the following disclaimer in the
171539Srgrimes *    documentation and/or other materials provided with the distribution.
18156960Sume *
191539Srgrimes * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
201539Srgrimes * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
211539Srgrimes * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
221539Srgrimes * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
231539Srgrimes * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
241539Srgrimes * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
251539Srgrimes * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
261539Srgrimes * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
271539Srgrimes * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
281539Srgrimes * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
291539Srgrimes * POSSIBILITY OF SUCH DAMAGE.
3021056Speter */
3121056Speter#include <sys/cdefs.h>
32156960Sume__RCSID("$NetBSD: t_tcsetpgrp.c,v 1.3 2012/03/18 07:14:08 jruoho Exp $");
3321056Speter
3421056Speter#include <sys/wait.h>
3521056Speter
3621056Speter#include <atf-c.h>
3721056Speter#include <errno.h>
3821056Speter#include <stdlib.h>
3921056Speter#include <unistd.h>
4021056Speter
4121056SpeterATF_TC(tcsetpgrp_err);
4221056SpeterATF_TC_HEAD(tcsetpgrp_err, tc)
4321056Speter{
4421056Speter	atf_tc_set_md_var(tc, "descr", "Test errors from tcsetpgrp(3)"
4521056Speter	    " (PR lib/41673)");
4621056Speter}
4721056Speter
48156960SumeATF_TC_BODY(tcsetpgrp_err, tc)
49156960Sume{
50156960Sume	int rv, sta;
51156960Sume	pid_t pid;
52170244Sume
531539Srgrimes	if (isatty(STDIN_FILENO) == 0)
54269867Sume		return;
5550473Speter
561539Srgrimes	pid = fork();
571539Srgrimes	ATF_REQUIRE(pid >= 0);
582163Spaul
592163Spaul	if (pid == 0) {
601539Srgrimes
61209715Smaxim		/*
621539Srgrimes		 * The child process ID doesn't match any active
631539Srgrimes		 * process group ID, so the following call should
64102227Smike		 * fail with EPERM (and not EINVAL).
651539Srgrimes		 */
6690868Smike		errno = 0;
6790868Smike		rv = tcsetpgrp(STDIN_FILENO, getpid());
6890868Smike
6991984Smike		if (rv == 0 || errno != EPERM)
7091984Smike			_exit(EXIT_FAILURE);
7191984Smike
7293514Smike		_exit(EXIT_SUCCESS);
7393514Smike	}
7493514Smike
7587158Smike	(void)wait(&sta);
7616352Swollman
7793514Smike	if (WIFEXITED(sta) == 0 || WEXITSTATUS(sta) != EXIT_SUCCESS)
7893514Smike		atf_tc_fail("wrong errno");
7993514Smike}
8087158Smike
8187158SmikeATF_TP_ADD_TCS(tp)
82101995Smike{
8393514Smike
8493514Smike	ATF_TP_ADD_TC(tp, tcsetpgrp_err);
8593514Smike
8693514Smike	return atf_no_error();
87101995Smike}
8893514Smike