int rt_start(struct rt_t *rt) { size_t n; /* If there are any devices which returned file descriptors for * poll() then launch the realtime thread to handle them */ if (rt->npt > 0) { fprintf(stderr, "Launching realtime thread to handle devices...\n"); if (pthread_create(&rt->ph, NULL, launch, (void*)rt)) { perror("pthread_create"); return -1; } } /* FIXME: To avoid audio drop on startup, devices should be * started after synchronising with the realtime thread */ for (n = 0; n < rt->ndv; n++) device_start(rt->dv[n]); return 0; }
static gboolean label_new_tape(taper_state_t * state, dump_info_t * dump_info) { char *old_volume_name = NULL; char *old_volume_time = NULL; tape_search_request_t request; gboolean search_result; DeviceStatusFlags status; /* If we got here, it means that we have found a tape to label and * have gotten permission from the driver to write it. But we * still can say NO-NEW-TAPE if a problem shows up, and must still * say NEW-TAPE if one doesn't. */ amfree(state->last_errmsg); state->device = device_open(state->next_tape_device); g_assert(state->device != NULL); amfree(state->next_tape_device); if (state->device->status != DEVICE_STATUS_SUCCESS) goto skip_volume; if (!device_configure(state->device, TRUE)) goto skip_volume; /* if we have an error, and are sure it isn't just an unlabeled volume, * then skip this volume */ status = device_read_label(state->device); if ((status & ~DEVICE_STATUS_VOLUME_UNLABELED) && !(status & DEVICE_STATUS_VOLUME_UNLABELED)) goto skip_volume; old_volume_name = g_strdup(state->device->volume_label); old_volume_time = g_strdup(state->device->volume_time); if (!device_start(state->device, ACCESS_WRITE, state->next_tape_label, state->driver_start_time)) { gboolean tape_used; /* Something broke, see if we can tell if the volume was erased or * not. */ g_fprintf(stderr, "taper: Error writing label %s to device %s: %s.\n", state->next_tape_label, state->device->device_name, device_error_or_status(state->device)); if (!device_finish(state->device)) goto request_new_volume; /* This time, if we can't read the label, assume we've overwritten * the volume or otherwise corrupted it */ status = device_read_label(state->device); if ((status & ~DEVICE_STATUS_VOLUME_UNLABELED) && !(status & DEVICE_STATUS_VOLUME_UNLABELED)) goto request_new_volume; tape_used = check_volume_changed(state->device, old_volume_name, old_volume_time); if (tape_used) goto request_new_volume; else goto skip_volume; } amfree(old_volume_name); amfree(old_volume_time); amfree(state->next_tape_label); update_tapelist(state); state->cur_tape++; if (state->have_changer && changer_label("UNKNOWN", state->device->volume_label) != 0) { error(_("couldn't update barcode database")); /*NOTREACHED*/ } log_add(L_START, "datestamp %s label %s tape %d", state->driver_start_time, state->device->volume_label, state->cur_tape); putresult(NEW_TAPE, "%s %s\n", dump_info->handle, state->device->volume_label); return TRUE; request_new_volume: /* Tell the driver we overwrote this volume, even if it was empty, and request * a new volume. */ if (state->device) state->last_errmsg = newstralloc(state->last_errmsg, device_error_or_status(state->device)); else state->last_errmsg = newstralloc(state->last_errmsg, "(unknown)"); putresult(NEW_TAPE, "%s %s\n", dump_info->handle, state->next_tape_label); if (old_volume_name) { log_add(L_WARNING, "Problem writing label '%s' to volume %s " "(volume may be erased): %s\n", state->next_tape_label, old_volume_name, state->last_errmsg); } else { log_add(L_WARNING, "Problem writing label '%s' to new volume " "(volume may be erased): %s\n", state->next_tape_label, state->last_errmsg); } if (state->device) { g_object_unref(state->device); state->device = NULL; } amfree(state->next_tape_label); amfree(old_volume_name); amfree(old_volume_time); return find_and_label_new_tape(state, dump_info); skip_volume: /* grab a new volume without talking to the driver again -- we do this if we're * confident we didn't overwrite the last tape we got. */ if (state->device) state->last_errmsg = newstralloc(state->last_errmsg, device_error_or_status(state->device)); else state->last_errmsg = newstralloc(state->last_errmsg, "(unknown)"); if (old_volume_name) { log_add(L_WARNING, "Problem writing label '%s' to volume '%s' " "(old volume data intact): %s\n", state->next_tape_label, old_volume_name, state->last_errmsg); } else { log_add(L_WARNING, "Problem writing label '%s' to new volume " "(old volume data intact): %s\n", state->next_tape_label, state->last_errmsg); } if (state->device) { g_object_unref(state->device); state->device = NULL; } amfree(state->next_tape_label); amfree(old_volume_name); amfree(old_volume_time); request.state = state; request.prolong = TRUE; request.errmsg = NULL; search_result = GPOINTER_TO_INT(tape_search_thread(&request)); if (search_result) { amfree(request.errmsg); return label_new_tape(state, dump_info); } else { /* Problem finding a new tape! */ log_taper_scan_errmsg(request.errmsg); putresult(NO_NEW_TAPE, "%s\n", dump_info->handle); return FALSE; } }
void beckerport_device::update_port(void) { device_stop(); m_dwtcpport = m_dwconfigport.read_safe(65504); device_start(); }