[GH-ISSUE #1954] New option: --queue #1300

Closed
opened 2026-10-14 03:43:22 +07:00 by bsakaguchi · 28 comments
Owner

Originally created by @magnumripper on GitHub (Dec 16, 2015).
Original GitHub issue: https://github.com/openwall/john/issues/1954

Originally assigned to: @magnumripper on GitHub.

Basic idea, usage:

Session 1:

$ ./john -session:thisorthat (...)
Loaded 123 hashes (...)
(...)

Session 2 (note that session 1 is still running):

$ ./john -session:thisorthat -queue (...)
Waiting...

Basic idea, how to implement:

  • If the session file doesn't exist, this is a no-op option - we just start the job as usual.
  • If the session file does exist, take a blocking write lock on it. Wait forever for the lock to disappear (the "Waiting..." message above is printed while waiting).
  • Once we got the lock, verify that the session file has been deleted. If it has, it's our turn and we start the job.
  • If the file was NOT deleted, the first job must have been aborted. Bail out saying "Queing failed" or something (this behavior can be enhanced later in various ways).

If this scheme works, this is a super trivial KISS[tm] way to add ability to queue jobs that need to be run in sequence.

Originally created by @magnumripper on GitHub (Dec 16, 2015). Original GitHub issue: https://github.com/openwall/john/issues/1954 Originally assigned to: @magnumripper on GitHub. Basic idea, usage: Session 1: ``` $ ./john -session:thisorthat (...) Loaded 123 hashes (...) (...) ``` Session 2 (note that session 1 is still _running_): ``` $ ./john -session:thisorthat -queue (...) Waiting... ``` Basic idea, how to implement: - If the session file doesn't exist, this is a no-op option - we just start the job as usual. - If the session file does exist, take a blocking write lock on it. Wait forever for the lock to disappear (the "Waiting..." message above is printed while waiting). - Once we got the lock, verify that the session file has been deleted. If it has, it's our turn and we start the job. - If the file was NOT deleted, the first job must have been aborted. Bail out saying "Queing failed" or something (this behavior can be enhanced later in various ways). If this scheme works, this is a super trivial KISS[tm] way to add ability to queue jobs that need to be run in sequence.
Author
Owner

@magnumripper commented on GitHub (Dec 16, 2015):

Caveat: The -queue option must not be stored in the session file.

<!-- gh-comment-id:165208511 --> @magnumripper commented on GitHub (Dec 16, 2015): Caveat: The `-queue` option must not be stored in the session file.
Author
Owner

@jfoug commented on GitHub (Dec 16, 2015):

I was going to comment about breaking out of the first process, but you handled that. I do like this, and yes, the caveat is valid.

One other thing. Yes, you mention KISS. but in the current form, you can only have a running process and 1 item in queue (if sequential processing is wanted.).

But a more simple KISS method would be:

#!/bin/sh
.....

:)

<!-- gh-comment-id:165211448 --> @jfoug commented on GitHub (Dec 16, 2015): I was going to comment about breaking out of the first process, but you handled that. I do like this, and yes, the caveat is valid. One other thing. Yes, you mention KISS. but in the current form, you can only have a running process and 1 item in queue (if sequential processing is wanted.). But a more simple KISS method would be: #!/bin/sh ..... :)
Author
Owner

@magnumripper commented on GitHub (Dec 16, 2015):

I often start things like this:

$ ./john -session:thisorthat (...) && ./john -session:thisorthat (...)

This is akin to your shell script (btw I think you need to use #!/bin/sh -e unless you end each john command with &&) and these are the simplest ways to achieve this of course. If a session is aborted or fails in any way, the rest of the line is aborted.

However, the -queue option can be used after the first session is already running. You start a job and only then realize another job you want to start after the first one is done. To accomplish this today, you need to abort session 1 and then do this oneliner:

$ ./john -restore:thisorthat && ./john -session:thisorthat (...)
<!-- gh-comment-id:165215398 --> @magnumripper commented on GitHub (Dec 16, 2015): I often start things like this: ``` $ ./john -session:thisorthat (...) && ./john -session:thisorthat (...) ``` This is akin to your shell script (btw I think you need to use `#!/bin/sh -e` unless you end each john command with &&) and these are the simplest ways to achieve this of course. If a session is aborted or fails in any way, the rest of the line is aborted. However, the `-queue` option can be used **after** the first session is already running. You start a job and only then realize another job you want to start after the first one is done. To accomplish this today, you need to abort session 1 and then do this oneliner: ``` $ ./john -restore:thisorthat && ./john -session:thisorthat (...) ```
Author
Owner

@jfoug commented on GitHub (Dec 16, 2015):

Do not take my KISS mention of a shell script as a poo poo against this function. I do see that it can certainly be beneficial. I also simply listed that you can only queue 1 item at a time, for a running session, unless you do not care about order.

<!-- gh-comment-id:165220615 --> @jfoug commented on GitHub (Dec 16, 2015): Do not take my KISS mention of a shell script as a poo poo against this function. I do see that it can certainly be beneficial. I also simply listed that you can only queue 1 item at a time, for a running session, unless you do not care about order.
Author
Owner

@frank-dittrich commented on GitHub (Dec 16, 2015):

One more caveat:
Decide how to handle LogFileProtect = Named | Always for --queue, and document that behavior.

<!-- gh-comment-id:165223454 --> @frank-dittrich commented on GitHub (Dec 16, 2015): One more caveat: Decide how to handle LogFileProtect = Named | Always for --queue, and document that behavior.
Author
Owner

@magnumripper commented on GitHub (Dec 16, 2015):

@jfoug but it's a valid concern. I actually had the idea you could queue more than one job but that won't work with the proposed design. I will ponder other options. If we can't make this really usable, we should just ditch this idea (after all it will add possible bugs!).

<!-- gh-comment-id:165225242 --> @magnumripper commented on GitHub (Dec 16, 2015): @jfoug but it's a valid concern. I actually had the idea you could queue more than one job but that won't work with the proposed design. I will ponder other options. If we can't make this **really** usable, we should just ditch this idea (after all it will add possible bugs!).
Author
Owner

@frank-dittrich commented on GitHub (Dec 16, 2015):

If you are willing to change the .rec file format, you could allow --queue for a session which is not currently running, by just appending the information for the next task(s) to the existing .rec file.
When you restore and finish the first task, you just have to remove the information related to the first task, then proceed with the next task.
But then you need to address issues related to --fork=n and possibly varying n for different wueued tasks...

<!-- gh-comment-id:165261483 --> @frank-dittrich commented on GitHub (Dec 16, 2015): If you are willing to change the .rec file format, you could allow --queue for a session which is not currently running, by just appending the information for the next task(s) to the existing .rec file. When you restore and finish the first task, you just have to remove the information related to the first task, then proceed with the next task. But then you need to address issues related to --fork=n and possibly varying n for different wueued tasks...
Author
Owner

@jfoug commented on GitHub (Dec 16, 2015):

I am pretty sure we 'could' queue as many as we wanted, and they should be released 1 at a time, BUT there is no assurance of order. It would be classic uncontrolled multi-processing problem (i.e. dining philosophers problem). 1 of them should get released, but there is no assurance of any order, and no assurance that some process would not starve and never get to work.

<!-- gh-comment-id:165268852 --> @jfoug commented on GitHub (Dec 16, 2015): I am pretty sure we 'could' queue as many as we wanted, and they should be released 1 at a time, BUT there is no assurance of order. It would be classic uncontrolled multi-processing problem (i.e. dining philosophers problem). 1 of them should get released, but there is no assurance of any order, and no assurance that some process would not starve and never get to work.
Author
Owner

@jfoug commented on GitHub (Dec 17, 2015):

Ok, how about this:

  1. a new file: called session_name.queue (has to be hand created).
  2. when a run completes fully, that file is looked for (same location as the *.rec file just removed).
  3. That search is done right at the end of main(). If found, then we 'fixup' the file (removing the top line, and rewrite the file, or delete it if there was only 1 entry).
  4. john then spawn a new john session using that command line

This is 'still' pretty KISS, and it allows ordered running, and only continuing upon full completion of the current run (we can talk about that also).

What do others 'think' about this. There would be NO additional command line args required. This would be driven by instruction file only.

TBD:

  • I would say that the full command line should be on each line, including the executable. That way, a different john exe could be hand chosen (openmp, non-openmp, opencl, etc).
  • How would we pass OMP_NUM_THREADS (or other env settings) ?
<!-- gh-comment-id:165489226 --> @jfoug commented on GitHub (Dec 17, 2015): Ok, how about this: 1. a new file: called session_name.queue (has to be hand created). 2. when a run completes fully, that file is looked for (same location as the *.rec file just removed). 3. That search is done right at the end of main(). If found, then we 'fixup' the file (removing the top line, and rewrite the file, or delete it if there was only 1 entry). 4. john then spawn a new john session using that command line This is 'still' pretty KISS, and it allows ordered running, and only continuing upon full completion of the current run (we can talk about that also). What do others 'think' about this. There would be NO additional command line args required. This would be driven by instruction file only. TBD: - I would say that the full command line should be on each line, including the executable. That way, a different john exe could be hand chosen (openmp, non-openmp, opencl, etc). - How would we pass OMP_NUM_THREADS (or other env settings) ?
Author
Owner

@magnumripper commented on GitHub (Dec 17, 2015):

It's too complicated to use. I have other vague ideas, will experiment a little.

<!-- gh-comment-id:165557366 --> @magnumripper commented on GitHub (Dec 17, 2015): It's too complicated to use. I have other vague ideas, will experiment a little.
Author
Owner

@jfoug commented on GitHub (Dec 17, 2015):

Why could we not have john itself add lines the queue file (if the --queue switch was used) ???

Thus it would be 100% user interface the same as you suggested from the start. But then we would not have a process doing a busy wait to run. It would simply add a line to the queue file. Then when the first process completes, that process will launch the next process while exiting.

<!-- gh-comment-id:165600479 --> @jfoug commented on GitHub (Dec 17, 2015): Why could we not have john itself add lines the queue file (if the --queue switch was used) ??? Thus it would be 100% user interface the same as you suggested from the start. But then we would not have a process doing a busy wait to run. It would simply add a line to the queue file. Then when the first process completes, that process will launch the next process while exiting.
Author
Owner

@magnumripper commented on GitHub (Dec 17, 2015):

Maybe. But this will be a good chunk of code, in core, with file locking and whatnot.

Another option would be a standalone thing, a wrapper for JtR, instead.

<!-- gh-comment-id:165611003 --> @magnumripper commented on GitHub (Dec 17, 2015): Maybe. But this will be a good chunk of code, in core, with file locking and whatnot. Another option would be a standalone thing, a wrapper for JtR, instead.
Author
Owner

@jfoug commented on GitHub (Dec 17, 2015):

Are you thinking of adding this to core??? (john proper).

I would see only a couple of lines added. One right after loading command params. The other within main() right before exit.

Then the rest would be 'hidden' in a new source file (the real guts). This really should not be 'that' big of an addition.

<!-- gh-comment-id:165613140 --> @jfoug commented on GitHub (Dec 17, 2015): Are you thinking of adding this to core??? (john proper). I would see only a couple of lines added. One right after loading command params. The other within main() right before exit. Then the rest would be 'hidden' in a new source file (the real guts). This really should not be 'that' big of an addition.
Author
Owner

@magnumripper commented on GitHub (Dec 17, 2015):

No I meant core code in Jumbo. And regardless of where we place the code, it will be a whole new world of possible bugs. There must be an easier way to do this!

<!-- gh-comment-id:165615547 --> @magnumripper commented on GitHub (Dec 17, 2015): No I meant core code in Jumbo. And regardless of where we place the code, it will be a whole new world of possible bugs. There must be an easier way to do this!
Author
Owner

@magnumripper commented on GitHub (Dec 17, 2015):

Like this scenario: First session is a single thread CPU format doing mask mode for lengths up to 4. Second session is an MPI job on several remote hosts with OpenCL, starting at length 5. Things like that was what I originally had in mind. And my original idea would work in that scenario, except it wouldn't be able to queue a third job.

<!-- gh-comment-id:165616901 --> @magnumripper commented on GitHub (Dec 17, 2015): Like this scenario: First session is a single thread CPU format doing mask mode for lengths up to 4. Second session is an MPI job on several remote hosts with OpenCL, starting at length 5. Things like that was what I originally had in mind. And my original idea would work in that scenario, except it wouldn't be able to queue a third job.
Author
Owner

@magnumripper commented on GitHub (Jan 7, 2016):

Here's an alternative that might work (needs more thought)

--queue[=session]  take a blocking lock on session.rec, once you get it ensure
                   it has been deleted. Then start. "session" must be different
                   from your own.

It would work something like this

$ john -ses:1 (...)

$ john -ses:2 --queue=1 (...)

$ john -ses:3 --queue=2 (...)
  • Session 1 starts and runs
  • Session 2 will create 2.rec and lock it, but will then pause waiting for [a lock on] 1.rec.
  • Session 3 will create 3.rec and lock it, but will then pause waiting for 2.rec.
<!-- gh-comment-id:169573642 --> @magnumripper commented on GitHub (Jan 7, 2016): Here's an alternative that might work (needs more thought) ``` --queue[=session] take a blocking lock on session.rec, once you get it ensure it has been deleted. Then start. "session" must be different from your own. ``` It would work something like this ``` $ john -ses:1 (...) $ john -ses:2 --queue=1 (...) $ john -ses:3 --queue=2 (...) ``` - Session 1 starts and runs - Session 2 will create 2.rec and lock it, but will then pause waiting for [a lock on] 1.rec. - Session 3 will create 3.rec and lock it, but will then pause waiting for 2.rec.
Author
Owner

@jfoug commented on GitHub (Jan 7, 2016):

That logic appears solid. However, what happens if session1 is killed (i.e. session 1.rec is not removed) ?

<!-- gh-comment-id:169773493 --> @jfoug commented on GitHub (Jan 7, 2016): That logic appears solid. However, what happens if session1 is killed (i.e. session 1.rec is not removed) ?
Author
Owner

@frank-dittrich commented on GitHub (Jan 7, 2016):

Or, what happens if session 1 still runs, but session 2 gets killed?

<!-- gh-comment-id:169796623 --> @frank-dittrich commented on GitHub (Jan 7, 2016): Or, what happens if session 1 still runs, but session 2 gets killed?
Author
Owner

@magnumripper commented on GitHub (Jan 7, 2016):

what happens if session1 is killed (i.e. session 1.rec is not removed) ?

We'll still have code for ensuring the preceding session file was deleted. So session 2 get a lock but then bail out with an error message because 1.rec was not deleted. After that, session 3 will bail for the same reason.

what happens if session 1 still runs, but session 2 gets killed?

Same code: Session 3 will get the lock of 2.rec but notices it wasn't deleted, so it bails out.

<!-- gh-comment-id:169832671 --> @magnumripper commented on GitHub (Jan 7, 2016): > what happens if session1 is killed (i.e. session 1.rec is not removed) ? We'll still have code for ensuring the preceding session file was deleted. So session 2 get a lock but then bail out with an error message because 1.rec was not deleted. After that, session 3 will bail for the same reason. > what happens if session 1 still runs, but session 2 gets killed? Same code: Session 3 will get the lock of 2.rec but notices it wasn't deleted, so it bails out.
Author
Owner

@magnumripper commented on GitHub (Feb 9, 2016):

1f34620 is a first step. Unfortunately it looks like this type of queueing can't be made safe on Windows since that poor OS can't delete a locked file (if it has locks at all).

<!-- gh-comment-id:181739832 --> @magnumripper commented on GitHub (Feb 9, 2016): 1f34620 is a first step. Unfortunately it looks like this type of queueing can't be made safe on Windows since that poor OS can't delete a locked file (if it has locks at all).
Author
Owner

@magnumripper commented on GitHub (Feb 9, 2016):

I'm regression testing a working commit implementing this. It will be completely disabled on Windows. It does support queueing after a session with same name as "our" session. Also, it does filter out the "--queue-after" from the session file.

<!-- gh-comment-id:181740587 --> @magnumripper commented on GitHub (Feb 9, 2016): I'm regression testing a working commit implementing this. It will be completely disabled on Windows. It _does_ support queueing after a session with same name as "our" session. Also, it does filter out the "--queue-after" from the session file.
Author
Owner

@frank-dittrich commented on GitHub (Feb 9, 2016):

Should john warn on Windows if it processes such a session file?

<!-- gh-comment-id:181740851 --> @frank-dittrich commented on GitHub (Feb 9, 2016): Should john warn on Windows if it processes such a session file?
Author
Owner

@magnumripper commented on GitHub (Feb 9, 2016):

There will be no such session files. The option is used and then discarded. When resuming, there is no queueing.

However, I'm considering the alternative to support adding queueing on resume: john -resume:yyy -queue=zzz. This is a core change (and may be tricky). Again, it will be used and then discarded so if resuming again later, there will be no --queue involved.

<!-- gh-comment-id:181743186 --> @magnumripper commented on GitHub (Feb 9, 2016): There will be no such session files. The option is used and then discarded. When resuming, there is no queueing. However, I'm considering the alternative to support adding queueing on resume: `john -resume:yyy -queue=zzz`. This is a core change (and may be tricky). Again, it will be used and then discarded so if resuming _again_ later, there will be no `--queue` involved.
Author
Owner

@frank-dittrich commented on GitHub (Feb 9, 2016):

Yes, you can't produce such session files on Windows. But what if you copy them from a Linux machine and try to restore on Windows?

<!-- gh-comment-id:181755713 --> @frank-dittrich commented on GitHub (Feb 9, 2016): Yes, you can't produce such session files on Windows. But what if you copy them from a Linux machine and try to restore on Windows?
Author
Owner

@magnumripper commented on GitHub (Feb 9, 2016):

Read it again. The option never ends up in the session file even on Linux. It happens for first run, not for resume (unless you give the option again when resuming).

<!-- gh-comment-id:181912363 --> @magnumripper commented on GitHub (Feb 9, 2016): Read it again. The option never ends up in the session file even on Linux. It happens for first run, not for resume (unless you give the option again when resuming).
Author
Owner

@magnumripper commented on GitHub (Feb 9, 2016):

Some testing indicates this works very poorly on NFS file systems due to cache incoherence. I'm currently considering ditching the whole idea or going for a completely different solution, possibly with a standalone wrapper.

<!-- gh-comment-id:181912853 --> @magnumripper commented on GitHub (Feb 9, 2016): Some testing indicates this works very poorly on NFS file systems due to cache incoherence. I'm currently considering ditching the whole idea or going for a completely different solution, possibly with a standalone wrapper.
Author
Owner

@magnumripper commented on GitHub (Oct 12, 2016):

Ditching this. One could implement a stand-alone tool but that'd be a new issue.

<!-- gh-comment-id:253199380 --> @magnumripper commented on GitHub (Oct 12, 2016): Ditching this. One could implement a stand-alone tool but that'd be a new issue.
Author
Owner

@magnumripper commented on GitHub (Sep 28, 2017):

Here's a KISS solution

filewait.c

/*
 * Usage: "filewait <file> && do_next"
 *
 * Main purpose is JtR session files. Eg:
 * $ ./filewait sessionA.rec && ./john -ses:sessionB (...)
 *
 * Check the file once every three seconds. Once the file no longer exists,
 * EXIT_SUCCESS.
 *
 * This file is Copyright (c) 2017 magnum
 * and is hereby released to the general public under the following terms:
 * Redistribution and use in source and binary forms, with or without
 * modifications, are permitted.
 */

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>

int main(int argc, char **argv)
{
	char *filename;

	if (argc != 2) {
		printf("Usage: %s <file>\n\n"
		       "If <file> does not exist, exit SUCCESS.\n"
		       "If it does, wait for its deletion. Once it's unlinked, exit SUCCESS.\n\n"
		       "Example use:\n"
		       "%s john.rec && ./john -ses:next_session (...)\n\n", argv[0], argv[0]);
		return EXIT_FAILURE;
	}

	filename = argv[1];

	fprintf(stderr, "Waiting for %s... ", filename);

	do {
		if (access(filename, F_OK) == -1)
			break;
		else
			sleep(3);
	} while (1);

	fprintf(stderr, "Done!\n");

	return EXIT_SUCCESS;
}

gcc -O2 -Wpedantic -o /usr/local/bin/filewait filewait.c

<!-- gh-comment-id:332938279 --> @magnumripper commented on GitHub (Sep 28, 2017): Here's a KISS solution filewait.c ```c /* * Usage: "filewait <file> && do_next" * * Main purpose is JtR session files. Eg: * $ ./filewait sessionA.rec && ./john -ses:sessionB (...) * * Check the file once every three seconds. Once the file no longer exists, * EXIT_SUCCESS. * * This file is Copyright (c) 2017 magnum * and is hereby released to the general public under the following terms: * Redistribution and use in source and binary forms, with or without * modifications, are permitted. */ #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h> int main(int argc, char **argv) { char *filename; if (argc != 2) { printf("Usage: %s <file>\n\n" "If <file> does not exist, exit SUCCESS.\n" "If it does, wait for its deletion. Once it's unlinked, exit SUCCESS.\n\n" "Example use:\n" "%s john.rec && ./john -ses:next_session (...)\n\n", argv[0], argv[0]); return EXIT_FAILURE; } filename = argv[1]; fprintf(stderr, "Waiting for %s... ", filename); do { if (access(filename, F_OK) == -1) break; else sleep(3); } while (1); fprintf(stderr, "Done!\n"); return EXIT_SUCCESS; } ``` `gcc -O2 -Wpedantic -o /usr/local/bin/filewait filewait.c`
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#1300
No description provided.