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
>Organization:
The NetBSD Foundation, Inc.
>Environment:
System: NetBSD night-owl.duskware.de 7.99.53 NetBSD 7.99.53 (NIGHT-OWL) #450: Wed Dec 28 12:18:50 CET 2016 martin%night-owl.duskware.de@localhost:/usr/src/sys/arch/amd64/compile/NIGHT-OWL amd64
Architecture: x86_64
Machine: amd64
>Description:

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.

>How-To-Repeat:

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;
	close(f);

	return st.st_mtime;
}

int
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);
		sleep(2);
	}

	unlink(buf);

	return 0;
}


>Fix:
n/a



Home | Main Index | Thread Index | Old Index