Merge pull request #16 from Oichkatzelesfrettschen/eirikr/remove-netbsd-files-and-keep-microkernel

This commit is contained in:
Eirikr Hinngart 2025-05-30 11:46:03 -07:00 committed by GitHub
commit 4397727c75
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
50 changed files with 0 additions and 28600 deletions

2320
build.sh

File diff suppressed because it is too large Load Diff

View File

@ -1,91 +0,0 @@
dnl Process this file with autoconf to produce a configure script.
AC_INIT([blacklistd],[0.1],[christos@netbsd.com])
AM_INIT_AUTOMAKE([subdir-objects foreign])
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_MACRO_DIR([m4])
AC_SUBST(WARNINGS)
dnl Checks for programs.
AC_PROG_CC_STDC
AC_USE_SYSTEM_EXTENSIONS
AM_PROG_CC_C_O
AC_C_BIGENDIAN
AC_PROG_INSTALL
AC_PROG_LN_S
LT_INIT([disable-static pic-only])
gl_VISIBILITY
dnl Checks for headers
AC_HEADER_STDC
AC_HEADER_MAJOR
AC_HEADER_SYS_WAIT
AC_CHECK_HEADERS(stdint.h fcntl.h stdint.h inttypes.h unistd.h)
AC_CHECK_HEADERS(sys/un.h sys/socket.h limits.h)
AC_CHECK_HEADERS(arpa/inet.h getopt.h err.h)
AC_CHECK_HEADERS(sys/types.h util.h sys/time.h time.h)
AC_CHECK_HEADERS(netatalk/at.h net/if_dl.h db.h db_185.h)
AC_CHECK_LIB(rt, clock_gettime)
AC_CHECK_LIB(db, __db185_open)
AC_CHECK_LIB(util, pidfile)
AC_CHECK_LIB(util, sockaddr_snprintf)
AH_BOTTOM([
#ifndef __NetBSD__
#include "port.h"
#endif
])
dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
AC_TYPE_OFF_T
AC_TYPE_SIZE_T
AC_SYS_LARGEFILE
AC_CHECK_MEMBERS([struct sockaddr.sa_len], [], [], [#include <sys/socket.h>])
AC_TYPE_PID_T
AC_TYPE_UINT8_T
AC_TYPE_UINT16_T
AC_TYPE_UINT32_T
AC_TYPE_INT32_T
AC_TYPE_UINT64_T
AC_TYPE_INT64_T
AC_TYPE_INTPTR_T
AC_TYPE_UINTPTR_T
AC_MSG_CHECKING(for gcc compiler warnings)
AC_ARG_ENABLE(warnings,
[ --disable-warnings disable compiler warnings],
[if test "${enableval}" = no -o "$GCC" = no; then
AC_MSG_RESULT(no)
WARNINGS=
else
AC_MSG_RESULT(yes)
WARNINGS="-Wall -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith \
-Wmissing-declarations -Wredundant-decls -Wnested-externs \
-Wsign-compare -Wreturn-type -Wswitch -Wshadow \
-Wcast-qual -Wwrite-strings -Wextra -Wunused-parameter -Wformat=2"
fi], [
if test "$GCC" = yes; then
AC_MSG_RESULT(yes)
WARNINGS="-Wall -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith \
-Wmissing-declarations -Wredundant-decls -Wnested-externs \
-Wsign-compare -Wreturn-type -Wswitch -Wshadow \
-Wcast-qual -Wwrite-strings -Wextra -Wunused-parameter -Wformat=2"
else
WARNINGS=
AC_MSG_RESULT(no)
fi])
dnl Checks for functions
AC_CHECK_FUNCS(strerror)
dnl Provide implementation of some required functions if necessary
AC_REPLACE_FUNCS(strtoi sockaddr_snprintf popenve clock_gettime strlcpy strlcat getprogname fparseln fgetln pidfile)
dnl See if we are cross-compiling
AM_CONDITIONAL(IS_CROSS_COMPILE, test "$cross_compiling" = yes)
AC_CONFIG_FILES([Makefile])
AC_OUTPUT

View File

@ -1,576 +0,0 @@
// Copyright 2012 Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of Google Inc. nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "fs.h"
#include <sys/stat.h>
#include <sys/wait.h>
#include <assert.h>
#include <dirent.h>
#include <err.h>
#include <errno.h>
#include <signal.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <atf-c.h>
#include "error.h"
static void run_mount_tmpfs(const char*) KYUA_DEFS_NORETURN;
/// Operating systems recognized by the code below.
enum os_type {
os_unsupported = 0,
os_freebsd,
os_linux,
os_netbsd,
os_sunos,
};
/// The current operating system.
static enum os_type current_os =
#if defined(__FreeBSD__)
os_freebsd
#elif defined(__linux__)
os_linux
#elif defined(__NetBSD__)
os_netbsd
#elif defined(__SunOS__)
os_sunos
#else
os_unsupported
#endif
;
/// Checks if a directory entry exists and matches a specific type.
///
/// \param dir The directory in which to look for the entry.
/// \param name The name of the entry to look up.
/// \param expected_type The expected type of the file as given by dir(5).
///
/// \return True if the entry exists and matches the given type; false
/// otherwise.
static bool
lookup(const char* dir, const char* name, const int expected_type)
{
DIR* dirp = opendir(dir);
ATF_REQUIRE(dirp != NULL);
bool found = false;
struct dirent* dp;
while (!found && (dp = readdir(dirp)) != NULL) {
if (strcmp(dp->d_name, name) == 0 &&
dp->d_type == expected_type) {
found = true;
}
}
closedir(dirp);
return found;
}
/// Executes 'mount -t tmpfs' (or a similar variant).
///
/// This function must be called from a subprocess, as it never returns.
///
/// \param mount_point Location on which to mount a tmpfs.
static void
run_mount_tmpfs(const char* mount_point)
{
const char* mount_args[16];
size_t last = 0;
switch (current_os) {
case os_freebsd:
mount_args[last++] = "mdmfs";
mount_args[last++] = "-s16m";
mount_args[last++] = "md";
mount_args[last++] = mount_point;
break;
case os_linux:
mount_args[last++] = "mount";
mount_args[last++] = "-ttmpfs";
mount_args[last++] = "tmpfs";
mount_args[last++] = mount_point;
break;
case os_netbsd:
mount_args[last++] = "mount";
mount_args[last++] = "-ttmpfs";
mount_args[last++] = "tmpfs";
mount_args[last++] = mount_point;
break;
case os_sunos:
mount_args[last++] = "mount";
mount_args[last++] = "-Ftmpfs";
mount_args[last++] = "tmpfs";
mount_args[last++] = mount_point;
break;
default:
err(123, "Don't know how to mount a file system for testing "
"purposes");
}
mount_args[last] = NULL;
const char** arg;
printf("Mounting tmpfs onto %s with:", mount_point);
for (arg = &mount_args[0]; *arg != NULL; arg++)
printf(" %s", *arg);
printf("\n");
const int ret = execvp(mount_args[0], KYUA_DEFS_UNCONST(mount_args));
assert(ret == -1);
err(EXIT_FAILURE, "Failed to exec %s", mount_args[0]);
};
/// Mounts a temporary file system.
///
/// This is only provided for testing purposes. The mounted file system
/// contains no valuable data.
///
/// Note that the calling test case is skipped if the current operating system
/// is not supported.
///
/// \param mount_point The path on which the file system will be mounted.
static void
mount_tmpfs(const char* mount_point)
{
// SunOS's mount(8) requires paths to be absolute. To err on the side of
// caution, let's make it absolute in all cases.
//const fspath abs_mount_point = mount_point.is_absolute() ?
// mount_point : mount_point.to_absolute();
pid_t pid = fork();
ATF_REQUIRE(pid != -1);
if (pid == 0)
run_mount_tmpfs(mount_point);
int status;
ATF_REQUIRE(waitpid(pid, &status, 0) != -1);
ATF_REQUIRE(WIFEXITED(status));
if (WEXITSTATUS(status) == 123)
atf_tc_skip("Don't know how to mount a file system for testing "
"purposes");
else
ATF_REQUIRE_EQ(EXIT_SUCCESS, WEXITSTATUS(status));
}
static bool
lchmod_fails(void)
{
ATF_REQUIRE(mkdir("test", 0755) != -1);
return lchmod("test", 0700) == -1 && chmod("test", 0700) != -1;
}
ATF_TC_WITHOUT_HEAD(cleanup__file);
ATF_TC_BODY(cleanup__file, tc)
{
atf_utils_create_file("root", "%s", "");
ATF_REQUIRE(lookup(".", "root", DT_REG));
ATF_REQUIRE(!kyua_error_is_set(kyua_fs_cleanup("root")));
ATF_REQUIRE(!lookup(".", "root", DT_REG));
}
ATF_TC_WITHOUT_HEAD(cleanup__subdir__empty);
ATF_TC_BODY(cleanup__subdir__empty, tc)
{
ATF_REQUIRE(mkdir("root", 0755) != -1);
ATF_REQUIRE(lookup(".", "root", DT_DIR));
ATF_REQUIRE(!kyua_error_is_set(kyua_fs_cleanup("root")));
ATF_REQUIRE(!lookup(".", "root", DT_DIR));
}
ATF_TC_WITHOUT_HEAD(cleanup__subdir__files_and_directories);
ATF_TC_BODY(cleanup__subdir__files_and_directories, tc)
{
ATF_REQUIRE(mkdir("root", 0755) != -1);
atf_utils_create_file("root/.hidden_file", "%s", "");
ATF_REQUIRE(mkdir("root/.hidden_dir", 0755) != -1);
atf_utils_create_file("root/.hidden_dir/a", "%s", "");
atf_utils_create_file("root/file", "%s", "");
atf_utils_create_file("root/with spaces", "%s", "");
ATF_REQUIRE(mkdir("root/dir1", 0755) != -1);
ATF_REQUIRE(mkdir("root/dir1/dir2", 0755) != -1);
atf_utils_create_file("root/dir1/dir2/file", "%s", "");
ATF_REQUIRE(mkdir("root/dir1/dir3", 0755) != -1);
ATF_REQUIRE(lookup(".", "root", DT_DIR));
ATF_REQUIRE(!kyua_error_is_set(kyua_fs_cleanup("root")));
ATF_REQUIRE(!lookup(".", "root", DT_DIR));
}
ATF_TC_WITHOUT_HEAD(cleanup__subdir__unprotect_regular);
ATF_TC_BODY(cleanup__subdir__unprotect_regular, tc)
{
ATF_REQUIRE(mkdir("root", 0755) != -1);
ATF_REQUIRE(mkdir("root/dir1", 0755) != -1);
ATF_REQUIRE(mkdir("root/dir1/dir2", 0755) != -1);
atf_utils_create_file("root/dir1/dir2/file", "%s", "");
ATF_REQUIRE(chmod("root/dir1/dir2/file", 0000) != -1);
ATF_REQUIRE(chmod("root/dir1/dir2", 0000) != -1);
ATF_REQUIRE(chmod("root/dir1", 0000) != -1);
ATF_REQUIRE(!kyua_error_is_set(kyua_fs_cleanup("root")));
ATF_REQUIRE(!lookup(".", "root", DT_DIR));
}
ATF_TC(cleanup__subdir__unprotect_symlink);
ATF_TC_HEAD(cleanup__subdir__unprotect_symlink, tc)
{
atf_tc_set_md_var(tc, "require.progs", "/bin/ls");
// We are ensuring that chmod is not run on the target of a symlink, so
// we cannot be root (nor we don't want to, to prevent unprotecting a
// system file!).
atf_tc_set_md_var(tc, "require.user", "unprivileged");
}
ATF_TC_BODY(cleanup__subdir__unprotect_symlink, tc)
{
ATF_REQUIRE(mkdir("root", 0755) != -1);
ATF_REQUIRE(mkdir("root/dir1", 0755) != -1);
ATF_REQUIRE(symlink("/bin/ls", "root/dir1/ls") != -1);
ATF_REQUIRE(chmod("root/dir1", 0555) != -1);
ATF_REQUIRE(!kyua_error_is_set(kyua_fs_cleanup("root")));
ATF_REQUIRE(!lookup(".", "root", DT_DIR));
}
ATF_TC_WITHOUT_HEAD(cleanup__subdir__links);
ATF_TC_BODY(cleanup__subdir__links, tc)
{
ATF_REQUIRE(mkdir("root", 0755) != -1);
ATF_REQUIRE(mkdir("root/dir1", 0755) != -1);
ATF_REQUIRE(symlink("../../root", "root/dir1/loop") != -1);
ATF_REQUIRE(symlink("non-existent", "root/missing") != -1);
ATF_REQUIRE(lookup(".", "root", DT_DIR));
kyua_error_t error = kyua_fs_cleanup("root");
if (kyua_error_is_set(error)) {
if (lchmod_fails())
atf_tc_expect_fail("lchmod(2) is not implemented in your system");
kyua_error_free(error);
atf_tc_fail("kyua_fs_cleanup returned an error");
}
ATF_REQUIRE(!lookup(".", "root", DT_DIR));
}
ATF_TC(cleanup__mount_point__simple);
ATF_TC_HEAD(cleanup__mount_point__simple, tc)
{
atf_tc_set_md_var(tc, "require.user", "root");
}
ATF_TC_BODY(cleanup__mount_point__simple, tc)
{
ATF_REQUIRE(mkdir("root", 0755) != -1);
ATF_REQUIRE(mkdir("root/dir1", 0755) != -1);
atf_utils_create_file("root/zz", "%s", "");
mount_tmpfs("root/dir1");
ATF_REQUIRE(!kyua_error_is_set(kyua_fs_cleanup("root")));
ATF_REQUIRE(!lookup(".", "root", DT_DIR));
}
ATF_TC(cleanup__mount_point__overlayed);
ATF_TC_HEAD(cleanup__mount_point__overlayed, tc)
{
atf_tc_set_md_var(tc, "require.user", "root");
}
ATF_TC_BODY(cleanup__mount_point__overlayed, tc)
{
ATF_REQUIRE(mkdir("root", 0755) != -1);
ATF_REQUIRE(mkdir("root/dir1", 0755) != -1);
atf_utils_create_file("root/zz", "%s", "");
mount_tmpfs("root/dir1");
mount_tmpfs("root/dir1");
ATF_REQUIRE(!kyua_error_is_set(kyua_fs_cleanup("root")));
ATF_REQUIRE(!lookup(".", "root", DT_DIR));
}
ATF_TC(cleanup__mount_point__nested);
ATF_TC_HEAD(cleanup__mount_point__nested, tc)
{
atf_tc_set_md_var(tc, "require.user", "root");
}
ATF_TC_BODY(cleanup__mount_point__nested, tc)
{
ATF_REQUIRE(mkdir("root", 0755) != -1);
ATF_REQUIRE(mkdir("root/dir1", 0755) != -1);
ATF_REQUIRE(mkdir("root/dir1/dir2", 0755) != -1);
ATF_REQUIRE(mkdir("root/dir3", 0755) != -1);
mount_tmpfs("root/dir1/dir2");
mount_tmpfs("root/dir3");
ATF_REQUIRE(mkdir("root/dir1/dir2/dir4", 0755) != -1);
mount_tmpfs("root/dir1/dir2/dir4");
ATF_REQUIRE(mkdir("root/dir1/dir2/not-mount-point", 0755) != -1);
ATF_REQUIRE(!kyua_error_is_set(kyua_fs_cleanup("root")));
ATF_REQUIRE(!lookup(".", "root", DT_DIR));
}
ATF_TC(cleanup__mount_point__links);
ATF_TC_HEAD(cleanup__mount_point__links, tc)
{
atf_tc_set_md_var(tc, "require.user", "root");
}
ATF_TC_BODY(cleanup__mount_point__links, tc)
{
ATF_REQUIRE(mkdir("root", 0755) != -1);
ATF_REQUIRE(mkdir("root/dir1", 0755) != -1);
ATF_REQUIRE(mkdir("root/dir3", 0755) != -1);
mount_tmpfs("root/dir1");
ATF_REQUIRE(symlink("../dir3", "root/dir1/link") != -1);
ATF_REQUIRE(!kyua_error_is_set(kyua_fs_cleanup("root")));
ATF_REQUIRE(!lookup(".", "root", DT_DIR));
}
ATF_TC(cleanup__mount_point__busy);
ATF_TC_HEAD(cleanup__mount_point__busy, tc)
{
atf_tc_set_md_var(tc, "require.user", "root");
}
ATF_TC_BODY(cleanup__mount_point__busy, tc)
{
ATF_REQUIRE(mkdir("root", 0755) != -1);
ATF_REQUIRE(mkdir("root/dir1", 0755) != -1);
mount_tmpfs("root/dir1");
pid_t pid = fork();
ATF_REQUIRE(pid != -1);
if (pid == 0) {
if (chdir("root/dir1") == -1)
abort();
atf_utils_create_file("dont-delete-me", "%s", "");
atf_utils_create_file("../../done", "%s", "");
pause();
exit(EXIT_SUCCESS);
} else {
fprintf(stderr, "Waiting for child to finish preparations\n");
while (!atf_utils_file_exists("done")) {}
fprintf(stderr, "Child done; cleaning up\n");
ATF_REQUIRE(kyua_error_is_set(kyua_fs_cleanup("root")));
ATF_REQUIRE(atf_utils_file_exists("root/dir1/dont-delete-me"));
fprintf(stderr, "Killing child\n");
ATF_REQUIRE(kill(pid, SIGKILL) != -1);
int status;
ATF_REQUIRE(waitpid(pid, &status, 0) != -1);
ATF_REQUIRE(!kyua_error_is_set(kyua_fs_cleanup("root")));
ATF_REQUIRE(!lookup(".", "root", DT_DIR));
}
}
ATF_TC_WITHOUT_HEAD(concat__one);
ATF_TC_BODY(concat__one, tc)
{
char* path;
ATF_REQUIRE(!kyua_error_is_set(kyua_fs_concat(&path, "foo", NULL)));
ATF_REQUIRE_STREQ("foo", path);
free(path);
}
ATF_TC_WITHOUT_HEAD(concat__two);
ATF_TC_BODY(concat__two, tc)
{
char* path;
ATF_REQUIRE(!kyua_error_is_set(kyua_fs_concat(&path, "foo", "bar", NULL)));
ATF_REQUIRE_STREQ("foo/bar", path);
free(path);
}
ATF_TC_WITHOUT_HEAD(concat__several);
ATF_TC_BODY(concat__several, tc)
{
char* path;
ATF_REQUIRE(!kyua_error_is_set(kyua_fs_concat(&path, "/usr", ".", "bin",
"ls", NULL)));
ATF_REQUIRE_STREQ("/usr/./bin/ls", path);
free(path);
}
ATF_TC_WITHOUT_HEAD(current_path__ok);
ATF_TC_BODY(current_path__ok, tc)
{
char* previous;
ATF_REQUIRE(!kyua_error_is_set(kyua_fs_current_path(&previous)));
ATF_REQUIRE(mkdir("root", 0755) != -1);
ATF_REQUIRE(chdir("root") != -1);
char* cwd;
ATF_REQUIRE(!kyua_error_is_set(kyua_fs_current_path(&cwd)));
char* exp_cwd;
ATF_REQUIRE(!kyua_error_is_set(kyua_fs_concat(&exp_cwd, previous, "root",
NULL)));
ATF_REQUIRE_STREQ(exp_cwd, cwd);
free(exp_cwd);
free(cwd);
free(previous);
}
ATF_TC_WITHOUT_HEAD(current_path__enoent);
ATF_TC_BODY(current_path__enoent, tc)
{
char* previous;
ATF_REQUIRE(!kyua_error_is_set(kyua_fs_current_path(&previous)));
ATF_REQUIRE(mkdir("root", 0755) != -1);
ATF_REQUIRE(chdir("root") != -1);
ATF_REQUIRE(rmdir("../root") != -1);
char* cwd = (char*)0xdeadbeef;
kyua_error_t error = kyua_fs_current_path(&cwd);
ATF_REQUIRE(kyua_error_is_set(error));
ATF_REQUIRE(kyua_error_is_type(error, "libc"));
ATF_REQUIRE_EQ(ENOENT, kyua_libc_error_errno(error));
ATF_REQUIRE_EQ((char*)0xdeadbeef, cwd);
kyua_error_free(error);
free(previous);
}
ATF_TC_WITHOUT_HEAD(make_absolute__absolute);
ATF_TC_BODY(make_absolute__absolute, tc)
{
char* absolute;
ATF_REQUIRE(!kyua_error_is_set(kyua_fs_make_absolute(
"/this/is/absolute", &absolute)));
ATF_REQUIRE_STREQ("/this/is/absolute", absolute);
free(absolute);
}
ATF_TC_WITHOUT_HEAD(make_absolute__relative);
ATF_TC_BODY(make_absolute__relative, tc)
{
kyua_error_t error;
char* absolute;
DIR* previous = opendir(".");
ATF_REQUIRE(previous != NULL);
ATF_REQUIRE(chdir("/usr") != -1);
error = kyua_fs_make_absolute("bin/foobar", &absolute);
const int previous_fd = dirfd(previous);
ATF_REQUIRE(fchdir(previous_fd) != -1);
close(previous_fd);
ATF_REQUIRE(!kyua_error_is_set(error));
ATF_REQUIRE_STREQ("/usr/bin/foobar", absolute);
free(absolute);
}
ATF_TC(unmount__ok);
ATF_TC_HEAD(unmount__ok, tc)
{
atf_tc_set_md_var(tc, "require.user", "root");
}
ATF_TC_BODY(unmount__ok, tc)
{
ATF_REQUIRE(mkdir("mount_point", 0755) != -1);
atf_utils_create_file("mount_point/test1", "%s", "");
mount_tmpfs("mount_point");
atf_utils_create_file("mount_point/test2", "%s", "");
ATF_REQUIRE(!atf_utils_file_exists("mount_point/test1"));
ATF_REQUIRE( atf_utils_file_exists("mount_point/test2"));
kyua_fs_unmount("mount_point");
ATF_REQUIRE( atf_utils_file_exists("mount_point/test1"));
ATF_REQUIRE(!atf_utils_file_exists("mount_point/test2"));
}
ATF_TC(unmount__fail);
ATF_TC_HEAD(unmount__fail, tc)
{
atf_tc_set_md_var(tc, "require.user", "root");
}
ATF_TC_BODY(unmount__fail, tc)
{
kyua_error_t error = kyua_fs_unmount("mount_point");
ATF_REQUIRE(kyua_error_is_set(error));
kyua_error_free(error);
}
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, cleanup__file);
ATF_TP_ADD_TC(tp, cleanup__subdir__empty);
ATF_TP_ADD_TC(tp, cleanup__subdir__files_and_directories);
ATF_TP_ADD_TC(tp, cleanup__subdir__unprotect_regular);
ATF_TP_ADD_TC(tp, cleanup__subdir__unprotect_symlink);
ATF_TP_ADD_TC(tp, cleanup__subdir__links);
ATF_TP_ADD_TC(tp, cleanup__mount_point__simple);
ATF_TP_ADD_TC(tp, cleanup__mount_point__overlayed);
ATF_TP_ADD_TC(tp, cleanup__mount_point__nested);
ATF_TP_ADD_TC(tp, cleanup__mount_point__links);
ATF_TP_ADD_TC(tp, cleanup__mount_point__busy);
ATF_TP_ADD_TC(tp, concat__one);
ATF_TP_ADD_TC(tp, concat__two);
ATF_TP_ADD_TC(tp, concat__several);
ATF_TP_ADD_TC(tp, current_path__ok);
ATF_TP_ADD_TC(tp, current_path__enoent);
ATF_TP_ADD_TC(tp, make_absolute__absolute);
ATF_TP_ADD_TC(tp, make_absolute__relative);
ATF_TP_ADD_TC(tp, unmount__ok);
ATF_TP_ADD_TC(tp, unmount__fail);
return atf_no_error();
}

View File

@ -1,121 +0,0 @@
#!/bin/sh
#
# $NetBSD: less2netbsd,v 1.5 2011/07/03 23:25:01 tron Exp $
#
# Copyright (c) 2011 The NetBSD Foundation, Inc.
# All rights reserved.
#
# This code is derived from software contributed to The NetBSD Foundation
# by Matthias Scheler.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# less2netbsd:
# Prepare a less source tree for import into the NetBSD source repository.
PROGNAME=$(basename "$0")
if [ $# -ne 1 ]
then
echo "Usage: $PROGNAME <dir>" >&2
exit 1
fi
DIRNAME="$1"
# Change to the source directory.
if [ -d "$DIRNAME" ] && cd "$DIRNAME"
then
:
else
echo "${PROGNAME}: cannot access directory \"$DIRNAME\"." >&2
exit
fi
# Check whether the source directory looks sane.
CHECK_FILES="LICENSE configure less.h version.c"
for FILENAME in $CHECK_FILES
do
if [ ! -f "$FILENAME" ]
then
echo "${PROGNAME}: less distribution incomplete." >&2
exit
fi
done
# Check whether the "configure" was run.
REQUIRED_HEADERS=defines.h
for FILENAME in $REQUIRED_HEADERS
do
if [ ! -f "$FILENAME" ]
then
echo "${PROGNAME}: Please run \"./configure\"." >&2
exit
fi
done
# Fix the permissions.
find . -type d -print0 | xargs -0 chmod 755
find . -type f -print0 | xargs -0 chmod 644
chmod 755 configure
# Remove files generated by "configure".
REMOVE_FILES="Makefile config.log config.status configure.lineno"
rm -f $REMOVE_FILES
# Add NetBSD RCS Ids.
find . -type f -name "*.[ch]" -print |
while read FILENAME
do
if ! grep -q '\$NetBSD' "$FILENAME"
then
NEW_FILENAME="${FILENAME}.new"
rm -f "${NEW_FILENAME}"
(echo "/* \$NetBSD\$ */"
echo ""
cat "$FILENAME") >"${NEW_FILENAME}"
mv -f "${NEW_FILENAME}" "$FILENAME"
fi
done
# Remove formatted manual pages.
find . -type f -name "*.man" -delete
# Rename unformatted manual pages.
find . -type f -name "*.nro" -print |
while read FILENAME
do
mv "$FILENAME" "${FILENAME%.nro}.1"
done
# Determine the version number.
VERSION=$(sed -n -e 's#char version\[\] = "\(.*\)";#\1#p' version.c)
# Print out information for the import.
cat <<EOF
You can import now.
Path: src/external/bsd/less/dist
Vendortag: GREENWOODSOFTWARE
Releasetag: LESS-$VERSION
EOF
exit 0

View File

@ -1,131 +0,0 @@
/* $NetBSD: paths.h,v 1.42 2015/05/06 23:06:26 pgoyette Exp $ */
/*
* Copyright (c) 1989, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)paths.h 8.1 (Berkeley) 6/2/93
*/
#ifndef _PATHS_H_
#define _PATHS_H_
/*
* Default user search path.
* Set by login(1), rshd(8), rexecd(8)
* Used by execvp(3) absent PATH from the environ(7)
*/
#ifdef RESCUEDIR
#define _PATH_DEFPATH RESCUEDIR ":/usr/bin:/bin:/usr/pkg/bin:/usr/local/bin"
#else
#define _PATH_DEFPATH "/usr/bin:/bin:/usr/pkg/bin:/usr/local/bin"
#endif
/*
* All standard utilities path.
* Set by init(8) for system programs & scripts (e.g. /etc/rc)
* Used by ttyaction(3), whereis(1)
*/
#define _PATH_STDPATH \
"/usr/bin:/bin:/usr/sbin:/sbin:/usr/pkg/bin:/usr/pkg/sbin:/usr/local/bin:/usr/local/sbin"
#define _PATH_AUDIO "/dev/audio"
#define _PATH_AUDIO0 "/dev/audio0"
#define _PATH_AUDIOCTL "/dev/audioctl"
#define _PATH_AUDIOCTL0 "/dev/audioctl0"
#define _PATH_BPF "/dev/bpf"
#define _PATH_CLOCKCTL "/dev/clockctl"
#define _PATH_CONSOLE "/dev/console"
#define _PATH_CONSTTY "/dev/constty"
#define _PATH_CPUCTL "/dev/cpuctl"
#define _PATH_CSMAPPER "/usr/share/i18n/csmapper"
#define _PATH_DEFTAPE "/dev/nrst0"
#define _PATH_DEVCDB "/var/run/dev.cdb"
#define _PATH_DEVDB "/var/run/dev.db"
#define _PATH_DEVNULL "/dev/null"
#define _PATH_DRUM "/dev/drum"
#define _PATH_ESDB "/usr/share/i18n/esdb"
#define _PATH_FTPUSERS "/etc/ftpusers"
#define _PATH_GETTYTAB "/etc/gettytab"
#define _PATH_I18NMODULE "/usr/lib/i18n"
#define _PATH_ICONV "/usr/share/i18n/iconv"
#define _PATH_KMEM "/dev/kmem"
#define _PATH_KSYMS "/dev/ksyms"
#define _PATH_KVMDB "/var/db/kvm.db"
#define _PATH_LOCALE "/usr/share/locale"
#define _PATH_MAILDIR "/var/mail"
#define _PATH_MAN "/usr/share/man"
#define _PATH_MEM "/dev/mem"
#define _PATH_MIXER "/dev/mixer"
#define _PATH_MIXER0 "/dev/mixer0"
#define _PATH_NOLOGIN "/etc/nologin"
#define _PATH_POWER "/dev/power"
#define _PATH_PRINTCAP "/etc/printcap"
#define _PATH_PUD "/dev/pud"
#define _PATH_PUFFS "/dev/puffs"
#define _PATH_RANDOM "/dev/random"
#define _PATH_SENDMAIL "/usr/sbin/sendmail"
#define _PATH_SHELLS "/etc/shells"
#define _PATH_SKEYKEYS "/etc/skeykeys"
#define _PATH_SOUND "/dev/sound"
#define _PATH_SOUND0 "/dev/sound0"
#define _PATH_SYSMON "/dev/sysmon"
#define _PATH_TTY "/dev/tty"
#define _PATH_UNIX "/netbsd"
#define _PATH_URANDOM "/dev/urandom"
#define _PATH_VIDEO "/dev/video"
#define _PATH_VIDEO0 "/dev/video0"
#define _PATH_WATCHDOG "/dev/watchdog"
/*
* Provide trailing slash, since mostly used for building pathnames.
* See the __CONCAT() macro from <sys/cdefs.h> for cpp examples.
*/
#define _PATH_DEV "/dev/"
#define _PATH_DEV_PTS "/dev/pts/"
#define _PATH_EMUL_AOUT "/emul/aout/"
#define _PATH_TMP "/tmp/"
#define _PATH_VARDB "/var/db/"
#define _PATH_VARRUN "/var/run/"
#define _PATH_VARTMP "/var/tmp/"
/*
* Paths that may change if RESCUEDIR is defined.
* Used by tools in /rescue.
*/
#ifdef RESCUEDIR
#define _PATH_BSHELL RESCUEDIR "/sh"
#define _PATH_CSHELL RESCUEDIR "/csh"
#define _PATH_VI RESCUEDIR "/vi"
#else
#define _PATH_BSHELL "/bin/sh"
#define _PATH_CSHELL "/bin/csh"
#define _PATH_VI "/usr/bin/vi"
#endif
#endif /* !_PATHS_H_ */

View File

@ -1,275 +0,0 @@
$eterna: CHANGES,v 1.78 2011/11/18 01:25:11 mrg Exp $
changes in bozohttpd 20150320:
o fix redirection handling
o support transport stream (.ts) and video object (.vob) files
o directory listings show correct file sizes for large files
changes in bozohttpd 20140717:
o properly handle SSL errors
changes in bozohttpd 20140708:
o fixes for virtual host support, from rajeev_v_pillai@yahoo.com
o avoid printing double errors, from shm@netbsd.org
o fix a security issue in basic HTTP authentication which would allow
authentication to be bypassed, from shm@netbsd.org
changes in bozohttpd 20140201:
o support .svg files
o fix a core dump when requests timeout
changes in bozohttpd 20140102:
o update a few content types
o add support for directly calling lua scripts to handle
processes, from mbalmer@netbsd.org
o properly escape generated HTML
o add authentication for redirections, from martin@netbsd.org
o handle chained ssl certifications, from elric@netbsd.org
o add basic support for gzipped files, from elric@netbsd.org
o properly escape generated URIs
changes in bozohttpd 20111118:
o add -P <pidfile> option, from jmmv@netbsd.org
o avoid crashes with http basic auth, from pooka@netbsd.org
o add support for REDIRECT_STATUS variable, from tls@netbsd.org
o support .mp4 files in the default map
o directory indexes with files with : are now displayed properly, from
reed@netbsd.org
o allow -I option to be useful in non-inetd mode as well
changes in bozohttpd 20100920:
o properly fully disable multi-file mode for now
o fix the -t and -U options when used without the -e option, broken since
the library-ifcation
o be explicit that logs go to the FTP facility in syslog
o use scandir() with alphasort() for sorted directory lists, from moof
o fix a serious error in vhost handling; "Host:.." would allow access to
the next level directory from the virtual root directory, from seanb
o fix some various non standard compile time errors, from rudolf
o fix dynamic CGI content maps, from rudolf
changes in bozohttpd 20100617:
o fix some compile issues
o fix SSL mode. from rtr
o fix some cgi-bin issues, as seen with cvsweb
o disable multi-file daemon mode for now, it breaks
o return 404's instead of 403's when chdir of ~user dirs fail
o remove "noreturn" attribute from bozo_http_error() that was
causing incorrect runtime behaviour
changes in bozohttpd 20100509:
o major rework and clean up of internal interfaces. move the main
program into main.c, the remaining parts are useable as library.
add bindings for lua. by Alistair G. Crooks <agc@netbsd.org>
o fix http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=566325
changes in bozohttpd 20090522:
o avoid dying in daemon mode for some uncommon, but recoverable, errors
o close leaking file descriptors for CGI and daemon mode
o handle poll errors properly
o don't try to handle more than one request per process yet
o add subdirs for build "debug" and "small" versions
o clean up a bad merge / duplicate code
o make mmap() usage portable, fixes linux & ranges: support
o document the -f option
o daemon mode now serves 6 files per child
changes in bozohttpd 20090417:
o make bozohttpd internally more modular, preparing the way
to handle more than one request per process
o fix http-auth, set $REMOTE_USER not $REMOTEUSER. also fix
cgi-bin with cvsweb, from Holger Weiss <holger@CIS.FU-Berlin.DE>
o fix an uninitialised variable use in daemon mode
o fix ssl mode with newer OpenSSL
o mmap large files in manageable sizes so we can serve any size file
o refactor url processing to handle query strings correctly for CGI
from Sergey Katsev at Coyote Point
o add If-Modified-Since support, from Joerg Sonnenberger
<joerg@netbsd.org>
o many more manual fixes, from NetBSD
changes in bozohttpd 20080303:
o fix some cgi header processing, from <thelsdj@gmail.com>
o add simple Range: header processing, from <bad@bsd.de>
o man page fixes, from NetBSD
o clean up various parts, from NetBSD
changes in bozohttpd 20060710:
o prefix some function names with "bozo"
o align directory indexing <hr> markers
o clean up some code GCC4 grumbled about
changes in bozohttpd 20060517:
o don't allow "/.." or "../" files
o don't write ":80" into urls for the http port
o fix a fd leak when fork() fails
o make directory indexing mode not look so ugly
o build a text version of the manual page
o make "make clean" work properly
changes in bozohttpd 20050410:
o fix some off-by-one errors from <roland.illig@gmx.de>
o properly support nph- CGI
o make content maps case insensitive
o fix proto header merging to include the missing comma
o major source reorganisation; most features are in separate files now
o new -V flag that makes unknown virtualhosts use slashdir
from <rumble@ephemeral.org>
o HTTP/1.x protocol headers are now properly merged for CGI
changes in bozohttpd 20040808:
o CGI status is now properly handled (-a flag has been removed)
o CGI file upload support works
o %xy translations are no longer ever applied after the first '?',
ala RFC2396. from lukem
o daemon mode (-b) should no longer hang spinning forever if it
sees no children. from lukem
o new .bzabsredirect file support. from <martin@netbsd.org>
o return a 404 error if we see %00 or %2f (/)
o don't print 2 "200" headers for CGI
o support .torrent files
changes in bozohttpd 20040218:
o new .bzredirect file support for sane directory redirection
o new -Z option that enables SSL mode, from <rtr@eterna.com.au>
o the -C option has been changed to take two explicit options, rather
than a single option with a space separating the suffix and the
interpreter. ``-C ".foo /path/to/bar"'' should now be written
as ``-C .foo /path/to/bar''
o the -M option has been changed like -C and no longer requires or
supports a single argument with space-separated options
o with -a, still print the 200 OK. from <rtr@eterna.com.au>
o with -r, if a .bzdirect file appears in a directory, allow direct
access to this directory
changes in bozohttpd 20031005:
o fixes for basic authorisation. from <ecu@ipv42.net>
o always display file size in directory index mode
o add .xbel, .xml & .xsl -> text/xml mappings. from
<wiz@danbala.ifoer.tuwien.ac.at>
changes in bozohttpd 20030626:
o fix a recent core dump when given no input
o add new -r flag that ensures referrer is set to this host
o fix several compile time errors with -DNO_CGIBIN_SUPPORT
o fix some man page details. from lukem@wasabisystems.com
o re-add a missing memset(), fixing a core dump. from lukem
o support HTTP basic authorisation, disabled by default. from lukem
o print the port number in redirects and errors. from lukem
o only syslog the basename of the program. from lukem
o add __attribute__() format checking. from lukem
o fix cgibin SCRIPT_NAME to have a leading /. from zakj@nox.cx
o simplify some code in -C to avoid a core dump. from lukem
o add a .css -> css/text entry to the content_map[]. from zakj@nox.cx
changes in bozohttpd 20030409:
o -d without DEBUG enabled only prints one warning and continues
o one can now define the C macro SERVER_SOFTWARE when building to
change the Server: header and CGI variable of the same name
o add new -s flag the force logging output to stderr. from zakj@nox.cx
o add new -a flag for CGI bin that stops bozohttpd from outputting
any HTTP reply, the CGI program must output these. from zakj@nox.cx
o new REQUEST_URI and DATE_GMT environment variables for CGI. from
zakj@nox.cx
o add a "Makefile.boot" that should work with any make program
o build on linux again
o fix core dumps when using -C
changes in bozohttpd 20030313:
o deprecate -r flag; make this the default and silently ignore -r now
o add support for file extentions to call CGI programs (from lukem)
o add dynamic support to add new content map entries, allowing both
new file types and non /cgi-bin CGI programs to be run with the
new -C "suffix cgihandler" and -M "suffix type encoding encoding11"
options
o in -b mode, set the http date after accept() returns, not before we
call accept()
o in -b mode, bind all addresses found not just the first one
o unsupport old hostname API
o in -b mode, set the SO_REUSEADDR socket option (lukem)
o allow -x (index.html) mode to work with CGI handlers
changes in bozohttpd 20021106:
o add .bz2 support
o properly escape <, > and & in error messages, partly from
Nicolas Jombart <ecu@mariejeanne.net>
o new -H flag to hide .* files in directory index mode
o fix buffer reallocation when parsing a request, to avoid
overflowing the buffer with carriage returns (\r)
o do not decode "%XY"-style cgi-bin data beyond the "?"
changes in bozohttpd 5.15 (20020913):
o add .ogg support -> `application/x-ogg'
o fix CGI requests with "/" in the query part
changes in bozohttpd 5.14 (20020823):
o allow -X mode to work for "/"
o work on systems without MADV_SEQUENTIAL
o make a local cut-down copy of "queue.h" (fixes linux & solaris
support at the very least)
o portability fixes for pre-ipv6 socket api systems (eg, solaris 7)
o portability fixes for missing _PATH_DEFPATH, LOG_FTP and __progname
o better documentation on virtual host support
changes in bozohttpd 5.13 (20020804):
o support .mp3 files (type audio/mpeg)
o use stat() to find out if something is a directory, for -X mode
changes in bozohttpd 5.12 (20020803):
o constification
o fixes & enhancements for directory index mode (-X)
changes in bozohttpd 5.11 (20020730):
o more man page fixes from Thomas Klausner
<wiz@danbala.ifoer.tuwien.ac.at>
o de-K&R C-ification
o fix Date: header for daemon mode
o fix core dump when asking for /cgi-bin/ when CGI isn't configured
o use a valid Server: header
changes in bozohttpd 5.10 (20020710):
- add freebsd support
- fix a couple of header typos
- many cgi-bin fixes from lukem@netbsd.org
- add -T chrootdir and -U user, plus several minor other cleanups
with signals and return values. from xs@kittenz.org
- add -e that does not clear the environment for -T/-U
- fix a formatting error noticed by ISIHARA Takanori <ishit@oak.dti.ne.jp>
changes in bozohttpd 5.09 (20010922):
- add a daemon mode
- document how to use bozohttpd in netbsd inetd with more than 40
connections per minute and also with cgibin
- man page fixes from wiz@netbsd.org
changes in bozohttpd 5.08 (20010812):
- add directory index generation support (-X) from ad@netbsd.org
- add .pa as an alias for .pac
- make server software version configurable (RFC)
changes in bozohttpd 5.07 (20010610):
- add .png support
- new "-x index.html" flag to change default file
- new "-p public_html" flag to change default ~user directory
- fixes cgi-bin support and more from chuck@research.att.com
- add many new content-types, now support most common ones
changes in bozohttpd 5.06 (20000825):
- add IPv6 suppor from itojun@iijlab.net
- man page fixes from jlam@netbsd.org
changes in bozohttpd 5.05 (20000815):
- fix a virtual host bug, from kleink@netbsd.org
changes in bozohttpd 5.04 (20000427):
- fix virtual host support; URI takes precedence over Host:
changes in bozohttpd 5.03 (20000427):
- fix a bug with chdir()
changes in bozohttpd 5.02 (20000426):
- .pac spport from simonb
changes in bozohttpd 5.01 (20000421):
- .swf support
- virtual hosting support

View File

@ -1,116 +0,0 @@
# $NetBSD: Makefile,v 1.24 2015/08/05 06:50:44 mrg Exp $
#
# $eterna: Makefile,v 1.30 2010/07/11 00:34:27 mrg Exp $
#
# berkeley (netbsd) makefile. see Makefile.boot for other systems.
# compile-time options are:
# NO_DEBUG /* don't include debugging support */
# NO_USER_SUPPORT /* don't support /~user requests */
# NO_CGIBIN_SUPPORT /* don't support cgi-bin requests */
# NO_DIRINDEX_SUPPORT /* don't support directory indexing */
# NO_DAEMON_MODE /* don't support daemon mode */
# NO_DYNAMIC_CONTENT /* don't support dynamic content updates */
# NO_SSL_SUPPORT /* don't support ssl (https) */
# DO_HTPASSWD /* support .htpasswd files */
# NO_LUA_SUPPORT /* don't support Lua for dynamic content */
#
# other system specific defines:
# HAVE_NBUTIL_H /* netbsd compat is in <nbutil.h>
# (don't forget to also enable -lnbutil)
#
# these are usually set via the "COPTS" variable, or some other method
# for setting CFLAGS relevant to your make, eg
# % make COPTS="-DDO_HTPASSWD"
COPTS+= -DDO_HTPASSWD
PROG= bozohttpd
LINKS= ${BINDIR}/bozohttpd ${BINDIR}/httpd
MAN= bozohttpd.8
MLINKS+=bozohttpd.8 httpd.8
SRCS= bozohttpd.c ssl-bozo.c auth-bozo.c cgi-bozo.c daemon-bozo.c \
tilde-luzah-bozo.c dir-index-bozo.c content-bozo.c lua-bozo.c
SRCS+= main.c
LDADD= -lcrypt -llua -lm
DPADD= ${LIBCRYPT} ${LIBLUA} ${LIBM}
WARNS?= 4
.if defined(.OS.MAKE)
OPSYS= ${.OS.MAKE}
.else
OPSYS:= ${:!uname -s!:S/-//g:S/\///g}
.endif
.if ${OPSYS} == "QNX"
CPPFLAGS+= -DHAVE_NBUTIL_H
LDADD+= -lnbutil
.endif
.include <bsd.own.mk>
.if defined(__MINIX)
.if !empty(DBG:M-Og) || !empty(CFLAGS:M-Og) || \
!empty(DBG:M-g) || !empty(CFLAGS:M-g)
#LSC: -Wno-maybe-uninitialized while compiling with -DNDEBUG -Og
CWARNFLAGS.gcc+= -Wno-maybe-uninitialized
.endif
.endif # defined(__MINIX)
.if ${MKCRYPTO} != "no"
LDADD+= -lssl -lcrypto
DPADD+= ${LIBSSL} ${LIBCRYPTO}
.else
COPTS+= -DNO_SSL_SUPPORT
.endif
#
# Build release things.
#
NROFF?= nroff
PREHTMLFROB= sed \
-e 's/&/\&amp;/' \
-e 's/</\&lt;/' \
-e 's/>/\&gt;/'
HTMLFROB= sed \
-e 's/\([MC] "[^"]*\)<dd>$$/\1<b>"<\/b><dd>/' \
-e 's/'"''"'/\&rdquo;/' \
-e 's/""/\&ldquo;/' \
-e 's/<a href="\.\.\/html[^>]*>\(.*\)<\/a>/\1/'
TXTFROB= col -b
bozohttpd.8.html: bozohttpd.8
$(PREHTMLFROB) $> | $(NROFF) -mdoc2html | $(HTMLFROB) > $@
bozohttpd.8.txt: bozohttpd.8
$(NROFF) -mdoc -Tascii $> | $(TXTFROB) > $@
CLEANFILES+= bozohttpd.8.html bozohttpd.8.txt
# Create a distfile: uses /tmp
BASE=bozohttpd-${BOZOVER}
TAR=${BASE}.tar
export-distfile:
dir=`mktemp -d /tmp/bozo-export-XXXXXX`; \
cd "$${dir}" || exit; \
mkdir ${BASE}; \
( cd ${BASE} || exit; \
cp -r "${.CURDIR}/." "."; \
find . -name .CVS | xargs rm -r; \
); \
pax -wf ${TAR} ${BASE}; \
gzip -nc9 ${TAR} > ${TAR}.gz; \
bzip2 -9 ${TAR}; \
echo "Exported two files in $${dir}:"; \
echo ${TAR}.gz; \
echo ${TAR}.bz2
.include <bsd.prog.mk>

View File

@ -1,683 +0,0 @@
.\" $NetBSD: bozohttpd.8,v 1.53 2015/08/13 12:30:08 wiz Exp $
.\"
.\" $eterna: bozohttpd.8,v 1.101 2011/11/18 01:25:11 mrg Exp $
.\"
.\" Copyright (c) 1997-2015 Matthew R. Green
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
.\" BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
.\" AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
.\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.Dd May 1, 2015
.Dt BOZOHTTPD 8
.Os
.Sh NAME
.Nm bozohttpd
.Nd hyper text transfer protocol version 1.1 daemon
.Sh SYNOPSIS
.Nm
.Op Fl CIMPSZciptvx
.Op Fl C Ar suffix cgihandler
.Op Fl I Ar port
.Op Fl L Ar prefix script
.Op Fl M Ar suffix type encoding encoding11
.Op Fl P Ar pidfile
.Op Fl S Ar server_software
.Op Fl Z Ar cert privkey
.Op Fl c Ar cgibin
.Op Fl i Ar address
.Op Fl p Ar pubdir
.Op Fl t Ar chrootdir
.Op Fl v Ar virtualroot
.Op Fl x Ar index
.Ar slashdir
.Op Ar myname
.Sh DESCRIPTION
The
.Nm
program reads a
.Em HTTP
request from the standard input, and sends a reply to the standard output.
Besides ~user translation and virtual hosting support (see below), all file
requests are from
.Ar slashdir
directory.
The server uses
.Ar myname
as its name, which defaults to the local hostname, obtained from
.Xr gethostname 3
(but see the
.Fl v
option for virtual hosting.)
.Nm
writes logs to
.Xr syslog 3
using the ftp facility (but see the
.Fl s
option for testing.)
.Nm
is designed to be small, simple and relatively featureless,
hopefully increasing its security.
.Ss OPTIONS
The following options are available:
.Bl -tag -width xxxcgibin
.It Fl b
Enables daemon mode, where
.Nm
detaches from the current terminal, running in the background and
servicing HTTP requests.
.It Fl C Ar suffix cgihandler
Adds a new CGI handler program for a particular file type.
The
.Ar suffix
should be any normal file suffix, and the
.Ar cgihandler
should be a full path to an interpreter.
This option is the only way to enable CGI programs that exist
outside of the cgibin directory to be executed.
Multiple
.Fl C
options may be passed.
.It Fl c Ar cgibin
Enables the CGI/1.1 interface.
The
.Ar cgibin
directory is expected to contain the CGI programs to be used.
.Nm
looks for URL's in the form of
.Em /cgi-bin/\*[Lt]scriptname\*[Gt]
where
.Aq scriptname
is a valid CGI program in the
.Ar cgibin
directory.
In other words, all CGI URL's must begin with
.Em \%/cgi-bin/ .
Note that the CGI/1.1 interface is not available with
.Em ~user
translation.
.It Fl e
Causes
.Nm
to not clear the environment when used with either the
.Fl t
or
.Fl U
options.
.It Fl f
Stops the
.Fl b
flag from
.Nm
detaching from the tty and going into the background.
.It Fl H
Causes directory index mode to hide files and directories
that start with a period, except for
.Pa .. .
Also see
.Fl X .
.It Fl I Ar port
Causes
.Nm
to use
.Ar port
instead of the default
.Dq http
port.
When used with the
.Fl b
option, it changes the bound port.
Otherwise it forces redirections to use this port instead of the
value obtained via
.Xr getsockname 2 .
.It Fl i Ar address
Causes
.Ar address
to be used as the address to bind daemon mode.
If otherwise unspecified, the address used to bind is derived from the
.Ar myname ,
which defaults to the name returned by
.Xr gethostname 3 .
Only the last
.Fl i
option is used.
This option is only valid with the
.Fl b
option.
.It Fl L Ar prefix script
Adds a new Lua script for a particular prefix.
The
.Ar prefix
should be an arbitrary text, and the
.Ar script
should be a full path to a Lua script.
Multiple
.Fl L
options may be passed.
A separate Lua state is created for each prefix.
The Lua script can register callbacks using the
httpd.register_handler('<name>', function) Lua function,
which will trigger the execution of the Lua function
.Em function
when a URL in the form
.Em http://<hostname>/<prefix>/<name>
is being accessed.
The function is passed three tables as arguments, the server
environment, the request headers, and the decoded query string
plus any data that was send as application/x-www-form-urlencoded.
.It Fl M Ar suffix type encoding encoding11
Adds a new entry to the table that converts file suffixes to
content type and encoding.
This option takes four additional arguments containing
the file prefix, its
.Dq Content-Type ,
.Dq Content-Encoding ,
and
.Dq Content-Encoding
for HTTP/1.1 connections, respectively.
If any of these are a single dash
.Pq Dq - ,
the empty string is used instead.
Multiple
.Fl M
options may be passed.
.It Fl n
Stops
.Nm
from doing IP address to name resolution of hosts for setting the
.Ev REMOTE_HOST
variable before running a CGI program.
This option has no effect without the
.Fl c
option.
.It Fl P Ar pidfile
Causes
.Nm
to create a pid file in
.Ar pidfile
when run in daemon mode with the
.Fl b
option.
.It Fl p Ar pubdir
Changes the default user directory for
.Em /~user/
translations from
.Dq public_html
to
.Ar pubdir .
.It Fl r
Forces pages besides the
.Dq index.html
(see the
.Fl X
option) page to require that the Referrer: header be present and
refer to this web server, otherwise a redirect to the
.Dq index.html
page will be returned instead.
.It Fl S Ar server_software
Sets the internal server version to
.Ar server_software .
.It Fl s
Forces logging to be set to stderr always.
.It Fl t Ar chrootdir
Makes
.Nm
chroot to the specified directory
before answering requests.
Every other path should be specified relative
to the new root, if this option is used.
Note that the current environment
is normally replaced with an empty environment with this option, unless the
.Fl e
option is also used.
.It Fl U Ar username
Causes
.Nm
to switch to the user and the groups of
.Ar username
after initialization.
This option, like
.Fl t
above, causes
.Nm
to clear the environment unless the
.Fl e
option is given.
.It Fl u
Enables the transformation of Uniform Resource Locators of
the form
.Em /~user/
into the directory
.Pa ~user/public_html
(but see the
.Fl p
option above).
.It Fl V
Sets the default virtual host directory to
.Ar slashdir .
If no directory exists in
.Ar virtualroot
for the request, then
.Ar slashdir
will be used.
The default behaviour is to return 404 (Not Found.)
.It Fl v Ar virtualroot
Enables virtual hosting support.
Directories in
.Ar virtualroot
will be searched for a matching virtual host name, when parsing
the HTML request.
If a matching name is found, it will be used
as both the server's real name,
.Op Ar myname ,
and as the
.Ar slashdir .
See the
.Sx EXAMPLES
section for an example of using this option.
.It Fl X
Enables directory indexing.
A directory index will be generated only when the default file (i.e.
.Pa index.html
normally) is not present.
.It Fl x Ar index
Changes the default file read for directories from
.Dq index.html
to
.Ar index .
.It Fl Z Ar certificate_path privatekey_path
Sets the path to the server certificate file and the private key file
in pem format.
It also causes
.Nm
to start SSL mode.
.El
.Pp
Note that in
.Nm
versions 20031005 and prior that supported the
.Fl C
and
.Fl M
options, they took a single space-separated argument that was parsed.
since version 20040828, they take multiple options (2 in the case of
.Fl C
and 4 in the case of
.Fl M . )
.Ss INETD CONFIGURATION
As
.Nm
uses
.Xr inetd 8
by default to process incoming TCP connections for HTTP requests
(but see the
.Fl b
option),
.Nm
has little internal networking knowledge.
(Indeed, you can run it on the command line with little change of functionality.)
A typical
.Xr inetd.conf 5
entry would be:
.Bd -literal
http stream tcp nowait:600 _httpd /usr/libexec/httpd httpd /var/www
http stream tcp6 nowait:600 _httpd /usr/libexec/httpd httpd /var/www
.Ed
.Pp
This would serve web pages from
.Pa /var/www
on both IPv4 and IPv6 ports.
The
.Em :600
changes the
requests per minute to 600, up from the
.Xr inetd 8
default of 40.
.Pp
Using the
.Nx
.Xr inetd 8 ,
you can provide multiple IP-address based HTTP servers by having multiple
listening ports with different configurations.
.Ss NOTES
This server supports the
.Em HTTP/0.9 ,
.Em HTTP/1.0 ,
and
.Em HTTP/1.1
standards.
Support for these protocols is very minimal and many optional features are
not supported.
.Pp
.Nm
can be compiled without
CGI support (NO_CGIBIN_SUPPORT),
user transformations (NO_USER_SUPPORT),
directory index support (NO_DIRINDEX_SUPPORT),
daemon mode support (NO_DAEMON_MODE),
dynamic MIME content (NO_DYNAMIC_CONTENT),
Lua suport (NO_LUA_SUPPORT),
and SSL support (NO_SSL_SUPPORT)
by defining the listed macros when building
.Nm .
.Ss HTTP BASIC AUTHORISATION
.Nm
has support for HTTP Basic Authorisation.
If a file named
.Pa .htpasswd
exists in the directory of the current request,
.Nm
will restrict access to documents in that directory
using the RFC 2617 HTTP
.Dq Basic
authentication scheme.
.Pp
Note:
This does not recursively protect any sub-directories.
.Pp
The
.Pa .htpasswd
file contains lines delimited with a colon containing
usernames and passwords hashed with
.Xr crypt 3 ,
for example:
.Bd -literal
heather:$1$pZWI4tH/$DzDPl63i6VvVRv2lJNV7k1
jeremy:A.xewbx2DpQ8I
.Ed
.Pp
On
.Nx ,
the
.Xr pwhash 1
utility may be used to generate hashed passwords.
.Pp
While
.Nm
distributed with
.Nx
has support for HTTP Basic Authorisation enabled by default,
in the portable distribution it is excluded.
Compile
.Nm
with
.Dq -DDO_HTPASSWD
on the compiler command line to enable this support.
It may require linking with the crypt library, using
.Dq -lcrypt .
.Ss SSL SUPPORT
.Nm
has support for SSLv2, SSLv3, and TLSv1 protocols that is included by
default.
It requires linking with the crypto and ssl library, using
.Dq -lcrypto -lssl .
To disable SSL SUPPORT compile
.Nm
with
.Dq -DNO_SSL_SUPPORT
on the compiler command line.
.Ss COMPRESSION
.Nm
supports a very basic form compression.
.Nm
will serve the requested file postpended with
.Dq Pa .gz
if it exists, it is readable, the client requested gzip compression, and
the client did not make a ranged request.
.Sh FILES
.Nm
looks for a couple of special files in directories that allow certain features
to be provided on a per-directory basis.
In addition to the
.Pa .htpasswd
used by HTTP basic authorisation,
if a
.Pa .bzdirect
file is found (contents are irrelevant)
.Nm
will allow direct access even with the
.Fl r
option.
If a
.Pa .bzredirect
symbolic link is found,
.Nm
will perform a smart redirect to the target of this symlink.
The target is assumed to live on the same server.
If a
.Pa .bzabsredirect
symbolic link is found,
.Nm
will redirect to the absolute url pointed to by this symlink.
This is useful to redirect to different servers.
.Sh EXAMPLES
To configure set of virtual hosts, one would use an
.Xr inetd.conf 5
entry like:
.Bd -literal
http stream tcp nowait:600 _httpd /usr/libexec/httpd httpd -v /var/vroot /var/www
.Ed
.Pp
and inside
.Pa /var/vroot
create a directory (or a symlink to a directory) with the same name as
the virtual host, for each virtual host.
Lookups for these names are done in a case-insensitive manner, and may
include the port number part of the request, allowing for distinct
virtual hosts on the same name.
.Pp
To use
.Nm
with PHP, one must use the
.Fl C
option to specify a CGI handler for a particular file type.
Typically this will be like:
.Bd -literal
httpd -C .php /usr/pkg/bin/php /var/www
.Ed
.Sh SEE ALSO
.Xr inetd.conf 5 ,
.Xr inetd 8
.Sh HISTORY
.Nm
was first written in perl, based on another perl http server
called
.Dq tinyhttpd .
It was then rewritten from scratch in perl, and then once again in C.
From
.Dq bozohttpd
version 20060517, it has been integrated into
.Nx .
The focus has always been simplicity and security, with minimal features
and regular code audits.
This manual documents
.Nm
version 20150501.
.Sh AUTHORS
.An -nosplit
.Nm
was written by
.An Matthew R. Green
.Aq Mt mrg@eterna.com.au .
.Pp
The large list of contributors includes:
.Bl -dash
.It
.An Marc Balmer
.Aq Mt mbalmer@NetBSD.org
added Lua support for dynamic content creation
.It
.An Christoph Badura
.Aq Mt bad@bsd.de
provided Range: header support
.It
.An Sean Boudreau
.Aq Mt seanb@NetBSD.org
provided a security fix for virtual hosting
.It
.An Julian Coleman
.Aq Mt jdc@coris.org.uk
provided an IPv6 bugfix
.It
.An Chuck Cranor
.Aq Mt chuck@research.att.com
provided cgi-bin support fixes, and more
.It
.An Alistair G. Crooks
.Aq Mt agc@NetBSD.org
cleaned up many internal interfaces, made
.Nm
linkable as a library and provided the Lua binding.
.It
.An DEGROOTE Arnaud
.Aq Mt degroote@NetBSD.org
provided a fix for daemon mode
.It
.An Andrew Doran
.Aq Mt ad@NetBSD.org
provided directory indexing support
.It
.An Per Ekman
.Aq Mt pek@pdc.kth.se
provided a fix for a minor (non-security) buffer overflow condition
.It
.An Roland Dowdeswell
.Aq Mt elric@NetBSD.org
added support for serving gzipped files and better SSL handling
.It
.An Jun-ichiro itojun Hagino, KAME
.Aq Mt itojun@iijlab.net
provided initial IPv6 support
.It
.An Martin Husemann
.Aq Mt martin@NetBSD.org
provided .bzabsredirect support, and fixed various redirection issues
.It
.An Arto Huusko
.Aq Mt arto.huusko@pp2.inet.fi
provided fixes cgi-bin
.It
.An Roland Illig
.Aq Mt roland.illig@gmx.de
provided some off-by-one fixes
.It
.An Zak Johnson
.Aq Mt zakj@nox.cx
provided cgi-bin enhancements
.It
.An Nicolas Jombart
.Aq Mt ecu@ipv42.net
provided fixes for HTTP basic authorisation support
.It
.An Antti Kantee
.Aq Mt pooka@NetBSD.org
provided fixes for HTTP basic authorisation support
.It
.An Thomas Klausner
.Aq Mt wiz@NetBSD.org
provided many fixes and enhancements for the man page
.It
.An Mateusz Kocielski
.Aq Mt shm@NetBSD.org
fixed memory leaks, various issues with userdir support,
information disclosure issues, added support for using CGI handlers
with directory indexing and provided various other fixes.
.It
.An Arnaud Lacombe
.Aq Mt alc@NetBSD.org
provided some clean up for memory leaks
.It
.An Johnny Lam
.Aq Mt jlam@NetBSD.org
provided man page fixes
.It
.An Julio Merino
.Aq Mt jmmv@NetBSD.org
Added the
.Fl P
option.
.It
.An Luke Mewburn
.Aq Mt lukem@NetBSD.org
provided many various fixes, including cgi-bin fixes and enhancements,
HTTP basic authorisation support and much code clean up
.It
.An Rajeev V. Pillai
.Aq Mt rajeev_v_pillai@yahoo.com
provided several fixes for virtual hosting
.It
.An Jeremy C. Reed
.Aq Mt reed@NetBSD.org
provided several clean up fixes, and man page updates
.It
.An Scott Reynolds
.Aq Mt scottr@NetBSD.org
provided various fixes
.It
.An Tyler Retzlaff
.Aq Mt rtr@eterna.com.au
provided SSL support, cgi-bin fixes and much other random other stuff
.It
.An rudolf
.Aq Mt netbsd@eq.cz
provided minor compile fixes and a CGI content map fix
.It
.An Steve Rumble
.Aq Mt rumble@ephemeral.org
provided the
.Fl V
option.
.It
.An Thor Lancelot Simon
.Aq Mt tls@NetBSD.org
enhanced cgi-bin support.
.It
.An Joerg Sonnenberger
.Aq Mt joerg@NetBSD.org
implemented If-Modified-Since support
.It
.An ISIHARA Takanori
.Aq Mt ishit@oak.dti.ne.jp
provided a man page fix
.It
.An Holger Weiss
.Aq Mt holger@CIS.FU-Berlin.DE
provided http authorisation fixes
.It
.Aq Mt xs@kittenz.org
provided chroot and change-to-user support, and other various fixes
.It
Coyote Point provided various CGI fixes.
.It
.An Julio Merino
added pidfile support and provided some man page fixes.
.El
.Pp
There are probably others I have forgotten (let me know if you care)
.Pp
Please send all updates to
.Nm
to
.Aq Mt mrg@eterna.com.au
for inclusion in future releases.
.Sh BUGS
.Nm
does not handle HTTP/1.1 chunked input from the client yet.

View File

@ -1,350 +0,0 @@
/* $NetBSD: bozohttpd.h,v 1.36 2015/08/05 06:50:44 mrg Exp $ */
/* $eterna: bozohttpd.h,v 1.39 2011/11/18 09:21:15 mrg Exp $ */
/*
* Copyright (c) 1997-2015 Matthew R. Green
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer and
* dedication in the documentation and/or other materials provided
* with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
*/
#ifndef BOZOHTTOPD_H_
#define BOZOHTTOPD_H_ 1
#include "netbsd_queue.h"
#include <sys/stat.h>
#ifndef NO_LUA_SUPPORT
#include <lua.h>
#endif
#include <stdio.h>
/* QNX provides a lot of NetBSD things in nbutil.h */
#ifdef USE_NBUTIL
#include <nbutil.h>
#endif
/* lots of "const" but gets free()'ed etc at times, sigh */
/* headers */
typedef struct bozoheaders {
/*const*/ char *h_header;
/*const*/ char *h_value; /* this gets free()'ed etc at times */
SIMPLEQ_ENTRY(bozoheaders) h_next;
} bozoheaders_t;
#ifndef NO_LUA_SUPPORT
typedef struct lua_handler {
const char *name;
int ref;
SIMPLEQ_ENTRY(lua_handler) h_next;
} lua_handler_t;
typedef struct lua_state_map {
const char *script;
const char *prefix;
lua_State *L;
SIMPLEQ_HEAD(, lua_handler) handlers;
SIMPLEQ_ENTRY(lua_state_map) s_next;
} lua_state_map_t;
#endif
typedef struct bozo_content_map_t {
const char *name; /* postfix of file */
const char *type; /* matching content-type */
const char *encoding; /* matching content-encoding */
const char *encoding11; /* matching content-encoding (HTTP/1.1) */
const char *cgihandler; /* optional CGI handler */
} bozo_content_map_t;
/* this struct holds the bozo constants */
typedef struct bozo_consts_t {
const char *http_09; /* "HTTP/0.9" */
const char *http_10; /* "HTTP/1.0" */
const char *http_11; /* "HTTP/1.1" */
const char *text_plain; /* "text/plain" */
} bozo_consts_t;
/* this structure encapsulates all the bozo flags and control vars */
typedef struct bozohttpd_t {
char *rootdir; /* root directory */
char *username; /* username to switch to */
int numeric; /* avoid gethostby*() */
char *virtbase; /* virtual directory base */
int unknown_slash; /* unknown vhosts go to normal slashdir */
int untrustedref; /* make sure referrer = me unless url = / */
int logstderr; /* log to stderr (even if not tty) */
int background; /* drop into daemon mode */
int foreground; /* keep daemon mode in foreground */
char *pidfile; /* path to the pid file, if any */
size_t page_size; /* page size */
char *slashdir; /* www slash directory */
char *bindport; /* bind port; default "http" */
char *bindaddress; /* address for binding - INADDR_ANY */
int debug; /* debugging level */
char *virthostname; /* my name */
const char *server_software;/* our brand :-) */
const char *index_html; /* our home page */
const char *public_html; /* ~user/public_html page */
int enable_users; /* enable public_html */
int *sock; /* bound sockets */
int nsock; /* number of above */
struct pollfd *fds; /* current poll fd set */
int request_times; /* # times a request was processed */
int dir_indexing; /* handle directories */
int hide_dots; /* hide .* */
int process_cgi; /* use the cgi handler */
char *cgibin; /* cgi-bin directory */
#ifndef NO_LUA_SUPPORT
int process_lua; /* use the Lua handler */
SIMPLEQ_HEAD(, lua_state_map) lua_states;
#endif
void *sslinfo; /* pointer to ssl struct */
int dynamic_content_map_size;/* size of dyn cont map */
bozo_content_map_t *dynamic_content_map;/* dynamic content map */
size_t mmapsz; /* size of region to mmap */
char *getln_buffer; /* space for getln buffer */
ssize_t getln_buflen; /* length of allocated space */
char *errorbuf; /* no dynamic allocation allowed */
bozo_consts_t consts; /* various constants */
} bozohttpd_t;
/* bozo_httpreq_t */
typedef struct bozo_httpreq_t {
bozohttpd_t *hr_httpd;
int hr_method;
#define HTTP_GET 0x01
#define HTTP_POST 0x02
#define HTTP_HEAD 0x03
#define HTTP_OPTIONS 0x04 /* not supported */
#define HTTP_PUT 0x05 /* not supported */
#define HTTP_DELETE 0x06 /* not supported */
#define HTTP_TRACE 0x07 /* not supported */
#define HTTP_CONNECT 0x08 /* not supported */
const char *hr_methodstr;
char *hr_virthostname; /* server name (if not identical
to hr_httpd->virthostname) */
char *hr_file;
char *hr_oldfile; /* if we added an index_html */
char *hr_query;
char *hr_host; /* HTTP/1.1 Host: or virtual hostname,
possibly including a port number */
const char *hr_proto;
const char *hr_content_type;
const char *hr_content_length;
const char *hr_allow;
const char *hr_referrer;
const char *hr_range;
const char *hr_if_modified_since;
const char *hr_accept_encoding;
int hr_have_range;
off_t hr_first_byte_pos;
off_t hr_last_byte_pos;
/*const*/ char *hr_remotehost;
/*const*/ char *hr_remoteaddr;
/*const*/ char *hr_serverport;
#ifdef DO_HTPASSWD
/*const*/ char *hr_authrealm;
/*const*/ char *hr_authuser;
/*const*/ char *hr_authpass;
#endif
SIMPLEQ_HEAD(, bozoheaders) hr_headers;
int hr_nheaders;
} bozo_httpreq_t;
/* helper to access the "active" host name from a httpd/request pair */
#define BOZOHOST(HTTPD,REQUEST) ((REQUEST)->hr_virthostname ? \
(REQUEST)->hr_virthostname : \
(HTTPD)->virthostname)
/* structure to hold string based (name, value) pairs with preferences */
typedef struct bozoprefs_t {
unsigned size; /* size of the two arrays */
unsigned c; /* # of entries in arrays */
char **name; /* names of each entry */
char **value; /* values for the name entries */
} bozoprefs_t;
/* by default write in upto 64KiB chunks, and mmap in upto 64MiB chunks */
#ifndef BOZO_WRSZ
#define BOZO_WRSZ (64 * 1024)
#endif
#ifndef BOZO_MMAPSZ
#define BOZO_MMAPSZ (BOZO_WRSZ * 1024)
#endif
/* debug flags */
#define DEBUG_NORMAL 1
#define DEBUG_FAT 2
#define DEBUG_OBESE 3
#define DEBUG_EXPLODING 4
#define strornull(x) ((x) ? (x) : "<null>")
#if defined(__GNUC__) && __GNUC__ >= 3
#define BOZO_PRINTFLIKE(x,y) __attribute__((__format__(__printf__, x,y)))
#define BOZO_DEAD __attribute__((__noreturn__))
#endif
#ifndef NO_DEBUG
void debug__(bozohttpd_t *, int, const char *, ...) BOZO_PRINTFLIKE(3, 4);
#define debug(x) debug__ x
#else
#define debug(x)
#endif /* NO_DEBUG */
void bozo_warn(bozohttpd_t *, const char *, ...)
BOZO_PRINTFLIKE(2, 3);
void bozo_err(bozohttpd_t *, int, const char *, ...)
BOZO_PRINTFLIKE(3, 4)
BOZO_DEAD;
int bozo_http_error(bozohttpd_t *, int, bozo_httpreq_t *, const char *);
int bozo_check_special_files(bozo_httpreq_t *, const char *);
char *bozo_http_date(char *, size_t);
void bozo_print_header(bozo_httpreq_t *, struct stat *, const char *, const char *);
char *bozo_escape_rfc3986(bozohttpd_t *httpd, const char *url);
char *bozo_escape_html(bozohttpd_t *httpd, const char *url);
char *bozodgetln(bozohttpd_t *, int, ssize_t *, ssize_t (*)(bozohttpd_t *, int, void *, size_t));
char *bozostrnsep(char **, const char *, ssize_t *);
void *bozomalloc(bozohttpd_t *, size_t);
void *bozorealloc(bozohttpd_t *, void *, size_t);
char *bozostrdup(bozohttpd_t *, const char *);
/* ssl-bozo.c */
#ifdef NO_SSL_SUPPORT
#define bozo_ssl_set_opts(w, x, y) do { /* nothing */ } while (0)
#define bozo_ssl_init(x) do { /* nothing */ } while (0)
#define bozo_ssl_accept(x) (0)
#define bozo_ssl_destroy(x) do { /* nothing */ } while (0)
#else
void bozo_ssl_set_opts(bozohttpd_t *, const char *, const char *);
void bozo_ssl_init(bozohttpd_t *);
int bozo_ssl_accept(bozohttpd_t *);
void bozo_ssl_destroy(bozohttpd_t *);
#endif
/* auth-bozo.c */
#ifdef DO_HTPASSWD
void bozo_auth_init(bozo_httpreq_t *);
int bozo_auth_check(bozo_httpreq_t *, const char *);
void bozo_auth_cleanup(bozo_httpreq_t *);
int bozo_auth_check_headers(bozo_httpreq_t *, char *, char *, ssize_t);
int bozo_auth_check_special_files(bozo_httpreq_t *, const char *);
void bozo_auth_check_401(bozo_httpreq_t *, int);
void bozo_auth_cgi_setenv(bozo_httpreq_t *, char ***);
int bozo_auth_cgi_count(bozo_httpreq_t *);
#else
#define bozo_auth_init(x) do { /* nothing */ } while (0)
#define bozo_auth_check(x, y) 0
#define bozo_auth_cleanup(x) do { /* nothing */ } while (0)
#define bozo_auth_check_headers(y, z, a, b) 0
#define bozo_auth_check_special_files(x, y) 0
#define bozo_auth_check_401(x, y) do { /* nothing */ } while (0)
#define bozo_auth_cgi_setenv(x, y) do { /* nothing */ } while (0)
#define bozo_auth_cgi_count(x) 0
#endif /* DO_HTPASSWD */
/* cgi-bozo.c */
#ifdef NO_CGIBIN_SUPPORT
#define bozo_process_cgi(h) 0
#else
void bozo_cgi_setbin(bozohttpd_t *, const char *);
void bozo_setenv(bozohttpd_t *, const char *, const char *, char **);
int bozo_process_cgi(bozo_httpreq_t *);
void bozo_add_content_map_cgi(bozohttpd_t *, const char *, const char *);
#endif /* NO_CGIBIN_SUPPORT */
/* lua-bozo.c */
#ifdef NO_LUA_SUPPORT
#define bozo_process_lua(h) 0
#else
void bozo_add_lua_map(bozohttpd_t *, const char *, const char *);
int bozo_process_lua(bozo_httpreq_t *);
#endif /* NO_LUA_SUPPORT */
/* daemon-bozo.c */
#ifdef NO_DAEMON_MODE
#define bozo_daemon_init(x) do { /* nothing */ } while (0)
#define bozo_daemon_fork(x) 0
#define bozo_daemon_closefds(x) do { /* nothing */ } while (0)
#else
void bozo_daemon_init(bozohttpd_t *);
int bozo_daemon_fork(bozohttpd_t *);
void bozo_daemon_closefds(bozohttpd_t *);
#endif /* NO_DAEMON_MODE */
/* tilde-luzah-bozo.c */
#ifdef NO_USER_SUPPORT
#define bozo_user_transform(a, c) 0
#else
int bozo_user_transform(bozo_httpreq_t *, int *);
#endif /* NO_USER_SUPPORT */
/* dir-index-bozo.c */
#ifdef NO_DIRINDEX_SUPPORT
#define bozo_dir_index(a, b, c) 0
#else
int bozo_dir_index(bozo_httpreq_t *, const char *, int);
#endif /* NO_DIRINDEX_SUPPORT */
/* content-bozo.c */
const char *bozo_content_type(bozo_httpreq_t *, const char *);
const char *bozo_content_encoding(bozo_httpreq_t *, const char *);
bozo_content_map_t *bozo_match_content_map(bozohttpd_t *, const char *, int);
bozo_content_map_t *bozo_get_content_map(bozohttpd_t *, const char *);
#ifndef NO_DYNAMIC_CONTENT
void bozo_add_content_map_mime(bozohttpd_t *, const char *, const char *, const char *, const char *);
#endif
/* I/O */
int bozo_printf(bozohttpd_t *, const char *, ...) BOZO_PRINTFLIKE(2, 3);;
ssize_t bozo_read(bozohttpd_t *, int, void *, size_t);
ssize_t bozo_write(bozohttpd_t *, int, const void *, size_t);
int bozo_flush(bozohttpd_t *, FILE *);
/* misc */
int bozo_init_httpd(bozohttpd_t *);
int bozo_init_prefs(bozoprefs_t *);
int bozo_set_defaults(bozohttpd_t *, bozoprefs_t *);
int bozo_setup(bozohttpd_t *, bozoprefs_t *, const char *, const char *);
bozo_httpreq_t *bozo_read_request(bozohttpd_t *);
void bozo_process_request(bozo_httpreq_t *);
void bozo_clean_request(bozo_httpreq_t *);
/* variables */
int bozo_set_pref(bozoprefs_t *, const char *, const char *);
char *bozo_get_pref(bozoprefs_t *, const char *);
#endif /* BOZOHTTOPD_H_ */

View File

@ -1,162 +0,0 @@
#! /usr/bin/env lua
--
-- Copyright (c) 2009 The NetBSD Foundation, Inc.
-- All rights reserved.
--
-- This code is derived from software contributed to The NetBSD Foundation
-- by Alistair Crooks (agc@netbsd.org)
--
-- Redistribution and use in source and binary forms, with or without
-- modification, are permitted provided that the following conditions
-- are met:
-- 1. Redistributions of source code must retain the above copyright
-- notice, this list of conditions and the following disclaimer.
-- 2. Redistributions in binary form must reproduce the above copyright
-- notice, this list of conditions and the following disclaimer in the
-- documentation and/or other materials provided with the distribution.
--
-- THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
-- ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
-- TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-- PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
-- BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-- POSSIBILITY OF SUCH DAMAGE.
--
-- command line args
dofile "optparse.lua"
opt = OptionParser{usage="%prog [options] root [vhost]", version="20091105"}
opt.add_option{"-C", "--cgimap", action="store", dest="cgimap", help="--cgimap 's t'"}
opt.add_option{"-H", "--hide-dots", action="store_true", dest="hidedots", help="--hide-dots"}
opt.add_option{"-I", "--portnum", action="store", dest="portnum", help="--portnum number"}
opt.add_option{"-M", "--dynamicmime", action="store", dest="dynmime", help="--dynamicmime 'suffix type a b'"}
opt.add_option{"-S", "--server-software", action="store", dest="serversw", help="--server-software name"}
opt.add_option{"-U", "--username", action="store", dest="username", help="--username name"}
opt.add_option{"-V", "--unknown-slash", action="store_true", dest="unknown", help="--unknown-slash"}
opt.add_option{"-X", "--dir-index", action="store_true", dest="dirindex", help="--dir-index"}
opt.add_option{"-Z", "--ssl", action="store", dest="ssl", help="--ssl 'cert priv'"}
opt.add_option{"-b", "--background", action="store", dest="background", help="--background count"}
opt.add_option{"-c", "--cgibin", action="store", dest="cgibin", help="--cgibin bin"}
opt.add_option{"-e", "--dirtyenv", action="store_true", dest="dirtyenv", help="--dirtyenv"}
opt.add_option{"-f", "--foreground", action="store_true", dest="foreground", help="--foreground"}
opt.add_option{"-i", "--bindaddr", action="store", dest="bindaddress", help="--bindaddr address"}
opt.add_option{"-n", "--numeric", action="store_true", dest="numeric", help="--numeric"}
opt.add_option{"-p", "--public-html", action="store", dest="public_html", help="--public-html dir"}
opt.add_option{"-r", "--trusted-referal", action="store_true", dest="trustedref", help="trusted referal"}
opt.add_option{"-s", "--logtostderr", action="store_true", dest="logstderr", help="log to stderr"}
opt.add_option{"-t", "--chroot", action="store", dest="chroot", help="--chroot dir"}
opt.add_option{"-u", "--enable-users", action="store_true", dest="enableusers", help="--enable-users"}
opt.add_option{"-v", "--virtbase", action="store", dest="virtbase", help="virtual base location"}
opt.add_option{"-x", "--index-html", action="store", dest="indexhtml", help="index.html name"}
-- caller lua script
local extension = ".so"
f = io.open("libluabozohttpd.dylib", "r")
if f then
extension = ".dylib"
io.close(f)
end
glupkg = package.loadlib("./" .. "libluabozohttpd" .. extension, "luaopen_bozohttpd")
bozohttpd = glupkg()
-- initialise
httpd = bozohttpd.new()
bozohttpd.init_httpd(httpd)
prefs = bozohttpd.init_prefs()
-- parse command line args
options,args = opt.parse_args()
if options.portnum then
bozohttpd.set_pref(prefs, "port number", options.portnum)
end
if options.background then
bozohttpd.set_pref(prefs, "background", options.background)
end
if options.numeric then
bozohttpd.set_pref(prefs, "numeric", "true")
end
if options.logstderr then
bozohttpd.set_pref(prefs, "log to stderr", "true")
end
if options.foreground then
bozohttpd.set_pref(prefs, "foreground", "true")
end
if options.trustedref then
bozohttpd.set_pref(prefs, "trusted referal", "true")
end
if options.dynmime then
suffix, type, s1, s2 = string.find(options.dynmime,
"(%S+)%s+(%S+)%s+(%S+)%s+(%S+)")
bozohttpd.dynamic_mime(httpd, suffix, type, s1, s2)
end
if options.serversw then
bozohttpd.set_pref(prefs, "server software", options.serversw)
end
if options.ssl then
cert, priv = string.find(options.ssl, "(%S+)%s+(%S+)")
bozohttpd.dynamic_mime(httpd, cert, priv)
end
if options.username then
bozohttpd.set_pref(prefs, "username", options.username)
end
if options.unknownslash then
bozohttpd.set_pref(prefs, "unknown slash", "true")
end
if options.virtbase then
bozohttpd.set_pref(prefs, "virtual base", options.virtbase)
end
if options.indexhtml then
bozohttpd.set_pref(prefs, "index.html", options.indexhtml)
end
if options.dirtyenv then
bozohttpd.set_pref(prefs, "dirty environment", "true")
end
if options.bindaddr then
bozohttpd.set_pref(prefs, "bind address", options.bindaddr)
end
if options.cgibin then
bozohttpd.cgi_setbin(httpd, options.cgibin)
end
if options.cgimap then
name, handler = string.find(options.cgimap, "(%S+)%s+(%S+)")
bozohttpd.cgi_map(httpd, name, handler)
end
if options.public_html then
bozohttpd.set_pref(prefs, "public_html", options.public_html)
end
if options.chroot then
bozohttpd.set_pref(prefs, "chroot dir", options.chroot)
end
if options.enableusers then
bozohttpd.set_pref(prefs, "enable users", "true")
end
if options.hidedots then
bozohttpd.set_pref(prefs, "hide dots", "true")
end
if options.dirindex then
bozohttpd.set_pref(prefs, "directory indexing", "true")
end
if #args < 1 then
print("At least one arg needed for root directory")
else
-- set up connections
local vhost = args[2] or ""
bozohttpd.setup(httpd, prefs, vhost, args[1])
-- loop, serving requests
local numreps = options.background or 0
repeat
req = bozohttpd.read_request(httpd)
bozohttpd.process_request(httpd, req)
bozohttpd.clean_request(req)
until numreps == 0
end

View File

@ -1,276 +0,0 @@
/*-
* Copyright (c) 2009 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Alistair Crooks (agc@netbsd.org)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/types.h>
#include <sys/param.h>
#include <sys/stat.h>
#include <bozohttpd.h>
#include <inttypes.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#define LUA_LIB
#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>
#ifndef __UNCONST
#define __UNCONST(a) ((void *)(unsigned long)(const void *)(a))
#endif /* !__UNCONST */
int luaopen_bozohttpd(lua_State *);
#if 0
typedef struct strarg_t {
const char *s; /* string */
const int n; /* corresponding int value */
} strarg_t;
/* map a string onto an int */
static int
findtype(strarg_t *strs, const char *s)
{
strarg_t *sp;
for (sp = strs ; sp->s && strcasecmp(sp->s, s) != 0 ; sp++) {
}
return sp->n;
}
#endif
/* init() */
static int
l_new(lua_State *L)
{
bozohttpd_t *httpd;
httpd = lua_newuserdata(L, sizeof(*httpd));
(void) memset(httpd, 0x0, sizeof(*httpd));
return 1;
}
/* initialise(httpd) */
static int
l_init_httpd(lua_State *L)
{
bozohttpd_t *httpd;
httpd = lua_touserdata(L, 1);
lua_pushnumber(L, bozo_init_httpd(httpd));
return 1;
}
/* initialise(prefs) */
static int
l_init_prefs(lua_State *L)
{
bozoprefs_t *prefs;
prefs = lua_newuserdata(L, sizeof(*prefs));
(void) memset(prefs, 0x0, sizeof(*prefs));
(void) bozo_init_prefs(prefs);
return 1;
}
/* bozo_set_pref(prefs, name, value) */
static int
l_bozo_set_pref(lua_State *L)
{
bozoprefs_t *prefs;
const char *name;
const char *value;
prefs = lua_touserdata(L, 1);
name = luaL_checkstring(L, 2);
value = luaL_checkstring(L, 3);
lua_pushnumber(L, bozo_set_pref(prefs, name, value));
return 1;
}
/* bozo_get_pref(prefs, name) */
static int
l_bozo_get_pref(lua_State *L)
{
bozoprefs_t *prefs;
const char *name;
prefs = lua_touserdata(L, 1);
name = luaL_checkstring(L, 2);
lua_pushstring(L, bozo_get_pref(prefs, name));
return 1;
}
/* bozo_setup(httpd, prefs, host, root) */
static int
l_bozo_setup(lua_State *L)
{
bozohttpd_t *httpd;
bozoprefs_t *prefs;
const char *vhost;
const char *root;
httpd = lua_touserdata(L, 1);
prefs = lua_touserdata(L, 2);
vhost = luaL_checkstring(L, 3);
if (vhost && *vhost == 0x0) {
vhost = NULL;
}
root = luaL_checkstring(L, 4);
lua_pushnumber(L, bozo_setup(httpd, prefs, vhost, root));
return 1;
}
/* bozo_read_request(httpd) */
static int
l_bozo_read_request(lua_State *L)
{
bozo_httpreq_t *req;
bozohttpd_t *httpd;
httpd = lua_touserdata(L, 1);
req = bozo_read_request(httpd);
lua_pushlightuserdata(L, req);
return 1;
}
/* bozo_process_request(httpd, req) */
static int
l_bozo_process_request(lua_State *L)
{
bozo_httpreq_t *req;
bozohttpd_t *httpd;
httpd = lua_touserdata(L, 1);
req = lua_touserdata(L, 2);
bozo_process_request(httpd, req);
lua_pushnumber(L, 1);
return 1;
}
/* bozo_clean_request(req) */
static int
l_bozo_clean_request(lua_State *L)
{
bozo_httpreq_t *req;
req = lua_touserdata(L, 1);
bozo_clean_request(req);
lua_pushnumber(L, 1);
return 1;
}
/* dynamic_mime(httpd, one, two, three, four) */
static int
l_bozo_dynamic_mime(lua_State *L)
{
bozohttpd_t *httpd;
const char *s[4];
httpd = lua_touserdata(L, 1);
s[0] = luaL_checkstring(L, 2);
s[1] = luaL_checkstring(L, 3);
s[2] = luaL_checkstring(L, 4);
s[3] = luaL_checkstring(L, 5);
bozo_add_content_map_mime(httpd, s[0], s[1], s[2], s[3]);
lua_pushnumber(L, 1);
return 1;
}
/* ssl_set_opts(httpd, one, two) */
static int
l_bozo_ssl_set_opts(lua_State *L)
{
bozohttpd_t *httpd;
const char *s[2];
httpd = lua_touserdata(L, 1);
s[0] = luaL_checkstring(L, 2);
s[1] = luaL_checkstring(L, 3);
bozo_ssl_set_opts(httpd, s[0], s[1]);
lua_pushnumber(L, 1);
return 1;
}
/* cgi_setbin(httpd, bin) */
static int
l_bozo_cgi_setbin(lua_State *L)
{
bozohttpd_t *httpd;
const char *bin;
httpd = lua_touserdata(L, 1);
bin = luaL_checkstring(L, 2);
bozo_cgi_setbin(httpd, bin);
lua_pushnumber(L, 1);
return 1;
}
/* cgi_map(httpd, 1, 2) */
static int
l_bozo_cgi_map(lua_State *L)
{
bozohttpd_t *httpd;
const char *s[2];
httpd = lua_touserdata(L, 1);
s[0] = luaL_checkstring(L, 2);
s[1] = luaL_checkstring(L, 3);
bozo_add_content_map_cgi(httpd, s[0], s[1]);
lua_pushnumber(L, 1);
return 1;
}
const struct luaL_reg libluabozohttpd[] = {
{ "new", l_new },
{ "init_httpd", l_init_httpd },
{ "init_prefs", l_init_prefs },
{ "set_pref", l_bozo_set_pref },
{ "get_pref", l_bozo_get_pref },
{ "setup", l_bozo_setup },
{ "dynamic_mime", l_bozo_dynamic_mime },
{ "ssl_set_opts", l_bozo_ssl_set_opts },
{ "cgi_setbin", l_bozo_cgi_setbin },
{ "cgi_map", l_bozo_cgi_map },
{ "read_request", l_bozo_read_request },
{ "process_request", l_bozo_process_request },
{ "clean_request", l_bozo_clean_request },
{ NULL, NULL }
};
int
luaopen_bozohttpd(lua_State *L)
{
luaL_openlib(L, "bozohttpd", libluabozohttpd, 0);
return 1;
}

View File

@ -1,105 +0,0 @@
/* $NetBSD: sysident.h,v 1.17 2014/01/12 19:36:08 joerg Exp $ */
/*
* Copyright (c) 1997 Christopher G. Demetriou
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed for the
* NetBSD Project. See http://www.NetBSD.org/ for
* information about NetBSD.
* 4. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* <<Id: LICENSE,v 1.2 2000/06/14 15:57:33 cgd Exp>>
*/
/*
* Here we define the NetBSD OS Version in an ELF .note section, structured
* like:
*
* [NOTE HEADER]
* long name size
* long description size
* long note type
*
* [NOTE DATUM]
* string OS name
*
* OSVERSION notes also have:
* long OS version (__NetBSD_Version__ constant from param.h)
*
* The DATUM fields should be padded out such that their actual (not
* declared) sizes % 4 == 0.
*
* These are used by the kernel to determine if this binary is really a
* NetBSD binary, or some other OS's.
*/
/* XXX: NetBSD 1.5 compatibility only! */
#if __NetBSD_Version__ < 105010000
#define ELF_NOTE_TYPE_NETBSD_TAG 1
#endif
#define __S(x) __STRING(x)
__asm(
".pushsection\t\".note.netbsd.ident\", \"a\"\n"
"\t.p2align\t2\n\n"
"\t.long\t" __S(ELF_NOTE_NETBSD_NAMESZ) "\n"
"\t.long\t" __S(ELF_NOTE_NETBSD_DESCSZ) "\n"
"\t.long\t" __S(ELF_NOTE_TYPE_NETBSD_TAG) "\n"
"\t.ascii\t" __S(ELF_NOTE_NETBSD_NAME) "\n"
"\t.long\t" __S(__NetBSD_Version__) "\n\n"
"\t.popsection\n"
);
__asm(
".pushsection\t\".note.netbsd.pax\", \"a\"\n"
"\t.p2align\t2\n\n"
"\t.long\t" __S(ELF_NOTE_PAX_NAMESZ) "\n"
"\t.long\t" __S(ELF_NOTE_PAX_DESCSZ) "\n"
"\t.long\t" __S(ELF_NOTE_TYPE_PAX_TAG) "\n"
"\t.ascii\t" __S(ELF_NOTE_PAX_NAME) "\n"
"\t.long\t" __S(0) "\n\n"
"\t.popsection\n"
);
#ifdef ELF_NOTE_MARCH_DESC
__asm(
".pushsection\t\".note.netbsd.march\", \"a\"\n"
"\t.p2align\t2\n\n"
"\t.long\t" __S(ELF_NOTE_MARCH_NAMESZ) "\n"
"\t.long\t2f-1f\n"
"\t.long\t" __S(ELF_NOTE_TYPE_MARCH_TAG) "\n"
"\t.ascii\t" __S(ELF_NOTE_MARCH_NAME) "\n"
"1:\t.asciz\t" __S(ELF_NOTE_MARCH_DESC) "\n"
"2:\n"
"\t.popsection\n"
);
#endif

View File

@ -1,606 +0,0 @@
#!/bin/sh
#
# setup 4.1 - install a MINIX distribution
#
# Changes:
# Aug 2005 robustness checks and beautifications (Jorrit N. Herder)
# Jul 2005 extended with autopart and networking (Ben Gras)
# Dec 20, 1994 created (Kees J. Bot)
#
ROOTMB=128
ROOTSECTS="`expr $ROOTMB '*' 1024 '*' 2`"
BOOTXXSECTS=32
#LSC: Slight over shoot, as files for / are taken into account, although
# metadata is not, all in all should be pretty accurate.
USRKB=$(cat /i386/binary/sets/*.size | awk '{s+=$1} END{print (s/1024)}')
TOTALMB="`expr 3 + $USRKB / 1024 + $ROOTMB`"
TOTALFILES="`find -x / | wc -l`"
# /usr/install isn't copied onto the new system; compensate
INSTALLDIR=/usr/install
if [ -d $INSTALLDIR ]
then USRFILES=$(($USRFILES - `find -x $INSTALLDIR | wc -l`))
USRKB=$(($USRKB - `du -sxk $INSTALLDIR | awk '{ print $1 }'`))
fi
if [ -z "$FSTYPE" ]
then FSTYPE=mfs
fi
PATH=/bin:/sbin:/usr/bin:/usr/sbin
export PATH
usage()
{
cat >&2 <<'EOF'
Usage: setup # Install a skeleton system on the hard disk.
setup /usr # Install the rest of the system (binaries or sources).
# To install from other things then floppies:
fetch -q -o - http://... | setup /usr # Read from a web site.
fetch -q -o - ftp://... | setup /usr # Read from an FTP site.
mtools copy c0d0p0:... - | setup /usr # Read from the C: drive.
dosread c0d0p0 ... | setup /usr # Likewise if no mtools.
EOF
exit 1
}
warn()
{
echo -e "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b ! $1"
}
check_mbr()
{
# check for potential problems with old mbr.
disk=`echo -n "/dev/$primary" | sed 's/p[0-3]//'`
minix_primaries=`echo -n "" | fdisk "$disk" | grep "MINIX" | wc -l`
if [ "$minix_primaries" -gt 1 ]
then
# old mbr + bootxx will not work with several partitions of
# the same type.
dd if=/usr/mdec/mbr of=temp_mbr_netbsd bs=1 count=440 2>/dev/null
dd if="$disk" bs=1 count=440 2>/dev/null | cmp - temp_mbr_netbsd >/dev/null
if [ "$?" -ne 0 ]
then
echo ""
echo "Warning: you have MBR which doesn't support multiple MINIX 3 partitions!"
echo "You will be able to boot from the first one only!"
echo -n "Do you want to install new MBR into $disk? [Y] "
read ok
if [ "$ok" = Y -o "$ok" = y -o "$ok" = "" ]
then
installboot_nbsd -m "$disk" /usr/mdec/mbr >/dev/null
fi
fi
rm temp_mbr_netbsd
fi
}
# No options.
while getopts '' opt; do usage; done
shift `expr $OPTIND - 1`
if [ "$USER" != root ]
then echo "Please run setup as root."
exit 1
fi
# Find out what we are running from.
exec 9<&0 </etc/mtab # Mounted file table.
read thisroot rest # Current root (/dev/ram or /dev/fd?)
read fdusr rest # USR (/dev/fd? or /dev/fd?p2)
exec 0<&9 9<&-
# What do we know about ROOT?
case $thisroot:$fdusr in
/dev/ram:/dev/fd0p2) fdroot=/dev/fd0 # Combined ROOT+USR in drive 0
;;
/dev/ram:/dev/fd1p2) fdroot=/dev/fd1 # Combined ROOT+USR in drive 1
;;
/dev/ram:/dev/fd*) fdroot=unknown # ROOT is some other floppy
;;
/dev/fd*:/dev/fd*) fdroot=$thisroot # ROOT is mounted directly
;;
*) fdroot=$thisroot # ?
esac
echo -n "
Welcome to the MINIX 3 setup script. This script will guide you in setting up
MINIX on your machine. Please consult the manual for detailed instructions.
Note 1: If the screen blanks, hit CTRL+F3 to select \"software scrolling\".
Note 2: If things go wrong then hit CTRL+C to abort and start over.
Note 3: Default answers, like [y], can simply be chosen by hitting ENTER.
Note 4: If you see a colon (:) then you should hit ENTER to continue.
:"
read ret
# begin Step 1
echo ""
echo " --- Step 1: Select keyboard type --------------------------------------"
echo ""
echo "What type of keyboard do you have? You can choose one of:"
echo ""
ls -C /usr/lib/keymaps | sed -e 's/\.map//g' -e 's/^/ /'
echo ""
step1=""
while [ "$step1" != ok ]
do
echo -n "Keyboard type? [us-std] "; read keymap
test -n "$keymap" || keymap=us-std
if loadkeys "/usr/lib/keymaps/$keymap.map" 2>/dev/null
then step1=ok
else warn "invalid keyboard"
fi
done
# end Step 1
# begin Step 2
#step2=""
#while [ "$step2" != ok ]
#do
# echo ""
# echo " --- Step 2: Select minimal or full distribution -----------------------"
# echo ""
# echo "You can install MINIX as (M)inimal or (F)ull. (M)inimal"
# echo "includes only the binary system and basic system sources."
# echo "(F)ull also includes commands sources."
# echo ""
# echo "Please select:"
# echo " (M)inimal install (only basic sources) ($NOSRCMB MB required)"
# echo " (F)ull install (full install) ($TOTALMB MB required)"
# echo " "
# echo -n "Basic (M)inimal or (F)ull install? [F] "
# read conf
# case "$conf" in
# "") step2="ok"; nobigsource="" ;;
# [Ff]*) step2="ok"; nobigsource="" ;;
# [Mm]*) step2="ok"; nobigsource="1"; TOTALMB=$NOSRCMB; USRFILES=$NOSRCUSRFILES ;;
# esac
#done
# end Step 2
echo ""
echo " --- Step 2: Selecting full distribution -------------------------------"
echo ""
nobigsource=""
# begin Step 3
step3=""
while [ "$step3" != ok ]
do
echo ""
echo " --- Step 3: Create or select a partition for MINIX 3 -------------------"
echo ""
echo "Now you need to create a MINIX 3 partition on your hard disk."
echo "You can also select one that's already there."
echo " "
echo "If you have an existing installation, reinstalling will let you"
echo "keep your current partitioning and subpartitioning, and overwrite"
echo "everything except your s1 subpartition (/home). If you want to"
echo "reinstall, select your existing minix partition."
echo " "
echo "Unless you are an expert, you are advised to use the automated"
echo "step-by-step help in setting up."
echo ""
ok=""
while [ "$ok" = "" ]
do
echo -n "Press ENTER for automatic mode, or type 'expert': "
read mode
if [ -z "$mode" ]; then auto="1"; ok="yes"; fi
if [ "$mode" = expert ]; then auto=""; ok="yes"; fi
if [ "$ok" != yes ]; then warn "try again"; fi
done
primary=
if [ -z "$auto" ]
then
# Expert mode
echo -n "
MINIX needs one primary partition of $TOTALMB MB for a full install,
plus what you want for /home.
If there is no free space on your disk then you have to choose an option:
(1) Delete one or more partitions
(2) Allocate an existing partition to MINIX 3
(3) Exit setup and shrink a partition using a different OS
To make this partition you will be put in the editor \"part\". Follow the
advice under the '!' key to make a new partition of type MINIX. Do not
touch an existing partition unless you know precisely what you are doing!
Please note the name of the partition (e.g. c0d0p1, c0d1p3, c1d1p0) you
make. (See the devices section in usage(8) on MINIX device names.)
:"
read ret
while [ -z "$primary" ]
do
part || exit
echo -n "
Please finish the name of the primary partition you have created:
(Just type ENTER if you want to rerun \"part\") /dev/"
read primary
done
echo ""
echo "This is the point of no return. You have selected to install MINIX"
echo "on partition /dev/$primary. Please confirm that you want to use this"
echo "selection to install MINIX."
echo ""
confirmation=""
if [ ! -b "/dev/$primary" ]
then echo "/dev/$primary is not a block device."
fi
while [ -z "$confirmation" -o "$confirmation" != yes -a "$confirmation" != no ]
do
echo -n "Are you sure you want to continue? Please enter 'yes' or 'no': "
read confirmation
if [ "$confirmation" = yes ]; then step3=ok; fi
done
biosdrivename="Actual BIOS device name unknown, due to expert mode."
else
if [ "$auto" = "1" ]
then
# Automatic mode
PF="/tmp/pf"
if autopart -m$TOTALMB -f$PF
then if [ -s "$PF" ]
then
set `cat $PF`
bd="$1"
bdn="$2"
biosdrivename="Probably, the right command is \"boot $bdn\"."
if [ -b "/dev/$bd" ]
then primary="$bd"
else echo "Funny device $bd from autopart."
fi
else
echo "Didn't find output from autopart."
fi
else echo "Autopart tool failed. Trying again."
fi
# Reset at retries and timeouts in case autopart left
# them messy.
atnormalize
if [ -n "$primary" ]; then step3=ok; fi
fi
fi
if [ ! -b "/dev/$primary" ]
then echo Doing step 3 again.
step3=""
else
devsize="`devsize /dev/$primary`"
if [ "$devsize" -lt 1 ]
then echo "/dev/$primary is a 0-sized device."
step3=""
fi
fi
done # while step3 != ok
# end Step 3
root=${primary}s0
home=${primary}s1
usr=${primary}s2
umount /dev/$home 2>/dev/null && echo "Unmounted $home for you."
umount /dev/$usr 2>/dev/null && echo "Unmounted $usr for you."
umount /dev/$root 2>/dev/null && echo "Unmounted $root for you."
devsizemb="`expr $devsize / 1024 / 2`"
maxhome="`expr $devsizemb - $TOTALMB - 1`"
if [ "$devsizemb" -lt "$TOTALMB" ]
then echo "The selected partition ($devsizemb MB) is too small."
echo "You'll need $TOTALMB MB at least."
exit 1
fi
if [ "$maxhome" -lt 1 ]
then echo "Note: you can't have /home with that size partition."
maxhome=0
fi
TMPMP=/mnt
mkdir $TMPMP >/dev/null 2>&1
confirm=""
while [ "$confirm" = "" ]
do
auto=""
echo ""
echo " --- Step 4: Reinstall choice ------------------------------------------"
if mount -r /dev/$home $TMPMP >/dev/null 2>&1
then umount /dev/$home >/dev/null 2>&1
echo ""
echo "You have selected an existing MINIX 3 partition."
echo "Type F for full installation (to overwrite entire partition)"
echo "Type R for a reinstallation (existing /home will not be affected)"
echo ""
echo -n "(F)ull or (R)einstall? [R] "
read conf
case "$conf" in
"") confirm="ok"; auto="r"; ;;
[Rr]*) confirm="ok"; auto="r"; ;;
[Ff]*) confirm="ok"; auto="" ;;
esac
else echo ""
echo "No old /home found. Doing full install."
echo ""
confirm="ok";
fi
done
rmdir $TMPMP
nohome="0"
homesize=""
if [ ! "$auto" = r ]
then
echo ""
echo " --- Step 5: Select the size of /home ----------------------------------"
while [ -z "$homesize" ]
do
# 20% of what is left over after / and /usr
# are taken.
defmb="`expr $maxhome / 5`"
if [ "$defmb" -gt "$maxhome" ]
then
defmb=$maxhome
fi
echo ""
echo "MINIX will take up $TOTALMB MB, without /home."
echo -n "How big do you want your /home to be in MB (0-$maxhome) ? [$defmb] "
read homesize
if [ "$homesize" = "" ] ; then homesize=$defmb; fi
if [ "$homesize" -lt 1 ]
then nohome=1
echo "Ok, not making a /home."
homesize=0
else
if [ "$homesize" -gt "$maxhome" ]
then echo "That won't fit!"
homesize=""
else
echo ""
echo -n "$homesize MB Ok? [Y] "
read ok
[ "$ok" = Y -o "$ok" = y -o "$ok" = "" ] || homesize=""
fi
fi
echo ""
done
# Homesize in sectors
homemb="$homesize MB"
homesize="`expr $homesize '*' 1024 '*' 2`"
else
# Root size same as our default? If not, warn and keep old root size
ROOTSECTSDEFAULT=$ROOTSECTS
ROOTSECTS="`devsize /dev/$root`"
ROOTMB="`expr $ROOTSECTS / 2048`"
if [ $ROOTSECTS -ne $ROOTSECTSDEFAULT ]
then
# Check if we
echo "Root partition size `expr $ROOTSECTS / 2`kb differs from default `expr $ROOTSECTSDEFAULT / 2`kb."
echo "This is not a problem, but you may want to do a fresh install at some point to"
echo "be able to benefit from the new default."
fi
# Check if enough space for new boot (even if old used)
bootspace=$((`devsize /dev/$primary`-`devsize /dev/$root`-`devsize /dev/$home`-`devsize /dev/$usr`)) >/dev/null
if [ $bootspace -lt $BOOTXXSECTS ]
then
echo "Root partition size will be reduced by up to 16Kb to fit new bootloader."
echo "This is not a problem."
ROOTSECTS=`expr $ROOTSECTS - $BOOTXXSECTS + $bootspace`
fi
# Recompute totals based on root size
TOTALMB="`expr 3 + $USRKB / 1024 + $ROOTMB`"
maxhome="`expr $devsizemb - $TOTALMB - 1`"
homepart="`devsize /dev/$home`"
homesize="`expr $homepart / 2 / 1024`"
if [ "$homesize" -gt "$maxhome" ]
then
echo "Sorry, but your /home is too big ($homesize MB) to leave enough"
echo "space on the rest of the partition ($devsizemb MB) for your"
echo "selected installation size ($TOTALMB MB)."
exit 1
fi
# Homesize unchanged (reinstall)
homesize=exist
homemb="current size"
fi
minblocksize=1
maxblocksize=64
blockdefault=4
if [ ! "$auto" = "r" ]
then
echo ""
echo " --- Step 6: Select a block size ---------------------------------------"
echo ""
echo "The default file system block size is $blockdefault kB."
echo ""
while [ -z "$blocksize" ]
do
echo -n "Block size in kilobytes? [$blockdefault] "; read blocksize
test -z "$blocksize" && blocksize=$blockdefault
if [ "$blocksize" -lt $minblocksize -o "$blocksize" -gt $maxblocksize ]
then
warn "At least $minblocksize kB and at most $maxblocksize kB please."
blocksize=""
fi
done
else
blocksize=$blockdefault
fi
blocksizebytes="`expr $blocksize '*' 1024`"
bootsectors=$BOOTXXSECTS
check_mbr
echo "
You have selected to (re)install MINIX 3 in the partition /dev/$primary.
The following subpartitions are now being created on /dev/$primary:
Root subpartition: /dev/$root $ROOTMB MB
/home subpartition: /dev/$home $homemb
/usr subpartition: /dev/$usr rest of $primary
"
# Secondary master bootstrap.
# New boot doesn't require mbr on pN (bootxx will be there)
# When necessarily mbr is installed on dN by partition.
# Partition the primary.
partition /dev/$primary $bootsectors 81:${ROOTSECTS}* 81:$homesize 81:0+ > /dev/null || exit
echo "Creating /dev/$root for / .."
mkfs.mfs /dev/$root || exit
if [ "$nohome" = 0 ]
then
if [ ! "$auto" = r ]
then echo "Creating /dev/$home for /home .."
mkfs.$FSTYPE -B $blocksizebytes /dev/$home || exit
fi
else echo "Skipping /home"
fi
echo "Creating /dev/$usr for /usr .."
mkfs.$FSTYPE -B $blocksizebytes /dev/$usr || exit
if [ "$nohome" = 0 ]
then
fshome="/dev/$home /home $FSTYPE rw 0 2"
else fshome=""
fi
echo ""
echo " --- Step 7: Wait for files to be copied -------------------------------"
echo ""
echo "All files will now be copied to your hard disk. This may take a while."
echo ""
mount /dev/$root /mnt >/dev/null || exit
mkdir -p /mnt/usr
mount /dev/$usr /mnt/usr >/dev/null || exit # Mount the intended /usr.
if [ "$nohome" = 0 ]; then
mkdir -p /mnt/home
mount /dev/$home /mnt/home >/dev/null || exit # Mount the intended /home
fi
# Running from the installation CD.
for set in /i386/binary/sets/*.tgz; do
echo "Extracting $(basename "$set")..."
COUNT_FILES=$(cat $(echo "$set" | sed -e "s/\.tgz/\.count/"))
(cd /mnt; pax -rz -f $set -v -pe 2>&1 | progressbar "$COUNT_FILES" || exit)
done;
echo "Creating device nodes..."
(cd /mnt/dev; MAKEDEV -s all)
# Fix permissions
chmod $(stat -f %Lp /usr) /mnt/usr
chown $(stat -f %u /usr) /mnt/usr
chgrp $(stat -f %g /usr) /mnt/usr
if [ "$nohome" = 0 ]; then
chmod $(stat -f %Lp /home) /mnt/home
chown $(stat -f %u /home) /mnt/home
chgrp $(stat -f %g /home) /mnt/home
fi
# CD remnants that aren't for the installed system
rm /mnt/etc/issue /mnt/CD /mnt/.* 2>/dev/null
echo >/mnt/etc/fstab "/dev/$root / mfs rw 0 1
/dev/$usr /usr $FSTYPE rw 0 2
$fshome
none /sys devman rw,rslabel=devman 0 0
none /dev/pts ptyfs rw,rslabel=ptyfs 0 0"
# National keyboard map.
test -n "$keymap" && cp -p "/usr/lib/keymaps/$keymap.map" /mnt/etc/keymap
# XXX we have to use "-f" here, because installboot worries about BPB, which
# we don't have...
installboot_nbsd -f /dev/$primary /usr/mdec/bootxx_minixfs3 >/dev/null || exit
# give the install the boot loader
cp /usr/mdec/boot_monitor /mnt/
minixdir=/mnt/boot/minix_default
if [ ! -f $minixdir/kernel ]
then rm -rf $minixdir
cp -r /mnt/boot/minix/.temp $minixdir
fi
if [ ! -e /mnt/boot/minix_latest ]
then ln -sf minix_default /mnt/boot/minix_latest
fi
chroot /mnt update_bootcfg
bios="`echo $primary | sed -e 's/d./dX/g' -e 's/c.//g'`"
echo "Saving random data.."
dd if=/dev/random of=/mnt/usr/adm/random.dat bs=1024 count=1
# Networking.
echo ""
echo " --- Step 8: Select your Ethernet chip ---------------------------------"
echo ""
/bin/netconf -p /mnt || echo FAILED TO CONFIGURE NETWORK
PACKAGES_DIR="/packages/$(uname -v | cut -f2 -d' ')/$(uname -p)/All"
if [ -e "$PACKAGES_DIR" ]
then
echo "Installing pkgin..."
sh -c "cp $PACKAGES_DIR/pkgin-* $PACKAGES_DIR/pkg_install-* $PACKAGES_DIR/libarchive-* /mnt/tmp &&
chroot /mnt pkg_add /tmp/pkgin-*"
rm -f /mnt/tmp/*
# Save name of CD drive
cddrive=$(mount | grep ' on / ' | cut -f1 -d' ')
echo "cddrive=$cddrive" >>/mnt/usr/etc/rc.package
else
echo "Package dir not found, skipping pkgin installation..."
fi
if [ "$nohome" = 0 ]; then
umount /dev/$home && echo Unmounted $home
fi
umount /dev/$usr && echo Unmounted $usr
umount /dev/$root && echo Unmounted $root
echo "
Please type 'shutdown -r now' to exit MINIX 3 and reboot. To boot into
your new system, you might have to remove the installation media.
This ends the MINIX 3 setup script. You may want to take care of post
installation steps, such as local testing and configuration.
Please consult the user manual for more information.
"

View File

@ -1,441 +0,0 @@
/******************************************************************************
*
* Name: acenv.h - Host and compiler configuration
*
*****************************************************************************/
/*
* Copyright (C) 2000 - 2014, Intel Corp.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer,
* without modification.
* 2. Redistributions in binary form must reproduce at minimum a disclaimer
* substantially similar to the "NO WARRANTY" disclaimer below
* ("Disclaimer") and any redistribution must be conditioned upon
* including a substantially similar Disclaimer requirement for further
* binary redistribution.
* 3. Neither the names of the above-listed copyright holders nor the names
* of any contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* Alternatively, this software may be distributed under the terms of the
* GNU General Public License ("GPL") version 2 as published by the Free
* Software Foundation.
*
* NO WARRANTY
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGES.
*/
#ifndef __ACENV_H__
#define __ACENV_H__
/*
* Environment configuration. The purpose of this file is to interface ACPICA
* to the local environment. This includes compiler-specific, OS-specific,
* and machine-specific configuration.
*/
/* Types for ACPI_MUTEX_TYPE */
#define ACPI_BINARY_SEMAPHORE 0
#define ACPI_OSL_MUTEX 1
/* Types for DEBUGGER_THREADING */
#define DEBUGGER_SINGLE_THREADED 0
#define DEBUGGER_MULTI_THREADED 1
/******************************************************************************
*
* Configuration for ACPI tools and utilities
*
*****************************************************************************/
/* iASL configuration */
#ifdef ACPI_ASL_COMPILER
#define ACPI_APPLICATION
#define ACPI_DISASSEMBLER
#define ACPI_DEBUG_OUTPUT
#define ACPI_CONSTANT_EVAL_ONLY
#define ACPI_LARGE_NAMESPACE_NODE
#define ACPI_DATA_TABLE_DISASSEMBLY
#define ACPI_SINGLE_THREADED
#endif
/* AcpiExec configuration. Multithreaded with full AML debugger */
#ifdef ACPI_EXEC_APP
#define ACPI_APPLICATION
#define ACPI_FULL_DEBUG
#define ACPI_MUTEX_DEBUG
#define ACPI_DBG_TRACK_ALLOCATIONS
#endif
/*
* AcpiBin/AcpiDump/AcpiHelp/AcpiNames/AcpiSrc/AcpiXtract/Example configuration.
* All single threaded.
*/
#if (defined ACPI_BIN_APP) || \
(defined ACPI_DUMP_APP) || \
(defined ACPI_HELP_APP) || \
(defined ACPI_NAMES_APP) || \
(defined ACPI_SRC_APP) || \
(defined ACPI_XTRACT_APP) || \
(defined ACPI_EXAMPLE_APP)
#define ACPI_APPLICATION
#define ACPI_SINGLE_THREADED
#endif
/* AcpiHelp configuration. Error messages disabled. */
#ifdef ACPI_HELP_APP
#define ACPI_NO_ERROR_MESSAGES
#endif
/* AcpiNames configuration. Debug output enabled. */
#ifdef ACPI_NAMES_APP
#define ACPI_DEBUG_OUTPUT
#endif
/* AcpiExec/AcpiNames/Example configuration. Native RSDP used. */
#if (defined ACPI_EXEC_APP) || \
(defined ACPI_EXAMPLE_APP) || \
(defined ACPI_NAMES_APP)
#define ACPI_USE_NATIVE_RSDP_POINTER
#endif
/* AcpiDump configuration. Native mapping used if provied by OSPMs */
#ifdef ACPI_DUMP_APP
#define ACPI_USE_NATIVE_MEMORY_MAPPING
#define USE_NATIVE_ALLOCATE_ZEROED
#endif
/* AcpiNames/Example configuration. Hardware disabled */
#if (defined ACPI_EXAMPLE_APP) || \
(defined ACPI_NAMES_APP)
#define ACPI_REDUCED_HARDWARE 1
#endif
/* Linkable ACPICA library */
#ifdef ACPI_LIBRARY
#define ACPI_USE_LOCAL_CACHE
#endif
/* Common for all ACPICA applications */
#ifdef ACPI_APPLICATION
#define ACPI_USE_SYSTEM_CLIBRARY
#define ACPI_USE_LOCAL_CACHE
#endif
/* Common debug support */
#ifdef ACPI_FULL_DEBUG
#define ACPI_DEBUGGER
#define ACPI_DEBUG_OUTPUT
#define ACPI_DISASSEMBLER
#endif
/*! [Begin] no source code translation */
/******************************************************************************
*
* Host configuration files. The compiler configuration files are included
* by the host files.
*
*****************************************************************************/
#if defined(_LINUX) || defined(__linux__)
#include "aclinux.h"
#elif defined(_APPLE) || defined(__APPLE__)
#include "acmacosx.h"
#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
#include "acfreebsd.h"
#elif defined(__NetBSD__)
#include "acnetbsd.h"
#elif defined(__sun)
#include "acsolaris.h"
#elif defined(MODESTO)
#include "acmodesto.h"
#elif defined(NETWARE)
#include "acnetware.h"
#elif defined(_CYGWIN)
#include "accygwin.h"
#elif defined(WIN32)
#include "acwin.h"
#elif defined(WIN64)
#include "acwin64.h"
#elif defined(_WRS_LIB_BUILD)
#include "acvxworks.h"
#elif defined(__OS2__)
#include "acos2.h"
#elif defined(_AED_EFI)
#include "acefi.h"
#elif defined(_GNU_EFI)
#include "acefi.h"
#elif defined(__HAIKU__)
#include "achaiku.h"
#elif defined(__minix)
#include "acminix.h"
#else
/* Unknown environment */
#error Unknown target environment
#endif
/*! [End] no source code translation !*/
/******************************************************************************
*
* Setup defaults for the required symbols that were not defined in one of
* the host/compiler files above.
*
*****************************************************************************/
/* 64-bit data types */
#ifndef COMPILER_DEPENDENT_INT64
#define COMPILER_DEPENDENT_INT64 long long
#endif
#ifndef COMPILER_DEPENDENT_UINT64
#define COMPILER_DEPENDENT_UINT64 unsigned long long
#endif
/* Type of mutex supported by host. Default is binary semaphores. */
#ifndef ACPI_MUTEX_TYPE
#define ACPI_MUTEX_TYPE ACPI_BINARY_SEMAPHORE
#endif
/* Global Lock acquire/release */
#ifndef ACPI_ACQUIRE_GLOBAL_LOCK
#define ACPI_ACQUIRE_GLOBAL_LOCK(GLptr, Acquired) Acquired = 1
#endif
#ifndef ACPI_RELEASE_GLOBAL_LOCK
#define ACPI_RELEASE_GLOBAL_LOCK(GLptr, Pending) Pending = 0
#endif
/* Flush CPU cache - used when going to sleep. Wbinvd or similar. */
#ifndef ACPI_FLUSH_CPU_CACHE
#define ACPI_FLUSH_CPU_CACHE()
#endif
/* "inline" keywords - configurable since inline is not standardized */
#ifndef ACPI_INLINE
#define ACPI_INLINE
#endif
/*
* Configurable calling conventions:
*
* ACPI_SYSTEM_XFACE - Interfaces to host OS (handlers, threads)
* ACPI_EXTERNAL_XFACE - External ACPI interfaces
* ACPI_INTERNAL_XFACE - Internal ACPI interfaces
* ACPI_INTERNAL_VAR_XFACE - Internal variable-parameter list interfaces
*/
#ifndef ACPI_SYSTEM_XFACE
#define ACPI_SYSTEM_XFACE
#endif
#ifndef ACPI_EXTERNAL_XFACE
#define ACPI_EXTERNAL_XFACE
#endif
#ifndef ACPI_INTERNAL_XFACE
#define ACPI_INTERNAL_XFACE
#endif
#ifndef ACPI_INTERNAL_VAR_XFACE
#define ACPI_INTERNAL_VAR_XFACE
#endif
/*
* Debugger threading model
* Use single threaded if the entire subsystem is contained in an application
* Use multiple threaded when the subsystem is running in the kernel.
*
* By default the model is single threaded if ACPI_APPLICATION is set,
* multi-threaded if ACPI_APPLICATION is not set.
*/
#ifndef DEBUGGER_THREADING
#ifdef ACPI_APPLICATION
#define DEBUGGER_THREADING DEBUGGER_SINGLE_THREADED
#else
#define DEBUGGER_THREADING DEBUGGER_MULTI_THREADED
#endif
#endif /* !DEBUGGER_THREADING */
/******************************************************************************
*
* C library configuration
*
*****************************************************************************/
/*
* ACPI_USE_SYSTEM_CLIBRARY - Define this if linking to an actual C library.
* Otherwise, local versions of string/memory functions will be used.
* ACPI_USE_STANDARD_HEADERS - Define this if linking to a C library and
* the standard header files may be used.
*
* The ACPICA subsystem only uses low level C library functions that do not call
* operating system services and may therefore be inlined in the code.
*
* It may be necessary to tailor these include files to the target
* generation environment.
*/
#ifdef ACPI_USE_SYSTEM_CLIBRARY
/* Use the standard C library headers. We want to keep these to a minimum. */
#ifdef ACPI_USE_STANDARD_HEADERS
/* Use the standard headers from the standard locations */
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#endif /* ACPI_USE_STANDARD_HEADERS */
/* We will be linking to the standard Clib functions */
#define ACPI_STRSTR(s1,s2) strstr((s1), (s2))
#define ACPI_STRCHR(s1,c) strchr((s1), (c))
#define ACPI_STRLEN(s) (ACPI_SIZE) strlen((s))
#define ACPI_STRCPY(d,s) (void) strcpy((d), (s))
#define ACPI_STRNCPY(d,s,n) (void) strncpy((d), (s), (ACPI_SIZE)(n))
#define ACPI_STRNCMP(d,s,n) strncmp((d), (s), (ACPI_SIZE)(n))
#define ACPI_STRCMP(d,s) strcmp((d), (s))
#define ACPI_STRCAT(d,s) (void) strcat((d), (s))
#define ACPI_STRNCAT(d,s,n) strncat((d), (s), (ACPI_SIZE)(n))
#define ACPI_STRTOUL(d,s,n) strtoul((d), (s), (ACPI_SIZE)(n))
#define ACPI_MEMCMP(s1,s2,n) memcmp((const char *)(s1), (const char *)(s2), (ACPI_SIZE)(n))
#define ACPI_MEMCPY(d,s,n) (void) memcpy((d), (s), (ACPI_SIZE)(n))
#define ACPI_MEMSET(d,s,n) (void) memset((d), (s), (ACPI_SIZE)(n))
#define ACPI_TOUPPER(i) toupper((int) (i))
#define ACPI_TOLOWER(i) tolower((int) (i))
#define ACPI_IS_XDIGIT(i) isxdigit((int) (i))
#define ACPI_IS_DIGIT(i) isdigit((int) (i))
#define ACPI_IS_SPACE(i) isspace((int) (i))
#define ACPI_IS_UPPER(i) isupper((int) (i))
#define ACPI_IS_PRINT(i) isprint((int) (i))
#define ACPI_IS_ALPHA(i) isalpha((int) (i))
#else
/******************************************************************************
*
* Not using native C library, use local implementations
*
*****************************************************************************/
/*
* Use local definitions of C library macros and functions. These function
* implementations may not be as efficient as an inline or assembly code
* implementation provided by a native C library, but they are functionally
* equivalent.
*/
#ifndef va_arg
#ifndef _VALIST
#define _VALIST
typedef char *va_list;
#endif /* _VALIST */
/* Storage alignment properties */
#define _AUPBND (sizeof (ACPI_NATIVE_INT) - 1)
#define _ADNBND (sizeof (ACPI_NATIVE_INT) - 1)
/* Variable argument list macro definitions */
#define _Bnd(X, bnd) (((sizeof (X)) + (bnd)) & (~(bnd)))
#define va_arg(ap, T) (*(T *)(((ap) += (_Bnd (T, _AUPBND))) - (_Bnd (T,_ADNBND))))
#define va_end(ap) (ap = (va_list) NULL)
#define va_start(ap, A) (void) ((ap) = (((char *) &(A)) + (_Bnd (A,_AUPBND))))
#endif /* va_arg */
/* Use the local (ACPICA) definitions of the clib functions */
#define ACPI_STRSTR(s1,s2) AcpiUtStrstr ((s1), (s2))
#define ACPI_STRCHR(s1,c) AcpiUtStrchr ((s1), (c))
#define ACPI_STRLEN(s) (ACPI_SIZE) AcpiUtStrlen ((s))
#define ACPI_STRCPY(d,s) (void) AcpiUtStrcpy ((d), (s))
#define ACPI_STRNCPY(d,s,n) (void) AcpiUtStrncpy ((d), (s), (ACPI_SIZE)(n))
#define ACPI_STRNCMP(d,s,n) AcpiUtStrncmp ((d), (s), (ACPI_SIZE)(n))
#define ACPI_STRCMP(d,s) AcpiUtStrcmp ((d), (s))
#define ACPI_STRCAT(d,s) (void) AcpiUtStrcat ((d), (s))
#define ACPI_STRNCAT(d,s,n) AcpiUtStrncat ((d), (s), (ACPI_SIZE)(n))
#define ACPI_STRTOUL(d,s,n) AcpiUtStrtoul ((d), (s), (ACPI_SIZE)(n))
#define ACPI_MEMCMP(s1,s2,n) AcpiUtMemcmp((const char *)(s1), (const char *)(s2), (ACPI_SIZE)(n))
#define ACPI_MEMCPY(d,s,n) (void) AcpiUtMemcpy ((d), (s), (ACPI_SIZE)(n))
#define ACPI_MEMSET(d,v,n) (void) AcpiUtMemset ((d), (v), (ACPI_SIZE)(n))
#define ACPI_TOUPPER(c) AcpiUtToUpper ((int) (c))
#define ACPI_TOLOWER(c) AcpiUtToLower ((int) (c))
#endif /* ACPI_USE_SYSTEM_CLIBRARY */
#ifndef ACPI_FILE
#ifdef ACPI_APPLICATION
#include <stdio.h>
#define ACPI_FILE FILE *
#define ACPI_FILE_OUT stdout
#define ACPI_FILE_ERR stderr
#else
#define ACPI_FILE void *
#define ACPI_FILE_OUT NULL
#define ACPI_FILE_ERR NULL
#endif /* ACPI_APPLICATION */
#endif /* ACPI_FILE */
#endif /* __ACENV_H__ */

View File

@ -1,116 +0,0 @@
/******************************************************************************
*
* Name: acnetbsd.h - OS specific defines, etc.
*
*****************************************************************************/
/*
* Copyright (C) 2000 - 2014, Intel Corp.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer,
* without modification.
* 2. Redistributions in binary form must reproduce at minimum a disclaimer
* substantially similar to the "NO WARRANTY" disclaimer below
* ("Disclaimer") and any redistribution must be conditioned upon
* including a substantially similar Disclaimer requirement for further
* binary redistribution.
* 3. Neither the names of the above-listed copyright holders nor the names
* of any contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* Alternatively, this software may be distributed under the terms of the
* GNU General Public License ("GPL") version 2 as published by the Free
* Software Foundation.
*
* NO WARRANTY
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGES.
*/
#ifndef __ACNETBSD_H__
#define __ACNETBSD_H__
/* NetBSD uses GCC */
#include "acgcc.h"
#ifdef _LP64
#define ACPI_MACHINE_WIDTH 64
#else
#define ACPI_MACHINE_WIDTH 32
#endif
#define COMPILER_DEPENDENT_INT64 int64_t
#define COMPILER_DEPENDENT_UINT64 uint64_t
#ifdef _KERNEL
#include "opt_acpi.h" /* collect build-time options here */
#include <sys/param.h>
#include <sys/systm.h>
#include <machine/stdarg.h>
#include <machine/acpi_func.h>
#define asm __asm
#define ACPI_USE_NATIVE_DIVIDE
#define ACPI_SYSTEM_XFACE
#define ACPI_EXTERNAL_XFACE
#define ACPI_INTERNAL_XFACE
#define ACPI_INTERNAL_VAR_XFACE
#ifdef ACPI_DEBUG
#define ACPI_DEBUG_OUTPUT
#define ACPI_DBG_TRACK_ALLOCATIONS
#ifdef DEBUGGER_THREADING
#undef DEBUGGER_THREADING
#endif /* DEBUGGER_THREADING */
#define DEBUGGER_THREADING 0 /* integrated with DDB */
#include "opt_ddb.h"
#ifdef DDB
#define ACPI_DISASSEMBLER
#define ACPI_DEBUGGER
#endif /* DDB */
#endif /* ACPI_DEBUG */
static __inline int
isprint(int ch)
{
return(isspace(ch) || isascii(ch));
}
#else /* _KERNEL */
#include <ctype.h>
/* Not building kernel code, so use libc */
#define ACPI_USE_STANDARD_HEADERS
#define __cli()
#define __sti()
/* XXX */
#define __inline inline
#endif /* _KERNEL */
/* Always use NetBSD code over our local versions */
#define ACPI_USE_SYSTEM_CLIBRARY
#define ACPI_USE_NATIVE_DIVIDE
#endif /* __ACNETBSD_H__ */

View File

@ -1,51 +0,0 @@
This directory contains code to access MMC based devices.
It was created during the initial port of MINIX to the ARM platform. mmbclk
implements a normal MINIX block device. It uses the interfaces defined in
mmchost.h to perform it's operations.
mmchost_mmchs is the MMC host controller driver for the TI omap device range.
It contains the logic to access SD cards on that device.
drivers/mmc
|-- Makefile (The makefile)
|-- mmclog.h (A simpel logging system)
|-- omap_mmc.h (TI Omap register definitions)
|-- sdhcreg.h (BSD headers for the MMC layer)
|-- sdmmcreg.h (BSD headers for the MMC layer)
|-- mmcblk.c (MINIX 3 block device)
|-- mmchost.h (interface between the block device and the MMC layer)
|-- mmchost_mmchs.c (Driver to use on the ARM port/beagle)
'-- README.txt (This file)
Future work:
============
* Creating a more generic MMC layer
The SD protocol is well defined and the imported the netbsd sdhcreg and
sdmmcreg headers will allow us to make the MMC interface more generic. We would
like mmchost_mmchs to be split in a generic part and a specific part.
* 8 bits access
The driver currently only reads data over 1 or 4 bits address lines. Adding support
for 4 or 8 bits(for movinands) mode is very welcome.
* DMA.
The OMAP driver allows the usage of DMA. Adding DMA support will increase the
performance of the driver
* Removal of the PRIVCTL call.
The MMC driver uses memory mapped IO to perform it's operations. On i386 it is
the pci driver that will grant access to certain piece of memory to a driver.
On the ARM port we lack pci and other self describing busses. In the current
driver the driver will itself grant itself access to the correct piece of
memory but this is unwanted behavior. We currently as thinking about two
possible solutions. The first would be to add the memory ranges in system.conf.
The second would be to modify the PCI driver to grant access to memory based on
a fixed configuration. For example we could use the driver tree to perform
device discovery and granting access to devices.
* TODO removal
The driver contains (quite a few) TODO's where the code need to be improved.

File diff suppressed because it is too large Load Diff

View File

@ -1,397 +0,0 @@
#include <sys/cdefs.h>
#include "namespace.h"
#include <lib.h>
#include <stdarg.h>
#include <sys/ioctl.h>
#include <minix/i2c.h>
#include <string.h>
#include <sys/ioccom.h>
#include <stdarg.h>
#include <fcntl.h>
#include <stdlib.h>
#include <minix/if.h>
#include <minix/bpf.h>
#include <assert.h>
static void rewrite_i2c_netbsd_to_minix(minix_i2c_ioctl_exec_t *out,
i2c_ioctl_exec_t *in);
static void rewrite_i2c_minix_to_netbsd(i2c_ioctl_exec_t *out,
minix_i2c_ioctl_exec_t *in);
static void rewrite_i2c_netbsd_to_minix(minix_i2c_ioctl_exec_t *out,
i2c_ioctl_exec_t *in)
{
memset(out, '\0', sizeof(minix_i2c_ioctl_exec_t));
out->iie_op = in->iie_op;
out->iie_addr = in->iie_addr;
out->iie_cmdlen = I2C_EXEC_MAX_CMDLEN < in->iie_cmdlen ?
I2C_EXEC_MAX_CMDLEN : in->iie_cmdlen;
out->iie_buflen = I2C_EXEC_MAX_BUFLEN < in->iie_buflen ?
I2C_EXEC_MAX_BUFLEN : in->iie_buflen;
if (in->iie_cmdlen > 0 && in->iie_cmd != NULL) {
memcpy(out->iie_cmd, in->iie_cmd, in->iie_cmdlen);
}
if (in->iie_buflen > 0 && in->iie_buf != NULL) {
memcpy(out->iie_buf, in->iie_buf, in->iie_buflen);
}
}
static void rewrite_i2c_minix_to_netbsd(i2c_ioctl_exec_t *out,
minix_i2c_ioctl_exec_t *in)
{
/* the only field that changes is iie_buf, everything else is the same */
if (in->iie_buflen > 0 ) {
memcpy(out->iie_buf, in->iie_buf, in->iie_buflen);
}
}
/*
* Convert a network interface related IOCTL with pointers to a flat format
* suitable for MINIX3. Return a pointer to the new data on success, or zero
* (with errno set) on failure. The original request code is given in
* 'request' and must be replaced by the new request code to be used.
*/
static vir_bytes
ioctl_convert_if_to_minix(void * data, unsigned long * request)
{
struct minix_ifmediareq *mifm;
struct ifmediareq *ifm;
struct minix_if_clonereq *mifcr;
struct if_clonereq *ifcr;
switch (*request) {
case SIOCGIFMEDIA:
ifm = (struct ifmediareq *)data;
mifm = (struct minix_ifmediareq *)malloc(sizeof(*mifm));
if (mifm != NULL) {
/*
* The count may exceed MINIX_IF_MAXMEDIA, and should
* be truncated as needed by the IF implementation.
*/
memcpy(&mifm->mifm_ifm, ifm, sizeof(*ifm));
*request = MINIX_SIOCGIFMEDIA;
} else
errno = ENOMEM;
return (vir_bytes)mifm;
case SIOCIFGCLONERS:
ifcr = (struct if_clonereq *)data;
mifcr = (struct minix_if_clonereq *)malloc(sizeof(*mifcr));
if (mifcr != NULL) {
/*
* The count may exceed MINIX_IF_MAXCLONERS, and should
* be truncated as needed by the IF implementation.
*/
memcpy(&mifcr->mifcr_ifcr, ifcr, sizeof(*ifcr));
*request = MINIX_SIOCIFGCLONERS;
} else
errno = ENOMEM;
return (vir_bytes)mifcr;
default:
assert(0);
errno = ENOTTY;
return 0;
}
}
/*
* Convert a the result of a network interface related IOCTL with pointers from
* the flat format used to make the call to MINIX3. Called on success only.
* The given request code is that of the (NetBSD-type) original.
*/
static void
ioctl_convert_if_from_minix(vir_bytes addr, void * data, unsigned long request)
{
struct minix_ifmediareq *mifm;
struct ifmediareq *ifm;
struct minix_if_clonereq *mifcr;
struct if_clonereq *ifcr;
int count;
switch (request) {
case SIOCGIFMEDIA:
mifm = (struct minix_ifmediareq *)addr;
ifm = (struct ifmediareq *)data;
memcpy(ifm, &mifm->mifm_ifm, sizeof(*ifm));
if (ifm->ifm_ulist != NULL && ifm->ifm_count > 0)
memcpy(ifm->ifm_ulist, mifm->mifm_list,
ifm->ifm_count * sizeof(ifm->ifm_ulist[0]));
break;
case SIOCIFGCLONERS:
mifcr = (struct minix_if_clonereq *)addr;
ifcr = (struct if_clonereq *)data;
memcpy(ifcr, &mifcr->mifcr_ifcr, sizeof(*ifcr));
count = (ifcr->ifcr_count < ifcr->ifcr_total) ?
ifcr->ifcr_count : ifcr->ifcr_total;
if (ifcr->ifcr_buffer != NULL && count > 0)
memcpy(ifcr->ifcr_buffer, mifcr->mifcr_buffer,
count * IFNAMSIZ);
break;
default:
assert(0);
}
}
/*
* Convert a BPF (Berkeley Packet Filter) related IOCTL with pointers to a flat
* format suitable for MINIX3. Return a pointer to the new data on success, or
* zero (with errno set) on failure. The original request code is given in
* 'request' and must be replaced by the new request code to be used.
*/
static vir_bytes
ioctl_convert_bpf_to_minix(void * data, unsigned long * request)
{
struct minix_bpf_program *mbf;
struct bpf_program *bf;
struct minix_bpf_dltlist *mbfl;
struct bpf_dltlist *bfl;
switch (*request) {
case BIOCSETF:
bf = (struct bpf_program *)data;
if (bf->bf_len > __arraycount(mbf->mbf_insns)) {
errno = EINVAL;
return 0;
}
mbf = (struct minix_bpf_program *)malloc(sizeof(*mbf));
if (mbf != NULL) {
mbf->mbf_len = bf->bf_len;
memcpy(mbf->mbf_insns, bf->bf_insns,
bf->bf_len * sizeof(mbf->mbf_insns[0]));
*request = MINIX_BIOCSETF;
} else
errno = ENOMEM;
return (vir_bytes)mbf;
case BIOCGDLTLIST:
bfl = (struct bpf_dltlist *)data;
mbfl = (struct minix_bpf_dltlist *)malloc(sizeof(*mbfl));
if (mbfl != NULL) {
/*
* The length may exceed MINIX_BPF_MAXDLT, and should
* be truncated as needed by the BPF implementation.
*/
memcpy(&mbfl->mbfl_dltlist, bfl, sizeof(*bfl));
*request = MINIX_BIOCGDLTLIST;
} else
errno = ENOMEM;
return (vir_bytes)mbfl;
default:
assert(0);
errno = ENOTTY;
return 0;
}
}
/*
* Convert a the result of BPF (Berkeley Packet Filter) related IOCTL with
* pointers from the flat format used to make the call to MINIX3. Called on
* success only. The given request code is that of the (NetBSD-type) original.
*/
static void
ioctl_convert_bpf_from_minix(vir_bytes addr, void * data,
unsigned long request)
{
struct minix_bpf_dltlist *mbfl;
struct bpf_dltlist *bfl;
switch (request) {
case BIOCGDLTLIST:
mbfl = (struct minix_bpf_dltlist *)addr;
bfl = (struct bpf_dltlist *)data;
memcpy(bfl, &mbfl->mbfl_dltlist, sizeof(*bfl));
if (bfl->bfl_list != NULL && bfl->bfl_len > 0)
memcpy(bfl->bfl_list, mbfl->mbfl_list,
bfl->bfl_len * sizeof(bfl->bfl_list[0]));
break;
default:
assert(0);
}
}
/*
* Library implementation of FIOCLEX and FIONCLEX.
*/
static int
ioctl_to_setfd(int fd, int mask, int val)
{
int fl;
if ((fl = fcntl(fd, F_GETFD)) == -1)
return -1;
fl = (fl & ~mask) | val;
return fcntl(fd, F_SETFD, fl);
}
/*
* Library implementation of FIONBIO and FIOASYNC.
*/
static int
ioctl_to_setfl(int fd, void * data, int sfl)
{
int arg, fl;
arg = *(int *)data;
if ((fl = fcntl(fd, F_GETFL)) == -1)
return -1;
if (arg)
fl |= sfl;
else
fl &= ~sfl;
return fcntl(fd, F_SETFL, fl & ~O_ACCMODE);
}
/*
* Library implementation of various deprecated IOCTLs. These particular IOCTL
* calls change how the file descriptors behave, and have nothing to do with
* the actual open file. They should therefore be handled by VFS rather than
* individual device drivers. We rewrite them to use fcntl(2) instead here.
*/
static int
ioctl_to_fcntl(int fd, unsigned long request, void * data)
{
switch (request) {
case FIOCLEX:
return ioctl_to_setfd(fd, FD_CLOEXEC, FD_CLOEXEC);
case FIONCLEX:
return ioctl_to_setfd(fd, FD_CLOEXEC, 0);
case FIONBIO:
return ioctl_to_setfl(fd, data, O_NONBLOCK);
case FIOASYNC:
return ioctl_to_setfl(fd, data, O_ASYNC);
case FIOSETOWN: /* XXX TODO */
case FIOGETOWN: /* XXX TODO */
default:
errno = ENOTTY;
return -1;
}
}
int ioctl(int fd, unsigned long request, ...)
{
minix_i2c_ioctl_exec_t i2c;
int r, request_save;
message m;
vir_bytes addr;
void *data;
va_list ap;
va_start(ap, request);
data = va_arg(ap, void *);
va_end(ap);
/*
* To support compatibility with interfaces on other systems, certain
* requests are re-written to flat structures (i.e. without pointers).
*/
request_save = request;
switch (request) {
case FIOCLEX:
case FIONCLEX:
case FIONBIO:
case FIOASYNC:
case FIOSETOWN:
case FIOGETOWN:
return ioctl_to_fcntl(fd, request, data);
case I2C_IOCTL_EXEC:
rewrite_i2c_netbsd_to_minix(&i2c, data);
addr = (vir_bytes) &i2c;
request = MINIX_I2C_IOCTL_EXEC;
break;
case SIOCGIFMEDIA:
case SIOCIFGCLONERS:
if ((addr = ioctl_convert_if_to_minix(data, &request)) == 0)
return -1; /* errno has already been set */
break;
case BIOCSETF:
case BIOCGDLTLIST:
if ((addr = ioctl_convert_bpf_to_minix(data, &request)) == 0)
return -1; /* errno has already been set */
break;
default:
/* Keep original as-is */
addr = (vir_bytes)data;
break;
}
memset(&m, 0, sizeof(m));
m.m_lc_vfs_ioctl.fd = fd;
m.m_lc_vfs_ioctl.req = request;
m.m_lc_vfs_ioctl.arg = addr;
r = _syscall(VFS_PROC_NR, VFS_IOCTL, &m);
/*
* Translate back to original form. Do this on failure as well, as
* temporarily allocated resources may have to be freed up again.
*/
switch (request_save) {
case I2C_IOCTL_EXEC:
rewrite_i2c_minix_to_netbsd(data, &i2c);
break;
case SIOCGIFMEDIA:
case SIOCIFGCLONERS:
if (r == 0)
ioctl_convert_if_from_minix(addr, data, request_save);
free((void *)addr);
break;
case BIOCGDLTLIST:
if (r == 0)
ioctl_convert_bpf_from_minix(addr, data, request_save);
/* FALLTHROUGH */
case BIOCSETF:
free((void *)addr);
break;
default:
/* Nothing to do */
break;
}
return r;
}

View File

@ -1,250 +0,0 @@
.\" $NetBSD: boot.cfg.5,v 1.24 2011/11/28 09:38:45 wiz Exp $
.\"
.\" Copyright (c) 2007 Stephen Borrill
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. The name of the author may not be used to endorse or promote products
.\" derived from this software without specific prior written permission
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
.\" INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd November 28, 2011
.Dt BOOT.CFG 5
.Os
.Sh NAME
.Nm boot.cfg
.Nd configuration file for /boot
.Sh DESCRIPTION
The file
.Pa /boot.cfg
is used to alter the behaviour of the standard boot loader described in
.Xr boot 8 .
Configuration changes include setting the timeout, choosing a console device,
altering the banner text and displaying a menu allowing boot commands to be
easily chosen.
If a
.Nm
file is not present, the system will boot as normal.
.Ss FILE FORMAT
The format of the file is a series of lines containing keyword/value pairs
separated by an equals sign
.Pq Sq = .
There should be no whitespace surrounding the equals sign.
Lines beginning with a hash
.Pq Sq #
are comments and will be ignored.
.Pp
Some keywords can be present multiple times in the file to define additional
items.
Such keywords are noted below.
.Pp
.Bl -tag -width timeout
.It Sy banner
(may be present multiple times)
The text from banner lines is displayed instead of the standard welcome text
by the boot loader.
Up to 10 lines can be defined.
No special character sequences are recognised, so to specify a blank line, a
banner line with no value should be given.
.It Sy clear
If nonzero, clear the screen before printing the banner.
If zero, do not clear the screen (the default).
.It Sy consdev
Changes the console device to that specified in the value.
Valid values are any of those that could be specified at the normal boot
prompt with the consdev command.
.It Sy default
Used to specify the default menu item which will be chosen in the case of
Return being pressed or the timeout timer reaching zero.
The value is the number of the menu item as displayed.
As described above, the menu items are counted from 1 in the order listed in
.Nm .
If not specified, the default value will be option 1, i.e. the first item.
.It Sy format
Changes how the menu options are displayed.
Should be set to one of
.Sq a
for automatic,
.Sq l
for letters and
.Sq n
for numbers.
If set to automatic (the default), menu options will be displayed numerically
unless there are more than 9 options and the timeout is greater than zero.
If there are more than 9 options with a timeout greater than zero and
the format is set to number, only the first 9 options will be available.
.It Sy load
Used to load kernel modules, which will be passed on to the kernel for
initialization during early boot.
The argument is either the complete path and file name of the module to be
loaded, or a symbolic module name.
When the argument is not an absolute path, the boot loader will first
attempt to load
.Pa /stand/\*[Lt]machine\*[Gt]/\*[Lt]kernel_version\*[Gt]/modules/\*[Lt]name\*[Gt]/\*[Lt]name\*[Gt].kmod .
If that file does not exist, it will then attempt to load
.Pa /\*[Lt]name\*[Gt] .
May be used as many times as needed.
.It Sy menu
(may be present multiple times)
Used to define a menu item to be displayed to the end-user at boot time
which allows a series of boot commands to be run without further typing.
The value consists of the required menu text, followed by a colon
.Pq Sq \&:
and then the desired command(s).
Multiple commands can be specified separated by a semi-colon.
If the specified menu text is empty
(the colon appears immediately after the equals sign),
then the displayed menu text is the same as the command.
For example:
.Bd -literal
menu=Boot normally:boot
menu=Boot single-user:boot -s
menu=Boot with module foo:load /foo.kmod;boot
menu=Boot with serial console:consdev com0;boot
menu=:boot hd1a:netbsd -as
.Ed
.Pp
Each menu item will be prefixed by an ascending number when displayed,
i.e. the order in the
.Nm
file is important.
.Pp
Each command is executed just as though the user had typed it in
and so can be any valid command that would be accepted at the
normal boot prompt.
In addition,
.Dq Ic edit
can be used to put the menu in editing mode, allowing the user to modify the
next selected option before executing it, and
.Dq Ic prompt
can be used to drop to the normal boot prompt.
.It Sy timeout
If the value is greater than zero, this specifies the time in seconds
that the boot loader will wait for the end-user to choose a menu item.
During the countdown period, they may press Return to choose the default
option or press a number key corresponding to a menu option.
If any other key is pressed, the countdown will stop and the user will be
prompted to choose a menu option with no further time limit.
If the timeout value is set to zero, the default option will be booted
immediately.
If the timeout value is negative or is not a number, there will be no
time limit for the user to choose an option.
.It Sy userconf
Passes a
.Xr userconf 4
command to the kernel at boot time .
.It Sy rndseed
Takes the path to a random-seed file as written by the
.Fl S
flag to
.Xr rndctl 8
as an argument.
This file is used to seed the kernel entropy pool
.Xr rnd 9
very early in kernel startup, so that high quality randomness is
available to all kernel modules.
This argument should be supplied
before any
.Dq Ic load
commands that may load executable modules.
.El
.Sh EXAMPLES
Here is an example
.Nm
file:
.Bd -literal -offset indent
banner=Welcome to MINIX
banner==================
banner=
banner=Please choose an option from the following menu:
menu=Boot normally:boot
menu=Boot single-user:boot -s
menu=Boot from second disk:boot hd1a:
menu=Boot with module foo:load /foo.kmod;boot
menu=Boot with modules foo and bar:load /foo.kmod;load /bar.kmod;boot
menu=Boot Xen with 256MB for dom0:load /netbsd-XEN3_DOM0 console=pc;multiboot /usr/pkg/xen3-kernel/xen.gz dom0_mem=256M
menu=Boot Xen with 256MB for dom0 (serial):load /netbsd-XEN3_DOM0 console=com0;multiboot /usr/pkg/xen3-kernel/xen.gz dom0_mem=256M console=com1 com1=115200,8n1
menu=Boot Xen with dom0 in single-user mode:load /netbsd-XEN3_DOM0 -s;multiboot /usr/pkg/xen3-kernel/xen.gz dom0_mem=256M
menu=Go to command line (advanced users only):prompt
clear=1
timeout=-1
default=1
userconf disable ehci*
# Always load ramdisk module
load=/miniroot.kmod
.Ed
.Pp
N.B. Xen counts serial ports from com1 upwards, but
.Mx
counts from com0, so the appropriate device name must be used.
Please see the Xen with serial console example above.
.Pp
This will clear the screen and display:
.Bd -literal -offset indent
Welcome to MINIX
=================
Please choose an option from the following menu:
1. Boot normally
2. Boot single-user
3. Boot from second disk
4. Boot with module foo
5. Boot with modules foo and bar
6. Boot Xen with 256 MB for dom0
7. Boot Xen with 256 MB for dom0 (serial)
8. Boot Xen with dom0 in single-user mode
9. Go to command line (advanced users only)
Option [1]:
.Ed
.Pp
It will then wait for the user to type 1, 2, 3, 4, 5, 6, 7, 8 or 9 followed by
Return.
Pressing Return by itself will run option 1.
There will be no timeout.
.Sh SEE ALSO
.Xr boot 8 ,
.Xr boothowto 9
.Sh HISTORY
The
.Nm
file appeared in
MINIX 3.
.Sh AUTHORS
The
.Nm
extensions to
.Xr boot 8
were written by
.An Stephen Borrill
.Aq sborrill@NetBSD.org .
.Sh BUGS
Support for
.Nm
is currently for
.Mx Ns /i386
and
.Mx Ns /amd64
only.
It is hoped that its use will be extended to other appropriate ports that
use the
.Xr boot 8
interface.

View File

@ -1,651 +0,0 @@
.\" $NetBSD: boot.8,v 1.58 2011/05/31 03:43:47 uebayasi Exp $
.\"
.\" Copyright (c) 1991, 1993
.\" The Regents of the University of California. All rights reserved.
.\"
.\" This code is derived from software written and contributed
.\" to Berkeley by William Jolitz.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. Neither the name of the University nor the names of its contributors
.\" may be used to endorse or promote products derived from this software
.\" without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" @(#)boot_i386.8 8.2 (Berkeley) 4/19/94
.\"
.Dd May 26, 2011
.Dt BOOT 8 i386
.Os
.Sh NAME
.Nm boot
.Nd
system bootstrapping procedures
.Sh DESCRIPTION
.Tn IA-32
computers
.Po
the
.Tn IBM PC
and its clones
.Pc
that can run
.Nx Ns /i386
can use any of the following boot procedures, depending on what the hardware and
.Tn BIOS
support:
.Pp
.Bl -tag -width "pxeboot(8)"
.It boot
bootstrap
.Nx
from the system
.Tn BIOS
.It Xr dosboot 8
bootstrap
.Nx
from
.Tn MS-DOS
.It Xr w95boot 8
bootstrap
.Nx
from
.Tn Windows 95
.It Xr pxeboot 8
network bootstrap
.Nx
from a
.Tn TCP/IP
.Tn LAN
with
.Tn DHCP ,
.Tn TFTP ,
and
.Tn NFS .
.El
.Ss Power fail and crash recovery
Normally, the system will reboot itself at power-up or after crashes.
An automatic consistency check of the file systems will be performed,
and unless this fails, the system will resume multi-user operations.
.Ss Cold starts
The 386
.Tn "PC AT"
clones attempt to boot the floppy disk drive A (otherwise known as drive
0) first, and failing that, attempt to boot the hard disk C (otherwise
known as hard disk controller 1, drive 0).
The
.Nx
bootblocks are loaded and started either by the
.Tn BIOS ,
or by a boot selector program (such as OS-BS, BOOTEASY, the OS/2 Boot Menu or
.Nx Ns 's
.No boot-selecting
master boot record - see
.Xr mbr 8 ) .
.Ss Normal Operation
Once running, a banner similar to the following will appear:
.Bd -unfilled -offset indent
\*[Gt]\*[Gt] MINIX BIOS Boot, revision 3.0
\*[Gt]\*[Gt] (user@buildhost, builddate)
\*[Gt]\*[Gt] Memory: 637/15360 k
Press return to boot now, any other key for boot menu
booting hd0a:netbsd - starting in 5
.Ed
.Pp
After a countdown, the system image listed will be loaded.
In the example above, it will be
.Dq Li hd0a:netbsd
which is the file
.Nm netbsd
on partition
.Dq a
of the
.Nx
.Tn MBR
partition of the first hard disk known to the
.Tn BIOS
.Po
which is an
.Tn IDE
or similar device - see the
.Sx BUGS
section
.Pc .
.Pp
Pressing a key within the time limit, or before the boot program starts, will
enter interactive mode.
When using a short or 0 timeout, it is often useful to interrupt the boot
by holding down a shift key, as some BIOSes and BIOS extensions will drain the
keystroke buffer at various points during POST.
.Pp
If present, the file
.Pa /boot.cfg
will be used to configure the behaviour of the boot loader including
setting the timeout, choosing a console device, altering the banner
text and displaying a menu allowing boot commands to be easily chosen.
See
.Xr boot.cfg 5 .
.Pp
The
.Nx Ns /i386
boot loader can boot a kernel using either the native
.Nx
boot protocol, or the
.Dq multiboot
protocol (which is compatible with some other operating systems).
In the native
.Nx
boot protocol, options are passed from the boot loader
to the kernel via flag bits in the
.Va boothowto
variable (see
.Xr boothowto 9 ) .
In the multiboot protocol, options are passed from the boot loader
to the kernel as strings.
.Ss Diagnostic Output
If the first stage boot fails to load the boot, it will print a terse
message indicating the reason for the failure.
The possible error messages and their cause are listed in
.Xr mbr 8 .
.Pp
If the first stage boot succeeds, the banner will be shown and the
error messages should be self-explanatory.
.Ss Interactive mode
In interactive mode, the boot loader will present a prompt, allowing
input of these commands:
.\" NOTE: much of this text is duplicated in the MI boot.8.
.\" Some of it is
.\" also duplicated in the i386-specific dosboot.8 and pxeboot.8;
.\" please try to keep all relevant files synchronized.
.Bl -tag -width 04n -offset 04n
.It Ic boot Oo Va device : Ns Oc Oo Va filename Oc Oo Fl 1234abcdmqsvxz Oc
The default
.Va device
will be set to the disk that the boot loader was
loaded from.
To boot from an alternate disk, the full name of the device should
be given at the prompt.
.Va device
is of the form
.Xo Va xd
.Op Va N Ns Op Va x
.Xc
where
.Va xd
is the device from which to boot,
.Va N
is the unit number, and
.Va x
is the partition letter.
.Pp
The following list of supported devices may vary from installation to
installation:
.Pp
.Bl -hang -compact
.It hd
Hard disks as numbered by the BIOS.
This includes ST506, IDE, ESDI, RLL disks on a WD100[2367] or
lookalike controller(s), and SCSI disks
on SCSI controllers recognized by the BIOS.
.It fd
Floppy drives as numbered by the BIOS.
.El
.Pp
The default
.Va filename
is
.Pa netbsd ;
if the boot loader fails to successfully
open that image, it then tries
.Pa netbsd.gz
(expected to be a kernel image compressed by gzip), followed by
.Pa netbsd.old ,
.Pa netbsd.old.gz ,
.Pa onetbsd ,
and finally
.Pa onetbsd.gz .
Alternate system images can be loaded by just specifying the name of the image.
.Pp
Options are:
.Bl -tag -width xxx
.It Fl 1
Sets the machine-dependent flag
.Sy RB_MD1
in
.Va boothowto .
In
.Nx Ns /i386 ,
this disables multiprocessor boot;
the kernel will boot in uniprocessor mode.
.It Fl 2
Sets the machine-dependent flag
.Sy RB_MD2
in
.Va boothowto .
In
.Nx Ns /i386 ,
this disables ACPI.
.It Fl 3
Sets the machine-dependent flag
.Sy RB_MD3
in
.Va boothowto .
In
.Nx Ns /i386 ,
this has no effect.
.It Fl 4
Sets the machine-dependent flag
.Sy RB_MD4
in
.Va boothowto .
In
.Nx Ns /i386 ,
this has no effect.
.It Fl a
Sets the
.Sy RB_ASKNAME
flag in
.Va boothowto .
This causes the kernel to prompt for the root file system device,
the system crash dump device, and the path to
.Xr init 8 .
.It Fl b
Sets the
.Sy RB_HALT
flag in
.Va boothowto .
This causes subsequent reboot attempts to halt instead of rebooting.
.It Fl c
Sets the
.Sy RB_USERCONF
flag in
.Va boothowto .
This causes the kernel to enter the
.Xr userconf 4
device configuration manager as soon as possible during the boot.
.Xr userconf 4
allows devices to be enabled or disabled, and allows device locators
(such as hardware addresses or bus numbers)
to be modified before the kernel attempts to attach the devices.
.It Fl d
Sets the
.Sy RB_KDB
flag in
.Va boothowto .
Requests the kernel to enter debug mode, in which it
waits for a connection from a kernel debugger; see
.Xr ddb 4 .
.It Fl m
Sets the
.Sy RB_MINIROOT
flag in
.Va boothowto .
Informs the kernel that a mini-root file system is present in memory.
.It Fl q
Sets the
.Sy AB_QUIET
flag in
.Va boothowto .
Boot the system in quiet mode.
.It Fl s
Sets the
.Sy RB_SINGLE
flag in
.Va boothowto .
Boot the system in single-user mode.
.It Fl v
Sets the
.Sy AB_VERBOSE
flag in
.Va boothowto .
Boot the system in verbose mode.
.It Fl x
Sets the
.Sy AB_DEBUG
flag in
.Va boothowto .
Boot the system with debug messages enabled.
.It Fl z
Sets the
.Sy AB_SILENT
flag in
.Va boothowto .
Boot the system in silent mode.
.El
.It Ic consdev Va dev
Immediately switch the console to the specified device
.Va dev
and reprint the banner.
.Va dev
must be one of
.\" .Bl -item -width com[0123]kbd -offset indent -compact
.Ar pc , com0 , com1 , com2 ,
.Ar com3 , com0kbd , com1kbd , com2kbd ,
.Ar com3kbd ,
or
.Ar auto .
See
.Sx Console Selection Policy
in
.Xr boot_console 8 .
.It Ic dev Op Va device
Set the default drive and partition for subsequent filesystem
operations.
Without an argument, print the current setting.
.Va device
is of the form specified in
.Cm boot .
.It Ic help
Print an overview about commands and arguments.
.It Ic load Va module Op Ar arguments
Load the specified kernel
.Va module ,
and pass it the specified
.Ar arguments .
If the module name is not an absolute path,
.Pa /stand/ Xo Ns
.Aq Sy arch Ns
.Pa / Ns
.Aq Sy osversion Ns
.Pa /modules/ Ns
.Aq Sy module Ns
.Pa / Ns
.Aq Sy module Ns
.Pa .kmod
.Xc
is used.
Possible used of the
.Ic load
command include loading a memory disk image before booting a kernel,
or loading a
.Tn Xen
DOM0 kernel before booting the
.Tn Xen
hypervisor.
See
.Xr boot.cfg 5
for examples.
.Pp
In addition to the
.Cm boot
options specified above, the DOM0 kernel accepts
.Po Ar arguments
being separated with spaces
.Pc :
.Bl -tag -width xxx
.It Ic bootdev Ns = Ns Ar dev Po or Ic root Ns = Ns Ar dev Pc
Override the default boot device.
.Ar dev
can be a unit name
.Po Dq wd0
.Pc ,
or an interface name
.Po Dq bge0 ,
.Dq wm0 ,
.Ns ...
.Pc ,
for cases where the root file system has to be loaded
from network (see the
.Sx BUGS
section in
.Xr pxeboot 8 ) .
.It Ic console Ns = Ns Ar dev
Console used by DOM0 kernel during boot.
.Ar dev
accepts the same values as the ones given for the
.Cm consdev
command.
See
.Sx Console Selection Policy
in
.Xr boot_console 8 .
.It Xo Ic ip Ns = Ns
.Ar my_ip Ns : Ns Ar serv_ip Ns : Ns Ar gw_ip Ns : Ns
.Ar mask Ns : Ns Ar host Ns : Ns Ar iface
.Xc
Specify various parameters for a network boot (IPs are in
dot notation),
each one separated by a colon:
.Bl -tag -width xxxxxxx
.It Va my_ip
address of the host
.It Va serv_ip
address of the NFS server
.It Va gw_ip
address of the gateway
.It Va mask
network mask
.It Va host
address of the host
.It Va iface
interface
.Po e.g. Dq xennet0
or
.Dq eth0
.Pc
.El
.It Ic nfsroot Ns = Ns Ar address Ns : Ns Ar rootpath
Boot the system with root on NFS.
.Ar address
is the address of the NFS server, and
.Ar rootpath
is the remote mount point for the root file system.
.It Ic pciback.hide Ns = Ns Ar pcidevs
Pass a list of PCI IDs for use with the PCI backend driver,
.Xr pciback 4 .
.Ar pcidevs
is formed of multiple IDs (in bus:device.function notation),
each ID being surrounded with brackets.
PCI domain IDs are currently ignored.
See
.Xr pciback 4 .
.El
.It Ic load_mods Va mods_path_pattern
Load modules specified by pattern like /some_path/mod*.
.It Ic ls Op Pa path
Print a directory listing of
.Pa path ,
containing inode number, filename, and file type.
.Pa path
can contain a device specification.
.It Ic modules Bro Ar on | off | enabled | disabled Brc
The values
.Ar enabled , on
will enable module loading for
.Cm boot
and
.Cm multiboot ,
whereas
.Ar disabled , off
will turn off the feature.
.It Ic multiboot Va kernel Op Ar arguments
Boot the specified
.Va kernel ,
using the
.Dq multiboot
protocol instead of the native
.Nx
boot protocol.
The
.Va kernel
is specified in the same way as with the
.Ic boot
command.
.Pp
The multiboot protocol may be used in the following cases:
.Bl -tag -width indent
.It Nx Ns / Ns Xen No kernels
The
.Tn Xen
DOM0 kernel must be loaded as a module using the
.Ic load
command, and the
.Tn Xen
hypervisor must be booted using the
.Ic multiboot
command.
Options for the DOM0 kernel (such as
.Dq -s
for single user mode) must be passed as options to the
.Ic load
command.
Options for the hypervisor (such as
.Dq dom0_mem=256M
to reserve 256 MB of memory for DOM0)
must be passed as options to the
.Ic multiboot
command.
See
.Xr boot.cfg 5
for examples on how to boot
.Nx Ns / Ns Xen.
.It Nx No multiboot kernels
A
.Nx
kernel that was built with
.Cd options MULTIBOOT
(see
.Xr multiboot 8 )
may be booted with either the
.Ic boot
or
.Ic multiboot
command, passing the same
.Ar arguments
in either case.
.It Non- Ns Nx No kernels
A kernel for a
.No non- Ns Nx
operating system that expects to be booted using the
multiboot protocol (such as by the GNU
.Dq GRUB
boot loader)
may be booted using the
.Ic multiboot
command.
See the foreign operating system's documentation for the available
.Ar arguments .
.El
.It Ic quit
Reboot the system.
.It Ic userconf Va command
Pass the
.Va command
to
.Xr userconf 4
at boot time .
These commands are processed before the interactive
.Xr userconf 4
shell is executed, if requested .
.It Ic vesa Bro Va modenum | Ar on | off | enabled | disabled | list Brc
Initialise the video card to the specified resolution and bit depth.
The
.Va modenum
should be in the form of
.Ar 0x100 , 800x600 , 800x600x32 .
The values
.Ar enabled , on
put the display into the default mode, and
.Ar disabled , off
returns the display into standard vga mode.
The value
.Ar list
lists all supported modes.
.El
.Pp
In an emergency, the bootstrap methods described in the
.Nx
installation notes for the i386 architecture
can be used to boot from floppy or other media,
or over the network.
.Sh FILES
.Bl -tag -width /usr/mdec/bootxx_fstype -compact
.It Pa /boot
boot program code loaded by the primary bootstrap
.It Pa /boot.cfg
optional configuration file
.It Pa /netbsd
system code
.It Pa /netbsd.gz
gzip-compressed system code
.It Pa /usr/mdec/boot
master copy of the boot program (copy to /boot)
.It Pa /usr/mdec/bootxx_fstype
primary bootstrap for filesystem type fstype, copied to the start of
the
.Nx
partition by
.Xr installboot 8 .
.El
.Sh SEE ALSO
.Xr ddb 4 ,
.Xr pciback 4 ,
.Xr userconf 4 ,
.Xr boot.cfg 5 ,
.Xr boot_console 8 ,
.Xr dosboot 8 ,
.Xr halt 8 ,
.Xr installboot 8 ,
.Xr mbr 8 ,
.Xr multiboot 8 ,
.Xr pxeboot 8 ,
.Xr reboot 8 ,
.Xr shutdown 8 ,
.Xr w95boot 8 ,
.Xr boothowto 9
.Sh BUGS
The kernel file name must be specified before, not after, the boot options.
Any
.Ar filename
specified after the boot options, e.g.:
.Pp
.Bd -unfilled -offset indent -compact
.Cm boot -d netbsd.test
.Ed
.Pp
is ignored, and the default kernel is booted.
.Pp
Hard disks are always accessed by
.Tn BIOS
functions.
Unit numbers are
.Tn BIOS
device numbers which might differ from numbering in the
.Nx
kernel or physical parameters
.Po
e.g.,
.Tn SCSI
slave numbers
.Pc .
There isn't any distinction between
.Dq sd
and
.Dq wd
devices at the bootloader level.
This is less a bug of the bootloader code than
a shortcoming of the PC architecture.
The default disk device's name printed in the starting message
is derived from the
.Dq type
field of the
.Nx
disklabel (if it is a hard disk).

View File

@ -1,761 +0,0 @@
/* LWIP service - ipsock.c - shared IP-level socket code */
#include "lwip.h"
#include "ifaddr.h"
#define ip6_hdr __netbsd_ip6_hdr /* conflicting definitions */
#include <net/route.h>
#include <netinet/ip.h>
#include <netinet/in_pcb.h>
#include <netinet6/in6_pcb.h>
#undef ip6_hdr
/* The following are sysctl(7) settings. */
int lwip_ip4_forward = 0; /* We patch lwIP to check these.. */
int lwip_ip6_forward = 0; /* ..two settings at run time. */
static int ipsock_v6only = 1;
/* The CTL_NET PF_INET IPPROTO_IP subtree. */
static struct rmib_node net_inet_ip_table[] = {
/* 1*/ [IPCTL_FORWARDING] = RMIB_INTPTR(RMIB_RW, &lwip_ip4_forward,
"forwarding",
"Enable forwarding of INET diagrams"),
/* 3*/ [IPCTL_DEFTTL] = RMIB_INT(RMIB_RO, IP_DEFAULT_TTL, "ttl",
"Default TTL for an INET diagram"),
/*23*/ [IPCTL_LOOPBACKCKSUM] = RMIB_FUNC(RMIB_RW | CTLTYPE_INT, sizeof(int),
loopif_cksum, "do_loopback_cksum",
"Perform IP checksum on loopback"),
};
static struct rmib_node net_inet_ip_node =
RMIB_NODE(RMIB_RO, net_inet_ip_table, "ip", "IPv4 related settings");
/* The CTL_NET PF_INET6 IPPROTO_IPV6 subtree. */
static struct rmib_node net_inet6_ip6_table[] = {
/* 1*/ [IPV6CTL_FORWARDING] = RMIB_INTPTR(RMIB_RW, &lwip_ip6_forward,
"forwarding",
"Enable forwarding of INET6 diagrams"),
/*
* The following functionality is not
* implemented in lwIP at this time.
*/
/* 2*/ [IPV6CTL_SENDREDIRECTS] = RMIB_INT(RMIB_RO, 0, "redirect", "Enable "
"sending of ICMPv6 redirect messages"),
/* 3*/ [IPV6CTL_DEFHLIM] = RMIB_INT(RMIB_RO, IP_DEFAULT_TTL, "hlim",
"Hop limit for an INET6 datagram"),
/*12*/ [IPV6CTL_ACCEPT_RTADV] = RMIB_INTPTR(RMIB_RW, &ifaddr_accept_rtadv,
"accept_rtadv",
"Accept router advertisements"),
/*16*/ [IPV6CTL_DAD_COUNT] = RMIB_INT(RMIB_RO,
LWIP_IPV6_DUP_DETECT_ATTEMPTS, "dad_count",
"Number of Duplicate Address Detection "
"probes to send"),
/*24*/ [IPV6CTL_V6ONLY] = RMIB_INTPTR(RMIB_RW, &ipsock_v6only,
"v6only", "Disallow PF_INET6 sockets from "
"connecting to PF_INET sockets"),
/*
* The following setting is significantly
* different from NetBSD, and therefore it has
* a somewhat different description as well.
*/
/*35*/ [IPV6CTL_AUTO_LINKLOCAL]= RMIB_INTPTR(RMIB_RW, &ifaddr_auto_linklocal,
"auto_linklocal", "Enable global support "
"for adding IPv6link-local addresses to "
"interfaces"),
/*
* Temporary addresses are managed entirely by
* userland. We only maintain the settings.
*/
/*+0*/ [IPV6CTL_MAXID] = RMIB_INT(RMIB_RW, 0, "use_tempaddr",
"Use temporary address"),
/*+1*/ [IPV6CTL_MAXID + 1] = RMIB_INT(RMIB_RW, 86400, "temppltime",
"Preferred lifetime of a temporary "
"address"),
/*+2*/ [IPV6CTL_MAXID + 2] = RMIB_INT(RMIB_RW, 604800, "tempvltime",
"Valid lifetime of a temporary address"),
};
static struct rmib_node net_inet6_ip6_node =
RMIB_NODE(RMIB_RO, net_inet6_ip6_table, "ip6", "IPv6 related settings");
/*
* Initialize the IP sockets module.
*/
void
ipsock_init(void)
{
/*
* Register the net.inet.ip and net.inet6.ip6 subtrees. Unlike for the
* specific protocols (TCP/UDP/RAW), here the IPv4 and IPv6 subtrees
* are and must be separate, even though many settings are shared
* between the two at the lwIP level. Ultimately we may have to split
* the subtrees for the specific protocols, too, though..
*/
mibtree_register_inet(AF_INET, IPPROTO_IP, &net_inet_ip_node);
mibtree_register_inet(AF_INET6, IPPROTO_IPV6, &net_inet6_ip6_node);
}
/*
* Return the lwIP IP address type (IPADDR_TYPE_) for the given IP socket.
*/
static int
ipsock_get_type(struct ipsock * ip)
{
if (!(ip->ip_flags & IPF_IPV6))
return IPADDR_TYPE_V4;
else if (ip->ip_flags & IPF_V6ONLY)
return IPADDR_TYPE_V6;
else
return IPADDR_TYPE_ANY;
}
/*
* Create an IP socket, for the given (PF_/AF_) domain and initial send and
* receive buffer sizes. Return the lwIP IP address type that should be used
* to create the corresponding PCB. Return a pointer to the libsockevent
* socket in 'sockp'. This function must not allocate any resources in any
* form, as socket creation may still fail later, in which case no destruction
* function is called.
*/
int
ipsock_socket(struct ipsock * ip, int domain, size_t sndbuf, size_t rcvbuf,
struct sock ** sockp)
{
ip->ip_flags = (domain == AF_INET6) ? IPF_IPV6 : 0;
if (domain == AF_INET6 && ipsock_v6only)
ip->ip_flags |= IPF_V6ONLY;
ip->ip_sndbuf = sndbuf;
ip->ip_rcvbuf = rcvbuf;
/* Important: when adding settings here, also change ipsock_clone(). */
*sockp = &ip->ip_sock;
return ipsock_get_type(ip);
}
/*
* Clone the given socket 'ip' into the new socket 'newip', using the socket
* identifier 'newid'. In particular, tell libsockevent about the clone and
* copy over any settings from 'ip' to 'newip' that can be inherited on a
* socket. Cloning is used for new TCP connections arriving on listening TCP
* sockets. This function must not fail.
*/
void
ipsock_clone(struct ipsock * ip, struct ipsock * newip, sockid_t newid)
{
sockevent_clone(&ip->ip_sock, &newip->ip_sock, newid);
/* Inherit all settings from the original socket. */
newip->ip_flags = ip->ip_flags;
newip->ip_sndbuf = ip->ip_sndbuf;
newip->ip_rcvbuf = ip->ip_rcvbuf;
}
/*
* Create an <any> address for the given socket, taking into account whether
* the socket is IPv4, IPv6, or mixed. The generated address, stored in
* 'ipaddr', will have the same type as returned from the ipsock_socket() call.
*/
void
ipsock_get_any_addr(struct ipsock * ip, ip_addr_t * ipaddr)
{
ip_addr_set_any(ipsock_is_ipv6(ip), ipaddr);
if (ipsock_is_ipv6(ip) && !ipsock_is_v6only(ip))
IP_SET_TYPE(ipaddr, IPADDR_TYPE_ANY);
}
/*
* Verify whether the given (properly scoped) IP address is a valid source
* address for the given IP socket. The 'allow_mcast' flag indicates whether
* the source address is allowed to be a multicast address. Return OK on
* success. If 'ifdevp' is not NULL, it is filled with either the interface
* that owns the address, or NULL if the address is (while valid) not
* associated with a particular interface. On failure, return a negative error
* code. This function must be called, in one way or another, for every source
* address used for binding or sending on a IP-layer socket.
*/
int
ipsock_check_src_addr(struct ipsock * ip, ip_addr_t * ipaddr, int allow_mcast,
struct ifdev ** ifdevp)
{
ip6_addr_t *ip6addr;
struct ifdev *ifdev;
uint32_t inaddr, zone;
int is_mcast;
/*
* TODO: for now, forbid binding to multicast addresses. Callers that
* never allow multicast addresses anyway (e.g., IPV6_PKTINFO) should
* do their own check for this; the one here may eventually be removed.
*/
is_mcast = ip_addr_ismulticast(ipaddr);
if (is_mcast && !allow_mcast)
return EADDRNOTAVAIL;
if (IP_IS_V6(ipaddr)) {
/*
* The given address must not have a KAME-style embedded zone.
* This check is already performed in addr_get_inet(), but we
* have to replicate it here because not all source addresses
* go through addr_get_inet().
*/
ip6addr = ip_2_ip6(ipaddr);
if (ip6_addr_has_scope(ip6addr, IP6_UNKNOWN) &&
(ip6addr->addr[0] & PP_HTONL(0x0000ffffUL)))
return EINVAL;
/*
* lwIP does not support IPv4-mapped IPv6 addresses, so these
* must be converted to plain IPv4 addresses instead. The IPv4
* 'any' address is not supported in this form. In V6ONLY
* mode, refuse connecting or sending to IPv4-mapped addresses
* at all.
*/
if (ip6_addr_isipv4mappedipv6(ip6addr)) {
if (ipsock_is_v6only(ip))
return EINVAL;
inaddr = ip6addr->addr[3];
if (inaddr == PP_HTONL(INADDR_ANY))
return EADDRNOTAVAIL;
ip_addr_set_ip4_u32(ipaddr, inaddr);
}
}
ifdev = NULL;
if (!ip_addr_isany(ipaddr)) {
if (IP_IS_V6(ipaddr) &&
ip6_addr_lacks_zone(ip_2_ip6(ipaddr), IP6_UNKNOWN))
return EADDRNOTAVAIL;
/*
* If the address is a unicast address, it must be assigned to
* an interface. Otherwise, if it is a zoned multicast
* address, the zone denotes the interface. For global
* multicast addresses, we cannot determine an interface.
*/
if (!is_mcast) {
if ((ifdev = ifaddr_map_by_addr(ipaddr)) == NULL)
return EADDRNOTAVAIL;
} else {
/* Some multicast addresses are not acceptable. */
if (!addr_is_valid_multicast(ipaddr))
return EINVAL;
if (IP_IS_V6(ipaddr) &&
ip6_addr_has_zone(ip_2_ip6(ipaddr))) {
zone = ip6_addr_zone(ip_2_ip6(ipaddr));
if ((ifdev = ifdev_get_by_index(zone)) == NULL)
return ENXIO;
}
}
}
if (ifdevp != NULL)
*ifdevp = ifdev;
return OK;
}
/*
* Retrieve and validate a source address for use in a socket bind call on
* socket 'ip'. The user-provided address is given as 'addr', with length
* 'addr_len'. The socket's current local IP address and port are given as
* 'local_ip' and 'local_port', respectively; for raw sockets, the given local
* port number is always zero. The caller's endpoint is given as 'user_endpt',
* used to make sure only root can bind to local port numbers. The boolean
* 'allow_mcast' flag indicates whether the source address is allowed to be a
* multicast address. On success, return OK with the source IP address stored
* in 'src_addr' and, if 'src_port' is not NULL, the port number to bind to
* stored in 'portp'. Otherwise, return a negative error code. This function
* performs all the tasks necessary before the socket can be bound using a lwIP
* call.
*/
int
ipsock_get_src_addr(struct ipsock * ip, const struct sockaddr * addr,
socklen_t addr_len, endpoint_t user_endpt, ip_addr_t * local_ip,
uint16_t local_port, int allow_mcast, ip_addr_t * src_addr,
uint16_t * src_port)
{
uint16_t port;
int r;
/*
* If the socket has been bound already, it cannot be bound again.
* We check this by checking whether the current local port is non-
* zero. This rule does not apply to raw sockets, but raw sockets have
* no port numbers anyway, so this conveniently works out. However,
* raw sockets may not be rebound after being connected, but that is
* checked before we even get here.
*/
if (local_port != 0)
return EINVAL;
/* Parse the user-provided address. */
if ((r = addr_get_inet(addr, addr_len, ipsock_get_type(ip), src_addr,
FALSE /*kame*/, &port)) != OK)
return r;
/* Validate the user-provided address. */
if ((r = ipsock_check_src_addr(ip, src_addr, allow_mcast,
NULL /*ifdevp*/)) != OK)
return r;
/*
* If we are interested in port numbers at all (for non-raw sockets,
* meaning portp is not NULL), make sure that only the superuser can
* bind to privileged port numbers. For raw sockets, only the
* superuser can open a socket anyway, so we need no check here.
*/
if (src_port != NULL) {
if (port != 0 && port < IPPORT_RESERVED &&
!util_is_root(user_endpt))
return EACCES;
*src_port = port;
}
return OK;
}
/*
* Retrieve and validate a destination address for use in a socket connect or
* sendto call. The user-provided address is given as 'addr', with length
* 'addr_len'. The socket's current local IP address is given as 'local_addr'.
* On success, return OK with the destination IP address stored in 'dst_addr'
* and, if 'dst_port' is not NULL, the port number to bind to stored in
* 'dst_port'. Otherwise, return a negative error code. This function must be
* called, in one way or another, for every destination address used for
* connecting or sending on a IP-layer socket.
*/
int
ipsock_get_dst_addr(struct ipsock * ip, const struct sockaddr * addr,
socklen_t addr_len, const ip_addr_t * local_addr, ip_addr_t * dst_addr,
uint16_t * dst_port)
{
uint16_t port;
int r;
/* Parse the user-provided address. */
if ((r = addr_get_inet(addr, addr_len, ipsock_get_type(ip), dst_addr,
FALSE /*kame*/, &port)) != OK)
return r;
/* Destination addresses are always specific. */
if (IP_GET_TYPE(dst_addr) == IPADDR_TYPE_ANY)
IP_SET_TYPE(dst_addr, IPADDR_TYPE_V6);
/*
* lwIP does not support IPv4-mapped IPv6 addresses, so these must be
* supported to plain IPv4 addresses instead. In V6ONLY mode, refuse
* connecting or sending to IPv4-mapped addresses at all.
*/
if (IP_IS_V6(dst_addr) &&
ip6_addr_isipv4mappedipv6(ip_2_ip6(dst_addr))) {
if (ipsock_is_v6only(ip))
return EINVAL;
ip_addr_set_ip4_u32(dst_addr, ip_2_ip6(dst_addr)->addr[3]);
}
/*
* Now make sure that the local and remote addresses are of the same
* family. The local address may be of type IPADDR_TYPE_ANY, which is
* allowed for both IPv4 and IPv6. Even for connectionless socket
* types we must perform this check as part of connect calls (as well
* as sendto calls!) because otherwise we will create problems for
* sysctl based socket enumeration (i.e., netstat), which uses the
* local IP address type to determine the socket family.
*/
if (IP_GET_TYPE(local_addr) != IPADDR_TYPE_ANY &&
IP_IS_V6(local_addr) != IP_IS_V6(dst_addr))
return EINVAL;
/*
* TODO: on NetBSD, an 'any' destination address is replaced with a
* local interface address.
*/
if (ip_addr_isany(dst_addr))
return EHOSTUNREACH;
/*
* If the address is a multicast address, the multicast address itself
* must be valid.
*/
if (ip_addr_ismulticast(dst_addr) &&
!addr_is_valid_multicast(dst_addr))
return EINVAL;
/*
* TODO: decide whether to add a zone to a scoped IPv6 address that
* lacks a zone. For now, we let lwIP handle this, as lwIP itself
* will always add the zone at some point. If anything changes there,
* this would be the place to set the zone (using a route lookup).
*/
/*
* For now, we do not forbid or alter any other particular destination
* addresses.
*/
if (dst_port != NULL) {
/*
* Disallow connecting/sending to port zero. There is no error
* code that applies well to this case, so we copy NetBSD's.
*/
if (port == 0)
return EADDRNOTAVAIL;
*dst_port = port;
}
return OK;
}
/*
* Store the address 'ipaddr' associated with the socket 'ip' (for example, it
* may be the local or remote IP address of the socket) as a sockaddr structure
* in 'addr'. A port number is provided as 'port' (in host-byte order) if
* relevant, and zero is passed in otherwise. This function MUST only be
* called from contexts where 'addr' is a buffer provided by libsockevent or
* libsockdriver, meaning that it is of size SOCKADDR_MAX. The value pointed
* to by 'addr_len' is not expected to be initialized in calls to this function
* (and will typically zero). On return, 'addr_len' is filled with the length
* of the address generated in 'addr'. This function never fails.
*/
void
ipsock_put_addr(struct ipsock * ip, struct sockaddr * addr,
socklen_t * addr_len, ip_addr_t * ipaddr, uint16_t port)
{
ip_addr_t mappedaddr;
/*
* If the socket is an AF_INET6-type socket, and the given address is
* an IPv4-type address, store it as an IPv4-mapped IPv6 address.
*/
if (ipsock_is_ipv6(ip) && IP_IS_V4(ipaddr)) {
addr_make_v4mapped_v6(&mappedaddr, ip_2_ip4(ipaddr));
ipaddr = &mappedaddr;
}
/*
* We have good reasons to keep the sockdriver and sockevent APIs as
* they are, namely, defaulting 'addr_len' to zero such that the caller
* must provide a non-zero length (only) when returning a valid
* address. The consequence here is that we have to know the size of
* the provided buffer. For libsockevent callbacks, we are always
* guaranteed to get a buffer of at least this size.
*/
*addr_len = SOCKADDR_MAX;
addr_put_inet(addr, addr_len, ipaddr, FALSE /*kame*/, port);
}
/*
* Set socket options on an IP socket.
*/
int
ipsock_setsockopt(struct ipsock * ip, int level, int name,
const struct sockdriver_data * data, socklen_t len,
struct ipopts * ipopts)
{
int r, val, allow;
uint8_t type;
switch (level) {
case SOL_SOCKET:
switch (name) {
case SO_SNDBUF:
if ((r = sockdriver_copyin_opt(data, &val, sizeof(val),
len)) != OK)
return r;
if (val <= 0 || (size_t)val < ipopts->sndmin ||
(size_t)val > ipopts->sndmax)
return EINVAL;
ip->ip_sndbuf = val;
return OK;
case SO_RCVBUF:
if ((r = sockdriver_copyin_opt(data, &val, sizeof(val),
len)) != OK)
return r;
if (val <= 0 || (size_t)val < ipopts->rcvmin ||
(size_t)val > ipopts->rcvmax)
return EINVAL;
ip->ip_rcvbuf = val;
return OK;
}
break;
case IPPROTO_IP:
if (ipsock_is_ipv6(ip))
break;
switch (name) {
case IP_TOS:
if ((r = sockdriver_copyin_opt(data, &val, sizeof(val),
len)) != OK)
return r;
if (val < 0 || val > UINT8_MAX)
return EINVAL;
*ipopts->tos = (uint8_t)val;
return OK;
case IP_TTL:
if ((r = sockdriver_copyin_opt(data, &val, sizeof(val),
len)) != OK)
return r;
if (val < 0 || val > UINT8_MAX)
return EINVAL;
*ipopts->ttl = (uint8_t)val;
return OK;
}
break;
case IPPROTO_IPV6:
if (!ipsock_is_ipv6(ip))
break;
switch (name) {
case IPV6_UNICAST_HOPS:
if ((r = sockdriver_copyin_opt(data, &val, sizeof(val),
len)) != OK)
return r;
if (val < -1 || val > UINT8_MAX)
return EINVAL;
if (val == -1)
val = IP_DEFAULT_TTL;
*ipopts->ttl = val;
return OK;
case IPV6_TCLASS:
if ((r = sockdriver_copyin_opt(data, &val, sizeof(val),
len)) != OK)
return r;
if (val < -1 || val > UINT8_MAX)
return EINVAL;
if (val == -1)
val = 0;
*ipopts->tos = val;
return OK;
case IPV6_V6ONLY:
if ((r = sockdriver_copyin_opt(data, &val, sizeof(val),
len)) != OK)
return r;
/*
* If the socket has been bound to an actual address,
* we still allow the option to be changed, but it no
* longer has any effect.
*/
type = IP_GET_TYPE(ipopts->local_ip);
allow = (type == IPADDR_TYPE_ANY ||
(type == IPADDR_TYPE_V6 &&
ip_addr_isany(ipopts->local_ip)));
if (val) {
ip->ip_flags |= IPF_V6ONLY;
type = IPADDR_TYPE_V6;
} else {
ip->ip_flags &= ~IPF_V6ONLY;
type = IPADDR_TYPE_ANY;
}
if (allow)
IP_SET_TYPE(ipopts->local_ip, type);
return OK;
}
break;
}
return ENOPROTOOPT;
}
/*
* Retrieve socket options on an IP socket.
*/
int
ipsock_getsockopt(struct ipsock * ip, int level, int name,
const struct sockdriver_data * data, socklen_t * len,
struct ipopts * ipopts)
{
int val;
switch (level) {
case SOL_SOCKET:
switch (name) {
case SO_SNDBUF:
val = ip->ip_sndbuf;
return sockdriver_copyout_opt(data, &val, sizeof(val),
len);
case SO_RCVBUF:
val = ip->ip_rcvbuf;
return sockdriver_copyout_opt(data, &val, sizeof(val),
len);
}
break;
case IPPROTO_IP:
if (ipsock_is_ipv6(ip))
break;
switch (name) {
case IP_TOS:
val = (int)*ipopts->tos;
return sockdriver_copyout_opt(data, &val, sizeof(val),
len);
case IP_TTL:
val = (int)*ipopts->ttl;
return sockdriver_copyout_opt(data, &val, sizeof(val),
len);
}
break;
case IPPROTO_IPV6:
if (!ipsock_is_ipv6(ip))
break;
switch (name) {
case IPV6_UNICAST_HOPS:
val = *ipopts->ttl;
return sockdriver_copyout_opt(data, &val, sizeof(val),
len);
case IPV6_TCLASS:
val = *ipopts->tos;
return sockdriver_copyout_opt(data, &val, sizeof(val),
len);
case IPV6_V6ONLY:
val = !!(ip->ip_flags & IPF_V6ONLY);
return sockdriver_copyout_opt(data, &val, sizeof(val),
len);
}
break;
}
return ENOPROTOOPT;
}
/*
* Fill the given kinfo_pcb sysctl(7) structure with IP-level information.
*/
void
ipsock_get_info(struct kinfo_pcb * ki, const ip_addr_t * local_ip,
uint16_t local_port, const ip_addr_t * remote_ip, uint16_t remote_port)
{
ip_addr_t ipaddr;
socklen_t len;
uint8_t type;
len = sizeof(ki->ki_spad); /* use this for the full size, not ki_src */
addr_put_inet(&ki->ki_src, &len, local_ip, TRUE /*kame*/, local_port);
/*
* At this point, the local IP address type has already been used to
* determine whether this is an IPv4 or IPv6 socket. While not ideal,
* that is the best we can do: we cannot use IPv4-mapped IPv6 addresses
* in lwIP PCBs, we cannot store the original type in those PCBs, and
* we also cannot rely on the PCB having an associated ipsock object
* anymore. We also cannot use the ipsock only when present: it could
* make a TCP PCB "jump" from IPv6 to IPv4 in the netstat listing when
* it goes into TIME_WAIT state, for example.
*
* So, use *only* the type of the local IP address to determine whether
* this is an IPv4 or an IPv6 socket. At the same time, do *not* rely
* on the remote IP address being IPv4 for a local IPv4 address; it may
* be of type IPADDR_TYPE_V6 for an unconnected socket bound to an
* IPv4-mapped IPv6 address. Pretty messy, but we're limited by what
* lwIP offers here. Since it's just netstat, it need not be perfect.
*/
if ((type = IP_GET_TYPE(local_ip)) == IPADDR_TYPE_V4) {
if (!ip_addr_isany(local_ip) || local_port != 0)
ki->ki_prstate = INP_BOUND;
/*
* Make sure the returned socket address types are consistent.
* The only case where the remote IP address is not IPv4 here
* is when it is not set yet, so there is no need to check
* whether it is the 'any' address: it always is.
*/
if (IP_GET_TYPE(remote_ip) != IPADDR_TYPE_V4) {
ip_addr_set_zero_ip4(&ipaddr);
remote_ip = &ipaddr;
}
} else {
if (!ip_addr_isany(local_ip) || local_port != 0)
ki->ki_prstate = IN6P_BOUND;
if (type != IPADDR_TYPE_ANY)
ki->ki_pflags |= IN6P_IPV6_V6ONLY;
}
len = sizeof(ki->ki_dpad); /* use this for the full size, not ki_dst */
addr_put_inet(&ki->ki_dst, &len, remote_ip, TRUE /*kame*/,
remote_port);
/* Check the type of the *local* IP address here. See above. */
if (!ip_addr_isany(remote_ip) || remote_port != 0) {
if (type == IPADDR_TYPE_V4)
ki->ki_prstate = INP_CONNECTED;
else
ki->ki_prstate = IN6P_CONNECTED;
}
}

View File

@ -1,477 +0,0 @@
#if HAVE_NBTOOL_CONFIG_H
#include "nbtool_config.h"
#else
#include <sys/cdefs.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <assert.h>
#include <getopt.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "pack_dev.h"
#define MAX_ENTRIES 100000
#define MAX_LINE_SIZE 0xfff
/*
* Tool to convert the netbsd METALOG into a proto file usable by mkfs.mfs
*
* todo:
* Possibly use netbsd usr.sbin/makefs to create mfs file systems.
*/
enum entry_type
{ ENTRY_DIR, ENTRY_FILE, ENTRY_LINK, ENTRY_BLOCK, ENTRY_CHAR };
struct entry
{
char *path;
char *filename; /* point to last component in the path */
enum entry_type type; /* entry type */
int mode; /* unix mode e.g. 0755 */
char *uid;
char *gid;
char *time; /* time 1365836670.000000000 */
char *size;
char *link;
/* Can't use devmajor_t/devminor_t on linux systems :( */
int32_t dev_major;
int32_t dev_minor;
/* just internal variables used to create a tree */
int depth;
struct entry *parent;
};
static struct entry entries[MAX_ENTRIES];
static int entry_total_count;
static int
convert_to_entry(char *line, struct entry *entry)
{
/* convert a input line from sanitized input into an entry */
char *saveptr;
char *key, *value;
saveptr = NULL;
/* we need to have a terminated string */
assert(strnlen(line, MAX_LINE_SIZE - 1) != MAX_LINE_SIZE - 1);
/* skip comment lines */
if (*line == '#')
return 1;
line = strtok_r(line, " ", &saveptr);
/* skip empty lines */
if (!line) {
return 1;
}
memset(entry, 0, sizeof(struct entry));
/* the first entry is the path name */
entry->path = strndup(line, MAX_LINE_SIZE);
/* the next entries are key,value pairs */
while ((line = strtok_r(NULL, " ", &saveptr)) != NULL) {
key = value = NULL;
char *p;
if (strstr(line, "=") == NULL) {
fprintf(stderr, "expected key/value pair in %s\n",
line);
free(entry->path);
return 1;
}
p = NULL;
key = strtok_r(line, "=", &p);
value = strtok_r(NULL, "=", &p);
if (value) {
if (strncmp(key, "type", 5) == 0) {
if (strncmp(value, "dir", 4) == 0) {
entry->type = ENTRY_DIR;
} else if (strncmp(value, "file", 5) == 0) {
entry->type = ENTRY_FILE;
} else if (strncmp(value, "link", 5) == 0) {
entry->type = ENTRY_LINK;
} else if (strncmp(value, "block", 6) == 0) {
entry->type = ENTRY_BLOCK;
} else if (strncmp(value, "char", 5) == 0) {
entry->type = ENTRY_CHAR;
} else {
fprintf(stderr,
"\tunknown type %s -> '%s'\n", key,
value);
}
} else if (strncmp(key, "mode", 5) == 0) {
sscanf(value,"%o",&entry->mode);
} else if (strncmp(key, "uid", 4) == 0) {
entry->uid = strndup(value, MAX_LINE_SIZE);
} else if (strncmp(key, "gid", 4) == 0) {
entry->gid = strndup(value, MAX_LINE_SIZE);
} else if (strncmp(key, "time", 5) == 0) {
entry->time = strndup(value, MAX_LINE_SIZE);
} else if (strncmp(key, "size", 5) == 0) {
entry->size = strndup(value, MAX_LINE_SIZE);
} else if (strncmp(key, "link", 5) == 0) {
entry->link = strndup(value, MAX_LINE_SIZE);
} else if (strncmp(key, "device", 7) == 0) {
long int dev_id;
dev_id = strtoul(value, NULL, 16);
entry->dev_major = major_netbsd(dev_id);
entry->dev_minor = minor_netbsd(dev_id);
} else {
fprintf(stderr,
"\tunknown attribute %s -> %s\n", key,
value);
}
}
}
return 0;
}
static int
iterate_over_input(int fh_in, void (*callback) (char *line))
{
char buf[MAX_LINE_SIZE];
int r_size, err;
int line_size;
int buf_end;
int line_nr;
char *p;
memset(buf, 0, MAX_LINE_SIZE);
r_size = 0;
buf_end = 0;
line_nr = 0;
while (1 == 1) {
/* fill buffer taking into account there can already be
* content at the start */
r_size = read(fh_in, &buf[buf_end], MAX_LINE_SIZE - buf_end);
if (r_size == -1) {
err = errno;
fprintf(stderr, "failed reading input:%s\n",
strerror(err));
return 1;
}
/* checking for read size of 0 is not enough as the buffer
* still can contain content */
buf_end = buf_end + r_size;
/* is there data we need to process ? */
if (buf_end == 0) {
return 0; /* normal exit is here */
}
/* find end of line or eof. start a the start of the buffer */
p = buf;
while (p < buf + buf_end) {
if (*p == '\n' || *p == '\0') {
/* replace either by a null terminator */
line_nr++;
*p = '\0';
break;
}
p++;
}
/* If we are at the end of the buffer we did not find a
* terminator */
if (p == buf + buf_end) {
fprintf(stderr,
"Line(%d) does not fit the buffer %d\n", line_nr,
MAX_LINE_SIZE);
return 1;
}
line_size = p - buf; /* size of the line we currently are
* reading */
/* here we have a valid line */
callback(buf);
/* copy the remaining data over to the start */
memmove(buf, p + 1, MAX_LINE_SIZE - line_size);
buf_end -= (line_size + 1);
}
return 0;
}
static void
parse_line_cb(char *line)
{
if (convert_to_entry(line, &entries[entry_total_count]) == 0) {
entry_total_count++;
assert(entry_total_count < MAX_ENTRIES);
} else {
memset(&entries[entry_total_count], 0, sizeof(struct entry));
}
}
static int
create_entries(int handle)
{
int c;
char *p;
struct entry *entry;
char tmppath[MAX_LINE_SIZE];
int i;
if (iterate_over_input(handle, parse_line_cb)) {
return 1;
}
/* calculate depth for each entry */
for (c = 0; c < entry_total_count; c++) {
p = entries[c].path;
while (*p != 0) {
if (*p == '/') {
entries[c].depth++;
}
p++;
}
}
/* find parent entry and set the filename */
for (c = 0; c < entry_total_count; c++) {
entry = &entries[c];
if (entry->depth > 0) {
/* calculate path */
/* find last "/" element and "null" it */
strncpy(tmppath, entry->path, MAX_LINE_SIZE - 1);
i = strlen(tmppath);
while (i > 0) {
if (tmppath[i] == '/') {
entry->filename = &entry->path[i + 1];
tmppath[i] = '\0';
break;
}
i--;
}
if (i == 0) {
fprintf
(stderr,
"error while searching for parent path of %s\n",
entry->path);
return 1;
}
/* now compare with the other entries */
for (i = 0; i < entry_total_count; i++) {
if (strncmp(entries[i].path, tmppath,
MAX_LINE_SIZE) == 0) {
/* found entry */
entry->parent = &entries[i];
break;
}
}
if (entry->parent == NULL) {
fprintf(stderr,
"Failed to find parent directory of %s\n",
entry->path);
return 1;
}
assert(entry->parent->type == ENTRY_DIR);
} else {
/* same in this case */
entry->filename = entry->path;
}
}
return 0;
}
static char * parse_mode(int mode){
/* Convert a 4 digit octal number int a proto entry as described in
the mkfs.mfs man page e.g. [suid-char][guid-char]0777 mode */
static char m[6];
memset(m,0,6);
char suid,guid;
suid = (mode & 04000)?'u':'-';
guid = (mode & 02000)?'g':'-';
snprintf(m,6,"%c%c%3o",suid,guid,mode & 0777);
return m;
}
static char *parse_filename(char *path)
{
/* Skipping the first . in the path */
return &path[1];
}
static int
dump_entry(FILE * out, int mindex, const char *base_dir)
{
int space;
int i;
struct entry *entry = &entries[mindex];
/* Ensure uid & gid are set to something meaningful. */
if (entry->uid == NULL) {
entry->uid = __UNCONST("0");
}
if (entry->gid == NULL) {
entry->gid = __UNCONST("0");
}
/* Indent the line */
for (space = 0; space < entries[mindex].depth; space++) {
fprintf(out, " ");
}
if (entry->type == ENTRY_DIR) {
if (entries[mindex].depth > 0) {
fprintf(out, "%s ", entry->filename);
}
fprintf(out, "d%s", parse_mode(entry->mode));
fprintf(out, " %s", entry->uid);
fprintf(out, " %s", entry->gid);
fprintf(out, "\n");
for (i = 0; i < entry_total_count; i++) {
if (entries[i].parent == entry) {
dump_entry(out, i, base_dir);
}
}
for (space = 0; space < entries[mindex].depth; space++) {
fprintf(out, " ");
}
fprintf(out, "$\n");
} else if (entry->type == ENTRY_FILE) {
fprintf(out, "%s -%s %s %s %s%s\n", entry->filename,
parse_mode(entry->mode), entry->uid, entry->gid,
base_dir, parse_filename(entry->path));
} else if (entry->type == ENTRY_LINK) {
fprintf(out, "%s s%s %s %s %s\n", entry->filename,
parse_mode(entry->mode), entry->uid, entry->gid,
entry->link);
} else if (entry->type == ENTRY_CHAR) {
fprintf(out, "%s c%s %s %s %d %d\n", entry->filename,
parse_mode(entry->mode), entry->uid, entry->gid,
entry->dev_major, entry->dev_minor);
} else if (entry->type == ENTRY_BLOCK) {
fprintf(out, "%s b%s %s %s %d %d\n", entry->filename,
parse_mode(entry->mode), entry->uid, entry->gid,
entry->dev_major, entry->dev_minor);
} else {
/* Unknown line type. */
fprintf(out, "#");
fprintf(out, "%i %s\n", entry->type, entry->path);
exit(1);
return 1;
}
return 0;
}
static int
dump_proto(FILE * out, const char *base_dir)
{
int i;
fprintf(out, "boot\n0 0");
for (i = 0; i < entry_total_count; i++) {
if (entries[i].depth == 0) {
fprintf(out, "\n");
dump_entry(out, i, base_dir);
}
}
return 0;
}
static void
print_usage(void)
{
printf("Usage: toproto [OPTION]...\n");
printf
("Convert a netbsd METALOG file into a proto file for mkfs.mfs.\n");
printf("\n");
printf(" -i input METALOG\n");
printf(" -b base_path\n");
printf(" -o output proto\n");
printf(" -h show this this help and exit\n");
}
int
main(int argc, char **argv)
{
int ch, fh_in;
FILE *out;
const char *base_path;
char *input_file, *output_file;
input_file = NULL;
output_file = NULL;
base_path = ".";
fh_in = STDIN_FILENO;
out = stdout;
while ((ch = getopt(argc, argv, "i:b:o:h")) != -1) {
switch (ch) {
case 'i':
input_file = optarg;
break;
case 'b':
base_path = optarg;
break;
case 'o':
output_file = optarg;
break;
case 'h':
print_usage();
exit(0);
break;
default:
print_usage();
exit(1);
}
}
argc -= optind;
argv += optind;
if (input_file) {
fh_in = open(input_file, O_RDONLY);
if (fh_in == -1) {
fprintf(stderr, "Failed to open input file (%s):%s\n",
input_file, strerror(errno));
exit(1);
}
}
if (output_file) {
out = fopen(output_file, "w+");
if (!out) {
fprintf(stderr, "Failed to open input file (%s):%s\n",
input_file, strerror(errno));
exit(1);
}
}
if (create_entries(fh_in)) {
fprintf(stderr, "Failed to create entries\n");
exit(1);
}
if (input_file)
close(fh_in);
if (dump_proto(out, base_path)) {
fprintf(stderr, "Failed to create entries\n");
exit(1);
}
if (output_file)
fclose(out);
return 0;
}

View File

@ -1,229 +0,0 @@
.\" $NetBSD: mknod.8,v 1.29 2016/09/11 23:02:54 sevan Exp $
.\"
.\" Copyright (c) 1980, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. Neither the name of the University nor the names of its contributors
.\" may be used to endorse or promote products derived from this software
.\" without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" @(#)mknod.8 8.2 (Berkeley) 12/11/93
.\"
.Dd September 12, 2016
.Dt MKNOD 8
.Os
.Sh NAME
.Nm mknod
.Nd make device special file
.Sh SYNOPSIS
.Nm
.Op Fl rR
.Op Fl F Ar fmt
.Op Fl g Ar gid
.Op Fl m Ar mode
.Op Fl u Ar uid
.Ar name
.Op Cm c | Cm b
.Op Ar driver | Ar major
.Ar minor
.Nm
.Op Fl rR
.Op Fl F Ar fmt
.Op Fl g Ar gid
.Op Fl m Ar mode
.Op Fl u Ar uid
.Ar name
.Op Cm c | Cm b
.Ar major unit subunit
.Nm
.Op Fl rR
.Op Fl g Ar gid
.Op Fl m Ar mode
.Op Fl u Ar uid
.Ar name
.Op Cm c | Cm b
.Ar number
.Nm
.Op Fl rR
.Op Fl g Ar gid
.Op Fl m Ar mode
.Op Fl u Ar uid
.Ar name
.Cm p
.Nm
.Fl l
.Sh DESCRIPTION
The
.Nm
command creates device special files, or fifos.
Normally the shell script
.Pa /dev/MAKEDEV
is used to create special files for commonly known devices; it executes
.Nm
with the appropriate arguments and can make all the files required for the
device.
.Pp
To make nodes manually, the arguments are:
.Pp
.Bl -tag -width xmxmode
.It Fl r
Replace an existing file if its type is incorrect.
.It Fl R
Replace an existing file if its type is incorrect.
Correct the mode, user and group.
.It Fl F Ar fmt
Create device nodes that may be used by an operating system which
uses device numbers packed in a different format than
.Nx
uses.
This is necessary when
.Nx
is used as an
.Tn NFS
server for netbooted computers running other operating systems.
.Pp
The following values for the
.Ar fmt
are recognized:
.Sy native ,
.Sy 386bsd ,
.Sy 4bsd ,
.Sy bsdos ,
.Sy freebsd ,
.Sy hpux ,
.Sy isc ,
.Sy linux ,
.Sy netbsd ,
.Sy osf1 ,
.Sy sco ,
.Sy solaris ,
.Sy sunos ,
.Sy svr3 ,
.Sy svr4 ,
and
.Sy ultrix .
.It Fl g Ar gid
Specify the group for the device node.
The
.Ar gid
operand may be a numeric group ID or a group name.
If a group name is also a numeric group ID,
the operand is used as a group name.
Precede a numeric group ID with a
.Cm #
to stop it being treated as a name.
.It Fl m Ar mode
Specify the mode for the device node.
The mode may be absolute or symbolic, see
.Xr chmod 1 .
.It Fl u Ar uid
Specify the user for the device node.
The
.Ar uid
operand may be a numeric user ID or a user name.
If a user name is also a numeric user ID,
the operand is used as a user name.
Precede a numeric user ID with a
.Cm #
to stop it being treated as a name.
.It Ar name
Device name, for example
.Dq sd
for a SCSI disk on an HP300 or a
.Dq pty
for pseudo-devices.
.It Cm b | Cm c | Cm p
Type of device.
If the device is a block type device such as a tape or disk drive
which needs both cooked and raw special files, the type is
.Cm b .
All other devices are character type devices, such as terminal
and pseudo devices, and are type
.Cm c .
Specifying
.Cm p
creates fifo files.
.It Ar driver | Ar major
The major device number is an integer number which tells the kernel
which device driver entry point to use.
If the device driver is configured into the current kernel it may be
specified by driver name or major number.
To find out which major device number to use for a particular device,
use
.Nm
.Fl l ,
check the file
.Pa /dev/MAKEDEV
to see if the device is known, or check
the system dependent device configuration file:
.Bd -filled -offset indent
.Dq Pa /usr/src/sys/arch/\*[Lt]arch\*[Gt]/\*[Lt]arch\*[Gt]/conf.c
.Ed
.Pp
.Po
e.g.
.Pa /usr/src/sys/arch/vax/vax/conf.c
.Pc .
.It Ar minor
The minor device number tells the kernel which one of several similar
devices the node corresponds to; for example, it may be a specific serial
port or pty.
.It Ar unit No and Ar subunit
The unit and subunit numbers select a subset of a device; for example, the
unit may specify a particular SCSI disk, and the subunit a partition on
that disk.
(Currently this form of specification is only supported by the
.Ar bsdos
format, for compatibility with the
.Bsx
.Nm ) .
.It Ar number
A single opaque device number.
Useful for netbooted computers which require device numbers packed
in a format that isn't supported by
.Fl F .
.It Fl l
List the device drivers configured into the current kernel together with their
block and character major numbers.
.El
.Sh SEE ALSO
.Xr chmod 1 ,
.Xr mkfifo 1 ,
.Xr mkfifo 2 ,
.Xr mknod 2 ,
.Xr MAKEDEV 8
.Sh HISTORY
A
.Nm
command appeared in
.At v4 .
The
.Fl F
option appeared in
.Nx 1.4 .
The
.Fl g , l , m , r , R ,
and
.Fl u
options, and the ability to specify a driver by name appeared in
.Nx 2.0 .

View File

@ -1,290 +0,0 @@
/* $NetBSD: pack_dev.c,v 1.12 2013/06/14 16:28:20 tsutsui Exp $ */
/*-
* Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Charles M. Hannum.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#if HAVE_NBTOOL_CONFIG_H
#include "nbtool_config.h"
#endif
#include <sys/cdefs.h>
#if !defined(lint)
__RCSID("$NetBSD: pack_dev.c,v 1.12 2013/06/14 16:28:20 tsutsui Exp $");
#endif /* not lint */
#include <sys/types.h>
#include <sys/stat.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "pack_dev.h"
static pack_t pack_netbsd;
static pack_t pack_freebsd;
static pack_t pack_8_8;
static pack_t pack_12_20;
static pack_t pack_14_18;
static pack_t pack_8_24;
static pack_t pack_bsdos;
static int compare_format(const void *, const void *);
static const char iMajorError[] = "invalid major number";
static const char iMinorError[] = "invalid minor number";
static const char tooManyFields[] = "too many fields for format";
/* exported */
dev_t
pack_native(int n, u_long numbers[], const char **error)
{
dev_t dev = 0;
if (n == 2) {
dev = makedev(numbers[0], numbers[1]);
if ((u_long)major(dev) != numbers[0])
*error = iMajorError;
else if ((u_long)minor(dev) != numbers[1])
*error = iMinorError;
} else
*error = tooManyFields;
return (dev);
}
static dev_t
pack_netbsd(int n, u_long numbers[], const char **error)
{
dev_t dev = 0;
if (n == 2) {
dev = makedev_netbsd(numbers[0], numbers[1]);
if ((u_long)major_netbsd(dev) != numbers[0])
*error = iMajorError;
else if ((u_long)minor_netbsd(dev) != numbers[1])
*error = iMinorError;
} else
*error = tooManyFields;
return (dev);
}
#define major_freebsd(x) ((int32_t)(((x) & 0x0000ff00) >> 8))
#define minor_freebsd(x) ((int32_t)(((x) & 0xffff00ff) >> 0))
#define makedev_freebsd(x,y) ((dev_t)((((x) << 8) & 0x0000ff00) | \
(((y) << 0) & 0xffff00ff)))
static dev_t
pack_freebsd(int n, u_long numbers[], const char **error)
{
dev_t dev = 0;
if (n == 2) {
dev = makedev_freebsd(numbers[0], numbers[1]);
if ((u_long)major_freebsd(dev) != numbers[0])
*error = iMajorError;
if ((u_long)minor_freebsd(dev) != numbers[1])
*error = iMinorError;
} else
*error = tooManyFields;
return (dev);
}
#define major_8_8(x) ((int32_t)(((x) & 0x0000ff00) >> 8))
#define minor_8_8(x) ((int32_t)(((x) & 0x000000ff) >> 0))
#define makedev_8_8(x,y) ((dev_t)((((x) << 8) & 0x0000ff00) | \
(((y) << 0) & 0x000000ff)))
static dev_t
pack_8_8(int n, u_long numbers[], const char **error)
{
dev_t dev = 0;
if (n == 2) {
dev = makedev_8_8(numbers[0], numbers[1]);
if ((u_long)major_8_8(dev) != numbers[0])
*error = iMajorError;
if ((u_long)minor_8_8(dev) != numbers[1])
*error = iMinorError;
} else
*error = tooManyFields;
return (dev);
}
#define major_12_20(x) ((int32_t)(((x) & 0xfff00000) >> 20))
#define minor_12_20(x) ((int32_t)(((x) & 0x000fffff) >> 0))
#define makedev_12_20(x,y) ((dev_t)((((x) << 20) & 0xfff00000) | \
(((y) << 0) & 0x000fffff)))
static dev_t
pack_12_20(int n, u_long numbers[], const char **error)
{
dev_t dev = 0;
if (n == 2) {
dev = makedev_12_20(numbers[0], numbers[1]);
if ((u_long)major_12_20(dev) != numbers[0])
*error = iMajorError;
if ((u_long)minor_12_20(dev) != numbers[1])
*error = iMinorError;
} else
*error = tooManyFields;
return (dev);
}
#define major_14_18(x) ((int32_t)(((x) & 0xfffc0000) >> 18))
#define minor_14_18(x) ((int32_t)(((x) & 0x0003ffff) >> 0))
#define makedev_14_18(x,y) ((dev_t)((((x) << 18) & 0xfffc0000) | \
(((y) << 0) & 0x0003ffff)))
static dev_t
pack_14_18(int n, u_long numbers[], const char **error)
{
dev_t dev = 0;
if (n == 2) {
dev = makedev_14_18(numbers[0], numbers[1]);
if ((u_long)major_14_18(dev) != numbers[0])
*error = iMajorError;
if ((u_long)minor_14_18(dev) != numbers[1])
*error = iMinorError;
} else
*error = tooManyFields;
return (dev);
}
#define major_8_24(x) ((int32_t)(((x) & 0xff000000) >> 24))
#define minor_8_24(x) ((int32_t)(((x) & 0x00ffffff) >> 0))
#define makedev_8_24(x,y) ((dev_t)((((x) << 24) & 0xff000000) | \
(((y) << 0) & 0x00ffffff)))
static dev_t
pack_8_24(int n, u_long numbers[], const char **error)
{
dev_t dev = 0;
if (n == 2) {
dev = makedev_8_24(numbers[0], numbers[1]);
if ((u_long)major_8_24(dev) != numbers[0])
*error = iMajorError;
if ((u_long)minor_8_24(dev) != numbers[1])
*error = iMinorError;
} else
*error = tooManyFields;
return (dev);
}
#define major_12_12_8(x) ((int32_t)(((x) & 0xfff00000) >> 20))
#define unit_12_12_8(x) ((int32_t)(((x) & 0x000fff00) >> 8))
#define subunit_12_12_8(x) ((int32_t)(((x) & 0x000000ff) >> 0))
#define makedev_12_12_8(x,y,z) ((dev_t)((((x) << 20) & 0xfff00000) | \
(((y) << 8) & 0x000fff00) | \
(((z) << 0) & 0x000000ff)))
static dev_t
pack_bsdos(int n, u_long numbers[], const char **error)
{
dev_t dev = 0;
if (n == 2) {
dev = makedev_12_20(numbers[0], numbers[1]);
if ((u_long)major_12_20(dev) != numbers[0])
*error = iMajorError;
if ((u_long)minor_12_20(dev) != numbers[1])
*error = iMinorError;
} else if (n == 3) {
dev = makedev_12_12_8(numbers[0], numbers[1], numbers[2]);
if ((u_long)major_12_12_8(dev) != numbers[0])
*error = iMajorError;
if ((u_long)unit_12_12_8(dev) != numbers[1])
*error = "invalid unit number";
if ((u_long)subunit_12_12_8(dev) != numbers[2])
*error = "invalid subunit number";
} else
*error = tooManyFields;
return (dev);
}
/* list of formats and pack functions */
/* this list must be sorted lexically */
static struct format {
const char *name;
pack_t *pack;
} formats[] = {
{"386bsd", pack_8_8},
{"4bsd", pack_8_8},
{"bsdos", pack_bsdos},
{"freebsd", pack_freebsd},
{"hpux", pack_8_24},
{"isc", pack_8_8},
{"linux", pack_8_8},
{"native", pack_native},
{"netbsd", pack_netbsd},
{"osf1", pack_12_20},
{"sco", pack_8_8},
{"solaris", pack_14_18},
{"sunos", pack_8_8},
{"svr3", pack_8_8},
{"svr4", pack_14_18},
{"ultrix", pack_8_8},
};
static int
compare_format(const void *key, const void *element)
{
const char *name;
const struct format *format;
name = key;
format = element;
return (strcmp(name, format->name));
}
pack_t *
pack_find(const char *name)
{
struct format *format;
format = bsearch(name, formats,
sizeof(formats)/sizeof(formats[0]),
sizeof(formats[0]), compare_format);
if (format == 0)
return (NULL);
return (format->pack);
}

View File

@ -1,47 +0,0 @@
/* $NetBSD: pack_dev.h,v 1.8 2013/06/14 16:28:20 tsutsui Exp $ */
/*-
* Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Charles M. Hannum.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _PACK_DEV_H
#define _PACK_DEV_H
typedef dev_t pack_t(int, u_long [], const char **);
pack_t *pack_find(const char *);
pack_t pack_native;
#define major_netbsd(x) ((int32_t)((((x) & 0x000fff00) >> 8)))
#define minor_netbsd(x) ((int32_t)((((x) & 0xfff00000) >> 12) | \
(((x) & 0x000000ff) >> 0)))
#define makedev_netbsd(x,y) ((dev_t)((((x) << 8) & 0x000fff00) | \
(((y) << 12) & 0xfff00000) | \
(((y) << 0) & 0x000000ff)))
#endif /* _PACK_DEV_H */

File diff suppressed because it is too large Load Diff

View File

@ -1,218 +0,0 @@
/* $NetBSD: getmntinfo.c,v 1.1 2012/03/17 16:33:11 jruoho Exp $ */
/*
* Copyright (c) 2007 The NetBSD Foundation, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/param.h>
#include <sys/ucred.h>
#include <sys/mount.h>
#include <err.h>
#include <stdlib.h>
#include <string.h>
#define KB * 1024
#define MB * 1024 KB
#define GB * 1024 MB
static struct statvfs *getnewstatvfs(void);
static void other_variants(const struct statvfs *, const int *, int,
const int *, int);
static void setup_filer(void);
static void setup_ld0g(void);
static void setup_strpct(void);
static struct statvfs *allstatvfs;
static int sftotal, sfused;
struct statvfs *
getnewstatvfs(void)
{
if (sftotal == sfused) {
sftotal = sftotal ? sftotal * 2 : 1;
allstatvfs = realloc(allstatvfs,
sftotal * sizeof(struct statvfs));
if (allstatvfs == NULL)
err(EXIT_FAILURE, "realloc");
}
return (&allstatvfs[sfused++]);
}
void
other_variants(const struct statvfs *tmpl, const int *minfree, int minfreecnt,
const int *consumed, int consumedcnt)
{
int64_t total, used;
struct statvfs *sf;
int i, j;
for (i = 0; i < minfreecnt; i++)
for (j = 0; j < consumedcnt; j++) {
sf = getnewstatvfs();
*sf = *tmpl;
total = (int64_t)(u_long)sf->f_blocks * sf->f_bsize;
used = total * consumed[j] / 100;
sf->f_bfree = (total - used) / sf->f_bsize;
sf->f_bavail = (total * (100 - minfree[i]) / 100 -
used) / (int)sf->f_bsize;
sf->f_bresvd = sf->f_bfree - sf->f_bavail;
}
}
/*
* Parameter taken from:
* http://mail-index.NetBSD.org/tech-userlevel/2004/03/24/0001.html
*/
void
setup_filer(void)
{
static const struct statvfs tmpl = {
#define BSIZE 512
#define TOTAL 1147ULL GB
#define USED 132ULL MB
.f_bsize = BSIZE,
.f_frsize = BSIZE,
.f_blocks = TOTAL / BSIZE,
.f_bfree = (TOTAL - USED) / BSIZE,
.f_bavail = (TOTAL - USED) / BSIZE,
.f_bresvd = 0,
.f_mntfromname = "filer:/",
.f_mntonname = "/filer",
#undef USED
#undef TOTAL
#undef BSIZE
};
static const int minfree[] = { 0, 5, 10, 15, };
static const int consumed[] = { 0, 20, 60, 95, 100 };
*getnewstatvfs() = tmpl;
other_variants(&tmpl, minfree, sizeof(minfree) / sizeof(minfree[0]),
consumed, sizeof(consumed) / sizeof(consumed[0]));
}
/*
* Parameter taken from:
* http://mail-index.NetBSD.org/current-users/2004/03/01/0038.html
*/
void
setup_ld0g(void)
{
static const struct statvfs tmpl = {
#define BSIZE 4096 /* Guess */
#define TOTAL 1308726116ULL KB
#define USED 17901268ULL KB
#define AVAIL 1225388540ULL KB
.f_bsize = BSIZE,
.f_frsize = BSIZE,
.f_blocks = TOTAL / BSIZE,
.f_bfree = (TOTAL - USED) / BSIZE,
.f_bavail = AVAIL / BSIZE,
.f_bresvd = (TOTAL - USED) / BSIZE - AVAIL / BSIZE,
.f_mntfromname = "/dev/ld0g",
.f_mntonname = "/anon-root",
#undef AVAIL
#undef USED
#undef TOTAL
#undef BSIZE
};
static const int minfree[] = { 0, 5, 10, 15, };
static const int consumed[] = { 0, 20, 60, 95, 100 };
*getnewstatvfs() = tmpl;
other_variants(&tmpl, minfree, sizeof(minfree) / sizeof(minfree[0]),
consumed, sizeof(consumed) / sizeof(consumed[0]));
}
/*
* Test of strpct() with huge number.
*/
void
setup_strpct(void)
{
static const struct statvfs tmpl = {
#define BSIZE 4096 /* Guess */
#define TOTAL 0x4ffffffffULL KB
#define USED (TOTAL / 2)
#define AVAIL (TOTAL / 2)
.f_bsize = BSIZE,
.f_frsize = BSIZE,
.f_blocks = TOTAL / BSIZE,
.f_bfree = (TOTAL - USED) / BSIZE,
.f_bavail = AVAIL / BSIZE,
.f_bresvd = (TOTAL - USED) / BSIZE - AVAIL / BSIZE,
.f_mntfromname = "/dev/strpct",
.f_mntonname = "/strpct",
#undef AVAIL
#undef USED
#undef TOTAL
#undef BSIZE
};
*getnewstatvfs() = tmpl;
}
/*
* Parameter taken from:
* http://www.netbsd.org/cgi-bin/query-pr-single.pl?number=23600
*/
static void
setup_pr23600(void)
{
static const struct statvfs tmpl = {
#define BSIZE 512
#define TOTAL 20971376ULL
#define USED 5719864ULL
#define AVAIL 15251512ULL
.f_bsize = BSIZE,
.f_frsize = BSIZE,
.f_blocks = TOTAL,
.f_bfree = TOTAL - USED,
.f_bavail = AVAIL,
.f_bresvd = TOTAL - USED - AVAIL,
.f_mntfromname = "/dev/wd0e",
.f_mntonname = "/mount/windows/C",
#undef AVAIL
#undef USED
#undef TOTAL
#undef BSIZE
};
*getnewstatvfs() = tmpl;
}
int
getmntinfo(struct statvfs **mntbuf, int flags)
{
setup_filer();
setup_ld0g();
setup_strpct();
setup_pr23600();
*mntbuf = allstatvfs;
return (sfused);
}

View File

@ -1,146 +0,0 @@
/* $NetBSD: h_dm.c,v 1.1 2010/10/06 11:24:55 haad Exp $ */
/*
* Copyright (c) 2010 Antti Kantee. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <sys/types.h>
#include <rump/rump.h>
#include <rump/rump_syscalls.h>
#include <sys/param.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/disklabel.h>
#include <ctype.h>
#include <err.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <util.h>
#include <dev/dm/netbsd-dm.h>
int dm_test_targets(void);
int dm_test_versions(void);
/*
* Test simple dm versions command on device-mapper device.
*/
int
dm_test_versions(void) {
int fd;
int error;
prop_dictionary_t dict_in, dict_out;
struct plistref prefp;
char *xml;
error = 0;
error = rump_init();
if (error != 0)
err(1, "Rump init failed");
fd = rump_sys_open("/dev/mapper/control", O_RDWR, 0);
if (fd == -1)
err(1, "Open dm device failed");
dict_in = prop_dictionary_internalize_from_file("dm_version_cmd.plist");
dict_out = prop_dictionary_create();
prop_dictionary_externalize_to_pref(dict_in, &prefp);
error = rump_sys_ioctl(fd, NETBSD_DM_IOCTL, &prefp);
if (error < 0)
err(1, "Dm control ioctl failed");
dict_out = prop_dictionary_internalize(prefp.pref_plist);
xml = prop_dictionary_externalize(dict_out);
rump_sys_close(fd);
return error;
}
/*
* Test simple dm targets command on device-mapper device.
*/
int
dm_test_targets(void) {
int fd;
int error;
prop_dictionary_t dict_in, dict_out;
struct plistref prefp;
char *xml;
error = 0;
error = rump_init();
if (error != 0)
err(1, "Rump init failed");
fd = rump_sys_open("/dev/mapper/control", O_RDWR, 0);
if (fd == -1)
err(1, "Open dm device failed");
dict_in = prop_dictionary_internalize_from_file("dm_targets_cmd.plist");
dict_out = prop_dictionary_create();
prop_dictionary_externalize_to_pref(dict_in, &prefp);
error = rump_sys_ioctl(fd, NETBSD_DM_IOCTL, &prefp);
if (error < 0)
err(1, "Dm control ioctl failed");
dict_out = prop_dictionary_internalize(prefp.pref_plist);
xml = prop_dictionary_externalize(dict_out);
rump_sys_close(fd);
return error;
}
int
main(int argc, char **argv) {
int error;
error = 0;
error = dm_test_versions();
if (error != 0)
err(1, "dm_test_versions failed");
error = dm_test_targets();
if (error != 0)
err(1, "dm_test_targets failed");
return error;
}

View File

@ -1,213 +0,0 @@
# $NetBSD: t_miscquota.sh,v 1.8 2013/01/22 06:24:11 dholland Exp $
#
# Copyright (c) 2011 Manuel Bouyer
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
test_case_root walk_list_user quota_walk_list \
"walk user quota list over several disk blocks" -b le 1 user
test_case_root psnapshot_user quota_snap \
"create a persistent shapshot of quota-enabled fs, and do some writes" \
-b le 1 user
test_case_root npsnapshot_user quota_snap \
"create a non-persistent shapshot of quota-enabled fs, and do some writes" \
-boL le 1 user
test_case_root psnapshot_unconf_user quota_snap \
"create a persistent shapshot of quota-enabled fs, and do some writes and unconf" \
-boC le 1 user
test_case_root npsnapshot_unconf_user quota_snap \
"create a non-persistent shapshot of quota-enabled fs, and do some writes and unconf" \
-boLC le 1 user
test_case log_unlink quota_log \
"an unlinked file cleaned by the log replay should update quota" \
-l le 1 user
test_case log_unlink_remount quota_log \
"an unlinked file cleaned by the log replay after remount" \
-oRL le 1 user
test_case_root default_deny_user quota_default_deny \
"new quota entry denied by default entry" 5 -b le 1 user
test_case_root default_deny_user_big quota_default_deny \
"new quota entry denied by default entry, with list on more than one block" 5000 -b le 1 user
quota_walk_list()
{
create_ffs_server $*
local q=$4
local expect
case ${q} in
user)
expect=u
fail=g
;;
group)
expect=g
fail=u
;;
*)
atf_fail "wrong quota type"
;;
esac
# create 100 users, all in the same hash list
local i=1;
while [ $i -lt 101 ]; do
atf_check -s exit:0 \
env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=vfs=getvfsstat,blanket=/mnt edquota -${expect} \
-s10k/20 -h40M/50k -t 2W/3D $((i * 4096))
i=$((i + 1))
done
# do a repquota
atf_check -s exit:0 -o 'match:user 409600 block *81920 20 0' \
env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=vfs=getvfsstat,blanket=/mnt repquota -x -${expect} /mnt
rump_quota_shutdown
}
quota_snap()
{
local flag=$1; shift
create_ffs $*
local q=$3
local expect
case ${q} in
user)
expect=u
fail=g
;;
group)
expect=g
fail=u
;;
*)
atf_fail "wrong quota type"
;;
esac
#start our server which takes a snapshot
atf_check -s exit:0 -o ignore \
$(atf_get_srcdir)/h_quota2_tests ${flag} 4 ${IMG} ${RUMP_SERVER}
# create a few users
local i=1;
while [ $i -lt 11 ]; do
atf_check -s exit:0 \
env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=vfs=getvfsstat,blanket=/mnt edquota -${expect} \
-s10k/20 -h40M/50k -t 2W/3D $i
i=$((i + 1))
done
# we should have 5 files (root + 4 regular files)
atf_check -s exit:0 \
-o 'match:- - 7days 5 - - 7days' \
env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=vfs=getvfsstat,blanket=/mnt repquota -av
#shutdown and check filesystem
rump_quota_shutdown
}
quota_log()
{
local srv2args=$1; shift
create_ffs $*
local q=$3
local expect
case ${q} in
user)
expect=u
fail=g
;;
group)
expect=g
fail=u
;;
*)
atf_fail "wrong quota type"
;;
esac
#start our server which create a file and unlink while keeping
# it open. The server halts itself without flush
atf_check -s exit:0 -o ignore \
$(atf_get_srcdir)/h_quota2_tests -loU 5 ${IMG} ${RUMP_SERVER}
# we should have one unlinked file, but the log covers it.
atf_check -s exit:0 -o match:'3 files' -e ignore \
fsck_ffs -nf -F ${IMG}
# have a kernel mount the fs again; it should cleanup the
# unlinked file
atf_check -o ignore -e ignore $(atf_get_srcdir)/h_quota2_tests \
${srv2args} -b 5 ${IMG} ${RUMP_SERVER}
#shutdown and check filesystem
rump_quota_shutdown
}
quota_default_deny()
{
local nusers=$1; shift
create_ffs_server $*
local q=$4
local expect
case ${q} in
user)
expect=u
fail=g
;;
group)
expect=g
fail=u
;;
*)
atf_fail "wrong quota type"
;;
esac
# create $nusers users, so we are sure the free list has entries
# from block 1. Start from 10, as non-root id is 1.
# set default to deny all
( echo "@format netbsd-quota-dump v1"
echo "# idtype id objtype hard soft usage expire grace"
echo "$q default block 0 0 0 0 0"
echo "$q default file 0 0 0 0 0"
local i=10;
while [ $i -lt $(($nusers + 10)) ]; do
echo "$q $i block 0 0 0 0 0"
echo "$q $i file 0 0 0 0 0"
i=$((i + 1))
done
) | atf_check -s exit:0 \
env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=vfs=getvfsstat,blanket=/mnt quotarestore -d /mnt
atf_check -s exit:0 rump.halt
#now start the server which does the limits tests
$(atf_get_srcdir)/h_quota2_tests -oC -b 0 ${IMG} ${RUMP_SERVER}
rump_quota_shutdown
}

View File

@ -1,138 +0,0 @@
/* $NetBSD: t_mount.c,v 1.13 2012/11/27 16:01:49 jakllsch Exp $ */
/*
* Basic tests for mounting
*/
/*
* 48Kimage:
* Adapted for rump and atf from a testcase supplied
* by Hubert Feyrer on netbsd-users@
*/
#include <atf-c.h>
#define FSTEST_IMGSIZE (96 * 512)
#include "../common/h_fsmacros.h"
#include <sys/types.h>
#include <sys/mount.h>
#include <stdlib.h>
#include <ufs/ufs/ufsmount.h>
#include <rump/rump.h>
#include <rump/rump_syscalls.h>
#include "../../h_macros.h"
ATF_TC(48Kimage);
ATF_TC_HEAD(48Kimage, tc)
{
atf_tc_set_md_var(tc, "descr", "mount small 48K ffs image");
}
ATF_TC_BODY(48Kimage, tc)
{
void *tmp;
atf_tc_expect_fail("PR kern/43573");
FSTEST_CONSTRUCTOR(tc, ffs, tmp);
atf_tc_expect_pass();
FSTEST_DESTRUCTOR(tc, ffs, tmp);
}
ATF_TC(fsbsizeovermaxphys);
ATF_TC_HEAD(fsbsizeovermaxphys, tc)
{
atf_tc_set_md_var(tc, "descr", "mounts file system with "
"blocksize > MAXPHYS");
/* PR kern/43727 */
}
ATF_TC_BODY(fsbsizeovermaxphys, tc)
{
char cmd[1024];
struct ufs_args args;
struct statvfs svb;
/*
* We cannot pass newfs parameters via the fstest interface,
* so do things the oldfashioned manual way.
*/
snprintf(cmd, sizeof(cmd), "newfs -G -b %d -F -s 10000 "
"ffs.img > /dev/null", MAXPHYS * 2);
if (system(cmd))
atf_tc_fail("cannot create file system");
rump_init();
if (rump_pub_etfs_register("/devdisk", "ffs.img", RUMP_ETFS_BLK))
atf_tc_fail("cannot register rump fake device");
args.fspec = __UNCONST("/devdisk");
if (rump_sys_mkdir("/mp", 0777) == -1)
atf_tc_fail_errno("create mountpoint");
/* mount succeeded? bad omen. confirm we're in trouble. */
if (rump_sys_mount(MOUNT_FFS, "/mp", 0, &args, sizeof(args)) != -1) {
rump_sys_statvfs1("/mp", &svb, ST_WAIT);
atf_tc_fail("not expecting to be alive");
}
/* otherwise we're do-ne */
}
ATF_TC(fsbsizeovermaxbsize);
ATF_TC_HEAD(fsbsizeovermaxbsize, tc)
{
atf_tc_set_md_var(tc, "descr", "mounts file system with "
"blocksize > MAXBSIZE");
}
ATF_TC_BODY(fsbsizeovermaxbsize, tc)
{
char cmd[1024];
struct ufs_args args;
struct statvfs svb;
/*
* We cannot pass newfs parameters via the fstest interface,
* so do things the oldfashioned manual way.
*/
snprintf(cmd, sizeof(cmd), "newfs -G -b %d -F -s 10000 "
"ffs.img > /dev/null", MAXBSIZE * 2);
if (system(cmd))
atf_tc_fail("cannot create file system");
rump_init();
if (rump_pub_etfs_register("/devdisk", "ffs.img", RUMP_ETFS_BLK))
atf_tc_fail("cannot register rump fake device");
args.fspec = __UNCONST("/devdisk");
if (rump_sys_mkdir("/mp", 0777) == -1)
atf_tc_fail_errno("create mountpoint");
/* mount succeeded? bad omen. confirm we're in trouble. */
if (rump_sys_mount(MOUNT_FFS, "/mp", 0, &args, sizeof(args)) != -1) {
rump_sys_statvfs1("/mp", &svb, ST_WAIT);
atf_tc_fail("not expecting to be alive");
}
/* otherwise we're do-ne */
}
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, 48Kimage);
ATF_TP_ADD_TC(tp, fsbsizeovermaxphys);
ATF_TP_ADD_TC(tp, fsbsizeovermaxbsize);
return atf_no_error();
}

View File

@ -1,16 +0,0 @@
$NetBSD: README,v 1.1 2010/07/26 15:53:00 pooka Exp $
This directory contains the necessary bits to get an NFS server
running in a rump kernel. In essence, it's:
* rpcbind
* mountd
* nfsd
Additionally, you need the libc rpc code which is in
tests/fs/common/nfsrpc.
TODO: make the standard nfs userspace services usable (the challenge
comes from rpc being in libc).
questions? ==> pooka@netbsd.org

View File

@ -1,102 +0,0 @@
/* $Id: t_bm.c,v 1.1 2014/06/23 10:53:20 shm Exp $ */
/*-
* Copyright (c) 2014 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Mateusz Kocielski.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__RCSID("$Id: t_bm.c,v 1.1 2014/06/23 10:53:20 shm Exp $");
#include <atf-c.h>
#include <stdio.h>
#include <sys/types.h>
#include <bm.h>
#include <string.h>
#include <stdlib.h>
ATF_TC(bm);
ATF_TC_HEAD(bm, tc)
{
atf_tc_set_md_var(tc, "descr", "Test bm(3)");
}
typedef struct {
const char *pattern;
const char *text;
const char *freq;
ssize_t match;
} t_testcase;
const t_testcase testcases[] = {
{"test", "test", NULL, 0},
{"test", "ttest", NULL, 1},
{"test", "tes", NULL, -1},
{"test", "testtesttest", NULL, 0},
{"test", "testtesttesttesttesttest", NULL, 0},
{"test", "------------------------", NULL, -1},
{"a", "a", NULL, 0},
{"a", "ba", NULL, 1},
{"a", "bba", NULL, 2},
{"bla", "bl", NULL, -1},
{"a", "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", NULL, -1},
{"test", "qfwiofjqeiwofjioqewfjeiqwjfiqewjfioqewfjioewqjfioewqjfioewqjoi",
NULL, -1},
{"needle", "haystack", NULL, -1},
{"netbsd", "freebsd netbsd openbsd", NULL, 8},
};
ATF_TC_BODY(bm, tc)
{
size_t ts;
u_char *off;
char *text;
bm_pat *pattern;
for (ts = 0; ts < sizeof(testcases)/sizeof(t_testcase); ts++) {
ATF_CHECK(pattern = bm_comp((const u_char *)testcases[ts].pattern,
strlen(testcases[ts].pattern), (const u_char *)testcases[ts].freq));
ATF_REQUIRE(text = strdup(testcases[ts].text));
off = bm_exec(pattern, (u_char *)text, strlen(text));
if (testcases[ts].match == -1)
ATF_CHECK_EQ(off, NULL);
else
ATF_CHECK_EQ(testcases[ts].match,
(off-(u_char *)text));
bm_free(pattern);
free(text);
}
}
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, bm);
return atf_no_error();
}

View File

@ -1,128 +0,0 @@
/* $NetBSD: t_connect.c,v 1.2 2015/04/05 23:17:41 rtr Exp $ */
/*
* Copyright (c) 2007, 2008 The NetBSD Foundation, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
* CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <err.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <atf-c.h>
ATF_TC(connect_low_port);
ATF_TC_HEAD(connect_low_port, tc)
{
atf_tc_set_md_var(tc, "descr", "Checks that low-port allocation "
"works");
atf_tc_set_md_var(tc, "require.user", "root");
}
ATF_TC_BODY(connect_low_port, tc)
{
struct sockaddr_in sin, sinlist;
int sd, val, slist;
socklen_t slen;
slist = socket(AF_INET, SOCK_STREAM, 0);
sd = socket(AF_INET, SOCK_STREAM, 0);
/* bind listening socket */
memset(&sinlist, 0, sizeof(sinlist));
sinlist.sin_family = AF_INET;
sinlist.sin_port = htons(31522);
sinlist.sin_addr.s_addr = inet_addr("127.0.0.1");
ATF_REQUIRE_EQ(bind(slist,
(struct sockaddr *)&sinlist, sizeof(sinlist)), 0);
ATF_REQUIRE_EQ(listen(slist, 1), 0);
val = IP_PORTRANGE_LOW;
if (setsockopt(sd, IPPROTO_IP, IP_PORTRANGE, &val,
sizeof(val)) == -1)
atf_tc_fail("setsockopt failed: %s", strerror(errno));
memset(&sin, 0, sizeof(sin));
sin.sin_port = htons(31522);
sin.sin_addr.s_addr = inet_addr("127.0.0.1");
sin.sin_family = AF_INET;
if (connect(sd, (struct sockaddr *)&sin, sizeof(sin)) == -1) {
int serrno = errno;
atf_tc_fail("connect failed: %s%s",
strerror(serrno),
serrno != EACCES ? "" :
" (see http://mail-index.netbsd.org/"
"source-changes/2007/12/16/0011.html)");
}
slen = sizeof(sin);
ATF_REQUIRE_EQ(getsockname(sd, (struct sockaddr *)&sin, &slen), 0);
ATF_REQUIRE_EQ(slen, sizeof(sin));
ATF_REQUIRE(ntohs(sin.sin_port) <= IPPORT_RESERVEDMAX);
close(sd);
}
ATF_TC(connect_foreign_family);
ATF_TC_HEAD(connect_foreign_family, tc)
{
atf_tc_set_md_var(tc, "descr", "Checks that connecting a socket "
"with a different address family fails");
}
ATF_TC_BODY(connect_foreign_family, tc)
{
struct sockaddr_in addr;
/* addr.sin_family = AF_UNSPEC = 0 */
memset(&addr, 0, sizeof(addr));
/*
* it is not necessary to initialize sin_{addr,port} since
* those structure members shall not be accessed if connect
* fails correctly.
*/
int sock = socket(AF_LOCAL, SOCK_STREAM, 0);
ATF_REQUIRE(sock != -1);
ATF_REQUIRE(-1 == connect(sock, (struct sockaddr *)&addr, sizeof(addr)));
ATF_REQUIRE(EAFNOSUPPORT == errno);
close(sock);
}
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, connect_low_port);
ATF_TP_ADD_TC(tp, connect_foreign_family);
return atf_no_error();
}

View File

@ -1,134 +0,0 @@
/* $NetBSD: t_listen.c,v 1.4 2012/03/18 07:00:52 jruoho Exp $ */
/*
* Copyright (c) 2007 The NetBSD Foundation, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
* CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <atf-c.h>
#include <err.h>
#include <errno.h>
#include <fcntl.h>
#include <string.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <netinet/in.h>
static const char *path = "listen";
ATF_TC_WITH_CLEANUP(listen_err);
ATF_TC_HEAD(listen_err, tc)
{
atf_tc_set_md_var(tc, "descr",
"Checks errors from listen(2) (PR standards/46150)");
}
ATF_TC_BODY(listen_err, tc)
{
static const size_t siz = sizeof(struct sockaddr_in);
struct sockaddr_in sina, sinb;
int fda, fdb, fdc;
(void)memset(&sina, 0, sizeof(struct sockaddr_in));
(void)memset(&sinb, 0, sizeof(struct sockaddr_in));
sina.sin_family = AF_INET;
sina.sin_port = htons(31522);
sina.sin_addr.s_addr = inet_addr("127.0.0.1");
sinb.sin_family = AF_INET;
sinb.sin_port = htons(31522);
sinb.sin_addr.s_addr = inet_addr("127.0.0.1");
fda = socket(AF_INET, SOCK_STREAM, 0);
fdb = socket(AF_INET, SOCK_STREAM, 0);
fdc = open("listen", O_RDWR | O_CREAT, 0600);
ATF_REQUIRE(fda >= 0 && fdb >= 0 && fdc >= 0);
ATF_REQUIRE_ERRNO(ENOTSOCK, listen(fdc, 1) == -1);
(void)close(fdc);
(void)unlink(path);
ATF_REQUIRE(bind(fda, (struct sockaddr *)&sina, siz) == 0);
ATF_REQUIRE(listen(fda, 1) == 0);
/*
* According to IEEE Std 1003.1-2008: if the socket is
* already connected, the call should fail with EINVAL.
*/
ATF_REQUIRE(connect(fdb, (struct sockaddr *)&sinb, siz) == 0);
ATF_REQUIRE_ERRNO(EINVAL, listen(fdb, 1) == -1);
(void)close(fda);
(void)close(fdb);
ATF_REQUIRE_ERRNO(EBADF, connect(fdb,
(struct sockaddr *)&sinb, siz) == -1);
}
ATF_TC_CLEANUP(listen_err, tc)
{
(void)unlink(path);
}
ATF_TC(listen_low_port);
ATF_TC_HEAD(listen_low_port, tc)
{
atf_tc_set_md_var(tc, "descr", "Does low-port allocation work?");
atf_tc_set_md_var(tc, "require.user", "root");
}
ATF_TC_BODY(listen_low_port, tc)
{
int sd, val;
sd = socket(AF_INET, SOCK_STREAM, 0);
val = IP_PORTRANGE_LOW;
if (setsockopt(sd, IPPROTO_IP, IP_PORTRANGE, &val,
sizeof(val)) == -1)
atf_tc_fail("setsockopt failed: %s", strerror(errno));
if (listen(sd, 5) == -1) {
int serrno = errno;
atf_tc_fail("listen failed: %s%s",
strerror(serrno),
serrno != EACCES ? "" :
" (see http://mail-index.netbsd.org/"
"source-changes/2007/12/16/0011.html)");
}
close(sd);
}
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, listen_err);
ATF_TP_ADD_TC(tp, listen_low_port);
return 0;
}

View File

@ -1,165 +0,0 @@
/* $NetBSD: t_posix_fadvise.c,v 1.1 2011/10/15 06:10:26 jruoho Exp $ */
/*-
* Copyright (c) 2008 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by YAMAMOTO Takashi.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*-
* Copyright (c)2005 YAMAMOTO Takashi,
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__COPYRIGHT("@(#) Copyright (c) 2008\
The NetBSD Foundation, inc. All rights reserved.");
__RCSID("$NetBSD: t_posix_fadvise.c,v 1.1 2011/10/15 06:10:26 jruoho Exp $");
#include <sys/fcntl.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
#include <atf-c.h>
#include "../../../h_macros.h"
#include <rump/rump.h>
#include <rump/rump_syscalls.h>
ATF_TC(posix_fadvise);
ATF_TC_HEAD(posix_fadvise, tc)
{
atf_tc_set_md_var(tc, "descr", "Checks posix_fadvise(2)");
}
ATF_TC(posix_fadvise_reg);
ATF_TC_HEAD(posix_fadvise_reg, tc)
{
atf_tc_set_md_var(tc, "descr", "Checks posix_fadvise(2) "
"for regular files");
}
ATF_TC_BODY(posix_fadvise, tc)
{
int fd;
int pipe_fds[2];
int badfd = 10;
int ret;
RL(fd = open("/dev/null", O_RDWR));
(void)close(badfd);
RL(pipe(pipe_fds));
/*
* it's hard to check if posix_fadvise is working properly.
* only check return values here.
*/
/* posix_fadvise shouldn't affect errno. */
#define CE(x, exp) \
do { \
int save = errno; \
errno = 999; \
ATF_CHECK_EQ_MSG(ret = (x), exp, "got: %d", ret); \
ATF_CHECK_EQ_MSG(errno, 999, "got: %s", strerror(errno)); \
errno = save; \
} while (0);
CE(posix_fadvise(fd, 0, 0, -1), EINVAL);
CE(posix_fadvise(pipe_fds[0], 0, 0, POSIX_FADV_NORMAL), ESPIPE);
CE(posix_fadvise(badfd, 0, 0, POSIX_FADV_NORMAL), EBADF);
CE(posix_fadvise(fd, 0, 0, POSIX_FADV_NORMAL), 0);
CE(posix_fadvise(fd, 0, 0, POSIX_FADV_SEQUENTIAL), 0);
CE(posix_fadvise(fd, 0, 0, POSIX_FADV_RANDOM), 0);
CE(posix_fadvise(fd, 0, 0, POSIX_FADV_WILLNEED), 0);
CE(posix_fadvise(fd, 0, 0, POSIX_FADV_DONTNEED), 0);
CE(posix_fadvise(fd, 0, 0, POSIX_FADV_NOREUSE), 0);
}
ATF_TC_BODY(posix_fadvise_reg, tc)
{
int rfd, ret;
rump_init();
RL(rfd = rump_sys_open("/a_file", O_CREAT, 0666));
CE(rump_sys_posix_fadvise(rfd, 0, 0, POSIX_FADV_NORMAL), 0);
CE(rump_sys_posix_fadvise(rfd, 0, 0, POSIX_FADV_SEQUENTIAL), 0);
CE(rump_sys_posix_fadvise(rfd, 0, 0, POSIX_FADV_RANDOM), 0);
CE(rump_sys_posix_fadvise(rfd, 0, 0, POSIX_FADV_WILLNEED), 0);
CE(rump_sys_posix_fadvise(rfd, 0, 0, POSIX_FADV_NOREUSE), 0);
CE(rump_sys_posix_fadvise(rfd,
INT64_MAX-getpagesize(), getpagesize(), POSIX_FADV_NORMAL), 0);
CE(rump_sys_posix_fadvise(rfd,
INT64_MAX-getpagesize(), getpagesize(), POSIX_FADV_SEQUENTIAL), 0);
CE(rump_sys_posix_fadvise(rfd,
INT64_MAX-getpagesize(), getpagesize(), POSIX_FADV_RANDOM), 0);
CE(rump_sys_posix_fadvise(rfd,
INT64_MAX-getpagesize(), getpagesize(), POSIX_FADV_WILLNEED), 0);
CE(rump_sys_posix_fadvise(rfd,
INT64_MAX-getpagesize(), getpagesize(), POSIX_FADV_NOREUSE), 0);
//atf_tc_expect_signal(-1, "http://mail-index.netbsd.org/source-changes-d/2010/11/11/msg002508.html");
CE(rump_sys_posix_fadvise(rfd,
INT64_MAX-getpagesize(), getpagesize(), POSIX_FADV_DONTNEED), 0);
CE(rump_sys_posix_fadvise(rfd, 0, 0, POSIX_FADV_DONTNEED), 0);
#undef CE
}
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, posix_fadvise);
ATF_TP_ADD_TC(tp, posix_fadvise_reg);
return atf_no_error();
}

View File

@ -1,92 +0,0 @@
above.warped.net
anoncvs.cirr.com
anoncvs.isc.netbsd.org
anoncvs.leo.org
anoncvs.netbsd.lt
anoncvs.netbsd.ro
anoncvs.netbsd.se
antioche.antioche.eu.org
boulder.tele.dk
centaurus.4web.cz
chur.math.ntnu.no
cnftp.bjpu.edu.cn
console.netbsd.org
cvs.fi.netbsd.org
cvs.mikrolahti.fi
cvs.netbsd.org
cvsup-netbsd.leo.org
cvsup.netbsd.se
cvsup.pasta.cs.uit.no
ftp.bitcon.no
ftp.chg.ru
ftp.duth.gr
ftp.estpak.ee
ftp.fsn.hu
ftp.funet.fi
ftp.grondar.za
ftp.leo.org
ftp.netbsd.lt
ftp.netbsd.org
ftp.nluug.nl
ftp.plig.org
ftp.uni-erlangen.de
ftp.xgate.co.kr
gd.tuwien.ac.at
gort.ludd.luth.se
grappa.unix-ag.uni-kl.de
info.wins.uva.nl
irc.warped.net
knug.youn.co.kr
lala.iri.co.jp
mail.jp.netbsd.org
mail.kr.netbsd.org
mail.netbsd.org
melanoma.cs.rmit.edu.au
mirror.aarnet.edu.au
mirror.netbsd.com.br
mirror03.inet.tele.dk
moon.vub.ac.be
nbwww.sergei.cc
net.bsd.cz
netbsd.3miasto.net
netbsd.4ka.mipt.ru
netbsd.apk.od.ua
netbsd.csie.nctu.edu.tw
netbsd.enderunix.org
netbsd.ftp.fu-berlin.de
netbsd.netlead.com.au
netbsd.nsysu.edu.tw
netbsd.pair.com
netbsd.stevens-tech.edu
netbsd.triada.bg
netbsd.unix.net.nz
netbsd.unixtech.be
netbsd.vejas.lt
netbsd.wagener-consulting.lu
netbsd.zarco.org
netbsdiso.interoute.net.uk
netbsdwww.bitcon.no
netbsdwww.cordef.com.pl
netbsdwww.cs.rmit.edu.au
netbsdwww.interoute.net.uk
news.gw.com
ns.netbsd.org
pigu.iri.co.jp
pluto.cdpa.nsysu.edu.tw
projects.slowass.net
server6.pasta.cs.uit.no
skeleton.phys.spbu.ru
snoopy.allbsd.org
spike.allbsd.org
sundry.netbsd.org
tanya.sergei.cc
web-a.fi.gw.com
web-a.us.gw.com
web.netbsd.mirror.arhea.net
www.en.netbsd.de
www.netbsd.cl
www.netbsd.nl
www.netbsd.org
www.netbsd.ro
zathras.netbsd.org
zeppo.rediris.es

View File

@ -1,148 +0,0 @@
/* $NetBSD: t_fpu.c,v 1.2 2013/01/27 14:47:37 mbalmer Exp $ */
/*
* Copyright (c) 2008 The NetBSD Foundation, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__COPYRIGHT("@(#) Copyright (c) 2008\
The NetBSD Foundation, inc. All rights reserved.");
__RCSID("$NetBSD: t_fpu.c,v 1.2 2013/01/27 14:47:37 mbalmer Exp $");
/*
* This is adapted from part of csw/cstest of the MPD implementation by
* the University of Arizona CS department (http://www.cs.arizona.edu/sr/)
* which is in the public domain:
*
* "The MPD system is in the public domain and you may use and distribute it
* as you wish. We ask that you retain credits referencing the University
* of Arizona and that you identify any changes you make.
*
* We can't provide a warranty with MPD; it's up to you to determine its
* suitability and reliability for your needs. We would like to hear of
* any problems you encounter but we cannot promise a timely correction."
*
* It was changed to use pthread_create() and sched_yield() instead of
* the internal MPD context switching primitives by Ignatios Souvatzis
* <is@netbsd.org>.
*/
#include <math.h>
#include <pthread.h>
#include <sched.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <atf-c.h>
#include "h_common.h"
#define N_RECURSE 10
static void recurse(void);
int recursion_depth = 0;
pthread_mutex_t recursion_depth_lock;
static void *
stir(void *p)
{
double *q = (double *)p;
double x = *q++;
double y = *q++;
double z = *q++;
for (;;) {
x = sin ((y = cos (x + y + .4)) - (z = cos (x + z + .6)));
PTHREAD_REQUIRE(sched_yield());
}
}
static double
mul3(double x, double y, double z)
{
PTHREAD_REQUIRE(sched_yield());
return x * y * z;
}
static void *
bar(void *p)
{
double d;
int rc;
d = mul3(mul3(2., 3., 5.), mul3(7., 11., 13.), mul3(17., 19., 23.));
ATF_REQUIRE_EQ(d, 223092870.);
PTHREAD_REQUIRE(pthread_mutex_lock(&recursion_depth_lock));
rc = recursion_depth++;
PTHREAD_REQUIRE(pthread_mutex_unlock(&recursion_depth_lock));
if (rc < N_RECURSE)
recurse();
else
atf_tc_pass();
/* NOTREACHED */
return NULL;
}
static void
recurse(void) {
pthread_t s2;
pthread_create(&s2, 0, bar, 0);
sleep(20); /* XXX must be long enough for our slowest machine */
}
ATF_TC(fpu);
ATF_TC_HEAD(fpu, tc)
{
atf_tc_set_md_var(tc, "descr",
"Checks that thread context switches will leave the "
"floating point computations unharmed");
}
ATF_TC_BODY(fpu, tc)
{
double stirseed[] = { 1.7, 3.2, 2.4 };
pthread_t s5;
printf("Testing threaded floating point computations...\n");
PTHREAD_REQUIRE(pthread_mutex_init(&recursion_depth_lock, 0));
pthread_create(&s5, 0, stir, stirseed);
recurse();
atf_tc_fail("exiting from main");
}
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, fpu);
return atf_no_error();
}

View File

@ -1,144 +0,0 @@
# $NetBSD: t_hello.sh,v 1.2 2012/07/21 12:30:55 martin Exp $
#
# Copyright (c) 2011 The NetBSD Foundation, Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
atf_test_case hello
hello_head() {
atf_set "descr" "compile and run \"hello world\""
atf_set "require.progs" "cc"
}
atf_test_case hello_pic
hello_pic_head() {
atf_set "descr" "compile and run PIC \"hello world\""
atf_set "require.progs" "cc"
}
atf_test_case hello_pie
hello_pie_head() {
atf_set "descr" "compile and run position independend (PIE) \"hello world\""
atf_set "require.progs" "cc"
}
atf_test_case hello32
hello32_head() {
atf_set "descr" "compile and run \"hello world\" for/in netbsd32 emulation"
atf_set "require.progs" "cc file diff cat"
}
hello_body() {
cat > test.c << EOF
#include <stdio.h>
#include <stdlib.h>
int main(void) {printf("hello world\n");exit(0);}
EOF
atf_check -s exit:0 -o ignore -e ignore cc -o hello test.c
atf_check -s exit:0 -o inline:"hello world\n" ./hello
}
hello_pic_body() {
cat > test.c << EOF
#include <stdlib.h>
int main(void) {callpic();exit(0);}
EOF
cat > pic.c << EOF
#include <stdio.h>
int callpic(void) {printf("hello world\n");}
EOF
atf_check -s exit:0 -o ignore -e ignore \
cc -fPIC -dPIC -shared -o libtest.so pic.c
atf_check -s exit:0 -o ignore -e ignore \
cc -o hello test.c -L. -ltest
export LD_LIBRARY_PATH=.
atf_check -s exit:0 -o inline:"hello world\n" ./hello
}
hello_pie_body() {
# check whether this arch supports -pie
if ! cc -pie -dM -E - < /dev/null 2>/dev/null >/dev/null; then
atf_skip "cc -pie not supported on this architecture"
fi
cat > test.c << EOF
#include <stdio.h>
#include <stdlib.h>
int main(void) {printf("hello world\n");exit(0);}
EOF
atf_check -s exit:0 -o ignore -e ignore cc -fpie -pie -o hello test.c
atf_check -s exit:0 -o inline:"hello world\n" ./hello
}
hello32_body() {
# check whether this arch is 64bit
if ! cc -dM -E - < /dev/null | fgrep -q _LP64; then
atf_skip "this is not a 64 bit architecture"
fi
if ! cc -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then
atf_skip "cc -m32 not supported on this architecture"
else
if fgrep -q _LP64 ./def32; then
atf_fail "cc -m32 does not generate netbsd32 binaries"
fi
fi
cat > test.c << EOF
#include <stdio.h>
#include <stdlib.h>
int main(void) {printf("hello world\n");exit(0);}
EOF
atf_check -s exit:0 -o ignore -e ignore cc -o hello32 -m32 test.c
atf_check -s exit:0 -o ignore -e ignore cc -o hello64 test.c
file -b ./hello32 > ./ftype32
file -b ./hello64 > ./ftype64
if diff ./ftype32 ./ftype64 >/dev/null; then
atf_fail "generated binaries do not differ"
fi
echo "32bit binaries on this platform are:"
cat ./ftype32
echo "While native (64bit) binaries are:"
cat ./ftype64
atf_check -s exit:0 -o inline:"hello world\n" ./hello32
# do another test with static 32bit binaries
cat > test.c << EOF
#include <stdio.h>
#include <stdlib.h>
int main(void) {printf("hello static world\n");exit(0);}
EOF
atf_check -s exit:0 -o ignore -e ignore cc -o hello -m32 \
-static test.c
atf_check -s exit:0 -o inline:"hello static world\n" ./hello
}
atf_init_test_cases()
{
atf_add_test_case hello
atf_add_test_case hello_pic
atf_add_test_case hello_pie
atf_add_test_case hello32
}

File diff suppressed because it is too large Load Diff

View File

@ -1,24 +0,0 @@
# $NetBSD: Makefile,v 1.2 2013/01/02 18:11:44 christos Exp $
NOMAN= # defined
.include <bsd.own.mk>
TESTSDIR= ${TESTSBASE}/usr.sbin/mtree
TESTS_SH= t_mtree
FILESDIR= ${TESTSDIR}
FILES+= d_convert.in
FILES+= d_convert_C.out
FILES+= d_convert_C_S.out
FILES+= d_convert_D.out
FILES+= d_convert_D_S.out
FILES+= netbsd6_d_create.out
FILES+= mtree_d_create.out
FILES+= d_merge.in
FILES+= d_merge_C_M.out
FILES+= d_merge_C_M_S.out
.include <bsd.test.mk>

View File

@ -1,425 +0,0 @@
# $NetBSD: t_mtree.sh,v 1.6 2013/02/05 16:49:42 christos Exp $
#
# Copyright (c) 2009, 2012 The NetBSD Foundation, Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# Postprocess mtree output, canonicalising portions that
# are expected to differ from one run to another.
#
# mtree is not in the default user PATH on MINIX
export PATH=$PATH:/usr/sbin
h_postprocess()
{
sed -e '
/^# user: /s/:.*/: x/
/^# machine: /s/:.*/: x/
/^# tree: /s/:.*/: x/
/^# date: /s/:.*/: x/
' \
-e '/type=dir/s/ size=[0-9]*//'
}
h_check()
{
diff -Nru "$1" "$2" || atf_fail "files $1 and $2 differ"
}
atf_test_case mtree_create
atf_test_case netbsd6_create
create_head()
{
atf_set "descr" "Create a specfile describing a directory tree"
}
create_setup()
{
# create some directories
rm -fr create
mkdir -p create/a/1 create/a/2 create/b
# create some files
for file in create/top.file.1 \
create/a/a.file.1 \
create/a/a.file.2 \
create/a/1/a1.file.1 \
create/b/b.file.1 \
create/b/b.file.2
do
echo "$file" >$file
done
# hard link to file in same dir
ln create/b/b.file.1 create/b/b.hardlink.1
# hard link to file in another dir
ln create/b/b.file.2 create/a/a.hardlink.b2
# symlink to file
ln -s a.file.1 create/a.symlink.1
# symlink to dir
ln -s b create/top.symlink.b
# dangling symlink
ln -s nonexistent create/top.dangling
}
create_body()
{
create_setup
# run mtree and check output
( cd create && mtree -F ${FLAVOR} -c -k type,nlink,link,size,sha256 ) >output.raw \
|| atf_fail "mtree exit status $?"
h_postprocess <output.raw >output
h_check "$(atf_get_srcdir)/${FLAVOR}_d_create.out" output
}
mtree_create_head()
{
FLAVOR=mtree create_head
}
netbsd6_create_head()
{
FLAVOR=netbsd6 create_head
}
mtree_create_body()
{
FLAVOR=mtree create_body
}
netbsd6_create_body()
{
FLAVOR=netbsd6 create_body
}
atf_test_case mtree_check
atf_test_case netbsd6_check
check_head()
{
atf_set "descr" "Check a directory tree against a specfile"
}
check_body()
{
# we use the same directory tree and specfile as in the "create" test
create_setup
# run mtree and check output
( cd create && mtree -F ${FLAVOR} ) <"$(atf_get_srcdir)/${FLAVOR}_d_create.out" >output \
|| atf_fail "mtree exit status $?"
h_check /dev/null output
}
mtree_check_head()
{
FLAVOR=mtree check_head
}
netbsd6_check_head()
{
FLAVOR=netbsd6 check_head
}
mtree_check_body()
{
FLAVOR=mtree check_body
}
netbsd6_check_body()
{
FLAVOR=netbsd6 check_body
}
atf_test_case mtree_convert_C
atf_test_case netbsd6_convert_C
convert_C_head()
{
atf_set "descr" "Convert a specfile to mtree -C format, unsorted"
}
convert_C_body()
{
mtree -F ${FLAVOR} -C -K all <"$(atf_get_srcdir)/d_convert.in" >output
h_check "$(atf_get_srcdir)/d_convert_C.out" output
}
mtree_convert_C_head()
{
FLAVOR=mtree convert_C_head
}
netbsd6_convert_C_head()
{
FLAVOR=netbsd6 convert_C_head
}
mtree_convert_C_body()
{
FLAVOR=mtree convert_C_body
}
netbsd6_convert_C_body()
{
FLAVOR=netbsd6 convert_C_body
}
atf_test_case mtree_convert_C_S
atf_test_case netbsd6_convert_C_S
convert_C_S_head()
{
atf_set "descr" "Convert a specfile to mtree -C format, sorted"
}
convert_C_S_body()
{
mtree -F ${FLAVOR} -C -S -K all <"$(atf_get_srcdir)/d_convert.in" >output
h_check "$(atf_get_srcdir)/d_convert_C_S.out" output
}
mtree_convert_C_S_head()
{
FLAVOR=mtree convert_C_S_head
}
netbsd6_convert_C_S_head()
{
FLAVOR=netbsd6 convert_C_S_head
}
mtree_convert_C_S_body()
{
FLAVOR=mtree convert_C_S_body
}
netbsd6_convert_C_S_body()
{
FLAVOR=netbsd6 convert_C_S_body
}
atf_test_case mtree_convert_D
atf_test_case netbsd6_convert_D
convert_D_head()
{
atf_set "descr" "Convert a specfile to mtree -D format, unsorted"
}
convert_D_body()
{
mtree -F ${FLAVOR} -D -K all <"$(atf_get_srcdir)/d_convert.in" >output
h_check "$(atf_get_srcdir)/d_convert_D.out" output
}
mtree_convert_D_head()
{
FLAVOR=mtree convert_D_head
}
netbsd6_convert_D_head()
{
FLAVOR=netbsd6 convert_D_head
}
mtree_convert_D_body()
{
FLAVOR=mtree convert_D_body
}
netbsd6_convert_D_body()
{
FLAVOR=netbsd6 convert_D_body
}
atf_test_case mtree_convert_D_S
atf_test_case netbsd6_convert_D_S
convert_D_S_head()
{
atf_set "descr" "Convert a specfile to mtree -D format, sorted"
}
convert_D_S_body()
{
mtree -F ${FLAVOR} -D -S -K all <"$(atf_get_srcdir)/d_convert.in" >output
h_check "$(atf_get_srcdir)/d_convert_D_S.out" output
}
mtree_convert_D_S_head()
{
FLAVOR=mtree convert_D_S_head
}
netbsd6_convert_D_S_head()
{
FLAVOR=netbsd6 convert_D_S_head
}
mtree_convert_D_S_body()
{
FLAVOR=mtree convert_D_S_body
}
netbsd6_convert_D_S_body()
{
FLAVOR=netbsd6 convert_D_S_body
}
atf_test_case mtree_ignore
atf_test_case netbs6_ignore
ignore_head()
{
atf_set "descr" "Test that -d ignores symlinks (PR bin/41061)"
}
ignore_body()
{
mkdir newdir
mtree -F ${FLAVOR} -c | mtree -F ${FLAVOR} -Ck uid,gid,mode > mtree.spec
ln -s newdir otherdir
# This yields "extra: otherdir" even with -d.
# (PR bin/41061)
atf_check -s ignore -o empty -e empty -x "mtree -F ${FLAVOR} -d < mtree.spec"
# Delete the symlink and re-verify.
#
rm otherdir
atf_check -s ignore -o empty -e empty -x "mtree -F ${FLAVOR} -d < mtree.spec"
}
mtree_ignore_head()
{
FLAVOR=mtree ignore_head
}
netbsd6_ignore_head()
{
FLAVOR=netbsd6 ignore_head
}
mtree_ignore_body()
{
FLAVOR=mtree ignore_body
}
netbsd6_ignore_body()
{
FLAVOR=netbsd6 ignore_body
}
atf_test_case mtree_merge
atf_test_case netbsd6_merge
merge_head()
{
atf_set "descr" "Merge records of different type"
}
merge_body()
{
mtree -F ${FLAVOR} -C -M -K all <"$(atf_get_srcdir)/d_merge.in" >output
h_check "$(atf_get_srcdir)/d_merge_C_M.out" output
# same again, with sorting
mtree -F ${FLAVOR} -C -M -S -K all <"$(atf_get_srcdir)/d_merge.in" >output
h_check "$(atf_get_srcdir)/d_merge_C_M_S.out" output
}
mtree_merge_head()
{
FLAVOR=mtree merge_head
}
netbsd6_merge_head()
{
FLAVOR=netbsd6 merge_head
}
mtree_merge_body()
{
FLAVOR=mtree merge_body
}
netbsd6_merge_body()
{
FLAVOR=netbsd6 merge_body
}
atf_test_case mtree_nonemptydir
atf_test_case netbsd6_nonemptydir
nonemptydir_head()
{
atf_set "descr" "Test that new non-empty " \
"directories are recorded (PR bin/25693)"
}
nonemptydir_body()
{
mkdir testdir
cd testdir
mtree -F ${FLAVOR} -c > mtree.spec
if [ ! -f mtree.spec ]; then
atf_fail "mtree failed"
fi
touch bar
atf_check -s ignore -o save:output -x "mtree -F ${FLAVOR} -f mtree.spec"
if [ ! -n "$(egrep "extra: bar" output)" ]; then
atf_fail "mtree did not record changes (PR bin/25693)"
fi
}
mtree_nonemptydir_head()
{
FLAVOR=mtree nonemptydir_head
}
netbsd6_nonemptydir_head()
{
FLAVOR=netbsd6 nonemptydir_head
}
mtree_nonemptydir_body()
{
FLAVOR=mtree nonemptydir_body
}
netbsd6_nonemptydir_body()
{
FLAVOR=netbsd6 nonemptydir_body
}
atf_init_test_cases()
{
atf_add_test_case mtree_create
atf_add_test_case mtree_check
atf_add_test_case mtree_convert_C
atf_add_test_case mtree_convert_C_S
atf_add_test_case mtree_convert_D
atf_add_test_case mtree_convert_D_S
atf_add_test_case mtree_ignore
atf_add_test_case mtree_merge
atf_add_test_case mtree_nonemptydir
atf_add_test_case netbsd6_create
atf_add_test_case netbsd6_check
atf_add_test_case netbsd6_convert_C
atf_add_test_case netbsd6_convert_C_S
atf_add_test_case netbsd6_convert_D
atf_add_test_case netbsd6_convert_D_S
atf_add_test_case netbsd6_ignore
atf_add_test_case netbsd6_merge
atf_add_test_case netbsd6_nonemptydir
}

View File

@ -1,241 +0,0 @@
.\" $NetBSD: calendar.1,v 1.25 2010/06/08 03:08:47 riz Exp $
.\"
.\" Copyright (c) 1989, 1990, 1993
.\" The Regents of the University of California. All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. Neither the name of the University nor the names of its contributors
.\" may be used to endorse or promote products derived from this software
.\" without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" @(#)calendar.1 8.1 (Berkeley) 6/29/93
.\"
.Dd August 27, 2009
.Dt CALENDAR 1
.Os
.Sh NAME
.Nm calendar
.Nd reminder service
.Sh SYNOPSIS
.Nm
.Op Fl ax
.Op Fl d Ar MMDD[[YY]YY]
.Op Fl f Ar file
.Op Fl l Ar days
.Op Fl w Ar days
.Sh DESCRIPTION
The
.Nm
utility processes text files and displays lines that match certain dates.
.Pp
The following options are available:
.Bl -tag -width Ds
.It Fl a
Process the
.Dq calendar
files of all users and mail the results to them.
This requires super-user privileges.
.It Fl d Ar MMDD[[YY]YY]
Display lines for the given date.
By default, the current date is used.
The year, which may be given in either two or four digit format, is used
only for purposes of determining whether the given date falls on a Friday
in that year (see below).
If the year is not specified, the current year is assumed.
.It Fl f Ar file
Display matching calendar files from the given filename.
By default, the following filenames are checked for:
.Bl -item -compact -offset indent
.It
.Pa ~/calendar
.It
.Pa ~/.calendar
.It
.Pa /etc/calendar
.El
and the first which is found is used.
The filename may be absolute.
If not absolute, it is taken relative to the
directory specified by the
.Ev CALENDAR_DIR
environment variable, if set; otherwise, it is taken relative to the
user's home directory.
Or, if the
.Fl a
flag is given, a non-absolute filename is taken relative to each user's
home directory in turn.
.It Fl l Ar days
Causes the program to
.Dq look ahead
a given number of days (default one) from the specified date and
display their entries as well.
.It Fl w Ar days
Causes the program to add the specified number of days to the
.Dq look ahead
number if and only if the day specified is a Friday.
The default value is two, which causes
.Nm
to print entries through the weekend on Fridays.
.It Fl x
Causes
.Nm
not to set the
.Ev CPP_RESTRICTED
environment variable.
Passing this flag allows users the (somewhat obscure) option of
including a named pipe via
.Xr cpp 1 Ns No 's
.Li #include
syntax, but opens up the possibility of
.Nm
hanging indefinitely if users do so incorrectly.
For this reason, the
.Fl x
flag should never be used with
.Nm
.Fl a .
.El
.Pp
Lines should begin with a month and day.
They may be entered in almost any format, either numeric or as character
strings.
A single asterisk
.Pq Sq *
matches every month, or every day if a month has been provided.
This means that two asterisks
.Pq Sq **
matches every day of the year, and is thus useful for ToDo tasks.
A day without a month matches that day of every week.
A month without a day matches the first of that month.
Two numbers default to the month followed by the day.
Lines with leading tabs default to the last entered date, allowing
multiple line specifications for a single date.
By convention, dates followed by an asterisk are not fixed, i.e., change
from year to year.
.Pp
The
.Dq calendar
file is preprocessed by
.Xr cpp 1 ,
allowing the inclusion of shared files such as company holidays or
meetings.
If the shared file is not referenced by a full pathname,
.Xr cpp 1
searches in the current (or home) directory first, and then in the
directory
.Pa /usr/share/calendar .
Empty lines and lines protected by the C commenting syntax
.Pq Li /* ... */
are ignored.
.Pp
Some possible calendar entries:
.Bd -literal -offset indent
#include \*[Lt]calendar.usholiday\*[Gt]
#include \*[Lt]calendar.birthday\*[Gt]
6/15 ... June 15 (if ambiguous, will default to month/day).
Jun. 15 ... June 15.
15 June ... June 15.
Thursday ... Every Thursday.
June ... Every June 1st.
15 * ... 15th of every month.
*15 ... 15th of every month.
June* ... Every day of June.
** ... Every day
.Ed
.Sh FILES
The following default calendar files are provided:
.Pp
.Bl -tag -width calendar.christian -compact
.It Pa calendar.birthday
Births and deaths of famous (and not-so-famous) people.
.It Pa calendar.christian
Christian holidays.
This calendar should be updated yearly by the local system administrator
so that roving holidays are set correctly for the current year.
.It Pa calendar.computer
Days of special significance to computer people.
.It Pa calendar.history
Everything else, mostly U.S. historical events.
.It Pa calendar.holiday
Other holidays, including the not-well-known, obscure, and
.Em really
obscure.
.It Pa calendar.judaic
Jewish holidays.
This calendar should be updated yearly by the local system administrator
so that roving holidays are set correctly for the current year.
.It Pa calendar.lotr
Important dates in the Lord of the Rings series.
.It Pa calendar.music
Musical events, births, and deaths.
Strongly oriented toward rock 'n' roll.
.It Pa calendar.netbsd
Important dates in the history of the
.Nx
project.
Mostly releases and port additions.
.It Pa calendar.usholiday
U.S. holidays.
This calendar should be updated yearly by the local system administrator
so that roving holidays are set correctly for the current year.
.El
.Sh COMPATIBILITY
The
.Nm
program previously selected lines which had the correct date anywhere
in the line.
This is no longer true, the date is only recognized when it occurs
first on the line.
.Pp
In
.Nx 3.0 ,
the
.Nm
command was modified to search the user's home directory instead of the current
directory by default.
Users desiring the historical behavior should set the
.Ev CALENDAR_DIR
environment variable to
.Pa \&. ,
or use the
.Fl f
flag.
.Sh SEE ALSO
.Xr at 1 ,
.Xr cpp 1 ,
.Xr cron 8
.Sh HISTORY
A
.Nm
command appeared in
.At v7 .
.Sh BUGS
.Nm
doesn't handle events that move around from year to year, i.e.,
.Dq the last Monday in April .
.Pp
The
.Fl a
option ignores the user's
.Ev CALENDAR_DIR
environment variable.

File diff suppressed because it is too large Load Diff

View File

@ -1,58 +0,0 @@
# $NetBSD: Makefile,v 1.58 2015/06/17 17:43:23 christos Exp $
# @(#)Makefile 5.2 (Berkeley) 12/28/90
PROG= make
SRCS= arch.c buf.c compat.c cond.c dir.c for.c hash.c job.c main.c \
make.c metachar.c parse.c str.c suff.c targ.c trace.c var.c util.c
SRCS+= strlist.c
SRCS+= make_malloc.c
SRCS+= lstAppend.c lstAtEnd.c lstAtFront.c lstClose.c lstConcat.c \
lstDatum.c lstDeQueue.c lstDestroy.c lstDupl.c lstEnQueue.c \
lstFind.c lstFindFrom.c lstFirst.c lstForEach.c lstForEachFrom.c \
lstInit.c lstInsert.c lstIsAtEnd.c lstIsEmpty.c lstLast.c \
lstMember.c lstNext.c lstOpen.c lstRemove.c lstReplace.c lstSucc.c
SRCS += lstPrev.c
# let people experiment for a bit
USE_META ?= no
.if ${USE_META:tl} != "no"
SRCS+= meta.c
CPPFLAGS+= -DUSE_META
FILEMON_H ?= ${.CURDIR:H:H}/sys/dev/filemon/filemon.h
.if exists(${FILEMON_H}) && ${FILEMON_H:T} == "filemon.h"
COPTS.meta.c += -DHAVE_FILEMON_H -I${FILEMON_H:H}
.endif
.endif
.if defined(__MINIX)
CPPFLAGS+= -DMAKE_MACHINE=\"${MACHINE}\" -DMAKE_MACHINE_ARCH=\"${MACHINE_ARCH}\"
.endif #defined(__MINIX)
.PATH: ${.CURDIR}/lst.lib
.if !defined(__MINIX)
SUBDIR= PSD.doc
.endif #!defined(__MINIX)
.if make(obj) || make(clean)
SUBDIR+= unit-tests
.endif
.include <bsd.prog.mk>
.include <bsd.subdir.mk>
CPPFLAGS+= -DMAKE_NATIVE
COPTS.var.c += -Wno-cast-qual
COPTS.job.c += -Wno-format-nonliteral
COPTS.parse.c += -Wno-format-nonliteral
COPTS.var.c += -Wno-format-nonliteral
.ifdef TOOLDIR
# this is a native netbsd build,
# use libutil rather than the local emalloc etc.
CPPFLAGS+= -DUSE_EMALLOC
LDADD+=-lutil
DPADD+=${LIBUTIL}
.endif
# A simple unit-test driver to help catch regressions
accept test:
cd ${.CURDIR}/unit-tests && MAKEFLAGS= ${.MAKE} -r -m / TEST_MAKE=${TEST_MAKE:U${.OBJDIR}/${PROG:T}} ${.TARGET}

View File

@ -1,119 +0,0 @@
/* $NetBSD: buf.h,v 1.17 2012/04/24 20:26:58 sjg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
*
* This code is derived from software contributed to Berkeley by
* Adam de Boor.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* from: @(#)buf.h 8.1 (Berkeley) 6/6/93
*/
/*
* Copyright (c) 1988, 1989 by Adam de Boor
* Copyright (c) 1989 by Berkeley Softworks
* All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Adam de Boor.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* from: @(#)buf.h 8.1 (Berkeley) 6/6/93
*/
/*-
* buf.h --
* Header for users of the buf library.
*/
#ifndef _BUF_H
#define _BUF_H
typedef char Byte;
typedef struct Buffer {
int size; /* Current size of the buffer */
int count; /* Number of bytes in buffer */
Byte *buffer; /* The buffer itself (zero terminated) */
} Buffer;
/* If we aren't on netbsd, __predict_false() might not be defined. */
#ifndef __predict_false
#define __predict_false(x) (x)
#endif
/* Buf_AddByte adds a single byte to a buffer. */
#define Buf_AddByte(bp, byte) do { \
int _count = ++(bp)->count; \
char *_ptr; \
if (__predict_false(_count >= (bp)->size)) \
Buf_Expand_1(bp); \
_ptr = (bp)->buffer + _count; \
_ptr[-1] = (byte); \
_ptr[0] = 0; \
} while (0)
#define BUF_ERROR 256
#define Buf_Size(bp) ((bp)->count)
void Buf_Expand_1(Buffer *);
void Buf_AddBytes(Buffer *, int, const Byte *);
Byte *Buf_GetAll(Buffer *, int *);
void Buf_Empty(Buffer *);
void Buf_Init(Buffer *, int);
Byte *Buf_Destroy(Buffer *, Boolean);
Byte *Buf_DestroyCompact(Buffer *);
#endif /* _BUF_H */

View File

@ -1,827 +0,0 @@
/* $NetBSD: menu_sys.def,v 1.59 2012/03/06 16:55:18 mbalmer Exp $ */
/*
* Copyright 1997 Piermont Information Systems Inc.
* All rights reserved.
*
* Written by Philip A. Nelson for Piermont Information Systems Inc.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of Piermont Information Systems Inc. may not be used to endorse
* or promote products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY PIERMONT INFORMATION SYSTEMS INC. ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL PIERMONT INFORMATION SYSTEMS INC. BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/* menu_sys.defs -- Menu system standard routines. */
#include <string.h>
#include <ctype.h>
#define REQ_EXECUTE 1000
#define REQ_NEXT_ITEM 1001
#define REQ_PREV_ITEM 1002
#define REQ_REDISPLAY 1003
#define REQ_SCROLLDOWN 1004
#define REQ_SCROLLUP 1005
#define REQ_HELP 1006
/* Macros */
#define MAX(x,y) ((x)>(y)?(x):(y))
#define MIN(x,y) ((x)<(y)?(x):(y))
/* Initialization state. */
static int __menu_init = 0;
static int max_lines = 0, max_cols = 0;
#ifndef scrolltext
static const char *scrolltext = " <: page up, >: page down";
#endif
#ifdef DYNAMIC_MENUS
static int num_menus = 0;
#define DYN_INIT_NUM 32
static menudesc **menu_list;
#define MENUS(n) (*(menu_list[n]))
#else
#define MENUS(n) (menu_def[n])
#endif
/* prototypes for in here! */
static void init_menu(menudesc *m);
static char opt_ch(menudesc *m, int op_no);
static void draw_menu(menudesc *m, void *arg);
static void process_help(menudesc *m);
static void process_req(menudesc *m, void *arg, int req);
static int menucmd(WINDOW *w);
#ifndef NULL
#define NULL 0
#endif
/* menu system processing routines */
#define mbeep() (void)fputc('\a', stderr)
static int
menucmd(WINDOW *w)
{
int ch;
while (TRUE) {
ch = wgetch(w);
switch (ch) {
case '\n':
return REQ_EXECUTE;
case '\016': /* Control-P */
case KEY_DOWN:
return REQ_NEXT_ITEM;
case '\020': /* Control-N */
case KEY_UP:
return REQ_PREV_ITEM;
case '\014': /* Control-L */
return REQ_REDISPLAY;
case '<':
case '\010': /* Control-H (backspace) */
case KEY_PPAGE:
case KEY_LEFT:
return REQ_SCROLLUP;
case '\026': /* Control-V */
case '>':
case ' ':
case KEY_NPAGE:
case KEY_RIGHT:
return REQ_SCROLLDOWN;
case '?':
return REQ_HELP;
case '\033': /* esc-v is scroll down */
ch = wgetch(w);
if (ch == 'v')
return REQ_SCROLLUP;
else
ch = 0; /* zap char so we beep */
}
if (isalpha(ch))
return ch;
mbeep();
wrefresh(w);
}
}
static void
init_menu(menudesc *m)
{
int wmax;
int hadd, wadd, exithadd;
int i;
int x, y, w;
const char *title, *tp, *ep;
x = m->x;
y = m->y;
w = m->w;
wmax = 0;
hadd = ((m->mopt & MC_NOBOX) ? 0 : 2);
wadd = ((m->mopt & MC_NOBOX) ? 2 : 4);
if (!(m->mopt & MC_NOSHORTCUT))
wadd += 3;
if (m->title && *(title = MSG_XLAT(m->title)) != 0) {
/* Allow multiple line titles */
for (tp = title; (ep = strchr(tp, '\n')); tp = ep + 1) {
i = ep - tp;
wmax = MAX(wmax, i);
hadd++;
}
hadd++;
i = strlen(tp);
wmax = MAX(wmax, i);
if (i != 0)
hadd++;
} else {
m->title = NULL;
title = "untitled";
}
exithadd = ((m->mopt & MC_NOEXITOPT) ? 0 : 1);
#ifdef MSG_DEFS_H
if (y < 0) {
/* put menu box below message text */
y = -y;
i = msg_row();
if (i > y)
y = i;
}
#endif
/* Calculate h? h == number of visible options. */
if (m->h == 0)
m->h = m->numopts + exithadd;
if (m->h > max_lines - y - hadd) {
/* Not enough space for all the options */
if (m->h <= 4 || !(m->mopt & (MC_SCROLL | MC_ALWAYS_SCROLL))) {
/* move menu up screen */
y = max_lines - hadd - m->h;
if (y < 0)
y = 0;
}
m->h = max_lines - y - hadd;
}
if (m->h < m->numopts + exithadd || m->mopt & MC_ALWAYS_SCROLL) {
/* We need to add the scroll text...
* The used to be a check for MC_SCROLL here, but it is
* fairly pointless - you just don't want the program
* to exit on this sort of error.
*/
if (m->h < 3) {
endwin();
(void)fprintf(stderr,
"Window too short (m->h %d, m->numopts %d, exithadd %d, y %d, max_lines %d, hadd %d) for menu \"%.30s\"\n",
m->h, m->numopts, exithadd, y, max_lines, hadd,
title);
exit(1);
}
hadd++;
m->h = MIN(m->h, max_lines - y - hadd);
i = strlen(scrolltext);
wmax = MAX(wmax, i);
}
/* Calculate w? */
if (w == 0) {
int l;
for (i = 0; i < m->numopts; i++) {
tp = MSG_XLAT(m->opts[i].opt_name);
if (tp == NULL)
continue;
l = strlen(tp);
wmax = MAX(wmax, l);
}
w = wmax;
}
/* check and adjust for screen fit */
if (w + wadd > max_cols) {
endwin();
(void)fprintf(stderr,
"Screen too narrow (%d + %d > %d) for menu \"%s\"\n",
w, wadd, max_cols, title);
exit(1);
}
if (x == -1)
x = (max_cols - (w + wadd)) / 2; /* center */
else if (x + w + wadd > max_cols)
x = max_cols - (w + wadd); /* right align */
if (y == 0) {
/* Center - rather than top */
y = (max_lines - hadd - m->h) / 2;
}
/* Get the windows. */
m->mw = newwin(m->h + hadd, w + wadd, y, x);
if (m->mw == NULL) {
endwin();
(void)fprintf(stderr,
"Could not create window (%d + %d, %d + %d, %d, %d) for menu \"%s\"\n",
m->h, hadd, w, wadd, y, x, title);
exit(1);
}
keypad(m->mw, TRUE); /* enable multi-key assembling for win */
/* XXX is it even worth doing this right? */
if (has_colors()) {
wbkgd(m->mw, COLOR_PAIR(1));
wattrset(m->mw, COLOR_PAIR(1));
}
if (m->mopt & MC_SUBMENU) {
/* Keep a copy of what is on the screen under the window */
m->sv_mw = newwin(m->h + hadd, w + wadd, y, x);
/*
* cursrc contains post-doupdate() data, not post-refresh()
* data so we must call doupdate to ensure we save the
* correct data. Avoids PR 26660.
*/
doupdate();
if (m->sv_mw)
overwrite(curscr, m->sv_mw);
}
}
static char
opt_ch(menudesc *m, int op_no)
{
char c;
if (op_no == m->numopts)
return 'x';
if (op_no < 25) {
c = 'a' + op_no;
if (c >= 'x')
c++;
} else
c = 'A' + op_no - 25;
return c;
}
static void
draw_menu_line(menudesc *m, int opt, int cury, void *arg, const char *text)
{
int hasbox = m->mopt & MC_NOBOX ? 0 : 1;
if (m->cursel == opt) {
mvwaddstr(m->mw, cury, hasbox, ">");
wstandout(m->mw);
} else
mvwaddstr(m->mw, cury, hasbox, " ");
if (!(m->mopt & MC_NOSHORTCUT))
wprintw(m->mw, "%c: ", opt_ch(m, opt));
if (!text && m->draw_line)
m->draw_line(m, opt, arg);
else
waddstr(m->mw, MSG_XLAT(text));
if (m->cursel == opt)
wstandend(m->mw);
}
static void
draw_menu(menudesc *m, void *arg)
{
int opt;
int hasbox, cury, maxy;
int tadd;
int hasexit = (m->mopt & MC_NOEXITOPT ? 0 : 1);
const char *tp, *ep;
hasbox = (m->mopt & MC_NOBOX ? 0 : 1);
/* Clear the window */
wclear(m->mw);
tadd = hasbox;
if (m->title) {
for (tp = MSG_XLAT(m->title); ; tp = ep + 1) {
ep = strchr(tp , '\n');
mvwaddnstr(m->mw, tadd++, hasbox + 1, tp,
ep ? ep - tp : -1);
if (ep == NULL || *ep == 0)
break;
}
tadd++;
}
cury = tadd;
maxy = getmaxy(m->mw) - hasbox;
if (m->numopts + hasexit > m->h)
/* allow for scroll text */
maxy--;
if (m->cursel == -1) {
m->cursel = m->numopts;
if (m->h <= m->numopts)
m->topline = m->numopts + 1 - m->h;
}
while (m->cursel >= m->topline + m->h)
m->topline = MIN(m->topline + m->h,
m->numopts + hasexit - m->h);
while (m->cursel < m->topline)
m->topline = MAX(0, m->topline - m->h);
for (opt = m->topline; opt < m->numopts; opt++) {
if (cury >= maxy)
break;
draw_menu_line(m, opt, cury++, arg, m->opts[opt].opt_name);
}
/* Add the exit option. */
if (!(m->mopt & MC_NOEXITOPT)) {
if (cury < maxy)
draw_menu_line(m, m->numopts, cury++, arg, m->exitstr);
else
opt = 0;
}
/* Add the scroll line */
if (opt != m->numopts || m->topline != 0)
mvwaddstr(m->mw, cury, hasbox, scrolltext);
/* Add the box. */
if (!(m->mopt & MC_NOBOX))
box(m->mw, 0, 0);
wmove(m->mw, tadd + m->cursel - m->topline, hasbox);
wrefresh(m->mw);
}
static void
/*ARGSUSED*/
process_help(menudesc *m)
{
const char *help = m->helpstr;
WINDOW *sv_curscr;
int lineoff = 0;
int curoff = 0;
int again;
int winin;
/* Is there help? */
if (!help) {
mbeep();
return;
}
sv_curscr = newwin(getmaxy(curscr), getmaxx(curscr), 0, 0);
if (!sv_curscr) {
mbeep();
return;
}
/*
* Save screen contents so we can restore before returning.
* cursrc contains post-doupdate() data, not post-refresh()
* data so we must call doupdate to ensure we save the
* correct data. Avoids PR 26660.
*/
doupdate();
overwrite(curscr, sv_curscr);
touchwin(stdscr);
help = MSG_XLAT(help);
/* Display the help information. */
do {
if (lineoff < curoff) {
help = MSG_XLAT(m->helpstr);
curoff = 0;
}
while (*help && curoff < lineoff) {
if (*help == '\n')
curoff++;
help++;
}
wclear(stdscr);
mvwaddstr(stdscr, 0, 0,
"Help: exit: x, page up: u <, page down: d >");
mvwaddstr(stdscr, 2, 0, help);
wmove(stdscr, 1, 0);
wrefresh(stdscr);
do {
winin = wgetch(stdscr);
if (winin < KEY_MIN)
winin = tolower(winin);
again = 0;
switch (winin) {
case '<':
case 'u':
case KEY_UP:
case KEY_LEFT:
case KEY_PPAGE:
if (lineoff)
lineoff -= max_lines - 2;
else
again = 1;
break;
case '>':
case 'd':
case KEY_DOWN:
case KEY_RIGHT:
case KEY_NPAGE:
if (*help)
lineoff += max_lines - 2;
else
again = 1;
break;
case 'q':
break;
case 'x':
winin = 'q';
break;
default:
again = 1;
}
if (again)
mbeep();
} while (again);
} while (winin != 'q');
/* Restore the original screen contents */
touchwin(sv_curscr);
wnoutrefresh(sv_curscr);
delwin(sv_curscr);
/* Some code thinks that wrefresh(stdout) is a good idea... */
wclear(stdscr);
}
static void
process_req(menudesc *m, void *arg, int req)
{
int ch;
int hasexit = (m->mopt & MC_NOEXITOPT ? 0 : 1);
switch(req) {
case REQ_EXECUTE:
return;
case REQ_NEXT_ITEM:
ch = m->cursel;
for (;;) {
ch++;
if (ch >= m->numopts + hasexit) {
mbeep();
return;
}
if (hasexit && ch == m->numopts)
break;
if (!(m->opts[ch].opt_flags & OPT_IGNORE))
break;
}
m->cursel = ch;
if (m->cursel >= m->topline + m->h)
m->topline = m->cursel - m->h + 1;
break;
case REQ_PREV_ITEM:
ch = m->cursel;
for (;;) {
if (ch <= 0) {
mbeep();
return;
}
ch--;
if (!(m->opts[ch].opt_flags & OPT_IGNORE))
break;
}
m->cursel = ch;
if (m->cursel < m->topline)
m->topline = m->cursel;
break;
case REQ_HELP:
process_help(m);
break;
case REQ_REDISPLAY:
endwin();
doupdate();
break;
case REQ_SCROLLUP:
if (m->cursel == 0) {
mbeep();
return;
}
m->topline = MAX(0, m->topline - m->h);
m->cursel = MAX(0, m->cursel - m->h);
wclear(m->mw);
break;
case REQ_SCROLLDOWN:
if (m->cursel >= m->numopts + hasexit - 1) {
mbeep();
return;
}
m->topline = MIN(m->topline + m->h,
MAX(m->numopts + hasexit - m->h, 0));
m->cursel = MIN(m->numopts + hasexit - 1, m->cursel + m->h);
wclear(m->mw);
break;
default:
ch = req;
if (ch == 'x' && hasexit) {
m->cursel = m->numopts;
break;
}
if (m->mopt & MC_NOSHORTCUT) {
mbeep();
return;
}
if (ch > 'z')
ch = 255;
if (ch >= 'a') {
if (ch > 'x')
ch--;
ch = ch - 'a';
} else
ch = 25 + ch - 'A';
if (ch < 0 || ch >= m->numopts) {
mbeep();
return;
}
if (m->opts[ch].opt_flags & OPT_IGNORE) {
mbeep();
return;
}
m->cursel = ch;
}
draw_menu(m, arg);
}
int
menu_init(void)
{
int i;
if (__menu_init)
return 0;
#ifdef USER_MENU_INIT
if (USER_MENU_INIT)
return 1;
#endif
if (initscr() == NULL)
return 1;
cbreak();
noecho();
/* XXX Should be configurable but it almost isn't worth it. */
if (has_colors()) {
start_color();
init_pair(1, COLOR_WHITE, COLOR_BLUE);
bkgd(COLOR_PAIR(1));
attrset(COLOR_PAIR(1));
}
max_lines = getmaxy(stdscr);
max_cols = getmaxx(stdscr);
keypad(stdscr, TRUE);
#ifdef DYNAMIC_MENUS
num_menus = DYN_INIT_NUM;
while (num_menus < DYN_MENU_START)
num_menus *= 2;
menu_list = malloc(sizeof *menu_list * num_menus);
if (menu_list == NULL)
return 2;
(void)memset(menu_list, 0, sizeof *menu_list * num_menus);
for (i = 0; i < DYN_MENU_START; i++)
menu_list[i] = &menu_def[i];
#endif
__menu_init = 1;
return 0;
}
void
process_menu(int num, void *arg)
{
int sel = 0;
int req;
menu_ent *opt;
menudesc *m;
/* Initialize? */
if (menu_init()) {
__menu_initerror();
return;
}
if (num < 0 || num >= num_menus)
return;
m = &MENUS(num);
if (m == NULL)
return;
/* Default to select option 0 and display from 0 */
m->topline = 0;
if ((m->mopt & (MC_DFLTEXIT | MC_NOEXITOPT)) == MC_DFLTEXIT)
m->cursel = -1;
else
m->cursel = 0;
for (;;) {
if (isendwin())
/* I'm not sure this is needed with netbsd's curses */
doupdate();
/* Process the display action */
if (m->post_act)
(*m->post_act)(m, arg);
if (m->mw == NULL)
init_menu(m);
draw_menu(m, arg);
while ((req = menucmd(m->mw)) != REQ_EXECUTE)
process_req(m, arg, req);
sel = m->cursel;
if (!(m->mopt & MC_NOCLEAR)) {
wclear(m->mw);
if (m->sv_mw)
overwrite(m->sv_mw, m->mw);
wnoutrefresh(m->mw);
}
/* Process the items */
if (sel >= m->numopts)
/* exit option */
break;
opt = &m->opts[sel];
if (opt->opt_flags & OPT_IGNORE)
continue;
if (opt->opt_flags & OPT_ENDWIN)
endwin();
if (opt->opt_action && (*opt->opt_action)(m, arg))
break;
if (opt->opt_menu != -1) {
if (!(opt->opt_flags & OPT_SUB)) {
num = opt->opt_menu;
wclear(m->mw);
if (m->sv_mw) {
overwrite(m->sv_mw, m->mw);
delwin(m->sv_mw);
m->sv_mw = NULL;
}
wnoutrefresh(m->mw);
delwin(m->mw);
m->mw = NULL;
m = &MENUS(num);
continue;
}
process_menu(opt->opt_menu, arg);
}
if (opt->opt_flags & OPT_EXIT)
break;
}
if (m->mopt & MC_NOCLEAR) {
wclear(m->mw);
if (m->sv_mw)
overwrite(m->sv_mw, m->mw);
wnoutrefresh(m->mw);
}
/* Process the exit action */
if (m->exit_act)
(*m->exit_act)(m, arg);
delwin(m->mw);
m->mw = NULL;
if (m->sv_mw) {
delwin(m->sv_mw);
m->sv_mw = NULL;
}
}
void
set_menu_numopts(int menu, int numopts)
{
MENUS(menu).numopts = numopts;
}
/* Control L is end of standard routines, remaining only for dynamic. */
/* Beginning of routines for dynamic menus. */
static int
double_menus(void)
{
menudesc **temp;
int sz = sizeof *menu_list * num_menus;
temp = realloc(menu_list, sz * 2);
if (temp == NULL)
return 0;
(void)memset(temp + num_menus, 0, sz);
menu_list = temp;
num_menus *= 2;
return 1;
}
int
new_menu(const char *title, menu_ent *opts, int numopts,
int x, int y, int h, int w, int mopt,
void (*post_act)(menudesc *, void *),
void (*draw_line)(menudesc *, int, void *),
void (*exit_act)(menudesc *, void *),
const char *help, const char *exit_str)
{
int ix;
menudesc *m;
/* Find free menu entry. */
for (ix = DYN_MENU_START; ; ix++) {
if (ix >= num_menus && !double_menus())
return -1;
m = menu_list[ix];
if (m == NULL) {
m = calloc(sizeof *m, 1);
if (m == NULL)
return -1;
menu_list[ix] = m;
break;
}
if (!(m->mopt & MC_VALID))
break;
}
/* Set Entries */
m->title = title;
m->opts = opts;
m->numopts = numopts;
m->x = x;
m->y = y;
m->h = h;
m->w = w;
m->mopt = mopt | MC_VALID;
m->post_act = post_act;
m->draw_line = draw_line;
m->exit_act = exit_act;
m->helpstr = help;
m->exitstr = exit_str ? exit_str : "Exit";
return ix;
}
void
free_menu(int menu_no)
{
menudesc *m;
if (menu_no < 0 || menu_no >= num_menus)
return;
m = menu_list[menu_no];
if (!(m->mopt & MC_VALID))
return;
if (m->mw != NULL)
delwin(m->mw);
memset(m, 0, sizeof *m);
}

View File

@ -1,260 +0,0 @@
/* $NetBSD: nbperf.c,v 1.5 2013/01/31 16:32:02 joerg Exp $ */
/*-
* Copyright (c) 2009 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Joerg Sonnenberger.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#if HAVE_NBTOOL_CONFIG_H
#include "nbtool_config.h"
#endif
#include <sys/cdefs.h>
__RCSID("$NetBSD: nbperf.c,v 1.5 2013/01/31 16:32:02 joerg Exp $");
#include <sys/endian.h>
#include <err.h>
#include <errno.h>
#include <inttypes.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include "nbperf.h"
static int predictable;
static __dead
void usage(void)
{
fprintf(stderr,
"%s [-ps] [-c utilisation] [-i iterations] [-n name] "
"[-o output] input\n",
getprogname());
exit(1);
}
#if HAVE_NBTOOL_CONFIG_H && defined(__minix)
#define arc4random() rand()
#endif
static void
mi_vector_hash_seed_hash(struct nbperf *nbperf)
{
static uint32_t predictable_counter;
if (predictable)
nbperf->seed[0] = predictable_counter++;
else
nbperf->seed[0] = arc4random();
}
static void
mi_vector_hash_compute(struct nbperf *nbperf, const void *key, size_t keylen,
uint32_t *hashes)
{
mi_vector_hash(key, keylen, nbperf->seed[0], hashes);
}
static void
mi_vector_hash_print_hash(struct nbperf *nbperf, const char *indent,
const char *key, const char *keylen, const char *hash)
{
fprintf(nbperf->output,
"%smi_vector_hash(%s, %s, 0x%08" PRIx32 "U, %s);\n",
indent, key, keylen, nbperf->seed[0], hash);
}
static void
set_hash(struct nbperf *nbperf, const char *arg)
{
if (strcmp(arg, "mi_vector_hash") == 0) {
nbperf->hash_size = 3;
nbperf->seed_hash = mi_vector_hash_seed_hash;
nbperf->compute_hash = mi_vector_hash_compute;
nbperf->print_hash = mi_vector_hash_print_hash;
return;
}
if (nbperf->hash_size > NBPERF_MAX_HASH_SIZE)
errx(1, "Hash function creates too many output values");
errx(1, "Unknown hash function: %s", arg);
}
int
main(int argc, char **argv)
{
struct nbperf nbperf = {
.c = 0,
.hash_name = "hash",
.map_output = NULL,
.output = NULL,
.static_hash = 0,
.first_round = 1,
.has_duplicates = 0,
};
FILE *input;
size_t curlen = 0, curalloc = 0;
char *line, *eos;
ssize_t line_len;
size_t line_allocated;
const void **keys = NULL;
size_t *keylens = NULL;
uint32_t max_iterations = 0xffffffU;
long long tmp;
int looped, ch;
int (*build_hash)(struct nbperf *) = chm_compute;
set_hash(&nbperf, "mi_vector_hash");
while ((ch = getopt(argc, argv, "a:c:h:i:m:n:o:ps")) != -1) {
switch (ch) {
case 'a':
/* Accept bdz as alias for netbsd-6 compat. */
if (strcmp(optarg, "chm") == 0)
build_hash = chm_compute;
else if (strcmp(optarg, "chm3") == 0)
build_hash = chm3_compute;
else if (strcmp(optarg, "bpz") == 0 ||
strcmp(optarg, "bdz") == 0)
build_hash = bpz_compute;
else
errx(1, "Unsupport algorithm: %s", optarg);
break;
case 'c':
errno = 0;
nbperf.c = strtod(optarg, &eos);
if (errno || eos[0] || !nbperf.c)
errx(2, "Invalid argument for -c");
break;
case 'h':
set_hash(&nbperf, optarg);
break;
case 'i':
errno = 0;
tmp = strtoll(optarg, &eos, 0);
if (errno || eos == optarg || eos[0] ||
tmp < 0 || tmp > 0xffffffffU)
errx(2, "Iteration count must be "
"a 32bit integer");
max_iterations = (uint32_t)tmp;
break;
case 'm':
if (nbperf.map_output)
fclose(nbperf.map_output);
nbperf.map_output = fopen(optarg, "w");
if (nbperf.map_output == NULL)
err(2, "cannot open map file");
break;
case 'n':
nbperf.hash_name = optarg;
break;
case 'o':
if (nbperf.output)
fclose(nbperf.output);
nbperf.output = fopen(optarg, "w");
if (nbperf.output == NULL)
err(2, "cannot open output file");
break;
case 'p':
predictable = 1;
break;
case 's':
nbperf.static_hash = 1;
break;
default:
usage();
}
}
argc -= optind;
argv += optind;
if (argc > 1)
usage();
if (argc == 1) {
input = fopen(argv[0], "r");
if (input == NULL)
err(1, "can't open input file");
} else
input = stdin;
if (nbperf.output == NULL)
nbperf.output = stdout;
line = NULL;
line_allocated = 0;
while ((line_len = getline(&line, &line_allocated, input)) != -1) {
if (line_len && line[line_len - 1] == '\n')
--line_len;
if (curlen == curalloc) {
if (curalloc < 256)
curalloc = 256;
else
curalloc += curalloc;
keys = realloc(keys, curalloc * sizeof(*keys));
if (keys == NULL)
err(1, "realloc failed");
keylens = realloc(keylens,
curalloc * sizeof(*keylens));
if (keylens == NULL)
err(1, "realloc failed");
}
if ((keys[curlen] = strndup(line, line_len)) == NULL)
err(1, "malloc failed");
keylens[curlen] = line_len;
++curlen;
}
free(line);
if (input != stdin)
fclose(input);
nbperf.n = curlen;
nbperf.keys = keys;
nbperf.keylens = keylens;
looped = 0;
while ((*build_hash)(&nbperf)) {
if (nbperf.has_duplicates)
errx(1, "Duplicate keys detected");
fputc('.', stderr);
looped = 1;
if (max_iterations == 0xffffffffU)
continue;
if (--max_iterations == 0) {
fputc('\n', stderr);
errx(1, "Iteration count reached");
}
}
if (looped)
fputc('\n', stderr);
return 0;
}

View File

@ -1,476 +0,0 @@
.\" $NetBSD: netstat.1,v 1.72 2015/03/23 18:33:17 roy Exp $
.\"
.\" Copyright (c) 1983, 1990, 1992, 1993
.\" The Regents of the University of California. All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. Neither the name of the University nor the names of its contributors
.\" may be used to endorse or promote products derived from this software
.\" without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" @(#)netstat.1 8.8 (Berkeley) 4/18/94
.\"
.Dd March 19, 2015
.Dt NETSTAT 1
.Os
.Sh NAME
.Nm netstat
.Nd show network status
.Sh SYNOPSIS
.ds address_family Fl f Ar address_family Ns Op , Ns Ar family ...
.Nm
.Op Fl Aan
.Op \*[address_family]
.Op Fl M Ar core
.Op Fl N Ar system
.Nm
.Op Fl bdghiLlmnqrSsTtv
.Op \*[address_family]
.Op Fl M Ar core
.Op Fl N Ar system
.Nm
.Op Fl dn
.Op Fl I Ar interface
.Op Fl M Ar core
.Op Fl N Ar system
.Op Fl w Ar wait
.Nm
.Op Fl M Ar core
.Op Fl N Ar system
.Op Fl p Ar protocol
.Nm
.Op Fl M Ar core
.Op Fl N Ar system
.Op Fl p Ar protocol
.Fl P Ar pcbaddr
.Nm
.Op Fl i
.Op Fl I Ar Interface
.Op Fl p Ar protocol
.Nm
.Op Fl is
.Op \*[address_family]
.Op Fl I Ar Interface
.Nm
.Op Fl s
.Op Fl I Ar Interface
.Fl B
.Sh DESCRIPTION
The
.Nm
command symbolically displays the contents of various network-related
data structures.
There are a number of output formats,
depending on the options for the information presented.
The first form of the command displays a list of active sockets for
each protocol.
The second form presents the contents of one of the other network
data structures according to the option selected.
Using the third form, with a
.Ar wait
interval specified,
.Nm
will continuously display the information regarding packet
traffic on the configured network interfaces.
The fourth form displays statistics about the named protocol.
The fifth and sixth forms display per interface statistics for
the specified protocol or address family.
.Pp
The options have the following meaning:
.Bl -tag -width flag
.It Fl A
With the default display,
show the address of any protocol control blocks associated with sockets; used
for debugging.
.It Fl a
With the default display,
show the state of all sockets; normally sockets used by
server processes are not shown.
.It Fl B
With the default display,
show the current
.Xr bpf 4
peers.
To show only the peers listening to a specific interface,
use the
.Fl I
option.
If the
.Fl s
option is present, show the current
.Xr bpf 4
statistics.
.It Fl b
With the interface display (option
.Fl i ) ,
show bytes in and out, instead of packets in and out.
.It Fl d
With either interface display (option
.Fl i
or an interval, as described below),
show the number of dropped packets.
.It \*[address_family]
Limit statistics or address control block reports to those
of the specified
.Ar address_families .
The following address families
are recognized:
.Ar inet ,
for
.Dv AF_INET ;
.Ar inet6 ,
for
.Dv AF_INET6 ;
.Ar arp ,
for
.Dv AF_ARP ;
.Ar ns ,
for
.Dv AF_NS ;
.Ar atalk ,
for
.Dv AF_APPLETALK ;
.Ar mpls ,
for
.Dv AF_MPLS ;
and
.Ar local
or
.Ar unix ,
for
.Dv AF_LOCAL .
.It Fl g
Show information related to multicast (group address) routing.
By default, show the IP Multicast virtual-interface and routing tables.
If the
.Fl s
option is also present, show multicast routing statistics.
.It Fl h
When used with
.Fl b
in combination with either
.Fl i
or
.Fl I ,
output "human-readable" byte counts.
.It Fl I Ar interface
Show information about the specified interface;
used with a
.Ar wait
interval as described below.
If the
.Fl f Ar address_family
option (with the
.Fl s
option) or the
.Fl p Ar protocol
option is present, show per-interface statistics on the
.Ar interface
for the specified
.Ar address_family
or
.Ar protocol ,
respectively.
.It Fl i
Show the state of interfaces which have been auto-configured
(interfaces statically configured into a system, but not
located at boot time are not shown).
If the
.Fl a
options is also present, multicast addresses currently in use are shown
for each Ethernet interface and for each IP interface address.
Multicast addresses are shown on separate lines following the interface
address with which they are associated.
If the
.Fl f Ar address_family
option (with the
.Fl s
option) or the
.Fl p Ar protocol
option is present, show per-interface statistics on all interfaces
for the specified
.Ar address_family
or
.Ar protocol ,
respectively.
.It Fl L
Don't show link-level routes (e.g., IPv4 ARP or IPv6 neighbour cache).
.It Fl l
With the
.Fl g
option, display wider fields for the IPv6 multicast routing table
.Qq Origin
and
.Qq Group
columns.
.It Fl M Ar core
Use
.Xr kvm 3
instead of
.Xr sysctl 3
to retrieve information and
extract values associated with the name list from the specified core.
If the
.Fl M
option is not given but the
.Fl N
option is given, the default
.Pa /dev/mem
is used.
.It Fl m
Show statistics recorded by the mbuf memory management routines
(the network manages a private pool of memory buffers).
.It Fl N Ar system
Use
.Xr kvm 3
instead of
.Xr sysctl 3
to retrieve information and extract the name list from the specified system.
For the default behavior when only
.Fl M
option is given, see the description about when
.Fa execfile
is
.Dv NULL
in
.Xr kvm_openfiles 3 .
.It Fl n
Show network addresses and ports as numbers (normally
.Nm
interprets addresses and ports and attempts to display them
symbolically).
This option may be used with any of the display formats.
.It Fl P Ar pcbaddr
Dump the contents of the protocol control block (PCB) located at kernel
virtual address
.Ar pcbaddr .
This address may be obtained using the
.Fl A
flag.
The default protocol is TCP, but may be overridden using the
.Fl p
flag.
.It Fl p Ar protocol
Show statistics about
.Ar protocol ,
which is either a well-known name for a protocol or an alias for it.
Some protocol names and aliases are listed in the file
.Pa /etc/protocols .
A null response typically means that there are no interesting numbers to
report.
The program will complain if
.Ar protocol
is unknown or if there is no statistics routine for it.
.It Fl q
Show software interrupt queue setting/statistics for all protocols.
.It Fl r
Show the routing tables.
When
.Fl s
is also present, show routing statistics instead.
.It Fl S
Show network addresses as numbers (as with
.Fl n ,
but show ports symbolically).
.It Fl s
Show per-protocol statistics.
If this option is repeated, counters with a value of zero are suppressed.
.It Fl T
Show MPLS Tags for the routing tables.
If multiple tags exists, they will
be comma separated, first tag being the BoS one.
.It Fl t
With the
.Fl i
option, display the current value of the watchdog timer function.
.It Fl v
Show extra (verbose) detail for the routing tables
.Pq Fl r ,
or avoid truncation of long addresses.
.It Fl w Ar wait
Show network interface statistics at intervals of
.Ar wait
seconds.
.It Fl X
Force use of
.Xr sysctl 3
when retrieving information.
Some features of
.Nm
may not be (fully) supported when using
.Xr sysctl 3 .
This flag forces the use of the latter regardless, and emits a message if a
not yet fully supported feature is used in conjunction with it.
This flag might be removed at any time; do not rely on its presence.
.El
.Pp
The default display, for active sockets, shows the local
and remote addresses, send and receive queue sizes (in bytes), protocol,
and the internal state of the protocol.
Address formats are of the form ``host.port'' or ``network.port''
if a socket's address specifies a network but no specific host address.
When known the host and network addresses are displayed symbolically
according to the data bases
.Pa /etc/hosts
and
.Pa /etc/networks ,
respectively.
If a symbolic name for an address is unknown, or if
the
.Fl n
option is specified, the address is printed numerically, according
to the address family.
For more information regarding
the Internet ``dot format,''
refer to
.Xr inet 3 ) .
Unspecified,
or ``wildcard'', addresses and ports appear as ``*''.
You can use the
.Xr fstat 1
command to find out which process or processes hold references to a socket.
.Pp
The interface display provides a table of cumulative
statistics regarding packets transferred, errors, and collisions.
The network addresses of the interface
and the maximum transmission unit (``mtu'') are also displayed.
.Pp
The routing table display indicates the available routes and
their status.
Each route consists of a destination host or network
and a gateway to use in forwarding packets.
The flags field shows
a collection of information about the route stored as
binary choices.
The individual flags are discussed in more
detail in the
.Xr route 8
and
.Xr route 4
manual pages.
The mapping between letters and flags is:
.Bl -column XXXX RTF_BLACKHOLE
.It 1 RTF_PROTO1 Protocol specific routing flag #1
.It 2 RTF_PROTO2 Protocol specific routing flag #2
.It B RTF_BLACKHOLE Just discard pkts (during updates)
.It b RTF_BROADCAST Route represents a broadcast address
.It C RTF_CLONING Generate new routes on use
.It c RTF_CLONED Cloned routes (generated from RTF_CLONING)
.It D RTF_DYNAMIC Created dynamically (by redirect)
.It G RTF_GATEWAY Destination requires forwarding by intermediary
.It H RTF_HOST Host entry (net otherwise)
.It L RTF_LLINFO Valid protocol to link address translation.
.It l RTF_LOCAL Route represents a local address
.It M RTF_MODIFIED Modified dynamically (by redirect)
.It p RTF_ANNOUNCE Link level proxy
.It R RTF_REJECT Host or net unreachable
.It S RTF_STATIC Manually added
.It U RTF_UP Route usable
.It X RTF_XRESOLVE External daemon translates proto to link address
.El
.Pp
Direct routes are created for each
interface attached to the local host;
the gateway field for such entries shows the address of the outgoing interface.
The refcnt field gives the
current number of active uses of the route.
Connection oriented
protocols normally hold on to a single route for the duration of
a connection while connectionless protocols obtain a route while sending
to the same destination.
The use field provides a count of the number of packets
sent using that route.
The mtu entry shows the mtu associated with
that route.
This mtu value is used as the basis for the TCP maximum
segment size.
The 'L' flag appended to the mtu value indicates that
the value is locked, and that path mtu discovery is turned off for
that route.
A
.Sq -
indicates that the mtu for this route has not been set, and a default
TCP maximum segment size will be used.
The interface entry indicates
the network interface used for the route.
.Pp
When
.Nm
is invoked with the
.Fl w
option and a
.Ar wait
interval argument, it displays a running count of statistics related to
network interfaces.
An obsolescent version of this option used a numeric parameter
with no option, and is currently supported for backward compatibility.
This display consists of a column for the primary interface (the first
interface found during autoconfiguration) and a column summarizing
information for all interfaces.
The primary interface may be replaced with another interface with the
.Fl I
option.
The first line of each screen of information contains a summary since the
system was last rebooted.
Subsequent lines of output show values
accumulated over the preceding interval.
.Pp
The first character of the flags column in the
.Fl B
option shows the status of the
.Xr bpf 4
descriptor which has three different values:
Idle ('I'), Waiting ('W') and Timed Out ('T').
The second character indicates whether the promisc flag is set.
The third character indicates the status of the immediate mode.
The fourth character indicates whether the peer will have the ability
to see the packets sent.
And the fifth character shows the header complete flag status.
.Sh SEE ALSO
.Xr fstat 1 ,
.Xr nfsstat 1 ,
.Xr ps 1 ,
.Xr sockstat 1 ,
.Xr vmstat 1 ,
.Xr inet 3 ,
.Xr bpf 4 ,
.Xr hosts 5 ,
.Xr networks 5 ,
.Xr protocols 5 ,
.Xr services 5 ,
.Xr iostat 8 ,
.Xr trpt 8
.Sh HISTORY
The
.Nm
command appeared in
.Bx 4.2 .
IPv6 support was added by WIDE/KAME project.
.\" .Sh FILES
.\" .Bl -tag -width /dev/mem -compact
.\" .It Pa /netbsd
.\" default kernel namelist
.\" .It Pa /dev/mem
.\" default memory file
.\" .El
.Sh BUGS
The notion of errors is ill-defined.

View File

@ -1,58 +0,0 @@
.\" $NetBSD: uptime.1,v 1.10 2003/08/07 11:17:13 agc Exp $
.\"
.\" Copyright (c) 1980, 1990, 1993, 1994
.\" The Regents of the University of California. All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. Neither the name of the University nor the names of its contributors
.\" may be used to endorse or promote products derived from this software
.\" without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" @(#)uptime.1 8.2 (Berkeley) 4/18/94
.\"
.Dd April 18, 1994
.Dt UPTIME 1
.Os
.Sh NAME
.Nm uptime
.Nd show how long system has been running
.Sh SYNOPSIS
.Nm
.Sh DESCRIPTION
The
.Nm
utility displays the current time,
the length of time the system has been up,
the number of users, and the load average of the system over the last
1, 5, and 15 minutes.
.Sh FILES
.Bl -tag -width /netbsd
.It Pa /netbsd
system name list
.El
.Sh SEE ALSO
.Xr w 1
.Sh HISTORY
The
.Nm
command appeared in
.Bx 3.0 .

View File

@ -1,126 +0,0 @@
.\" $NetBSD: w.1,v 1.18 2005/01/11 09:39:12 wiz Exp $
.\"
.\" Copyright (c) 1980, 1990, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. Neither the name of the University nor the names of its contributors
.\" may be used to endorse or promote products derived from this software
.\" without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" @(#)w.1 8.1 (Berkeley) 6/6/93
.\"
.Dd January 11, 2005
.Dt W 1
.Os
.Sh NAME
.Nm w
.Nd who present users are and what they are doing
.Sh SYNOPSIS
.Nm
.Op Fl hinw
.Op Fl M Ar core
.Op Fl N Ar system
.Op Ar user
.Sh DESCRIPTION
The
.Nm
utility prints a summary of the current activity on the system,
including what each user is doing.
The first line displays the current time of day, how long the system has
been running, the number of users logged into the system, and the load
averages.
The load average numbers give the number of jobs in the run queue averaged
over 1, 5, and 15 minutes.
.Pp
The fields output are the user's login name, the name of the terminal the
user is on, the host from which the user is logged in, the time the user
logged on, the time since the user last typed anything,
and the name and arguments of the current process.
.Pp
The options are as follows:
.Bl -tag -width Ds
.It Fl h
Suppress the heading.
.It Fl i
Output is sorted by idle time.
.It Fl M
Extract values associated with the name list from the specified
core instead of the default
.Dq /dev/kmem .
.It Fl N
Extract the name list from the specified system instead of the
default
.Dq /netbsd .
.It Fl n
Show network addresses as numbers (normally
.Nm
interprets addresses and attempts to display them symbolically).
.It Fl w
Show wide output without truncating any fields.
.El
.Pp
If a
.Ar user
name is specified, the output is restricted to that user.
.Sh FILES
.Bl -tag -width /var/run/utmp -compact
.It Pa /var/run/utmp
list of users on the system
.El
.Sh SEE ALSO
.Xr finger 1 ,
.Xr ps 1 ,
.Xr uptime 1 ,
.Xr who 1
.Sh HISTORY
The
.Nm
command appeared in
.Bx 3.0 .
.Sh BUGS
The notion of the
.Dq current process
is muddy.
The current algorithm is ``the highest numbered process on the terminal
that is not ignoring interrupts, or, if there is none, the highest numbered
process on the terminal''.
This fails, for example, in critical sections of programs like the shell
and editor, or when faulty programs running in the background fork and fail
to ignore interrupts.
(In cases where no process can be found,
.Nm
prints
.Dq \- . )
.Pp
Background processes are not shown, even though they account for
much of the load on the system.
.Pp
Sometimes processes, typically those in the background, are printed with
null or garbaged arguments.
In these cases, the name of the command is printed in parentheses.
.Pp
The
.Nm
utility does not know about the new conventions for detection of background
jobs.
It will sometimes find a background job instead of the right one.