+static void cleanup_old_files()
+{
+ POOLMEM *cleanup = get_pool_memory(PM_MESSAGE);
+ int len = strlen(me->working_directory);
+#if defined(HAVE_WIN32)
+ pm_strcpy(cleanup, "del /q ");
+#else
+ pm_strcpy(cleanup, "/bin/rm -f ");
+#endif
+ pm_strcat(cleanup, me->working_directory);
+ if (len > 0 && !IsPathSeparator(me->working_directory[len-1])) {
+ pm_strcat(cleanup, "/");
+ }
+ pm_strcat(cleanup, my_name);
+ pm_strcat(cleanup, "*.spool");
+ run_program(cleanup, 0, NULL);
+ free_pool_memory(cleanup);
+}
+
+
+/*
+ * Here we attempt to init and open each device. This is done
+ * once at startup in a separate thread.
+ */
+extern "C"
+void *device_initialization(void *arg)
+{
+ DEVRES *device;
+ DCR *dcr;
+ JCR *jcr;
+ DEVICE *dev;
+
+ LockRes();
+
+ pthread_detach(pthread_self());
+ jcr = new_jcr(sizeof(JCR), stored_free_jcr);
+ jcr->JobType = JT_SYSTEM;
+ /* Initialize FD start condition variable */
+ int errstat = pthread_cond_init(&jcr->job_start_wait, NULL);
+ if (errstat != 0) {
+ Jmsg1(jcr, M_ABORT, 0, _("Unable to init job cond variable: ERR=%s\n"), strerror(errstat));
+ }
+
+ foreach_res(device, R_DEVICE) {
+ Dmsg1(90, "calling init_dev %s\n", device->device_name);
+ dev = init_dev(NULL, device);
+ Dmsg1(10, "SD init done %s\n", device->device_name);
+ if (!dev) {
+ Jmsg1(NULL, M_ERROR, 0, _("Could not initialize %s\n"), device->device_name);
+ continue;
+ }
+
+ jcr->dcr = dcr = new_dcr(jcr, dev);
+ if (dev->is_autochanger()) {
+ /* If autochanger set slot in dev sturcture */
+ get_autochanger_loaded_slot(dcr);
+ }
+
+ if (device->cap_bits & CAP_ALWAYSOPEN) {
+ Dmsg1(20, "calling first_open_device %s\n", dev->print_name());
+ if (!first_open_device(dcr)) {
+ Jmsg1(NULL, M_ERROR, 0, _("Could not open device %s\n"), dev->print_name());
+ Dmsg1(20, "Could not open device %s\n", dev->print_name());
+ free_dcr(dcr);
+ jcr->dcr = NULL;
+ continue;
+ }
+ }
+ if (device->cap_bits & CAP_AUTOMOUNT && dev->is_open()) {
+ switch (read_dev_volume_label(dcr)) {
+ case VOL_OK:
+ memcpy(&dev->VolCatInfo, &dcr->VolCatInfo, sizeof(dev->VolCatInfo));
+ break;
+ default:
+ Jmsg1(NULL, M_WARNING, 0, _("Could not mount device %s\n"), dev->print_name());
+ break;
+ }
+ }
+ free_dcr(dcr);
+ jcr->dcr = NULL;
+ }
+#ifdef xxx
+ if (jcr->dcr) {
+ Dmsg1(000, "free_dcr=%p\n", jcr->dcr);
+ free_dcr(jcr->dcr);
+ jcr->dcr = NULL;
+ }
+#endif
+ free_jcr(jcr);
+ init_done = true;
+ UnlockRes();
+ return NULL;
+}
+
+