-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Fix utime() syscall #16460
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix utime() syscall #16460
Changes from all commits
ef5bd8c
b37e3a5
e83521f
8c4fb68
79c506b
d5921a9
154a2f3
af928b0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1006,10 +1006,15 @@ long __syscall_utimensat(int dirFD, | |
|
|
||
| // TODO: Set tv_nsec (nanoseconds) as well. | ||
| // TODO: Handle tv_nsec being UTIME_NOW or UTIME_OMIT. | ||
| // TODO: Handle NULL times. | ||
| // TODO: Check for write access to the file (see man page for specifics). | ||
| auto aSeconds = times[0].tv_sec; | ||
| auto mSeconds = times[1].tv_sec; | ||
| time_t aSeconds, mSeconds; | ||
| if (times == NULL) { | ||
| aSeconds = time(NULL); | ||
| mSeconds = aSeconds; | ||
| } else { | ||
| aSeconds = times[0].tv_sec; | ||
| mSeconds = times[1].tv_sec; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm curious how / why this was needed? Do we run test_utime under WASMFS? Or did you try running manually with this flag?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was needed to implement
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At thanks.. i had forgotten that we can run the whole of the core tests suite in wasmfs mode |
||
| } | ||
|
|
||
| auto locked = parsed.getFile()->locked(); | ||
| locked.setATime(aSeconds); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ | |
| #include <stdio.h> | ||
| #include <stdlib.h> | ||
| #include <string.h> | ||
| #include <time.h> | ||
| #include <unistd.h> | ||
| #include <utime.h> | ||
| #include <sys/stat.h> | ||
|
|
@@ -32,20 +33,38 @@ void test() { | |
| // will fail | ||
| struct utimbuf t = {1000000000, 1000000000}; | ||
|
|
||
| utime("writeable", &t); | ||
| errno = 0; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm .. if this line is needed.. how was the test passing before?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have no clue ...
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What test are you running that fails if you remove this line?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I executed the test manually with From man errno(3):
In other words, if you want to use errno for error checking, then you have to reset errno to 0 before a function call and check it immediately after the function call.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I'm only confused about how that test was passing before. It sounds like the tests passes because its not run with NODERAWFS today? i.e. |
||
| int rv = utime("writeable", &t); | ||
| assert(rv == 0); | ||
| assert(!errno); | ||
| memset(&s, 0, sizeof s); | ||
| stat("writeable", &s); | ||
| rv = stat("writeable", &s); | ||
| assert(rv == 0); | ||
| assert(s.st_atime == t.actime); | ||
| assert(s.st_mtime == t.modtime); | ||
|
|
||
| // NULL sets atime and mtime to current time. | ||
| long now = time(NULL); | ||
| rv = utime("writeable", NULL); | ||
| assert(rv == 0); | ||
| memset(&s, 0, sizeof s); | ||
| stat("writeable", &s); | ||
| assert(s.st_atime == s.st_mtime); | ||
| long diff = s.st_atime - now; | ||
| if (abs(diff) > 5) { | ||
| fprintf(stderr, "st_atime: %li, now: %li, diff: %li\n ", s.st_atime, now, diff); | ||
| assert(abs(diff) <= 5); | ||
| } | ||
|
|
||
| // write permissions aren't checked when setting node | ||
| // attributes unless the user uid isn't the owner (so | ||
| // therefor, this should work fine) | ||
| utime("unwriteable", &t); | ||
| rv = utime("unwriteable", &t); | ||
| assert(rv == 0); | ||
| assert(!errno); | ||
| memset(&s, 0, sizeof s); | ||
| stat("unwriteable", &s); | ||
| rv = stat("unwriteable", &s); | ||
| assert(rv == 0); | ||
| assert(s.st_atime == t.actime); | ||
| assert(s.st_mtime == t.modtime); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems a little odd to declare
var mtimeandvar atimein both branches of the if/else. Maybe just declare them in one? (I'm not a JS expert but IIRC you just need onevardecl for a give variable it it will be hoisted to function level).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know any JS at all. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mtimeandatimeshould be declared on level up (var mtime, atime;).Otherwise the
FS.utime(path, atime, mtime)will not be able to access the variables on the scope.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is that true? I thought
vardeclaration were hoisted to the function level in JS. This seems to work just fine:It looks odd but its saves a few bytes in code size.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are completely right! I got a bit confused with var and let :P