/*
 * DF-0001 trigger (truncate-only). Run AFTER the target file is populated
 * and AFTER the NFS server has been frozen (kill -STOP) so VOP_GETATTR
 * issues a fresh RPC (attribute cache disabled via acregmax=0) that times
 * out on a soft mount -> returns EIO to kern_truncate/kern_ftruncate ->
 * KASSERT(error==0) fires -> panic.
 *
 * If GETATTR returns 0 (cache / no real RPC failure) this prints the errno
 * from SETATTR instead and exits 0 -- meaning the trigger did NOT reach the
 * KASSERT. The harness distinguishes: panic (ssh dies, boot.log has the
 * signature) == reproduced; clean errno print == GETATTR returned 0.
 */
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <err.h>

int
main(int argc, char **argv)
{
	const char *path = argc > 1 ? argv[1] : "/mnt/nfs_target";
	int fd;

	errno = 0;
	if (truncate(path, 0) < 0)
		warn("TRUNCATE returned error (GETATTR=0 path, SETATTR failed): errno");
	else
		printf("TRUNCATE returned 0\n");
	fflush(stdout);

	fd = open(path, O_RDWR);
	if (fd < 0) {
		warn("open for ftruncate");
	} else {
		errno = 0;
		if (ftruncate(fd, 0) < 0)
			warn("FTRUNCATE returned error (GETATTR=0 path, SETATTR failed): errno");
		else
			printf("FTRUNCATE returned 0\n");
		close(fd);
	}
	fflush(stdout);
	return 0;
}
