[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Bacula-devel] Status Command Changes The Job Type

On Wednesday 13 February 2008 21.23:21 Allan Black wrote:
> Just had a look at ua_status.c, because of something which
> has been annoying me for a while.
> If there are any scheduled jobs, the "st dir" command causes
> num_jobs_run to be incremented when the console disconnects.
> [ I noticed this while I was testing a script, and could not
> understand why the "jobs run since started" kept increasing
> every time I ran it ]

Very observant of you!

> What is happening is this:
> The console's JCR starts off with its JobType set to JT_ADMIN.
> The list_scheduled_jobs() function calls prt_runtime() on any
> jobs in the sched list. prt_runtime re-uses the console's JCR
> to emulate the job which is being examined, and to do so, it
> has to change some of the JCR's values.
> In particular, prt_runtime() calls complete_jcr_for_job(),
> which in turn calls set_jcr_defaults(), which sets the JCR's
> JobType to be the Job's JobType, i.e. JT_BACKUP.
> prt_runtime() restores the JCR's db field to its original
> value (which is in the UAContext), but not any of the other
> values.
> As a result, when the console disconnects, the director frees
> the JCR and increments num_jobs_run, because jcr->JobType is
> set to JT_BACKUP.
> This is a trivial bug, but of more concern to me is the fact
> that the console's JCR has been 'corrupted'.

Well the consequences you indicate above are not terribly serious as you 
indicate, but it is a bit ugly and incorrect.

> I would like to fix this, but would appreciate your opinions
> on the correct way to go about it:
> 1) Restore the JobType to the correct value at the end of
>    prt_runtime(), either by saving it, or by explicitly
>    setting it to JT_ADMIN (I would probably prefer to
>    save/restore, just in case).
> 2) Create and destroy a new JCR object in prt_runtime()
>    instead of re-using the console's JCR.
> I think 2 is technically the correct way to do it, since
> there may be other fields in the JCR which are changed, but
> it may be more difficult.

Yes, I agree that 2 is technically the correct way to do it.  However for 
efficiency reasons, I prefer to create the jcr before the loop that calls 
prt_runtime().  Doing so will be more efficient, but could possibly lead to a 
new bug if ever someone adds more calls to prt_runtime().  However, I think 
that can be mitigated by adding a warning to the top of prt_runtime that says 
that it "corrupts" the jcr so that the caller should use one that is going to 
be discarded ...

Best regards,


This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
Bacula-devel mailing list

This mailing list archive is a service of Copilot Consulting.