void qmp_migrate(const char *uri, bool has_blk, bool blk, bool has_inc, bool inc, bool has_detach, bool detach, Error **errp) { Error *local_err = NULL; MigrationState *s = migrate_get_current(); MigrationParams params; const char *p; params.blk = has_blk && blk; params.shared = has_inc && inc; if (s->state == MIG_STATE_ACTIVE || s->state == MIG_STATE_SETUP || s->state == MIG_STATE_CANCELLING) { error_set(errp, QERR_MIGRATION_ACTIVE); return; } if (runstate_check(RUN_STATE_INMIGRATE)) { error_setg(errp, "Guest is waiting for an incoming migration"); return; } if (qemu_savevm_state_blocked(errp)) { return; } if (migration_blockers) { *errp = error_copy(migration_blockers->data); return; } s = migrate_init(¶ms); if (strstart(uri, "tcp:", &p)) { tcp_start_outgoing_migration(s, p, &local_err); #ifdef CONFIG_RDMA } else if (strstart(uri, "rdma:", &p)) { rdma_start_outgoing_migration(s, p, &local_err); #endif #if !defined(WIN32) } else if (strstart(uri, "exec:", &p)) { exec_start_outgoing_migration(s, p, &local_err); } else if (strstart(uri, "unix:", &p)) { unix_start_outgoing_migration(s, p, &local_err); } else if (strstart(uri, "fd:", &p)) { fd_start_outgoing_migration(s, p, &local_err); #endif } else { error_set(errp, QERR_INVALID_PARAMETER_VALUE, "uri", "a valid migration protocol"); s->state = MIG_STATE_ERROR; return; } if (local_err) { migrate_fd_error(s); error_propagate(errp, local_err); return; } }
void SpotifyService::LoginCompleted( bool success, const QString& error, pb::spotify::LoginResponse_Error error_code) { if (login_task_id_) { app_->task_manager()->SetTaskFinished(login_task_id_); login_task_id_ = 0; } if (!success) { bool show_error_dialog = true; QString error_copy(error); switch (error_code) { case pb::spotify::LoginResponse_Error_BadUsernameOrPassword: login_state_ = LoginState_BadCredentials; break; case pb::spotify::LoginResponse_Error_UserBanned: login_state_ = LoginState_Banned; break; case pb::spotify::LoginResponse_Error_UserNeedsPremium: login_state_ = LoginState_NoPremium; break; case pb::spotify::LoginResponse_Error_ReloginFailed: if (login_state_ == LoginState_LoggedIn) { // This is the first time the relogin has failed - show a message this // time only. error_copy = tr("You have been logged out of Spotify, please re-enter your " "password in the Settings dialog."); } else { show_error_dialog = false; } login_state_ = LoginState_ReloginFailed; break; default: login_state_ = LoginState_OtherError; break; } if (show_error_dialog) { QMessageBox::warning(nullptr, tr("Spotify login error"), error_copy, QMessageBox::Close); } } else { login_state_ = LoginState_LoggedIn; } QSettings s; s.beginGroup(kSettingsGroup); s.setValue("login_state", login_state_); emit LoginFinished(success); }
static bool_t connector_ok(struct connector *c, struct error *err) { /* We are ok if we have more addrinfos to try, or if there was no error. */ if (c->next_addrinfo || error_ok(&c->err)) return 1; error_copy(&c->err, err); return 0; }
static ssize_t qio_channel_websock_writev(QIOChannel *ioc, const struct iovec *iov, size_t niov, int *fds, size_t nfds, Error **errp) { QIOChannelWebsock *wioc = QIO_CHANNEL_WEBSOCK(ioc); size_t i; ssize_t done = 0; ssize_t ret; if (wioc->io_err) { *errp = error_copy(wioc->io_err); return -1; } if (wioc->io_eof) { error_setg(errp, "%s", "Broken pipe"); return -1; } for (i = 0; i < niov; i++) { size_t want = iov[i].iov_len; if ((want + wioc->rawoutput.offset) > QIO_CHANNEL_WEBSOCK_MAX_BUFFER) { want = (QIO_CHANNEL_WEBSOCK_MAX_BUFFER - wioc->rawoutput.offset); } if (want == 0) { goto done; } buffer_reserve(&wioc->rawoutput, want); buffer_append(&wioc->rawoutput, iov[i].iov_base, want); done += want; if (want < iov[i].iov_len) { break; } } done: ret = qio_channel_websock_write_wire(wioc, errp); if (ret < 0 && ret != QIO_CHANNEL_ERR_BLOCK) { qio_channel_websock_unset_watch(wioc); return -1; } qio_channel_websock_set_watch(wioc); if (done == 0) { return QIO_CHANNEL_ERR_BLOCK; } return done; }
void nbd_tls_handshake(Object *src, Error *err, void *opaque) { struct NBDTLSHandshakeData *data = opaque; if (err) { TRACE("TLS failed %s", error_get_pretty(err)); data->error = error_copy(err); } data->complete = true; g_main_loop_quit(data->loop); }
void qmp_migrate(const char *uri, bool has_blk, bool blk, bool has_inc, bool inc, bool has_detach, bool detach, Error **errp) { Error *local_err = NULL; MigrationState *s = migrate_get_current(); MigrationParams params; const char *p; params.blk = blk; params.shared = inc; if (s->state == MIG_STATE_ACTIVE) { error_set(errp, QERR_MIGRATION_ACTIVE); return; } if (qemu_savevm_state_blocked(errp)) { return; } if (migration_blockers) { *errp = error_copy(migration_blockers->data); return; } s = migrate_init(¶ms); if (strstart(uri, "tcp:", &p)) { tcp_start_outgoing_migration(s, p, &local_err); #if !defined(WIN32) } else if (strstart(uri, "exec:", &p)) { exec_start_outgoing_migration(s, p, &local_err); } else if (strstart(uri, "unix:", &p)) { unix_start_outgoing_migration(s, p, &local_err); } else if (strstart(uri, "fd:", &p)) { fd_start_outgoing_migration(s, p, &local_err); #endif } else { error_set(errp, QERR_INVALID_PARAMETER_VALUE, "uri", "a valid migration protocol"); return; } if (local_err) { migrate_fd_error(s); error_propagate(errp, local_err); return; } notifier_list_notify(&migration_state_notifiers, s); }
static ssize_t qio_channel_websock_readv(QIOChannel *ioc, const struct iovec *iov, size_t niov, int **fds, size_t *nfds, Error **errp) { QIOChannelWebsock *wioc = QIO_CHANNEL_WEBSOCK(ioc); size_t i; ssize_t got = 0; ssize_t ret; if (wioc->io_err) { *errp = error_copy(wioc->io_err); return -1; } if (!wioc->rawinput.offset) { ret = qio_channel_websock_read_wire(QIO_CHANNEL_WEBSOCK(ioc), errp); if (ret < 0) { return ret; } } for (i = 0 ; i < niov ; i++) { size_t want = iov[i].iov_len; if (want > (wioc->rawinput.offset - got)) { want = (wioc->rawinput.offset - got); } memcpy(iov[i].iov_base, wioc->rawinput.buffer + got, want); got += want; if (want < iov[i].iov_len) { break; } } buffer_advance(&wioc->rawinput, got); qio_channel_websock_set_watch(wioc); return got; }
///------------------------------------------------------------------------------------------------- /// Scan a single file. Everything that applies to ms_scan also applies to this function. If /// you know the type of the file, set the type paramter to one of TYPE_AUDIO, TYPE_VIDEO, or /// TYPE_IMAGE. Set it to TYPE_UNKNOWN to have it determined automatically. /// /// @author Andy Grundman /// @date 03/15/2011 /// /// @param [in,out] s If non-null, the. /// @param full_path Full pathname of the full file. /// /// ### remarks . ///------------------------------------------------------------------------------------------------- void ms_scan_file(MediaScan *s, const char *full_path, enum media_type type) { MediaScanError *e = NULL; MediaScanResult *r = NULL; int ret; uint32_t hash; int mtime = 0; uint64_t size = 0; DBT key, data; char tmp_full_path[MAX_PATH_STR_LEN]; #ifdef WIN32 char *ext = strrchr(full_path, '.'); #endif if (s == NULL) { ms_errno = MSENO_NULLSCANOBJ; LOG_ERROR("MediaScan = NULL, aborting scan\n"); return; } if (s->on_result == NULL) { ms_errno = MSENO_NORESULTCALLBACK; LOG_ERROR("Result callback not set, aborting scan\n"); return; } #if (defined(__APPLE__) && defined(__MACH__)) if (isAlias(full_path)) { LOG_INFO("File %s is a mac alias\n", full_path); // Check if this file is a shortcut and if so resolve it if (!CheckMacAlias(full_path, tmp_full_path)) { LOG_ERROR("Failure to follow symlink or alias, skipping file\n"); return; } } else { strcpy(tmp_full_path, full_path); } #elif defined(__unix__) || defined(__unix) if (isAlias(full_path)) { LOG_INFO("File %s is a unix symlink\n", full_path); // Check if this file is a shortcut and if so resolve it FollowLink(full_path, tmp_full_path); } else { strcpy(tmp_full_path, full_path); } #elif defined(WIN32) if (strcasecmp(ext, ".lnk") == 0) { // Check if this file is a shortcut and if so resolve it parse_lnk(full_path, tmp_full_path, MAX_PATH_STR_LEN); if (PathIsDirectory(tmp_full_path)) return; } else { strcpy(tmp_full_path, full_path); } #endif // Check if the file has been recently scanned hash = HashFile(tmp_full_path, &mtime, &size); // Skip 0-byte files if (unlikely(size == 0)) { LOG_WARN("Skipping 0-byte file: %s\n", tmp_full_path); return; } // Setup DBT values memset(&key, 0, sizeof(DBT)); memset(&data, 0, sizeof(DBT)); key.data = (char *)full_path; key.size = strlen(full_path) + 1; data.data = &hash; data.size = sizeof(uint32_t); if ((s->flags & MS_RESCAN) || (s->flags & MS_FULL_SCAN)) { // s->dbp will be null if this function is called directly, if not check if this file is // already scanned. if (s->dbp != NULL) { // DB_GET_BOTH will only return OK if both key and data match, this avoids the need to check // the returned data against hash int ret = s->dbp->get(s->dbp, NULL, &key, &data, DB_GET_BOTH); if (ret != DB_NOTFOUND) { // LOG_INFO("File %s already scanned, skipping\n", tmp_full_path); return; } } } LOG_INFO("Scanning file %s\n", tmp_full_path); if (type == TYPE_UNKNOWN || type == TYPE_LNK) { // auto-detect type type = _should_scan(s, tmp_full_path); if (!type) { if (s->on_error) { ms_errno = MSENO_SCANERROR; e = error_create(tmp_full_path, MS_ERROR_TYPE_UNKNOWN, "Unrecognized file extension"); send_error(s, e); return; } } } r = result_create(s); if (r == NULL) return; r->type = type; r->path = strdup(full_path); if (result_scan(r)) { // These were determined by HashFile r->mtime = mtime; r->size = size; r->hash = hash; // Store path -> hash data in cache if (s->dbp != NULL) { memset(&data, 0, sizeof(DBT)); data.data = &hash; data.size = sizeof(uint32_t); ret = s->dbp->put(s->dbp, NULL, &key, &data, 0); if (ret != 0) { s->dbp->err(s->dbp, ret, "Cache store failed: %s", db_strerror(ret)); } } send_result(s, r); } else { if (s->on_error && r->error) { // Copy the error, because the original will be cleaned up by result_destroy below MediaScanError *ecopy = error_copy(r->error); send_error(s, ecopy); } result_destroy(r); } } /* ms_scan_file() */
int copy(char *dst, char *pattern, struct CopySource *src , int openMode) { char mode[3], *p; struct ffblk ff; struct CopySource *h; char *rDest, *rSrc; FILE *fin, *fout; int rc, asc; char *buf; size_t len; assert(dst); assert(pattern); assert(src); if(FINDFIRST(pattern, &ff, FA_RDONLY | FA_ARCH) != 0) { error_sfile_not_found(pattern); return 0; } mode[2] = '\0'; do { if((rDest = fillFnam(dst, ff.ff_name)) == 0) return 0; h = src; do { /* to prevent to open a source file for writing, e.g. for COPY *.c *.? */ if((rSrc = fillFnam(h->fnam, ff.ff_name)) == 0) { free(rDest); return 0; } rc = samefile(rDest, rSrc); free(rSrc); if(rc < 0) { error_out_of_memory(); free(rDest); return 0; } else if(rc) { error_selfcopy(rDest); free(rDest); return 0; } } while((h = h->app) != 0); if(interactive_command /* Suppress prompt if in batch file */ && openMode != 'a' && !optY && (fout = fopen(rDest, "rb")) != 0) { int destIsDevice = isadev(fileno(fout)); fclose(fout); if(!destIsDevice) { /* Devices do always exist */ switch(userprompt(PROMPT_OVERWRITE_FILE, rDest)) { default: /* Error */ case 4: /* Quit */ free(rDest); return 0; case 3: /* All */ optY = 1; case 1: /* Yes */ break; case 2: /* No */ free(rDest); continue; } } } if(cbreak) { free(rDest); return 0; } mode[0] = openMode; mode[1] = 'b'; if((fout = fdevopen(rDest, mode)) == 0) { error_open_file(rDest); free(rDest); return 0; } mode[0] = 'r'; h = src; do { if((rSrc = fillFnam(h->fnam, ff.ff_name)) == 0) { fclose(fout); free(rDest); return 0; } mode[1] = (asc = h->flags & ASCII) != 0? 't': 'b'; reOpenIn: if((fin = fdevopen(rSrc, mode)) == 0) { error_open_file(rSrc); fclose(fout); free(rSrc); free(rDest); return 0; } if(isadev(fileno(fin)) && mode[1] != 't' && (h->flags & BINARY) == 0) { /* character devices are opened in textmode by default */ fclose(fin); mode[1] = 't'; goto reOpenIn; } dispCopy(rSrc, rDest, openMode == 'a' || h != src); if(cbreak) { fclose(fin); fclose(fout); free(rSrc); free(rDest); return 0; } /* Now copy the file */ rc = 1; if(mode[1] != 't') { /* binary file */ if(Fcopy(fout, fin) != 0) { if(ferror(fin)) { error_read_file(rSrc); } else if(ferror(fout)) { error_write_file(rDest); } else error_copy(); rc = 0; } } else { /* text file, manually transform '\n' */ if(Fmaxbuf((byte**)&buf, &len) == 0) { if(len > INT_MAX) len = INT_MAX; while(fgets(buf, len, fin)) { p = strchr(buf, '\0'); if(*--p == '\n') { *p = '\0'; fputs(buf, fout); putc('\r', fout); putc('\n', fout); } else fputs(buf, fout); } free(buf); } else { error_out_of_memory(); rc = 0; } } if(rc) if(ferror(fin)) { error_read_file(rSrc); rc = 0; } else if(ferror(fout)) { error_write_file(rDest); rc = 0; } if(cbreak) rc = 0; fclose(fin); free(rSrc); if(!rc) { fclose(fout); free(rDest); return 0; } } while((h = h->app) != 0); if(asc) { /* append the ^Z as we copied in ASCII mode */ putc(0x1a, fout); } rc = ferror(fout); fclose(fout); if(rc) { error_write_file(rDest); free(rDest); return 0; } free(rDest); } while(FINDNEXT(&ff) == 0); return 1; }