rump_open_tap.c revision 1.1 1 1.1 roy /* $NetBSD: rump_open_tap.c,v 1.1 2020/09/30 14:43:15 roy Exp $ */
2 1.1 roy
3 1.1 roy /*
4 1.1 roy * Copyright (c) 2020 The NetBSD Foundation, Inc.
5 1.1 roy *
6 1.1 roy * This code is derived from software contributed to The NetBSD Foundation
7 1.1 roy * by Roy Marples.
8 1.1 roy *
9 1.1 roy * Redistribution and use in source and binary forms, with or without
10 1.1 roy * modification, are permitted provided that the following conditions
11 1.1 roy * are met:
12 1.1 roy * 1. Redistributions of source code must retain the above copyright
13 1.1 roy * notice, this list of conditions and the following disclaimer.
14 1.1 roy * 2. Redistributions in binary form must reproduce the above copyright
15 1.1 roy * notice, this list of conditions and the following disclaimer in the
16 1.1 roy * documentation and/or other materials provided with the distribution.
17 1.1 roy *
18 1.1 roy * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 1.1 roy * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 1.1 roy * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 1.1 roy * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 1.1 roy * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 1.1 roy * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 1.1 roy * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 1.1 roy * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 1.1 roy * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 1.1 roy * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 1.1 roy */
29 1.1 roy
30 1.1 roy #include <sys/cdefs.h>
31 1.1 roy __RCSID("$NetBSD: rump_open_tap.c,v 1.1 2020/09/30 14:43:15 roy Exp $");
32 1.1 roy
33 1.1 roy #include <err.h>
34 1.1 roy #include <fcntl.h>
35 1.1 roy #include <stdio.h>
36 1.1 roy #include <stdlib.h>
37 1.1 roy #include <unistd.h>
38 1.1 roy
39 1.1 roy #include <rump/rump_syscalls.h>
40 1.1 roy #include <rump/rumpclient.h>
41 1.1 roy
42 1.1 roy int
43 1.1 roy main(int argc, char **argv)
44 1.1 roy {
45 1.1 roy int fd;
46 1.1 roy
47 1.1 roy if (argc < 2)
48 1.1 roy errx(EXIT_FAILURE, "No path specified");
49 1.1 roy
50 1.1 roy rumpclient_init();
51 1.1 roy
52 1.1 roy fd = rump_sys_open(argv[1], O_RDWR);
53 1.1 roy if (fd == -1)
54 1.1 roy err(EXIT_FAILURE, "open: %s", argv[1]);
55 1.1 roy
56 1.1 roy if (argc > 2) {
57 1.1 roy FILE *fp;
58 1.1 roy pid_t pid;
59 1.1 roy
60 1.1 roy fp = fopen(argv[2], "w");
61 1.1 roy if (fp == NULL)
62 1.1 roy err(EXIT_FAILURE, "fopen: %s", argv[2]);
63 1.1 roy
64 1.1 roy pid = fork();
65 1.1 roy switch (pid) {
66 1.1 roy case -1:
67 1.1 roy err(EXIT_FAILURE, "fork");
68 1.1 roy case 0:
69 1.1 roy break;
70 1.1 roy default:
71 1.1 roy fprintf(fp, "%d\n", pid);
72 1.1 roy exit(EXIT_SUCCESS);
73 1.1 roy }
74 1.1 roy }
75 1.1 roy
76 1.1 roy /* Spin with the fd open */
77 1.1 roy for (;;)
78 1.1 roy sleep(100);
79 1.1 roy }
80