NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

kern/51762: mtime not updated by open(O_TRUNC)

>Number:         51762
>Category:       kern
>Synopsis:       mtime not updated by open(O_TRUNC)
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    kern-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Jan 02 16:15:00 +0000 2017
>Originator:     Martin Husemann
>Release:        NetBSD 7.99.53
The NetBSD Foundation, Inc.
System: NetBSD 7.99.53 NetBSD 7.99.53 (NIGHT-OWL) #450: Wed Dec 28 12:18:50 CET 2016 amd64
Architecture: x86_64
Machine: amd64

Opening an existing file with O_TRUNC should update the mtime of the file,
but does not do this in -current.

This came up during debugging a firefox "Welcome back" warning at startup.


Run this test program. The seconds printed should montonically increase.

#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <sys/stat.h>

static time_t
lock_it(const char *file)
	struct stat st;

	if (stat(file, &st) != 0)
		st.st_mtime = 0;

	int f = open(file, O_WRONLY | O_CREAT | O_TRUNC, 0666);
	if (f == -1) return 0;

	return st.st_mtime;

main(int argc, char **argv)
	char buf[1000];

	sprintf(buf, "/tmp/test%d.lock", getpid());

	printf("lock file: %s\n", buf);

	for (int i = 0; i < 10; i++) {
		time_t l = lock_it(buf);
		printf("last lock: %ld\n", (long)l);


	return 0;


Home | Main Index | Thread Index | Old Index