[GH-ISSUE #1044] Cygwin fails (deadlock) for -fork=x #643

Closed
opened 2026-10-14 03:17:03 +07:00 by bsakaguchi · 38 comments
Owner

Originally created by @jfoug on GitHub (Feb 6, 2015).
Original GitHub issue: https://github.com/openwall/john/issues/1044

Currently, we disable (forcibly) within the configure script because it is well know to be broken.

However, I did some work (I will document here), and it was also documented here: #1043 and have actually gotten cygwin to work 'better' with -fork, but it is still busted. Now with some of the other debugging we have in the logger.c, it is becoming pretty appearent that with our current code, cygwin is failing with some form of race condition / deadlock within the flock() function, interaction between 2 processes. Possibly we can get this working in some other way (there are other things than flock), or possibly we can escalate this up to the cygwin folks, showing that there IS a problem on their end.

Originally created by @jfoug on GitHub (Feb 6, 2015). Original GitHub issue: https://github.com/openwall/john/issues/1044 Currently, we disable (forcibly) within the configure script because it is well know to be broken. However, I did some work (I will document here), and it was also documented here: #1043 and have actually gotten cygwin to work 'better' with -fork, but it is still busted. Now with some of the other debugging we have in the logger.c, it is becoming pretty appearent that with our current code, cygwin is failing with some form of race condition / deadlock within the flock() function, interaction between 2 processes. Possibly we can get this working in some other way (there are other things than flock), or possibly we can escalate this up to the cygwin folks, showing that there IS a problem on their end.
bsakaguchi 2026-10-14 03:17:03 +07:00
Author
Owner

@magnumripper commented on GitHub (Feb 6, 2015):

Sounds like first thing to try is just commenting out all flock() calls and see how well it behaves. I presume O_APPEND on a non-network file system is 100.0% safe under Windows.

<!-- gh-comment-id:73310970 --> @magnumripper commented on GitHub (Feb 6, 2015): Sounds like first thing to try is just commenting out all flock() calls and see how well it behaves. I presume O_APPEND on a non-network file system is 100.0% safe under Windows.
Author
Owner

@jfoug commented on GitHub (Feb 6, 2015):

That should be VERY easy to check. AND simple to implement (#ifndef CYGWIN32 wrappers)

Is log file also opened in append mode?

<!-- gh-comment-id:73311820 --> @jfoug commented on GitHub (Feb 6, 2015): That should be VERY easy to check. AND simple to implement (#ifndef **CYGWIN32** wrappers) Is log file also opened in append mode?
Author
Owner

@jfoug commented on GitHub (Feb 6, 2015):

FU. worked first time. You suk! lol.

at least my flock-tst script is working just fine. I still need to test more.

<!-- gh-comment-id:73312262 --> @jfoug commented on GitHub (Feb 6, 2015): FU. worked first time. You suk! lol. at least my flock-tst script is working just fine. I still need to test more.
Author
Owner

@jfoug commented on GitHub (Feb 6, 2015):

I guess the 'non-trivial' may not have been a proper label,

<!-- gh-comment-id:73312417 --> @jfoug commented on GitHub (Feb 6, 2015): I guess the 'non-trivial' may not have been a proper label,
Author
Owner

@magnumripper commented on GitHub (Feb 6, 2015):

Ha ha, that was too easy after the brain massage in #1043

<!-- gh-comment-id:73312528 --> @magnumripper commented on GitHub (Feb 6, 2015): Ha ha, that was too easy after the brain massage in #1043
Author
Owner

@magnumripper commented on GitHub (Feb 6, 2015):

So then it's just a matter of documenting that you've gotta run on a local drive. Everyone will do that anyway but just for good measure.

<!-- gh-comment-id:73312714 --> @magnumripper commented on GitHub (Feb 6, 2015): So then it's just a matter of documenting that you've gotta run on a local drive. Everyone will do that anyway but just for good measure.
Author
Owner

@jfoug commented on GitHub (Feb 6, 2015):

Agreed, but we would not have gotten there, without the back/forth work trying to explain to each other just wtf was happening.

There are other changes for getting cygwin to fork, but those are trivial, and are already in my testing stuff.

The problem is that cygwin DOES have an flock, so AC finds it. but (at least the way we are using it), deadlocks.

<!-- gh-comment-id:73312752 --> @jfoug commented on GitHub (Feb 6, 2015): Agreed, but we would not have gotten there, without the back/forth work trying to explain to each other just wtf was happening. There are other changes for getting cygwin to fork, but those are trivial, and are already in my testing stuff. The problem is that cygwin DOES have an flock, so AC finds it. but (at least the way we are using it), deadlocks.
Author
Owner

@jfoug commented on GitHub (Feb 6, 2015):

I am also ONLY running under the cygwin shell. I need to make sure this also works from a windows cmd prompt. (and also works for cygwin32). BUT this has not been like this before, that is for sure.

<!-- gh-comment-id:73312887 --> @jfoug commented on GitHub (Feb 6, 2015): I am also ONLY running under the cygwin shell. I need to make sure this also works from a windows cmd prompt. (and also works for cygwin32). BUT this has not been like this before, that is for sure.
Author
Owner

@magnumripper commented on GitHub (Feb 6, 2015):

I bet after a night's sleep one or both of us will come up with an idea regarding those flocks. Maybe we can keep them, with some twist. But as we learnt in #1043 the flock() is not needed at all on a local drive.

<!-- gh-comment-id:73313118 --> @magnumripper commented on GitHub (Feb 6, 2015): I bet after a night's sleep one or both of us will come up with an idea regarding those flocks. Maybe we can keep them, with some twist. But as we learnt in #1043 the flock() is not needed at all on a local drive.
Author
Owner

@jfoug commented on GitHub (Feb 6, 2015):

my cygwin64 build is absolutely using the -fork, and absolutely working. NOTE, we can not simply turn off FLOCK in AC, or we get an error message listing to NOT use --fork. We have to build with it, but then make sure we do NOT use it in cygwin.

<!-- gh-comment-id:73313214 --> @jfoug commented on GitHub (Feb 6, 2015): my cygwin64 build is absolutely using the -fork, and absolutely working. NOTE, we can not simply turn off FLOCK in AC, or we get an error message listing to NOT use --fork. We have to build with it, but then make sure we do NOT use it in cygwin.
Author
Owner

@jfoug commented on GitHub (Feb 6, 2015):

learnt in #1043 the flock() is not needed at all on a local drive.

That is a damn good point. and it actually might speed things up (probably not too much). I wonder how hard it would be to detect the FS underlying the file itself ?

<!-- gh-comment-id:73313403 --> @jfoug commented on GitHub (Feb 6, 2015): > learnt in #1043 the flock() is not needed at all on a local drive. That is a damn good point. and it actually might speed things up (probably not too much). I wonder how hard it would be to detect the FS underlying the file itself ?
Author
Owner

@magnumripper commented on GitHub (Feb 6, 2015):

The problem is that cygwin DOES have an flock, so AC finds it

Like you said somewhere it's as easy as wrapping them like this (pseudo diff, not sure what macro to use)

diff --git a/src/logger.c b/src/logger.c
index 4b96136..02c0f80 100644
--- a/src/logger.c
+++ b/src/logger.c
@@ -108,7 +108,7 @@ static void log_file_flush(struct log_file *f)
        count = f->ptr - f->buffer;
        if (count <= 0) return;

-#if OS_FLOCK
+#if OS_FLOCK && !__CYGWIN__
        while (flock(f->fd, LOCK_EX)) {
                if (errno != EINTR)
                        pexit("flock(LOCK_EX)");
<!-- gh-comment-id:73313658 --> @magnumripper commented on GitHub (Feb 6, 2015): > The problem is that cygwin DOES have an flock, so AC finds it Like you said somewhere it's as easy as wrapping them like this (pseudo diff, not sure what macro to use) ``` diff --git a/src/logger.c b/src/logger.c index 4b96136..02c0f80 100644 --- a/src/logger.c +++ b/src/logger.c @@ -108,7 +108,7 @@ static void log_file_flush(struct log_file *f) count = f->ptr - f->buffer; if (count <= 0) return; -#if OS_FLOCK +#if OS_FLOCK && !__CYGWIN__ while (flock(f->fd, LOCK_EX)) { if (errno != EINTR) pexit("flock(LOCK_EX)"); ```
Author
Owner

@jfoug commented on GitHub (Feb 6, 2015):

First, before I go too deep, I need to back out some other changes. On thing is I commented out some code (needed code), getting to the point where cygwin worked at all. The call to rec_save in crk_init() is one such thing. So cygwin working may still be a little premature.

<!-- gh-comment-id:73313713 --> @jfoug commented on GitHub (Feb 6, 2015): First, before I go too deep, I need to back out some other changes. On thing is I commented out some code (needed code), getting to the point where cygwin worked at all. The call to rec_save in crk_init() is one such thing. So cygwin working may still be a little premature.
Author
Owner

@jfoug commented on GitHub (Feb 6, 2015):

I bet after a night's sleep one or both of us will come up with an idea

I will be a night-ranger quiet-riot concert tonite, and the babysitting in morning, so I doubt it will be me that has any thing close to an 'idea', lol.

<!-- gh-comment-id:73316963 --> @jfoug commented on GitHub (Feb 6, 2015): > I bet after a night's sleep one or both of us will come up with an idea I will be a night-ranger quiet-riot concert tonite, and the babysitting in morning, so I doubt it will be me that has any thing close to an 'idea', lol.
Author
Owner

@jfoug commented on GitHub (Feb 6, 2015):

-#if OS_FLOCK
+#if OS_FLOCK && !__CYGWIN__

Pretty much exact code I have (but in 2 places)

<!-- gh-comment-id:73317267 --> @jfoug commented on GitHub (Feb 6, 2015): > -#if OS_FLOCK > +#if OS_FLOCK && `!__CYGWIN__` Pretty much exact code I have (but in 2 places)
Author
Owner

@magnumripper commented on GitHub (Feb 6, 2015):

You should probably put them in cracker.c too around the LOCK_SH calls

<!-- gh-comment-id:73319749 --> @magnumripper commented on GitHub (Feb 6, 2015): You should probably put them in cracker.c too around the LOCK_SH calls
Author
Owner

@magnumripper commented on GitHub (Feb 6, 2015):

Oh, and recovery.c too. But if they don't deadlock maybe you can keep them.

<!-- gh-comment-id:73319944 --> @magnumripper commented on GitHub (Feb 6, 2015): Oh, and recovery.c too. But if they don't deadlock maybe you can keep them.
Author
Owner

@jfoug commented on GitHub (Feb 6, 2015):

I had to comment out rec_save at one time. Now, I have it back in code with no problems.

I really think it is best to comment them all out (for cygwin), until they can show that the code works ALL the time. There certainly could be cases/places where these will fail (even though not failing now). NOTE, there is very little recovery.c testing done in the TS. I am not sure how to auto do that.

<!-- gh-comment-id:73320806 --> @jfoug commented on GitHub (Feb 6, 2015): I had to comment out rec_save at one time. Now, I have it back in code with no problems. I really think it is best to comment them all out (for cygwin), until they can show that the code works ALL the time. There certainly could be cases/places where these will fail (even though not failing now). NOTE, there is very little recovery.c testing done in the TS. I am not sure how to auto do that.
Author
Owner

@jfoug commented on GitHub (Feb 6, 2015):

Note, I will probalby have to test a much longer run, to make sure things like recovery, and cracker (pot reload), works with no problems, once I add the && !__CYGWIN__ wrapper to the FLOCK code.

<!-- gh-comment-id:73322704 --> @jfoug commented on GitHub (Feb 6, 2015): Note, I will probalby have to test a much longer run, to make sure things like recovery, and cracker (pot reload), works with no problems, once I add the `&& !__CYGWIN__` wrapper to the FLOCK code.
Author
Owner

@jfoug commented on GitHub (Feb 6, 2015):

I did get a deadlock in cygwin build, but that was before I commented out the flocks in cracker/recovery. I am re-running the TS now, after changing those.

<!-- gh-comment-id:73326897 --> @jfoug commented on GitHub (Feb 6, 2015): I did get a deadlock in cygwin build, but that was before I commented out the flocks in cracker/recovery. I am re-running the TS now, after changing those.
Author
Owner

@jfoug commented on GitHub (Feb 6, 2015):

c54daec is many changes. NOTE, I still want to test this some more (and do not have time for a while), before calling this good. I need to test more on cygwin64, and have not tested at all on cygwin32.

Also needing tested is running this outside of a cygwin bash shell.

<!-- gh-comment-id:73332243 --> @jfoug commented on GitHub (Feb 6, 2015): c54daec is many changes. NOTE, I still want to test this some more (and do not have time for a while), before calling this good. I need to test more on cygwin64, and have not tested at all on cygwin32. Also needing tested is running this outside of a cygwin bash shell.
Author
Owner

@magnumripper commented on GitHub (Feb 7, 2015):

Good Stuff. I saw you added a debug print right before trying to lock, that was one thing I was going to suggest. Another thing one could try is something like this:

Current code

while (flock(f->fd, LOCK_EX)) {
    if (errno != EINTR)
        pexit("flock(LOCK_EX)");
}

Debug code

while (flock(f->fd, LOCK_EX | LOCK_NB)) {
    if (errno != EINTR && errno != EWOULDBLOCK)
        pexit("flock(LOCK_EX)");
    sleep(1);
    fprintf(stderr, "%s(%u) %s, retrying lock\n", __FUNCTION__, options.node_min, strerror(errno));
}

Well, something like this. This will be awfully slow, always waits a full second before retrying, but you will see whether this one too deadlocks, or if it's just blocking lock calls that do.

<!-- gh-comment-id:73339100 --> @magnumripper commented on GitHub (Feb 7, 2015): Good Stuff. I saw you added a debug print right before trying to lock, that was one thing I was going to suggest. Another thing one could try is something like this: Current code ``` C while (flock(f->fd, LOCK_EX)) { if (errno != EINTR) pexit("flock(LOCK_EX)"); } ``` Debug code ``` C while (flock(f->fd, LOCK_EX | LOCK_NB)) { if (errno != EINTR && errno != EWOULDBLOCK) pexit("flock(LOCK_EX)"); sleep(1); fprintf(stderr, "%s(%u) %s, retrying lock\n", __FUNCTION__, options.node_min, strerror(errno)); } ``` Well, something like this. This will be awfully slow, always waits a full second before retrying, but you will see whether this one too deadlocks, or if it's just blocking lock calls that do.
Author
Owner

@magnumripper commented on GitHub (Feb 7, 2015):

Note also that we need to answer this question: Are we really sure Windows has an atomic O_APPEND? Some googling indicates it does not. Cygwin may emulate it with just a non-atomic seek-to-end before write, but that will lead to guaranteed file corruption unless we can find out how to lock files properly.

For locking, we could try fcntl() instead. Or perhaps lockf()? Or even some Windows-specific code - maybe that is the safest bet and we'll have it -D__CYGWIN__ anyway.

<!-- gh-comment-id:73341303 --> @magnumripper commented on GitHub (Feb 7, 2015): Note also that we need to answer this question: Are we really sure Windows has an _atomic_ O_APPEND? Some googling indicates it does not. Cygwin may emulate it with just a non-atomic seek-to-end before write, but that will lead to guaranteed file corruption unless we can find out how to lock files properly. For locking, we could try fcntl() instead. Or perhaps lockf()? Or even some Windows-specific code - maybe that is the safest bet and we'll have it -D__CYGWIN__ anyway.
Author
Owner

@magnumripper commented on GitHub (Feb 7, 2015):

http://www.perlmonks.org/?node_id=486488 (a thread from 2005)
Note that Win32 doesn't do the seek-then-write atomicly, so you should lock if your code might be/is run on Win32. Also note that if you didn't use binmode (which is likely true and usually for good reason), then the order of things is seek, then newline conversion, then write, which makes the race even racier.

<!-- gh-comment-id:73342151 --> @magnumripper commented on GitHub (Feb 7, 2015): http://www.perlmonks.org/?node_id=486488 (a thread from 2005) _Note that Win32 doesn't do the seek-then-write atomicly, so you should lock if your code might be/is run on Win32. Also note that if you didn't use binmode (which is likely true and usually for good reason), then the order of things is seek, then newline conversion, then write, which makes the race even racier._
Author
Owner

@magnumripper commented on GitHub (Feb 7, 2015):

Better news from 2009: https://cygwin.com/cygwin-ug-net/ov-new1.7.html

What's new and what changed from 1.5 to 1.7
...
Implement atomic O_APPEND mode.

<!-- gh-comment-id:73342494 --> @magnumripper commented on GitHub (Feb 7, 2015): Better news from 2009: https://cygwin.com/cygwin-ug-net/ov-new1.7.html _What's new and what changed from 1.5 to 1.7 ... Implement atomic O_APPEND mode._
Author
Owner

@magnumripper commented on GitHub (Feb 7, 2015):

Also some info on what is "supposed" from POSIX: http://stackoverflow.com/questions/1154446/is-file-append-atomic-in-unix

That also includes someone saying

I wrote a script to empirically test the maximum atomic append size. As @freiheit mentioned, on Linux you can write up to 4096 bytes atomically. On Windows, the maximum size is 1024

...which indicates we really want locking anyway. On the other hand, it's not the end of the world (at all) if two processes' pot file writes are interleaved as long as they are interleaved at line boundaries. I'm not sure Solar's code (write_loop() in misc.c) take care of that - it doesn't seem to.

<!-- gh-comment-id:73342861 --> @magnumripper commented on GitHub (Feb 7, 2015): Also some info on what is "supposed" from POSIX: http://stackoverflow.com/questions/1154446/is-file-append-atomic-in-unix That also includes someone saying _I wrote a script to empirically test the maximum atomic append size. As @freiheit mentioned, on Linux you can write up to 4096 bytes atomically. On Windows, the maximum size is 1024_ ...which indicates we really want locking anyway. On the other hand, it's not the end of the world (at all) if two processes' pot file writes are interleaved as long as they are interleaved at line boundaries. I'm not sure Solar's code (write_loop() in misc.c) take care of that - it doesn't seem to.
Author
Owner

@magnumripper commented on GitHub (Feb 7, 2015):

Oh, and here's a test script!
http://www.notthewizard.com/2014/06/17/are-files-appends-really-atomic/

<!-- gh-comment-id:73343405 --> @magnumripper commented on GitHub (Feb 7, 2015): Oh, and here's a test script! http://www.notthewizard.com/2014/06/17/are-files-appends-really-atomic/
Author
Owner

@magnumripper commented on GitHub (Feb 7, 2015):

OSX only seem to have a 256 byte max without locking

$ ./test_appends.sh 256
Launching 20 worker processes
Each line will be 256 characters long
Waiting for processes to exit
Testing output file
........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
All's good! The output file had no corrupted lines. 

$ ./test_appends.sh 257
Launching 20 worker processes
Each line will be 257 characters long
Waiting for processes to exit
Testing output file
........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
Found 1000 instances of corrupted lines
<!-- gh-comment-id:73343571 --> @magnumripper commented on GitHub (Feb 7, 2015): OSX only seem to have a 256 byte max without locking ``` $ ./test_appends.sh 256 Launching 20 worker processes Each line will be 256 characters long Waiting for processes to exit Testing output file ........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................ All's good! The output file had no corrupted lines. $ ./test_appends.sh 257 Launching 20 worker processes Each line will be 257 characters long Waiting for processes to exit Testing output file ........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................ Found 1000 instances of corrupted lines ```
Author
Owner

@jfoug commented on GitHub (Feb 7, 2015):

I've been warning folks that this type fork code is VERY tricky. That some OS's babysit u does not mean it's great code for general purpose. It is good we have been digging in to learn the good and the ugly. Btw, Quiet Riot just got done. Waiting for Night Ranger.

<!-- gh-comment-id:73347178 --> @jfoug commented on GitHub (Feb 7, 2015): I've been warning folks that this type fork code is VERY tricky. That some OS's babysit u does not mean it's great code for general purpose. It is good we have been digging in to learn the good and the ugly. Btw, Quiet Riot just got done. Waiting for Night Ranger.
Author
Owner

@jfoug commented on GitHub (Feb 7, 2015):

I will work with that test script later

<!-- gh-comment-id:73347218 --> @jfoug commented on GitHub (Feb 7, 2015): I will work with that test script later
Author
Owner

@jfoug commented on GitHub (Feb 7, 2015):

Here is a run under cygwin64 (updated pretty recently, last Dec I think). NOTE, this only allows for testing under cygwin bash terminal. It does not allow testing a native cygwin 'program' that is run under Win32 (64) cmd shell. While they are similar, there are some differences which I am not fully aware of. It could be for this case that there is no difference at all. A HUGE amount of differences are due to nuances in the shells.

One note to cygwin, I am not 100% sure that processes launched with the & in a loop like that, are not all completed fast enough, so that there is no overlapped running of processes. Well, now I am more sure cygwin 'IS' working properly, since adding 1 byte to length in cygwin32 did show the problem perfectly.

CYGWIN-64
$ ./tst-appends.sh
Buffer length not specified, defaulting to 4096
Launching 20 worker processes
Each line will be 4096 characters long
Waiting for processes to exit
Testing output file
All's good! The output file had no corrupted lines.

Launching 20 worker processes
Each line will be 8192 characters long
Waiting for processes to exit
Testing output file
All's good! The output file had no corrupted lines.

I am not going over 8192 chars, until the compare is changed. Just takes too long.
CYGWIN-32
$ ./tst-appends.sh 1024
Launching 20 worker processes
Each line will be 1024 characters long
Waiting for processes to exit
Testing output file
All's good! The output file had no corrupted lines.

$ ./tst-appends.sh 1025
Launching 20 worker processes
Each line will be 1025 characters long
Waiting for processes to exit
Testing output file
Found 50 instances of corrupted lines
Ubuntu64 14.4_LTS on virtualbox (ext4fs /tmp/) 

NOTE, I am getting exact same results on the vboxfs file system???  But I bet
the shell is locking with flock() on the >>

$ ./tst-appends.sh 1008
Launching 20 worker processes
Each line will be 1008 characters long
Waiting for processes to exit
Testing output file
All's good! The output file had no corrupted lines. 

$ ./tst-appends.sh 1009
Launching 20 worker processes
Each line will be 1009 characters long
Waiting for processes to exit
Testing output file
Found 66 instances of corrupted lines
<!-- gh-comment-id:73361698 --> @jfoug commented on GitHub (Feb 7, 2015): Here is a run under cygwin64 (updated pretty recently, last Dec I think). NOTE, this only allows for testing under cygwin bash terminal. It does not allow testing a native cygwin 'program' that is run under Win32 (64) cmd shell. While they are similar, there are some differences which I am not fully aware of. It could be for this case that there is no difference at all. A HUGE amount of differences are due to nuances in the shells. One note to cygwin, I am not 100% sure that processes launched with the & in a loop like that, are not all completed fast enough, so that there is no overlapped running of processes. Well, now I am more sure cygwin 'IS' working properly, since adding 1 byte to length in cygwin32 did show the problem perfectly. ``` CYGWIN-64 $ ./tst-appends.sh Buffer length not specified, defaulting to 4096 Launching 20 worker processes Each line will be 4096 characters long Waiting for processes to exit Testing output file All's good! The output file had no corrupted lines. Launching 20 worker processes Each line will be 8192 characters long Waiting for processes to exit Testing output file All's good! The output file had no corrupted lines. I am not going over 8192 chars, until the compare is changed. Just takes too long. ``` ``` CYGWIN-32 $ ./tst-appends.sh 1024 Launching 20 worker processes Each line will be 1024 characters long Waiting for processes to exit Testing output file All's good! The output file had no corrupted lines. $ ./tst-appends.sh 1025 Launching 20 worker processes Each line will be 1025 characters long Waiting for processes to exit Testing output file Found 50 instances of corrupted lines ``` ``` Ubuntu64 14.4_LTS on virtualbox (ext4fs /tmp/) NOTE, I am getting exact same results on the vboxfs file system??? But I bet the shell is locking with flock() on the >> $ ./tst-appends.sh 1008 Launching 20 worker processes Each line will be 1008 characters long Waiting for processes to exit Testing output file All's good! The output file had no corrupted lines. $ ./tst-appends.sh 1009 Launching 20 worker processes Each line will be 1009 characters long Waiting for processes to exit Testing output file Found 66 instances of corrupted lines ```
Author
Owner

@jfoug commented on GitHub (Feb 7, 2015):

For locking, we could try fcntl() instead. Or perhaps lockf()? Or even some Windows-specific code - maybe that is the safest bet and we'll have it -D__CYGWIN__ anyway.

I think that is very good idea. During a TS run, I actually locked up the machine, It was still working, but even the mouse would only move a few dozen pixels ever 20-30s or so. Something had enough threads hard locked and busy, and was not even giving it up to the OS. So it 'almost' works, without any locking, but really not good enough. I really think fcntl() may be the way to do (but it could be the lockf() ) The cygwin page you found DID list that each of these API implementations WAS independent of the others.

<!-- gh-comment-id:73361937 --> @jfoug commented on GitHub (Feb 7, 2015): > For locking, we could try fcntl() instead. Or perhaps lockf()? Or even some Windows-specific code - maybe that is the safest bet and we'll have it -D__CYGWIN__ anyway. I think that is very good idea. During a TS run, I actually locked up the machine, It was still working, but even the mouse would only move a few dozen pixels ever 20-30s or so. Something had enough threads hard locked and busy, and was not even giving it up to the OS. So it 'almost' works, without any locking, but really not good enough. I really think fcntl() may be the way to do (but it could be the lockf() ) The cygwin page you found DID list that each of these API implementations WAS independent of the others.
Author
Owner

@jfoug commented on GitHub (Feb 7, 2015):

I am doing fcntl() for cywin in logger.c to see how things go. But from this page:

http://www.informit.com/articles/article.aspx?p=23618&seqNum=4

Linux provides another implementation of file locking with the flock call. The fcntl version has a major
advantage: It works with files on NFS3 file systems (as long as the NFS server is reasonably recent and
correctly configured). So, if you have access to two machines that both mount the same file system via
NFS, you can repeat the previous example using two different machines. Run lock-file on one machine,
specifying a file on an NFS file system, and then run it again on another machine, specifying the same
file. NFS wakes up the second program when the lock is released by the first program.

So we may really want to look at this, along with ask Solar on to why his choice for that BSD flock() interface?? It may be that it is available on my platforms. BUT as per that statment, it sounds like this 'may' be a much better way to go, even handling NFS (possibly).

<!-- gh-comment-id:73362733 --> @jfoug commented on GitHub (Feb 7, 2015): I am doing fcntl() for cywin in logger.c to see how things go. But from this page: http://www.informit.com/articles/article.aspx?p=23618&seqNum=4 ``` Linux provides another implementation of file locking with the flock call. The fcntl version has a major advantage: It works with files on NFS3 file systems (as long as the NFS server is reasonably recent and correctly configured). So, if you have access to two machines that both mount the same file system via NFS, you can repeat the previous example using two different machines. Run lock-file on one machine, specifying a file on an NFS file system, and then run it again on another machine, specifying the same file. NFS wakes up the second program when the lock is released by the first program. ``` So we may really want to look at this, along with ask Solar on to why his choice for that BSD flock() interface?? It may be that it is available on my platforms. BUT as per that statment, it sounds like this 'may' be a much better way to go, even handling NFS (possibly).
Author
Owner

@jfoug commented on GitHub (Feb 7, 2015):

Ok, I implemented a 'simple' fcntl. simply following exact same instructions as on

http://www.informit.com/articles/article.aspx?p=23618&seqNum=4

fcntl() is working (I hope, I have more testing to do).

Ok, I have checked in logger.c 7a9d98e . It ONLY does this code for cygwin, but shows the simplisity, and we certainly should relay this information upstream to Solar. The simple fact that he could get -fork working properly in cygwin on core should be an indication to him that it is something to look at, along with that statement (unverified), that fcntl() works with NFS (newer ones).

<!-- gh-comment-id:73363037 --> @jfoug commented on GitHub (Feb 7, 2015): Ok, I implemented a 'simple' fcntl. simply following exact same instructions as on http://www.informit.com/articles/article.aspx?p=23618&seqNum=4 fcntl() is working (I hope, I have more testing to do). Ok, I have checked in logger.c 7a9d98e . It ONLY does this code for cygwin, but shows the simplisity, and we certainly should relay this information upstream to Solar. The simple fact that he could get -fork working properly in cygwin on core should be an indication to him that it is something to look at, along with that statement (unverified), that fcntl() works with NFS (newer ones).
Author
Owner

@magnumripper commented on GitHub (Feb 7, 2015):

The fcntl version has a major advantage: It works with files on NFS3 file systems (as long as the NFS server is reasonably recent and correctly configured).

This is very outdated information (2001!). I know flock() works fine in Linux w/ NFS and has done so for six years or more.

<!-- gh-comment-id:73369586 --> @magnumripper commented on GitHub (Feb 7, 2015): > The fcntl version has a major advantage: It works with files on NFS3 file systems (as long as the NFS server is reasonably recent and correctly configured). This is very outdated information (2001!). I know flock() works fine in Linux w/ NFS and has done so for six years or more.
Author
Owner

@magnumripper commented on GitHub (Feb 7, 2015):

I presume Solar picked flock() for a good reason, since fcntl() is more portable if I got things right. We should simply ask him.

<!-- gh-comment-id:73369622 --> @magnumripper commented on GitHub (Feb 7, 2015): I presume Solar picked flock() for a good reason, since fcntl() is more portable if I got things right. We should simply ask him.
Author
Owner

@magnumripper commented on GitHub (Feb 7, 2015):

NOTE, I am getting exact same results on the vboxfs file system??? But I bet the shell is locking with flock() on the >>

I doubt that. If it does, you would get zero failures regardless of size - you should be able to run it with 65536 and it would still not fail.

<!-- gh-comment-id:73370033 --> @magnumripper commented on GitHub (Feb 7, 2015): > NOTE, I am getting exact same results on the vboxfs file system??? But I bet the shell is locking with flock() on the >> I doubt that. If it does, you would get zero failures regardless of size - you should be able to run it with 65536 and it would still not fail.
Author
Owner

@magnumripper commented on GitHub (Feb 7, 2015):

05b51935 wraps up Jim's initial work and makes fcntl() the default locking scheme. After testing, we can hopefully close this.

<!-- gh-comment-id:73378945 --> @magnumripper commented on GitHub (Feb 7, 2015): 05b51935 wraps up Jim's initial work and makes fcntl() the default locking scheme. After testing, we can hopefully close this.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
openwall/john#643
No description provided.