+ if (sig == SIGTERM) { /* normal shutdown request? */
+ /*
+ * This is a normal shutdown request. We wiffle through
+ * all open jobs canceling them and trying to wake
+ * them up so that they will report back the correct
+ * volume status.
+ */
+ lock_jcr_chain();
+ foreach_jcr(jcr) {
+ BSOCK *fd;
+ free_locked_jcr(jcr);
+ if (jcr->JobId == 0) {
+ continue; /* ignore console */
+ }
+ set_jcr_job_status(jcr, JS_Canceled);
+ fd = jcr->file_bsock;
+ if (fd) {
+ fd->timed_out = TRUE;
+ Dmsg1(100, "killing JobId=%d\n", jcr->JobId);
+ pthread_kill(jcr->my_thread_id, TIMEOUT_SIGNAL);
+ if (jcr->device && jcr->device->dev && jcr->device->dev->dev_blocked) {
+ pthread_cond_signal(&jcr->device->dev->wait_next_vol);
+ }
+ bmicrosleep(0, 50000);
+ }
+ }
+ unlock_jcr_chain();
+ bmicrosleep(0, 500000); /* give them 1/2 sec to clean up */
+ }
+
+ write_state_file(me->working_directory, "bacula-sd", me->SDport);