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

stat results are faked incorrectly #183

Open
bmwiedemann opened this Issue Jan 30, 2019 · 2 comments

Comments

Projects
None yet
2 participants
@bmwiedemann
Copy link

bmwiedemann commented Jan 30, 2019

I am working on reproducible builds for openSUSE and there I would like to use libfaketime to make software behave exactly as if date+time were

  • in the future
  • deterministic (this is why I use the i1 param)

e.g. I would like to use faketime -f '@2020-01-01 01:01:01 i1'

But one problem with stat is visible when you compare

cmd='echo $SECONDS;touch /tmp/x ; stat /tmp/x ; echo $SECONDS; sleep 1 ; stat /tmp/x ; echo $SECONDS;echo $SECONDS'
bash -c "$cmd"
faketime -f '+0y i1' bash -c "$cmd"

That produces

> bash -c "$cmd"
0
  File: /tmp/x
  Size: 7               Blocks: 8          IO Block: 4096   regular file
Device: 803h/2051d      Inode: 531866      Links: 1
Access: (0644/-rw-r--r--)  Uid: (16894/bwiedemann)   Gid: (   50/    suse)
Access: 2019-01-30 15:26:01.572086689 +0100
Modify: 2019-01-30 15:26:01.572086689 +0100
Change: 2019-01-30 15:26:01.572086689 +0100
 Birth: -
0

  File: /tmp/x
  Size: 7               Blocks: 8          IO Block: 4096   regular file
Device: 803h/2051d      Inode: 531866      Links: 1
Access: (0644/-rw-r--r--)  Uid: (16894/bwiedemann)   Gid: (   50/    suse)
Access: 2019-01-30 15:26:01.572086689 +0100
Modify: 2019-01-30 15:26:01.572086689 +0100
Change: 2019-01-30 15:26:01.572086689 +0100
 Birth: -
1
1


> faketime -f '+0y i1' bash -c "$cmd"
32
  File: /tmp/x
  Size: 7               Blocks: 8          IO Block: 4096   regular file
Device: 803h/2051d      Inode: 531866      Links: 1
Access: (0644/-rw-r--r--)  Uid: (16894/bwiedemann)   Gid: (   50/    suse)
Access: 2019-01-30 15:27:02.605862595 +0100
Modify: 2019-01-30 15:27:03.605862595 +0100
Change: 2019-01-30 15:27:01.605862595 +0100
 Birth: -
62
  File: /tmp/x
  Size: 7               Blocks: 8          IO Block: 4096   regular file
Device: 803h/2051d      Inode: 531866      Links: 1
Access: (0644/-rw-r--r--)  Uid: (16894/bwiedemann)   Gid: (   50/    suse)
Access: 2019-01-30 15:27:15.605862595 +0100
Modify: 2019-01-30 15:27:16.605862595 +0100
Change: 2019-01-30 15:27:14.605862595 +0100
 Birth: -
75
76

With faketime, the stat results are shifting, when nothing touched the file, which can confuse programs like make.

@wolfcw

This comment has been minimized.

Copy link
Owner

wolfcw commented Jan 30, 2019

Yes, I can reproduce that problem.

Could you please try LD_PRELOAD'ing libfaketime.so.1 directly instead of using the faketime wrapper?

LD_PRELOAD=/path/to/libfaketime.so.1 FAKETIME='+0y i1' bash -c "$cmd"

produces the desired output here, and using libfaketime[MT].so.1 directly instead of the wrapper is generally recommended for more advanced use cases.

@bmwiedemann

This comment has been minimized.

Copy link
Author

bmwiedemann commented Jan 31, 2019

Using plain LD_PRELOAD lacks the other variable for shared memory required for the synchronized counter, so the two echo $SECONDS at the end print the same value

@wolfcw wolfcw added the confirmed label Jan 31, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment