/*
* Copyright (c) 2005, 2006 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.
*/
/*
* Helper tools for several tests. These are kept in a single file due
* to the limitations of bsd.prog.mk to build a single program in a
* given directory.
*/
static int getfh_main(int, char **);
static int kqueue_main(int, char **);
static int rename_main(int, char **);
static int sockets_main(int, char **);
static int statvfs_main(int, char **);
int
getfh_main(int argc, char **argv)
{
int error;
void *fh;
size_t fh_size;
if (argc < 2)
return EXIT_FAILURE;
fh_size = 0;
fh = NULL;
for (;;) {
if (fh_size) {
fh = malloc(fh_size);
if (fh == NULL) {
fprintf(stderr, "out of memory");
return EXIT_FAILURE;
}
}
/*
* The kernel provides the necessary size in fh_size -
* but it may change if someone moves things around,
* so retry untill we have enough memory.
*/
error = getfh(argv[1], fh, &fh_size);
if (error == 0) {
break;
} else {
if (fh != NULL)
free(fh);
if (errno != E2BIG) {
warn("getfh");
return EXIT_FAILURE;
}
}
}
do {
nev = kevent(kq, changes, argc, &event, 1, &to);
if (nev == -1)
err(EXIT_FAILURE, "kevent");
else if (nev > 0) {
for (i = 0; i < argc; i++)
if (event.ident == changes[i].ident)
break;
if (event.fflags & NOTE_ATTRIB)
printf("%s - NOTE_ATTRIB\n", argv[i]);
if (event.fflags & NOTE_DELETE)
printf("%s - NOTE_DELETE\n", argv[i]);
if (event.fflags & NOTE_EXTEND)
printf("%s - NOTE_EXTEND\n", argv[i]);
if (event.fflags & NOTE_LINK)
printf("%s - NOTE_LINK\n", argv[i]);
if (event.fflags & NOTE_RENAME)
printf("%s - NOTE_RENAME\n", argv[i]);
if (event.fflags & NOTE_REVOKE)
printf("%s - NOTE_REVOKE\n", argv[i]);
if (event.fflags & NOTE_WRITE)
printf("%s - NOTE_WRITE\n", argv[i]);
}
} while (nev > 0);
}
for (i = 0; i < argc; i++)
close(changes[i].ident);
free(changes);