Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Rename silent flag to interactive.
- Lets call the silent flag of the cancel_storage_daemon_job() function
  interactive which covers the actual meaning a bit better e.g. are we
  doing an interactive cancel or not.
- When we are doing a non-interactive cancel we shouldn't kill the
  thread as we are on the cancel path our self. There are some safeguards
  in place that catch the thread id not being the same as pthread_self()
  so we shouldn't be able to commit suicide but as we know we are in the
  cancel path there is no need for all the trickery. For an interactive
  cancel e.g. one invoked by the user an external thread is canceling so
  we should let the actual Job thread that is doing the actual work know
  things are being canceled.

Fixes #446: bareos-dir segfault
  • Loading branch information
Marco van Wieringen committed Sep 15, 2015
1 parent 058f81a commit f3e9c9d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/dird/protos.h
Expand Up @@ -228,7 +228,7 @@ void free_vol_list(dlist *vol_list);
int get_num_slots_from_SD(UAContext *ua);
int get_num_drives_from_SD(UAContext *ua);
bool cancel_storage_daemon_job(UAContext *ua, STORERES *store, char *JobId);
bool cancel_storage_daemon_job(UAContext *ua, JCR *jcr, bool silent = false);
bool cancel_storage_daemon_job(UAContext *ua, JCR *jcr, bool interactive = true);
void cancel_storage_daemon_job(JCR *jcr);
void do_native_storage_status(UAContext *ua, STORERES *store, char *cmd);
bool transfer_volume(UAContext *ua, STORERES *store, int src_slot, int dst_slot);
Expand Down
25 changes: 16 additions & 9 deletions src/dird/sd_cmds.c
Expand Up @@ -648,11 +648,11 @@ bool cancel_storage_daemon_job(UAContext *ua, STORERES *store, char *JobId)
}

/*
* Cancel a running job on a storage daemon. The silent flag sets
* if we need to be silent or not e.g. when doing an interactive cancel
* Cancel a running job on a storage daemon. The interactive flag sets
* if we are interactive or not e.g. when doing an interactive cancel
* or a system invoked one.
*/
bool cancel_storage_daemon_job(UAContext *ua, JCR *jcr, bool silent)
bool cancel_storage_daemon_job(UAContext *ua, JCR *jcr, bool interactive)
{
BSOCK *sd;
USTORERES store;
Expand All @@ -673,7 +673,7 @@ bool cancel_storage_daemon_job(UAContext *ua, JCR *jcr, bool silent)
}

if (!connect_to_storage_daemon(ua->jcr, 10, me->SDConnectTimeout, true)) {
if (!silent) {
if (interactive) {
ua->error_msg(_("Failed to connect to Storage daemon.\n"));
}
return false;
Expand All @@ -682,29 +682,36 @@ bool cancel_storage_daemon_job(UAContext *ua, JCR *jcr, bool silent)
sd = ua->jcr->store_bsock;
sd->fsend(canceljobcmd, jcr->Job);
while (sd->recv() >= 0) {
if (!silent) {
if (interactive) {
ua->send_msg("%s", sd->msg);
}
}
sd->signal(BNET_TERMINATE);
sd->close();
delete ua->jcr->store_bsock;
ua->jcr->store_bsock = NULL;
if (silent) {
if (!interactive) {
jcr->sd_canceled = true;
}
jcr->store_bsock->set_timed_out();
jcr->store_bsock->set_terminated();
sd_msg_thread_send_signal(jcr, TIMEOUT_SIGNAL);
jcr->my_thread_send_signal(TIMEOUT_SIGNAL);

/*
* An interactive cancel means we need to send a signal to the actual
* controlling JCR of the Job to let it know it got canceled.
*/
if (interactive) {
jcr->my_thread_send_signal(TIMEOUT_SIGNAL);
}

return true;
}

/*
* Cancel a running job on a storage daemon. System invoked
* non interactive version this builds a ua context and calls
* the interactive one with the silent flag set.
* the interactive one with the interactive flag set to false.
*/
void cancel_storage_daemon_job(JCR *jcr)
{
Expand All @@ -720,7 +727,7 @@ void cancel_storage_daemon_job(JCR *jcr)

ua->jcr = control_jcr;
if (jcr->store_bsock) {
if (!cancel_storage_daemon_job(ua, jcr, true)) {
if (!cancel_storage_daemon_job(ua, jcr, false)) {
goto bail_out;
}
}
Expand Down

0 comments on commit f3e9c9d

Please sign in to comment.