t_nullpts.c revision 1.1
1/* $NetBSD: t_nullpts.c,v 1.1 2010/06/11 23:52:38 pooka Exp $ */ 2 3#include <sys/types.h> 4#include <sys/mount.h> 5#include <sys/ioctl.h> 6 7#include <atf-c.h> 8#include <err.h> 9#include <errno.h> 10#include <fcntl.h> 11#include <stdio.h> 12#include <unistd.h> 13#include <string.h> 14#include <stdlib.h> 15 16#include <rump/rump.h> 17#include <rump/rump_syscalls.h> 18 19#include <fs/ptyfs/ptyfs.h> 20#include <miscfs/nullfs/null.h> 21 22#include "../../h_macros.h" 23 24static void 25mountptyfs(const char *mp, int flags) 26{ 27 struct ptyfs_args args; 28 29 if (rump_sys_mkdir(mp, 0777) == -1) { 30 if (errno != EEXIST) 31 atf_tc_fail_errno("null create %s", mp); 32 } 33 memset(&args, 0, sizeof(args)); 34 args.version = PTYFS_ARGSVERSION; 35 args.mode = 0777; 36 if (rump_sys_mount(MOUNT_PTYFS, mp, flags, &args, sizeof(args)) == -1) 37 atf_tc_fail_errno("could not mount ptyfs"); 38} 39 40static void 41mountnull(const char *what, const char *mp, int flags) 42{ 43 struct null_args nargs; 44 45 if (rump_sys_mkdir(what, 0777) == -1) { 46 if (errno != EEXIST) 47 atf_tc_fail_errno("null create %s", what); 48 } 49 if (rump_sys_mkdir(mp, 0777) == -1) { 50 if (errno != EEXIST) 51 atf_tc_fail_errno("null create %s", mp); 52 } 53 memset(&nargs, 0, sizeof(nargs)); 54 nargs.nulla_target = __UNCONST(what); 55 if (rump_sys_mount(MOUNT_NULL, mp, flags, &nargs, sizeof(nargs)) == -1) 56 atf_tc_fail_errno("could not mount nullfs"); 57} 58 59ATF_TC(nullrevoke); 60ATF_TC_HEAD(nullrevoke, tc) 61{ 62 atf_tc_set_md_var(tc, "descr", "null mount ptyfs and revoke " 63 "(PR kern/43456)"); 64} 65 66ATF_TC_BODY(nullrevoke, tc) 67{ 68 char path[MAXPATHLEN]; 69 struct ptmget ptg; 70 int ptm; 71 72 rump_init(); 73 74 /* 75 * mount /dev/pts 76 */ 77 mountptyfs("/dev/pts", 0); 78 79 /* 80 * null mount /dev to /null/dev 81 */ 82 if (rump_sys_mkdir("/null", 0777) == -1) { 83 if (errno != EEXIST) 84 atf_tc_fail_errno("null create /null"); 85 } 86 mountnull("/dev", "/null/dev", 0); 87 88 /* 89 * get slave/master pair. 90 */ 91 ptm = rump_sys_open("/dev/ptm", O_RDWR); 92 if (rump_sys_ioctl(ptm, TIOCPTMGET, &ptg) == -1) 93 atf_tc_fail_errno("get pty"); 94 95 /* 96 * Build nullfs path to slave. 97 */ 98 strcpy(path, "/null/"); 99 strcat(path, ptg.sn); 100 101 /* 102 * Open slave tty via nullfs. 103 */ 104 if (rump_sys_open(path, O_RDWR) == -1) 105 atf_tc_fail_errno("slave null open"); 106 107 /* 108 * Close slave opened with /dev/ptm. Need purely non-null refs to it. 109 */ 110 rump_sys_close(ptg.sfd); 111 112 /* revoke slave tty. boom */ 113 rump_sys_revoke(path); 114 115 /* done? */ 116} 117 118ATF_TP_ADD_TCS(tp) 119{ 120 121 ATF_TP_ADD_TC(tp, nullrevoke); 122 123 return atf_no_error(); 124} 125