bool queue_push(Queue queue, ...) { if ( queue_is_full(queue) ) { if ( queue->resizable ) { struct gdt_generic_datatype * new_elements; const size_t new_capacity = queue->capacity * GROWTH; new_elements = realloc(queue->elements, sizeof *queue->elements * new_capacity); if ( !new_elements ) { if ( queue->exit_on_error ) { quit_strerror("gds library", "memory allocation failed"); } else { log_strerror("gds library", "memory allocation failed"); return false; } } queue->elements = new_elements; if ( queue->back < queue->front || queue->size == queue->capacity ) { /* If we get here, then the back of the queue * is at a lower index than the front of it * (or the queue is full and both the back and * front are zero). Conceptually the queue is * wrapping around the back of the array, and if * we resize it, there'll be a gap unless we move * those wrapped elements back into the new space. * Note that because we always grow by a factor of * at least two, there'll always be enough space to * move all the wrapped elements. In fact, we here * move the entire array from the start through to * the front element, including any "empty" ones, * which is not really necessary. */ /** \todo Rewrite to move only the required elements */ const size_t excess = new_capacity - queue->capacity; const size_t nfelem = queue->capacity - queue->front; struct gdt_generic_datatype * old_front, * new_front; old_front = queue->elements + queue->front; new_front = old_front + excess; memmove(new_front, old_front, nfelem * sizeof *old_front); queue->front += excess; } queue->capacity = new_capacity; } else if ( queue->exit_on_error ) { quit_error("gds library", "queue full"); } else { log_error("gds library", "queue full"); return false; } } va_list ap; va_start(ap, queue); gdt_set_value(&queue->elements[queue->back++], queue->type, NULL, ap); va_end(ap); if ( queue->back == queue->capacity ) { queue->back = 0; } queue->size += 1; return true; }
/* Startup the server. CTRL must have been allocated by the caller and set to the default values. */ int gpg_server (ctrl_t ctrl) { int rc; int filedes[2]; assuan_context_t ctx = NULL; static const char hello[] = ("GNU Privacy Guard's OpenPGP server " VERSION " ready"); /* We use a pipe based server so that we can work from scripts. assuan_init_pipe_server will automagically detect when we are called with a socketpair and ignore FILEDES in this case. */ filedes[0] = assuan_fdopen (0); filedes[1] = assuan_fdopen (1); rc = assuan_new (&ctx); if (rc) { log_error ("failed to allocate the assuan context: %s\n", gpg_strerror (rc)); goto leave; } rc = assuan_init_pipe_server (ctx, filedes); if (rc) { log_error ("failed to initialize the server: %s\n", gpg_strerror (rc)); goto leave; } rc = register_commands (ctx); if (rc) { log_error ("failed to the register commands with Assuan: %s\n", gpg_strerror(rc)); goto leave; } assuan_set_pointer (ctx, ctrl); if (opt.verbose || opt.debug) { char *tmp = NULL; const char *s1 = getenv ("GPG_AGENT_INFO"); if (asprintf (&tmp, "Home: %s\n" "Config: %s\n" "AgentInfo: %s\n" "%s", opt.homedir, "fixme: need config filename", s1?s1:"[not set]", hello) > 0) { assuan_set_hello_line (ctx, tmp); free (tmp); } } else assuan_set_hello_line (ctx, hello); assuan_register_reset_notify (ctx, reset_notify); assuan_register_input_notify (ctx, input_notify); assuan_register_output_notify (ctx, output_notify); assuan_register_option_handler (ctx, option_handler); ctrl->server_local = xtrycalloc (1, sizeof *ctrl->server_local); if (!ctrl->server_local) { rc = gpg_error_from_syserror (); goto leave; } ctrl->server_local->assuan_ctx = ctx; ctrl->server_local->message_fd = GNUPG_INVALID_FD; if (DBG_ASSUAN) assuan_set_log_stream (ctx, log_get_stream ()); for (;;) { rc = assuan_accept (ctx); if (rc == -1) { rc = 0; break; } else if (rc) { log_info ("Assuan accept problem: %s\n", gpg_strerror (rc)); break; } rc = assuan_process (ctx); if (rc) { log_info ("Assuan processing failed: %s\n", gpg_strerror (rc)); continue; } } leave: xfree (ctrl->server_local); ctrl->server_local = NULL; assuan_release (ctx); return rc; }
static int global_init(const struct instance *gi, global_context *gc) { int ret; #ifdef __APPLE__ // MacOS/X requires an additional call int one = 1; #endif const char *pers = "goldy"; memset(gc, 0, sizeof(*gc)); gc->options = gi; mbedtls_ssl_config_init(&gc->conf); mbedtls_ssl_cookie_init(&gc->cookie_ctx); #if defined(MBEDTLS_SSL_CACHE_C) mbedtls_ssl_cache_init(&gc->cache); #endif mbedtls_x509_crt_init(&gc->cacert); mbedtls_entropy_init(&gc->entropy); mbedtls_ctr_drbg_init(&gc->ctr_drbg); log_info("Goldy %s starting up", GOLDY_VERSION); mbedtls_net_init(&gc->listen_fd); ret = bind_listen_fd(gc); if (ret != 0) { goto exit; } #ifdef __APPLE__ // MacOS/X requires an additional call ret = setsockopt(gc->listen_fd.fd, SOL_SOCKET, SO_REUSEPORT, (char*)&one, sizeof(one)); if (ret != 0) { goto exit; } #endif ret = mbedtls_x509_crt_parse_file(&gc->cacert, gi->cert_file); if (ret != 0) { log_error("mbedtls_x509_crt_parse returned %d", ret); goto exit; } log_debug("Loaded server cacert file"); if ((ret = mbedtls_ctr_drbg_seed(&gc->ctr_drbg, mbedtls_entropy_func, &gc->entropy, (const unsigned char *)pers, strlen(pers))) != 0) { printf(" failed\n ! mbedtls_ctr_drbg_seed returned %d\n", ret); goto exit; } log_debug("Seeded random number generator"); if ((ret = mbedtls_ssl_config_defaults(&gc->conf, MBEDTLS_SSL_IS_CLIENT, MBEDTLS_SSL_TRANSPORT_DATAGRAM, MBEDTLS_SSL_PRESET_DEFAULT)) != 0) { log_error("mbedtls_ssl_config_defaults returned %d", ret); goto exit; } mbedtls_ssl_conf_dbg(&gc->conf, log_mbedtls_debug_callback, NULL); mbedtls_debug_set_threshold(MBEDTLS_DEBUG_LOGGING_LEVEL); mbedtls_ssl_conf_rng(&gc->conf, mbedtls_ctr_drbg_random, &gc->ctr_drbg); #if defined(MBEDTLS_SSL_CACHE_C) mbedtls_ssl_conf_session_cache(&gc->conf, &gc->cache, mbedtls_ssl_cache_get, mbedtls_ssl_cache_set); #endif /* Now we can support verify server client, however for performance, * just change to none because openvpn will do the auth again */ mbedtls_ssl_conf_authmode(&gc->conf, MBEDTLS_SSL_VERIFY_NONE); mbedtls_ssl_conf_ca_chain(&gc->conf, &gc->cacert, NULL); mbedtls_ssl_conf_verify(&gc->conf, server_cert_verify, NULL); if ((ret = mbedtls_ssl_cookie_setup(&gc->cookie_ctx, mbedtls_ctr_drbg_random, &gc->ctr_drbg)) != 0) { log_error("mbedtls_ssl_cookie_setup returned %d", ret); goto exit; } mbedtls_ssl_conf_dtls_cookies(&gc->conf, mbedtls_ssl_cookie_write, mbedtls_ssl_cookie_check, &gc->cookie_ctx); log_info("Proxy is ready, listening for connections on UDP %s:%s", gi->listen_host, gi->listen_port); exit: check_return_code(ret, "global_init - exit"); if (ret != 0) { global_deinit(gc); } return ret == 0 ? 0 : 1; }
void interrupt_log_wrong_nnmi(void) { log_error(LOG_DEFAULT, "interrupt_set_nmi(): wrong nnmi!"); }
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void* reserved) { JNIEnv* env = NULL; jint result = -1; jclass aClass; g_vm = vm; if ((*vm)->GetEnv(vm, (void**) &env, JNI_VERSION_1_4) != JNI_OK) { fprintf(stderr,"jahspotify::JNI_OnLoad: GetEnv for JNI_OnLoad failed\n"); goto error; } aClass = (*env)->FindClass(env, "jahspotify/impl/NativeLogger"); if (aClass == NULL ) { fprintf(stderr,"jahspotify::JNI_OnLoad: could not load jahnotify.impl.NativeLogger\n"); goto error; } g_loggerClass = (*env)->NewGlobalRef(env, aClass); log_debug("jnihelpers", "JNI_OnLoad", "vm: 0x%x env: 0x%x", (int) g_vm, (int) env); aClass = (*env)->FindClass(env, "jahspotify/impl/NativePlaybackListener"); if (aClass == NULL ) { log_error("jahspotify", "JNI_OnLoad", "Could not load jahnotify.impl.NativePlaybackListener"); goto error; } g_playbackListenerClass = (*env)->NewGlobalRef(env, aClass); aClass = (*env)->FindClass(env, "jahspotify/SearchResult"); if (aClass == NULL ) { log_error("jahspotify", "JNI_OnLoad", "Could not load jahspotify.SearchResult"); goto error; } g_nativeSearchResultClass = (*env)->NewGlobalRef(env, aClass); aClass = (*env)->FindClass(env, "jahspotify/impl/NativeConnectionListener"); if (aClass == NULL ) { log_error("jahspotify", "JNI_OnLoad", "Could not load jahspotify.NativeConnectionListener"); goto error; } g_connectionListenerClass = (*env)->NewGlobalRef(env, aClass); aClass = (*env)->FindClass(env, "jahspotify/impl/NativeMediaLoadedListener"); if (aClass == NULL ) { log_error("jahspotify", "JNI_OnLoad", "Could not load jahspotify.NativeMediaLoadedListener"); goto error; } g_mediaLoadedListenerClass = (*env)->NewGlobalRef(env, aClass); aClass = (*env)->FindClass(env, "jahspotify/impl/NativeSearchCompleteListener"); if (aClass == NULL ) { log_error("jahspotify", "JNI_OnLoad", "Could not load jahnotify.impl.NativeSearchCompleteListener"); goto error; } g_searchCompleteListenerClass = (*env)->NewGlobalRef(env, aClass); aClass = (*env)->FindClass(env, "jahspotify/media/Link"); if (aClass == NULL ) { log_error("jahspotify", "JNI_OnLoad", "Could not load jahspotify.media.Link"); goto error; } g_linkClass = (*env)->NewGlobalRef(env, aClass); aClass = (*env)->FindClass(env, "jahspotify/media/Playlist"); if (aClass == NULL ) { log_error("jahspotify", "JNI_OnLoad", "Could not load jahspotify.media.Playlist"); goto error; } g_playlistCLass = (*env)->NewGlobalRef(env, aClass); /* success -- return valid version number */ result = JNI_VERSION_1_4; goto exit; error: result = 0; log_error("jahspotify", "JNI_OnLoad", "Error occured during initialization"); exit: log_debug("jahspotify", "JNI_OnLoad", "Exiting (result=0x%x)", result); return result; }
void Sound_as::loadSound(const std::string& file, bool streaming) { if (!_mediaHandler || !_soundHandler) { log_debug("No media or sound handlers, won't load any sound"); return; } /// If we are already streaming stop doing so as we'll replace /// the media parser if (_inputStream) { _soundHandler->unplugInputStream(_inputStream); _inputStream = 0; } /// Mark sound as not being loaded // TODO: should we check for _soundLoaded == true? _soundLoaded = false; /// Delete any media parser being used (make sure we have detached!) _mediaParser.reset(); /// Start at offset 0, in case a previous ::start() call /// changed that. _startTime = 0; const RunResources& rr = getRunResources(owner()); URL url(file, rr.streamProvider().baseURL()); const RcInitFile& rcfile = RcInitFile::getDefaultInstance(); const StreamProvider& streamProvider = rr.streamProvider(); std::auto_ptr<IOChannel> inputStream(streamProvider.getStream(url, rcfile.saveStreamingMedia())); if (!inputStream.get()) { log_error(_("Gnash could not open this URL: %s"), url ); // dispatch onLoad (false) callMethod(&owner(), NSV::PROP_ON_LOAD, false); return; } externalSound = true; isStreaming = streaming; _mediaParser.reset(_mediaHandler->createMediaParser(inputStream).release()); if (!_mediaParser) { log_error(_("Unable to create parser for Sound at %s"), url); // not necessarely correct, the stream might have been found... // dispatch onLoad (false) callMethod(&owner(), NSV::PROP_ON_LOAD, false); return; } // TODO: use global _soundbuftime _mediaParser->setBufferTime(60000); // one minute buffer... should be fine startProbeTimer(); owner().set_member(NSV::PROP_DURATION, getDuration()); owner().set_member(NSV::PROP_POSITION, getPosition()); }
void dnode_client_close(struct context *ctx, struct conn *conn) { rstatus_t status; struct msg *msg, *nmsg; /* current and next message */ ASSERT(conn->dnode_client && !conn->dnode_server); dnode_client_close_stats(ctx, conn->owner, conn->err, conn->eof); if (conn->sd < 0) { conn->unref(conn); conn_put(conn); return; } msg = conn->rmsg; if (msg != NULL) { conn->rmsg = NULL; ASSERT(msg->peer == NULL); ASSERT(msg->request && !msg->done); if (log_loggable(LOG_INFO)) { log_debug(LOG_INFO, "dyn: close c %d discarding pending req %"PRIu64" len " "%"PRIu32" type %d", conn->sd, msg->id, msg->mlen, msg->type); } req_put(msg); } ASSERT(conn->smsg == NULL); ASSERT(TAILQ_EMPTY(&conn->imsg_q)); for (msg = TAILQ_FIRST(&conn->omsg_q); msg != NULL; msg = nmsg) { nmsg = TAILQ_NEXT(msg, c_tqe); /* dequeue the message (request) from client outq */ conn->dequeue_outq(ctx, conn, msg); if (msg->done) { if (log_loggable(LOG_INFO)) { log_debug(LOG_INFO, "dyn: close c %d discarding %s req %"PRIu64" len " "%"PRIu32" type %d", conn->sd, msg->error ? "error": "completed", msg->id, msg->mlen, msg->type); } req_put(msg); } else { msg->swallow = 1; ASSERT(msg->request); ASSERT(msg->peer == NULL); if (log_loggable(LOG_INFO)) { log_debug(LOG_INFO, "dyn: close c %d schedule swallow of req %"PRIu64" " "len %"PRIu32" type %d", conn->sd, msg->id, msg->mlen, msg->type); } } } ASSERT(TAILQ_EMPTY(&conn->omsg_q)); conn->unref(conn); status = close(conn->sd); if (status < 0) { log_error("dyn: close c %d failed, ignored: %s", conn->sd, strerror(errno)); } conn->sd = -1; conn_put(conn); }
int import_pv(const struct format_type *fmt, struct dm_pool *mem, struct device *dev, struct volume_group *vg, struct physical_volume *pv, struct pv_disk *pvd, struct vg_disk *vgd) { uint64_t size; memset(pv, 0, sizeof(*pv)); memcpy(&pv->id, pvd->pv_uuid, ID_LEN); pv->dev = dev; if (!*pvd->vg_name) pv->vg_name = fmt->orphan_vg_name; else if (!(pv->vg_name = dm_pool_strdup(mem, (char *)pvd->vg_name))) { log_error("Volume Group name allocation failed."); return 0; } memcpy(&pv->vgid, vgd->vg_uuid, sizeof(vg->id)); /* Store system_id from first PV if PV belongs to a VG */ if (vg && !*vg->system_id) strncpy(vg->system_id, (char *)pvd->system_id, NAME_LEN); if (vg && strncmp(vg->system_id, (char *)pvd->system_id, sizeof(pvd->system_id))) log_very_verbose("System ID %s on %s differs from %s for " "volume group", pvd->system_id, pv_dev_name(pv), vg->system_id); /* * If exported, we still need to flag in pv->status too because * we don't always have a struct volume_group when we need this. */ if (pvd->pv_status & VG_EXPORTED) pv->status |= EXPORTED_VG; if (pvd->pv_allocatable) pv->status |= ALLOCATABLE_PV; pv->size = pvd->pv_size; pv->pe_size = pvd->pe_size; pv->pe_start = pvd->pe_start; pv->pe_count = pvd->pe_total; pv->pe_alloc_count = 0; pv->pe_align = 0; pv->is_labelled = 0; /* format1 PVs have no label */ pv->label_sector = 0; /* Fix up pv size if missing or impossibly large */ if (!pv->size || pv->size > (1ULL << 62)) { if (!dev_get_size(dev, &pv->size)) { log_error("%s: Couldn't get size.", pv_dev_name(pv)); return 0; } log_verbose("Fixing up missing format1 size (%s) " "for PV %s", display_size(fmt->cmd, pv->size), pv_dev_name(pv)); if (vg) { size = pv->pe_count * (uint64_t) vg->extent_size + pv->pe_start; if (size > pv->size) log_warn("WARNING: Physical Volume %s is too " "large for underlying device", pv_dev_name(pv)); } } dm_list_init(&pv->tags); dm_list_init(&pv->segments); if (!alloc_pv_segment_whole_pv(mem, pv)) return_0; return 1; }
/* modified lambda (mlambda) search (ref. [2]) -------------------------------*/ static int search(int n, int m, const double *L, const double *D, const double *zs, double *zn, double *s) { int i,j,k,c,nn=0,imax=0; double newdist,maxdist=1E99,y; double S[n*n]; double dist[n]; double zb[n]; double z[n]; double step[n]; memset(S, 0, sizeof(double)*n*n); k=n-1; dist[k]=0.0; zb[k]=zs[k]; z[k]=ROUND(zb[k]); y=zb[k]-z[k]; step[k]=SGN(y); for (c=0;c<LOOPMAX;c++) { newdist=dist[k]+y*y/D[k]; if (newdist<maxdist) { if (k!=0) { dist[--k]=newdist; for (i=0;i<=k;i++) S[k+i*n]=S[k+1+i*n]+(z[k+1]-zb[k+1])*L[k+1+i*n]; zb[k]=zs[k]+S[k+k*n]; z[k]=ROUND(zb[k]); y=zb[k]-z[k]; step[k]=SGN(y); } else { if (nn<m) { if (nn==0||newdist>s[imax]) imax=nn; for (i=0;i<n;i++) zn[i+nn*n]=z[i]; s[nn++]=newdist; } else { if (newdist<s[imax]) { for (i=0;i<n;i++) zn[i+imax*n]=z[i]; s[imax]=newdist; for (i=imax=0;i<m;i++) if (s[imax]<s[i]) imax=i; } maxdist=s[imax]; } z[0]+=step[0]; y=zb[0]-z[0]; step[0]=-step[0]-SGN(step[0]); } } else { if (k==n-1) break; else { k++; z[k]+=step[k]; y=zb[k]-z[k]; step[k]=-step[k]-SGN(step[k]); } } } for (i=0;i<m-1;i++) { /* sort by s */ for (j=i+1;j<m;j++) { if (s[i]<s[j]) continue; SWAP(s[i],s[j]); for (k=0;k<n;k++) SWAP(zn[k+i*n],zn[k+j*n]); } } if (c>=LOOPMAX) { log_error("LAMBDA search loop count overflow\n"); return -1; } return 0; }
int main(void) { FILE *fd; int length = 4; uint32_t j; uint32_t init32[4] = { UINT32_C(0x123), UINT32_C(0x234), UINT32_C(0x345), UINT32_C(0x456) }; #ifdef UINT64_C uint64_t k; uint64_t init64[4] = { UINT64_C(0x12345), UINT64_C(0x23456), UINT64_C(0x34567), UINT64_C(0x45678) }; #endif /* ifdef UINT64_C */ /* Test the 32-bit Mersenne Twister generator. */ init_mt19937ar_by_array(init32, length); fd = fopen(EXPECTED_OUTPUT_32, "r"); if (fd == NULL) { log_error("Unable to open '%s'.", EXPECTED_OUTPUT_32); return EXIT_FAILURE; } /* Check for the correct first 1000 output values. */ for (int i = 0; i < 1000; i++) { if (fscanf(fd, "%"PRIu32"", &j) != 1) { log_error("Error on line %d while reading '%s'.", i+1, EXPECTED_OUTPUT_32); return EXIT_FAILURE; } assert(mt19937ar() == j); } fclose(fd); #ifdef UINT64_C /* Test the 64-bit Mersenne Twister generator. */ init_mt19937_64_by_array(init64, length); fd = fopen(EXPECTED_OUTPUT_64, "r"); if (fd == NULL) { log_error("Unable to open '%s'.", EXPECTED_OUTPUT_64); return EXIT_FAILURE; } /* Check for the correct first 1000 output values. */ for (int i = 0; i < 1000; i++) { if (fscanf(fd, "%"PRIu64"", &k) != 1) { log_error("Error on line %d while reading '%s'.\n", i+1, EXPECTED_OUTPUT_64); return EXIT_FAILURE; } assert(mt19937_64() == k); } fclose(fd); #endif /* ifdef UINT64_C */ return EXIT_SUCCESS; }
int main(int argc, char *argv[]) { _cleanup_udev_unref_ struct udev *udev = NULL; _cleanup_udev_event_unref_ struct udev_event *event = NULL; _cleanup_udev_device_unref_ struct udev_device *dev = NULL; _cleanup_udev_rules_unref_ struct udev_rules *rules = NULL; char syspath[UTIL_PATH_SIZE]; const char *devpath; const char *action; sigset_t mask, sigmask_orig; int err; err = fake_filesystems(); if (err < 0) return EXIT_FAILURE; udev = udev_new(); if (udev == NULL) return EXIT_FAILURE; log_debug("version %s", VERSION); mac_selinux_init("/dev"); sigprocmask(SIG_SETMASK, NULL, &sigmask_orig); action = argv[1]; if (action == NULL) { log_error("action missing"); goto out; } devpath = argv[2]; if (devpath == NULL) { log_error("devpath missing"); goto out; } rules = udev_rules_new(udev, 1); strscpyl(syspath, sizeof(syspath), "/sys", devpath, NULL); dev = udev_device_new_from_synthetic_event(udev, syspath, action); if (dev == NULL) { log_debug("unknown device '%s'", devpath); goto out; } event = udev_event_new(dev); sigfillset(&mask); sigprocmask(SIG_SETMASK, &mask, &sigmask_orig); event->fd_signal = signalfd(-1, &mask, SFD_NONBLOCK|SFD_CLOEXEC); if (event->fd_signal < 0) { fprintf(stderr, "error creating signalfd\n"); goto out; } /* do what devtmpfs usually provides us */ if (udev_device_get_devnode(dev) != NULL) { mode_t mode = 0600; if (streq(udev_device_get_subsystem(dev), "block")) mode |= S_IFBLK; else mode |= S_IFCHR; if (!streq(action, "remove")) { mkdir_parents_label(udev_device_get_devnode(dev), 0755); mknod(udev_device_get_devnode(dev), mode, udev_device_get_devnum(dev)); } else { unlink(udev_device_get_devnode(dev)); rmdir_parents(udev_device_get_devnode(dev), "/"); } } udev_event_execute_rules(event, 3 * USEC_PER_SEC, USEC_PER_SEC, NULL, rules, &sigmask_orig); udev_event_execute_run(event, 3 * USEC_PER_SEC, USEC_PER_SEC, NULL); out: if (event != NULL && event->fd_signal >= 0) close(event->fd_signal); mac_selinux_finish(); return err ? EXIT_FAILURE : EXIT_SUCCESS; }
int main(int argc, char *argv[]) { _cleanup_bus_unref_ sd_bus *a = NULL, *b = NULL; sd_id128_t server_id; bool is_unix; int r; if (argc > 1) { log_error("This program takes no argument."); return EXIT_FAILURE; } log_set_target(LOG_TARGET_JOURNAL_OR_KMSG); log_parse_environment(); log_open(); is_unix = sd_is_socket(STDIN_FILENO, AF_UNIX, 0, 0) > 0 && sd_is_socket(STDOUT_FILENO, AF_UNIX, 0, 0) > 0; r = sd_bus_new(&a); if (r < 0) { log_error("Failed to allocate bus: %s", strerror(-r)); goto finish; } r = sd_bus_set_address(a, "unix:path=/run/dbus/system_bus_socket"); if (r < 0) { log_error("Failed to set address to connect to: %s", strerror(-r)); goto finish; } r = sd_bus_negotiate_fds(a, is_unix); if (r < 0) { log_error("Failed to set FD negotiation: %s", strerror(-r)); goto finish; } r = sd_bus_start(a); if (r < 0) { log_error("Failed to start bus client: %s", strerror(-r)); goto finish; } r = sd_bus_get_server_id(a, &server_id); if (r < 0) { log_error("Failed to get server ID: %s", strerror(-r)); goto finish; } r = sd_bus_new(&b); if (r < 0) { log_error("Failed to allocate bus: %s", strerror(-r)); goto finish; } r = sd_bus_set_fd(b, STDIN_FILENO, STDOUT_FILENO); if (r < 0) { log_error("Failed to set fds: %s", strerror(-r)); goto finish; } r = sd_bus_set_server(b, 1, server_id); if (r < 0) { log_error("Failed to set server mode: %s", strerror(-r)); goto finish; } r = sd_bus_negotiate_fds(b, is_unix); if (r < 0) { log_error("Failed to set FD negotiation: %s", strerror(-r)); goto finish; } r = sd_bus_set_anonymous(b, true); if (r < 0) { log_error("Failed to set anonymous authentication: %s", strerror(-r)); goto finish; } r = sd_bus_start(b); if (r < 0) { log_error("Failed to start bus client: %s", strerror(-r)); goto finish; } for (;;) { _cleanup_bus_message_unref_ sd_bus_message *m = NULL; int events_a, events_b, fd; uint64_t timeout_a, timeout_b, t; struct timespec _ts, *ts; r = sd_bus_process(a, &m); if (r < 0) { log_error("Failed to process bus: %s", strerror(-r)); goto finish; } if (m) { r = sd_bus_send(b, m, NULL); if (r < 0) { log_error("Failed to send message: %s", strerror(-r)); goto finish; } } if (r > 0) continue; r = sd_bus_process(b, &m); if (r < 0) { log_error("Failed to process bus: %s", strerror(-r)); goto finish; } if (m) { r = sd_bus_send(a, m, NULL); if (r < 0) { log_error("Failed to send message: %s", strerror(-r)); goto finish; } } if (r > 0) continue; fd = sd_bus_get_fd(a); if (fd < 0) { log_error("Failed to get fd: %s", strerror(-r)); goto finish; } events_a = sd_bus_get_events(a); if (events_a < 0) { log_error("Failed to get events mask: %s", strerror(-r)); goto finish; } r = sd_bus_get_timeout(a, &timeout_a); if (r < 0) { log_error("Failed to get timeout: %s", strerror(-r)); goto finish; } events_b = sd_bus_get_events(b); if (events_b < 0) { log_error("Failed to get events mask: %s", strerror(-r)); goto finish; } r = sd_bus_get_timeout(b, &timeout_b); if (r < 0) { log_error("Failed to get timeout: %s", strerror(-r)); goto finish; } t = timeout_a; if (t == (uint64_t) -1 || (timeout_b != (uint64_t) -1 && timeout_b < timeout_a)) t = timeout_b; if (t == (uint64_t) -1) ts = NULL; else { usec_t nw; nw = now(CLOCK_MONOTONIC); if (t > nw) t -= nw; else t = 0; ts = timespec_store(&_ts, t); } { struct pollfd p[3] = { {.fd = fd, .events = events_a, }, {.fd = STDIN_FILENO, .events = events_b & POLLIN, }, {.fd = STDOUT_FILENO, .events = events_b & POLLOUT, }};
int vg_remove_snapshot(struct logical_volume *cow) { int merging_snapshot = 0; struct logical_volume *origin = origin_from_cow(cow); int is_origin_active = lv_is_active(origin); if (is_origin_active && lv_is_virtual_origin(origin)) { if (!deactivate_lv(origin->vg->cmd, origin)) { log_error("Failed to deactivate logical volume \"%s\"", origin->name); return 0; } is_origin_active = 0; } dm_list_del(&cow->snapshot->origin_list); origin->origin_count--; if (lv_is_merging_origin(origin) && (find_snapshot(origin) == find_snapshot(cow))) { clear_snapshot_merge(origin); /* * preload origin IFF "snapshot-merge" target is active * - IMPORTANT: avoids preload if inactivate merge is pending */ if (lv_has_target_type(origin->vg->vgmem, origin, NULL, "snapshot-merge")) { /* * preload origin to: * - allow proper release of -cow * - avoid allocations with other devices suspended * when transitioning from "snapshot-merge" to * "snapshot-origin after a merge completes. */ merging_snapshot = 1; } } if (!lv_remove(cow->snapshot->lv)) { log_error("Failed to remove internal snapshot LV %s", cow->snapshot->lv->name); return 0; } cow->snapshot = NULL; lv_set_visible(cow); /* format1 must do the change in one step, with the commit last. */ if (!(origin->vg->fid->fmt->features & FMT_MDAS)) { /* Get the lock for COW volume */ if (is_origin_active && !activate_lv(cow->vg->cmd, cow)) { log_error("Unable to activate logical volume \"%s\"", cow->name); return 0; } return 1; } if (!vg_write(origin->vg)) return_0; /* Skip call suspend, if device is not active */ if (is_origin_active && !suspend_lv(origin->vg->cmd, origin)) { log_error("Failed to refresh %s without snapshot.", origin->name); vg_revert(origin->vg); return 0; } if (!vg_commit(origin->vg)) return_0; if (is_origin_active) { /* * If the snapshot was active and the COW LV is taken away * the LV lock on cluster has to be grabbed, so use * activate_lv() which resumes suspend cow device. */ if (!merging_snapshot && !activate_lv(cow->vg->cmd, cow)) { log_error("Failed to activate %s.", cow->name); return 0; } if (!resume_lv(origin->vg->cmd, origin)) { log_error("Failed to resume %s.", origin->name); return 0; } /* * For merged snapshot and clustered VG activate cow LV so * the following call to deactivate_lv() can clean-up table * entries. For this clustered lock need to be held. */ if (vg_is_clustered(cow->vg) && merging_snapshot && !activate_lv(cow->vg->cmd, cow)) { log_error("Failed to activate %s.", cow->name); return 0; } } return 1; }
static int _write_node(const struct dm_config_node *cn, int only_one, dm_putline_fn putline, const struct dm_config_node_out_spec *out_spec, void *baton) { struct config_output out = { .mem = dm_pool_create("config_output", 1024), .putline = putline, .spec = out_spec, .baton = baton }; if (!out.mem) return_0; if (!_write_config(cn, only_one, &out, 0)) { dm_pool_destroy(out.mem); return_0; } dm_pool_destroy(out.mem); return 1; } int dm_config_write_one_node(const struct dm_config_node *cn, dm_putline_fn putline, void *baton) { return _write_node(cn, 1, putline, NULL, baton); } int dm_config_write_node(const struct dm_config_node *cn, dm_putline_fn putline, void *baton) { return _write_node(cn, 0, putline, NULL, baton); } int dm_config_write_one_node_out(const struct dm_config_node *cn, const struct dm_config_node_out_spec *out_spec, void *baton) { return _write_node(cn, 1, NULL, out_spec, baton); } int dm_config_write_node_out(const struct dm_config_node *cn, const struct dm_config_node_out_spec *out_spec, void *baton) { return _write_node(cn, 0, NULL, out_spec, baton); } /* * parser */ static char *_dup_string_tok(struct parser *p) { char *str; p->tb++, p->te--; /* strip "'s */ if (p->te < p->tb) { log_error("Parse error at byte %" PRIptrdiff_t " (line %d): " "expected a string token.", p->tb - p->fb + 1, p->line); return NULL; } if (!(str = _dup_tok(p))) return_NULL; p->te++; return str; }
void as_global_netstream_ctor(const fn_call& fn) { log_error("video requires FFMPEG library\n"); }
/** * Main function * * @param argc * @param argv * * @return */ int main(int argc, char *argv[]) { struct fuse_args args = FUSE_ARGS_INIT(argc, argv); struct fusefat32_context_t fusefat32 = { .config = FUSEFAT32_CONFIG_DEFAULT, .fs = NULL }; bool logging_used = false; int return_code = EXIT_FAILURE; struct fusefat32_config_t *config = NULL; if (fuse_opt_parse(&args, &fusefat32, fusefat32_options, fusefat32_process_options) == -1) { goto main_cleanup; } config = &fusefat32.config; /* if we are here then it means that neither version nor help key has been activated */ if (config->device == NULL) { fputs(_("A device to mount must be specified (use `dev` option)\n"), stderr); goto main_cleanup; } if (config->mount_point == NULL) { fputs(_("A mount point must be specified\n"), stderr); goto main_cleanup; } /* Initializing logging. If @em log option has been specified then we use specified file for logging. If @em foreground option has been chosen then we use @em stderr for logging. If both options has been chosen at the same time then we prefer @em foreground option. Default importance level for logs is #LOG_WARNING. If @em verbose flag is set then log level to use is #LOG_DEBUG. */ enum log_level_t log_level = LOG_WARNING; if (config->verbose) { log_level = LOG_DEBUG; } if (config->log != NULL && !config->foreground) { int lret = log_init_from_path(config->log, log_level); if (lret < 0) { // @em strerror function is used only in the main thread fprintf(stderr, _("Can't initialize logging facility. Error: %s\n"), strerror(errno)); goto main_cleanup; } else { logging_used = true; } } else if (config->foreground) { log_init_from_file(stderr, log_level); logging_used = true; } /* otherwise no logging required */ log_info(_("Opening file system...")); enum fat32_error_t ret; struct fat32_fs_params_t params = { .file_table_size = 1024, .fh_table_size = 1024, }; ret = fat32_fs_open(config->device, ¶ms, &fusefat32.fs); if (ret == FE_OK) { log_info(_("File system has been opened successfully.")); } else { log_error(_("Error occured while opening file system.")); if (ret == FE_ERRNO) { log_error(_("Error description: %s"), strerror(errno)); } else { log_error(_("Can't get error description. Error code is %d"), ret); } goto main_cleanup; } if (fat32_bpb_verbose_info(fusefat32.fs->bpb) < 0) { goto main_cleanup; } if (fat32_fs_info_verbose_info(fusefat32.fs->fs_info) < 0) { goto main_cleanup; } log_info(_("Starting main FUSE loop...")); int fret = fuse_main(args.argc, args.argv, &fusefat32_operations, &fusefat32); if (fret != 0) { log_error(_("Unable to start FUSE loop: %s"), strerror(errno)); goto main_cleanup; } return_code = EXIT_SUCCESS; main_cleanup: log_info(_("Freeing acquired resources...")); fuse_opt_free_args(&args); if (fusefat32.fs != NULL) { if (fat32_fs_close(fusefat32.fs) < 0) { log_error(_("Can't close filesystem correctly: %s"), strerror(errno)); } } if (logging_used) { log_close(); } if (config != NULL) { if (config->mount_point != NULL) { free(config->mount_point); } } return return_code; }
void Sound_as::probeAudio() { if ( ! externalSound ) { // Only probe for sound complete assert(_soundHandler); assert(!_soundCompleted); if (!_soundHandler->isSoundPlaying(soundId)) { stopProbeTimer(); // dispatch onSoundComplete callMethod(&owner(), NSV::PROP_ON_SOUND_COMPLETE); } return; } if (!_mediaParser) return; // nothing to do here w/out a media parser if ( ! _soundLoaded ) { #ifdef GNASH_DEBUG_SOUND_AS log_debug("Probing audio for load"); #endif if (_mediaParser->parsingCompleted()) { _soundLoaded = true; if (!isStreaming) { stopProbeTimer(); // will be re-started on Sound.start() } bool success = _mediaParser->getAudioInfo() != 0; callMethod(&owner(), NSV::PROP_ON_LOAD, success); // TODO: check if this should be called anyway. if (success) handleId3Data(_mediaParser->getId3Info(), owner()); } return; } if (isAttached()) { #ifdef GNASH_DEBUG_SOUND_AS log_debug("Probing audio for end"); #endif boost::mutex::scoped_lock lock(_soundCompletedMutex); if (_soundCompleted) { // when _soundCompleted is true we're NOT attached ! // MediaParser may be still needed, // if this is a non-streaming sound if ( isStreaming ) { _mediaParser.reset(); // no use for this anymore... } _inputStream = 0; _soundCompleted = false; stopProbeTimer(); // dispatch onSoundComplete callMethod(&owner(), NSV::PROP_ON_SOUND_COMPLETE); } } else { #ifdef GNASH_DEBUG_SOUND_AS log_debug("Probing audio for start"); #endif bool parsingCompleted = _mediaParser->parsingCompleted(); try { log_debug("Attaching aux streamer"); _inputStream = attachAuxStreamerIfNeeded(); } catch (const MediaException& e) { assert(!_inputStream); assert(!_audioDecoder.get()); log_error(_("Could not create audio decoder: %s"), e.what()); _mediaParser.reset(); // no use for this anymore... stopProbeTimer(); return; } if ( ! _inputStream ) { if ( parsingCompleted ) { log_error(_("No audio in Sound input.")); stopProbeTimer(); _mediaParser.reset(); // no use for this anymore... } else { // keep probing } } else { // An audio decoder was constructed, good! assert(_audioDecoder.get()); } } }
int main(int argc, char *argv[]) { static const char virtualization_consoles[] = "hvc0\0" "xvc0\0" "hvsi0\0" "sclp_line0\0" "ttysclp0\0" "3270!tty1\0"; _cleanup_free_ char *active = NULL; const char *j; int r; if (argc > 1 && argc != 4) { log_error("This program takes three or no arguments."); return EXIT_FAILURE; } if (argc > 1) arg_dest = argv[1]; log_set_target(LOG_TARGET_SAFE); log_parse_environment(); log_open(); umask(0022); if (detect_container() > 0) { _cleanup_free_ char *container_ttys = NULL; log_debug("Automatically adding console shell."); if (add_symlink("console-getty.service", "console-getty.service") < 0) return EXIT_FAILURE; /* When $container_ttys is set for PID 1, spawn * gettys on all ptys named therein. Note that despite * the variable name we only support ptys here. */ r = getenv_for_pid(1, "container_ttys", &container_ttys); if (r > 0) { const char *word, *state; size_t l; FOREACH_WORD(word, l, container_ttys, state) { const char *t; char tty[l + 1]; memcpy(tty, word, l); tty[l] = 0; /* First strip off /dev/ if it is specified */ t = path_startswith(tty, "/dev/"); if (!t) t = tty; /* Then, make sure it's actually a pty */ t = path_startswith(t, "pts/"); if (!t) continue; if (add_container_getty(t) < 0) return EXIT_FAILURE; } } /* Don't add any further magic if we are in a container */ return EXIT_SUCCESS; }
/************************************************************************** Main entry point for freeciv-ruledit **************************************************************************/ int main(int argc, char **argv) { enum log_level loglevel = LOG_NORMAL; int ui_options; init_nls(); #ifdef ENABLE_NLS (void) bindtextdomain("freeciv-ruledit", LOCALEDIR); #endif registry_module_init(); init_character_encodings(FC_DEFAULT_DATA_ENCODING, FALSE); log_init(NULL, loglevel, NULL, NULL, -1); ui_options = re_parse_cmdline(argc, argv); if (ui_options != -1) { init_connections(); settings_init(FALSE); /* Reset aifill to zero */ game.info.aifill = 0; game_init(); i_am_server(); if (source_rs != NULL) { sz_strlcpy(game.server.rulesetdir, source_rs); } if (load_rulesets(NULL, FALSE)) { log_normal("Terrains: %d", game.control.terrain_count); log_normal("Resources: %d", game.control.resource_count); log_normal("Techs: %d", game.control.num_tech_types); log_normal("Unit classes: %d", game.control.num_unit_classes); log_normal("Unit types: %d", game.control.num_unit_types); log_normal("Buildings: %d", game.control.num_impr_types); log_normal("Nations: %d", game.control.nation_count); log_normal("City Styles: %d", game.control.styles_count); log_normal("Specialists: %d", game.control.num_specialist_types); log_normal("Governments: %d", game.control.government_count); log_normal("Disasters: %d", game.control.num_disaster_types); log_normal("Achievements: %d", game.control.num_achievement_types); log_normal("Extras: %d", game.control.num_extra_types); log_normal("Bases: %d", game.control.num_base_types); log_normal("Roads: %d", game.control.num_road_types); ruledit_qt_setup(ui_options, argv); ruledit_qt_run(); ruledit_qt_close(); } else { log_error("Loading ruleset %s failed", game.server.rulesetdir); } } log_close(); registry_module_close(); return EXIT_SUCCESS; }
isc_result_t trace_begin (const char *filename, const char *file, int line) { tracefile_header_t tfh; int status; trace_type_t *tptr, *next; isc_result_t result; if (traceoutfile) { log_error ("%s(%d): trace_begin called twice", file, line); return ISC_R_INVALIDARG; } traceoutfile = open (filename, O_CREAT | O_WRONLY | O_EXCL, 0600); if (traceoutfile < 0 && errno == EEXIST) { log_error ("WARNING: Overwriting trace file \"%s\"", filename); traceoutfile = open (filename, O_WRONLY | O_EXCL, 0600); } if (traceoutfile < 0) { log_error ("%s(%d): trace_begin: %s: %m", file, line, filename); return ISC_R_UNEXPECTED; } #if defined (HAVE_SETFD) if (fcntl (traceoutfile, F_SETFD, 1) < 0) log_error ("Can't set close-on-exec on %s: %m", filename); #endif tfh.magic = htonl (TRACEFILE_MAGIC); tfh.version = htonl (TRACEFILE_VERSION); tfh.hlen = htonl (sizeof (tracefile_header_t)); tfh.phlen = htonl (sizeof (tracepacket_t)); status = write (traceoutfile, &tfh, sizeof tfh); if (status < 0) { log_error ("%s(%d): trace_begin write failed: %m", file, line); return ISC_R_UNEXPECTED; } else if (status != sizeof tfh) { log_error ("%s(%d): trace_begin: short write (%d:%ld)", file, line, status, (long)(sizeof tfh)); trace_stop (); return ISC_R_UNEXPECTED; } /* Stash all the types that have already been set up. */ if (new_trace_types) { next = new_trace_types; new_trace_types = (trace_type_t *)0; for (tptr = next; tptr; tptr = next) { next = tptr -> next; if (tptr -> index != 0) { result = (trace_type_record (tptr, strlen (tptr -> name), file, line)); if (result != ISC_R_SUCCESS) return status; } } } return ISC_R_SUCCESS; }
void interrupt_log_wrong_nirq(void) { log_error(LOG_DEFAULT, "interrupt_set_irq(): wrong nirq!"); }
isc_result_t trace_write_packet_iov (trace_type_t *ttype, int count, trace_iov_t *iov, const char *file, int line) { tracepacket_t tmp; int status; int i; int length; /* Really shouldn't get called here, but it may be hard to turn off tracing midstream if the trace file write fails or something. */ if (tracing_stopped) return 0; if (!ttype) { log_error ("%s(%d): trace_write_packet with null trace type", file ? file : "<unknown file>", line); return ISC_R_INVALIDARG; } if (!traceoutfile) { log_error ("%s(%d): trace_write_packet with no tracefile.", file ? file : "<unknown file>", line); return ISC_R_INVALIDARG; } /* Compute the total length of the iov. */ length = 0; for (i = 0; i < count; i++) length += iov [i].len; /* We have to swap out the data, because it may be read back on a machine of different endianness. */ tmp.type_index = htonl (ttype -> index); tmp.when = htonl (time ((time_t *)0)); /* XXX */ tmp.length = htonl (length); status = write (traceoutfile, &tmp, sizeof tmp); if (status < 0) { log_error ("%s(%d): trace_write_packet write failed: %m", file, line); return ISC_R_UNEXPECTED; } else if (status != sizeof tmp) { log_error ("%s(%d): trace_write_packet: short write (%d:%ld)", file, line, status, (long)(sizeof tmp)); trace_stop (); } for (i = 0; i < count; i++) { status = write (traceoutfile, iov [i].buf, iov [i].len); if (status < 0) { log_error ("%s(%d): %s write failed: %m", file, line, "trace_write_packet"); return ISC_R_UNEXPECTED; } else if (status != iov [i].len) { log_error ("%s(%d): %s: short write (%d:%d)", file, line, "trace_write_packet", status, length); trace_stop (); } } /* Write padding on the end of the packet to align the next packet to an 8-byte boundary. This is in case we decide to use mmap in some clever way later on. */ if (length % 8) { static char zero [] = { 0, 0, 0, 0, 0, 0, 0 }; unsigned padl = 8 - (length % 8); status = write (traceoutfile, zero, padl); if (status < 0) { log_error ("%s(%d): trace_write_packet write failed: %m", file, line); return ISC_R_UNEXPECTED; } else if (status != padl) { log_error ("%s(%d): trace_write_packet: short write (%d:%d)", file, line, status, padl); trace_stop (); } } return ISC_R_SUCCESS; }
int dev_open_flags(struct device *dev, int flags, int direct, int quiet) { struct stat buf; const char *name; int need_excl = 0, need_rw = 0; if ((flags & O_ACCMODE) == O_RDWR) need_rw = 1; if ((flags & O_EXCL)) need_excl = 1; if (dev->fd >= 0) { if (((dev->flags & DEV_OPENED_RW) || !need_rw) && ((dev->flags & DEV_OPENED_EXCL) || !need_excl)) { dev->open_count++; return 1; } if (dev->open_count && !need_excl) { /* FIXME Ensure we never get here */ log_debug("WARNING: %s already opened read-only", dev_name(dev)); dev->open_count++; } dev_close_immediate(dev); } if (memlock()) log_error("WARNING: dev_open(%s) called while suspended", dev_name(dev)); if (dev->flags & DEV_REGULAR) name = dev_name(dev); else if (!(name = dev_name_confirmed(dev, quiet))) return_0; if (!(dev->flags & DEV_REGULAR)) { if (stat(name, &buf) < 0) { log_sys_error("%s: stat failed", name); return 0; } if (buf.st_rdev != dev->dev) { log_error("%s: device changed", name); return 0; } } #ifdef O_DIRECT_SUPPORT if (direct) { if (!(dev->flags & DEV_O_DIRECT_TESTED)) dev->flags |= DEV_O_DIRECT; if ((dev->flags & DEV_O_DIRECT)) flags |= O_DIRECT; } #endif #ifdef O_NOATIME /* Don't update atime on device inodes */ if (!(dev->flags & DEV_REGULAR)) flags |= O_NOATIME; #endif if ((dev->fd = open(name, flags, 0777)) < 0) { #ifdef O_DIRECT_SUPPORT if (direct && !(dev->flags & DEV_O_DIRECT_TESTED)) { flags &= ~O_DIRECT; if ((dev->fd = open(name, flags, 0777)) >= 0) { dev->flags &= ~DEV_O_DIRECT; log_debug("%s: Not using O_DIRECT", name); goto opened; } } #endif if (quiet) log_sys_debug("open", name); else log_sys_error("open", name); return 0; } #ifdef O_DIRECT_SUPPORT opened: if (direct) dev->flags |= DEV_O_DIRECT_TESTED; #endif dev->open_count++; dev->flags &= ~DEV_ACCESSED_W; if (need_rw) dev->flags |= DEV_OPENED_RW; else dev->flags &= ~DEV_OPENED_RW; if (need_excl) dev->flags |= DEV_OPENED_EXCL; else dev->flags &= ~DEV_OPENED_EXCL; if (!(dev->flags & DEV_REGULAR) && ((fstat(dev->fd, &buf) < 0) || (buf.st_rdev != dev->dev))) { log_error("%s: fstat failed: Has device name changed?", name); dev_close_immediate(dev); return 0; } #ifndef O_DIRECT_SUPPORT if (!(dev->flags & DEV_REGULAR)) dev_flush(dev); #endif if ((flags & O_CREAT) && !(flags & O_TRUNC)) dev->end = lseek(dev->fd, (off_t) 0, SEEK_END); dm_list_add(&_open_devices, &dev->open_list); log_debug("Opened %s %s%s%s", dev_name(dev), dev->flags & DEV_OPENED_RW ? "RW" : "RO", dev->flags & DEV_OPENED_EXCL ? " O_EXCL" : "", dev->flags & DEV_O_DIRECT ? " O_DIRECT" : ""); return 1; }
void trace_file_replay (const char *filename) { tracepacket_t *tpkt = (tracepacket_t *)0; int status; char *buf = (char *)0; unsigned buflen; unsigned bufmax = 0; trace_type_t *ttype = (trace_type_t *)0; isc_result_t result; int len; traceinfile = fopen (filename, "r"); if (!traceinfile) { log_error ("Can't open tracefile %s: %m", filename); return; } #if defined (HAVE_SETFD) if (fcntl (fileno (traceinfile), F_SETFD, 1) < 0) log_error ("Can't set close-on-exec on %s: %m", filename); #endif status = fread (&tracefile_header, 1, sizeof tracefile_header, traceinfile); if (status < sizeof tracefile_header) { if (ferror (traceinfile)) log_error ("Error reading trace file header: %m"); else log_error ("Short read on trace file header: %d %ld.", status, (long)(sizeof tracefile_header)); goto out; } tracefile_header.magic = ntohl (tracefile_header.magic); tracefile_header.version = ntohl (tracefile_header.version); tracefile_header.hlen = ntohl (tracefile_header.hlen); tracefile_header.phlen = ntohl (tracefile_header.phlen); if (tracefile_header.magic != TRACEFILE_MAGIC) { log_error ("%s: not a dhcp trace file.", filename); goto out; } if (tracefile_header.version > TRACEFILE_VERSION) { log_error ("tracefile version %ld > current %ld.", (long int)tracefile_header.version, (long int)TRACEFILE_VERSION); goto out; } if (tracefile_header.phlen < sizeof *tpkt) { log_error ("tracefile packet size too small - %ld < %ld", (long int)tracefile_header.phlen, (long int)sizeof *tpkt); goto out; } len = (sizeof tracefile_header) - tracefile_header.hlen; if (len < 0) { log_error ("tracefile header size too small - %ld < %ld", (long int)tracefile_header.hlen, (long int)sizeof tracefile_header); goto out; } if (len > 0) { status = fseek (traceinfile, (long)len, SEEK_CUR); if (status < 0) { log_error ("can't seek past header: %m"); goto out; } } tpkt = dmalloc ((unsigned)tracefile_header.phlen, MDL); if (!tpkt) { log_error ("can't allocate trace packet header."); goto out; } while ((result = trace_get_next_packet (&ttype, tpkt, &buf, &buflen, &bufmax)) == ISC_R_SUCCESS) { (*ttype -> have_packet) (ttype, tpkt -> length, buf); ttype = (trace_type_t *)0; } out: fclose (traceinfile); if (buf) dfree (buf, MDL); if (tpkt) dfree (tpkt, MDL); }
/* * Logs an attempt to read an invalid format file. */ static void _invalid_format(const char *str) { log_error("Can't process text format file - %s.", str); }
isc_result_t trace_get_next_packet (trace_type_t **ttp, tracepacket_t *tpkt, char **buf, unsigned *buflen, unsigned *bufmax) { trace_type_t *ttype; unsigned paylen; int status; int len; fpos_t curpos; status = fgetpos (traceinfile, &curpos); if (status < 0) log_error ("Can't save tracefile position: %m"); status = fread (tpkt, 1, (size_t)tracefile_header.phlen, traceinfile); if (status < tracefile_header.phlen) { if (ferror (traceinfile)) log_error ("Error reading trace packet header: %m"); else if (status == 0) return ISC_R_EOF; else log_error ("Short read on trace packet header: " "%ld %ld.", (long int)status, (long int)tracefile_header.phlen); return ISC_R_PROTOCOLERROR; } /* Swap the packet. */ tpkt -> type_index = ntohl (tpkt -> type_index); tpkt -> length = ntohl (tpkt -> length); tpkt -> when = ntohl (tpkt -> when); /* See if there's a handler for this packet type. */ if (tpkt -> type_index < trace_type_count && trace_types [tpkt -> type_index]) ttype = trace_types [tpkt -> type_index]; else { log_error ("Trace packet with unknown index %ld", (long int)tpkt -> type_index); return ISC_R_PROTOCOLERROR; } /* If we were just hunting for the time marker, we've found it, so back up to the beginning of the packet and return its type. */ if (ttp && *ttp == &trace_time_marker) { *ttp = ttype; status = fsetpos (traceinfile, &curpos); if (status < 0) { log_error ("fsetpos in tracefile failed: %m"); return ISC_R_PROTOCOLERROR; } return ISC_R_EXISTS; } /* If we were supposed to get a particular kind of packet, check to see that we got the right kind. */ if (ttp && *ttp && ttype != *ttp) { log_error ("Read packet type %s when expecting %s", ttype -> name, (*ttp) -> name); status = fsetpos (traceinfile, &curpos); if (status < 0) { log_error ("fsetpos in tracefile failed: %m"); return ISC_R_PROTOCOLERROR; } return ISC_R_UNEXPECTEDTOKEN; } paylen = tpkt -> length; if (paylen % 8) paylen += 8 - (tpkt -> length % 8); if (paylen > (*bufmax)) { if ((*buf)) dfree ((*buf), MDL); (*bufmax) = ((paylen + 1023) & ~1023U); (*buf) = dmalloc ((*bufmax), MDL); if (!(*buf)) { log_error ("Can't allocate input buffer sized %d", (*bufmax)); return ISC_R_NOMEMORY; } } status = fread ((*buf), 1, paylen, traceinfile); if (status < paylen) { if (ferror (traceinfile)) log_error ("Error reading trace payload: %m"); else log_error ("Short read on trace payload: %d %d.", status, paylen); return ISC_R_PROTOCOLERROR; } /* Store the actual length of the payload. */ *buflen = tpkt -> length; if (trace_set_time_hook) (*trace_set_time_hook) (tpkt -> when); if (ttp) *ttp = ttype; return ISC_R_SUCCESS; }
void GPFSConfigHandler::task() { int nFSs = 0; int nPools = 0; int nDisks = 0; int nFsets = 0; int nNodes = 0; TEAL_ERR_T ret; string msg; char tmp[10]; string fsName; string stgName; string diskName; string fsetName; string nodeName; string clusterName; FilesystemInfo* fsInfo = NULL; StoragePoolInfo* stgInfo = NULL; DiskInfo* diskInfo = NULL; FileSet* fsetInfo = NULL; FileSet* fileSetList = NULL; MErrno err = M_OK; log_info("########################Start refreshing all entities#########################################"); err = GPFSHandler::getPollHandler()->getDaemonState(); if(err != M_OK) { msg = "daemon is down on local node "; msg += Utils::int_to_char(tmp,10,(unsigned int*)&err); log_warn(msg); /* Simply ignore this error to continue.... log_error(msg); return; */ } err = GPFSHandler::getPollHandler()->refreshClusterRecipe(); if(err != M_OK) { msg = "refresh cluster failed with "; msg += Utils::int_to_char(tmp,10,(unsigned int*)&err); log_warn(msg); /* Simply ignore this error to continue.... log_error(msg); return; */ } ClusterInfo* clusterInfo = new ClusterInfo(&err); //update cluster info err = GPFSHandler::getPollHandler()->updateClusterInfo(clusterInfo); if(err != M_OK) { msg = "update cluster info failed with "; msg += Utils::int_to_char(tmp,10,(unsigned int*)&err); log_warn(msg); /* Simply ignore this error to continue.... log_error(msg); return; */ } //update all nodes info err = GPFSHandler::getPollHandler()->updateNodeInfo(clusterInfo); if(err != M_OK) { msg = "update node failed with "; msg += Utils::int_to_char(tmp,10,(unsigned int*)&err); log_warn(msg); /* Simply ignore this error to continue.... log_error(msg); return; */ } err = GPFSHandler::getPollHandler()->getClusterInfo(clusterInfo); //this maybe not needed if(err != M_OK) { msg = "get cluster info failed with "; msg += Utils::int_to_char(tmp,10,(unsigned int*)&err); log_warn(msg); /* Simply ignore this error to continue.... log_error(msg); return; */ } err = GPFSHandler::getPollHandler()->updateDiskSDRInfo(); if(err != M_OK) { /*TODO: This API invokes "mmsdrquery 30 3001:3004:3005:3006:3007:3008:3002:3003" under the cover. Need to check if it is a real error or an expected configuration to determin whether to ignore it or not.*/ msg = "update disk SDR info failed with "; msg += Utils::int_to_char(tmp,10,(unsigned int*)&err); msg += ", ignore it..."; log_warn(msg); // return; // simply ignore it since there a configuration of two clusters and NSD may not be seen from the FS cluster. } err = GPFSHandler::getPollHandler()->updateFilesystemInfo(clusterInfo, 1);// to get perfermance statics even if not used. if(err != M_OK) { msg = "update file system failed with "; msg += Utils::int_to_char(tmp,10,(unsigned int*)&err); log_warn(msg); /* Simply ignore this error to continue.... log_error(msg); return; */ } err = GPFSHandler::getPollHandler()->updateMountedNodeInfo(clusterInfo); // to get mounted node info if(err != M_OK) { /*TODO: This API invokes "mmlsmount all_local -Y" under the cover. Need to check if it is a real error or an expected configuration to determin whether to ignore it or not.*/ msg = "update mounted node info failed with "; msg += Utils::int_to_char(tmp,10,(unsigned int*)&err); msg += ", ignore it..."; log_warn(msg); // return; // simply ignore it since there maybe no local file system configured } err = GPFSHandler::getPollHandler()->updateVfsStatsInfo(clusterInfo); // to get vfs info if(err != M_OK) { msg = "update vfs info failed with "; msg += Utils::int_to_char(tmp,10,(unsigned int*)&err); log_warn(msg); /* Simply ignore this error to continue.... log_error(msg); return; */ } err = GPFSHandler::getPollHandler()->updateThreadUtilInfo(clusterInfo); // to get thread util info if(err != M_OK) { msg = "update thread util info failed with "; msg += Utils::int_to_char(tmp,10,(unsigned int*)&err); log_warn(msg); /* Simply ignore this error to continue.... log_error(msg); return; */ } err = GPFSHandler::getPollHandler()->updateIocStatsInfo(clusterInfo); // to get ioc statics info if(err != M_OK) { msg = "update ioc statics info failed with "; msg += Utils::int_to_char(tmp,10,(unsigned int*)&err); log_warn(msg); /* Simply ignore this error to continue.... log_error(msg); return; */ } err = GPFSHandler::getPollHandler()->updateCacheStatsInfo(clusterInfo); // to get cache statics info if(err != M_OK) { msg = "update cache statics info failed with "; msg += Utils::int_to_char(tmp,10,(unsigned int*)&err); log_warn(msg); /* Simply ignore this error to continue.... log_error(msg); return; */ } err = GPFSHandler::getPollHandler()->updatePCacheStatsInfo(clusterInfo); // to get pcache statics info if(err != M_OK) { msg = "update pcache statics info failed with "; msg += Utils::int_to_char(tmp,10,(unsigned int*)&err); log_warn(msg); /* Simply ignore this error to continue.... log_error(msg); return; */ } err = GPFSHandler::getPollHandler()->updateFilesystemManagerInfo(clusterInfo);// update fs manager if(err != M_OK) { msg = "update file system manager failed with "; msg += Utils::int_to_char(tmp,10,(unsigned int*)&err); log_warn(msg); /* Simply ignore this error to continue.... log_error(msg); return; */ } err = GPFSHandler::getPollHandler()->updatePolicyInfo(clusterInfo); // to get policy info if(err != M_OK) { msg = "update policy info failed with "; msg += Utils::int_to_char(tmp,10,(unsigned int*)&err); log_warn(msg); /* Simply ignore this error to continue.... log_error(msg); return; */ } err = GPFSHandler::getPollHandler()->updateFilesystemConfigInfo(clusterInfo);// update fs config if(err != M_OK) { msg = "update file system config failed with "; msg += Utils::int_to_char(tmp,10,(unsigned int*)&err); log_warn(msg); /* Simply ignore this error to continue.... log_error(msg); return; */ } ClusterStatus* clusterStatus = new ClusterStatus(); err = GPFSHandler::getPollHandler()->getClusterStatus(clusterStatus); if(err != M_OK) { msg = "get cluster status failed with "; msg += Utils::int_to_char(tmp,10,(unsigned int*)&err); log_warn(msg); /* Simply ignore this error to continue.... log_error(msg); return; */ } clusterName = clusterInfo->getName(); int i = 0; string clusterid = clusterInfo->getId(); nFSs = clusterInfo->getNumFilesystems(); //log fs one by one for( i = 0 ; i < nFSs; i++) { fsInfo = clusterInfo->getFilesystem(i); if (fsInfo == NULL) { msg = "NULL filesystem "; msg += Utils::int_to_char(tmp,10,(unsigned int*)&i); log_error(msg); continue; } fsName = fsInfo->getName(); err = GPFSHandler::getPollHandler()->updateStoragePoolInfo(clusterInfo, (char*)fsName.c_str()); if(err != M_OK) { msg = "update storage pool info for file system: "; msg += fsName; msg += " failed with "; msg += Utils::int_to_char(tmp,10,(unsigned int*)&err); log_warn(msg); continue; } msg = "Refresh file system: "; msg += fsName; log_debug(msg); ret = refreshFS(fsInfo, clusterid); if(ret != TEAL_SUCCESS) { msg = "Refresh file system: "; msg += fsName; msg += " failed with "; msg += Utils::int_to_char(tmp,10,(unsigned int*)&ret); log_error(msg); } nPools = fsInfo->getNumStoragePools(); int j = 0; //log stg one by one for(; j < nPools; j++ ) { stgInfo = fsInfo->getStoragePool(j); if(stgInfo == NULL) { msg = "ERR stgInfo for storage pool: "; msg += Utils::int_to_char(tmp,10,(unsigned int*)&j); msg += " in (fs: "; msg += fsName; msg += ") is NULL"; log_error(msg); continue; } stgName = stgInfo->getName(); err = GPFSHandler::getPollHandler()->updateDiskInfo(clusterInfo, (char*)fsName.c_str(), (char*)stgName.c_str(),1); if(err != M_OK) { msg = "update disk info in (file system: "; msg += fsName; msg += ", storage pool: "; msg += stgName; msg += ") failed with "; msg += Utils::int_to_char(tmp,10,(unsigned int*)&err); log_warn(msg); continue; } msg = "Refresh storage pool: "; msg += stgName; msg += " in (fs: "; msg += fsName; msg += ")"; log_debug(msg); ret = refreshStgPool(stgInfo, clusterid, fsName); if(ret != TEAL_SUCCESS) { msg = "Refresh storage pool: "; msg += stgName; msg += " in (fs: "; msg += fsName; msg += ") failed with "; msg += Utils::int_to_char(tmp,10,(unsigned int*)&ret); log_error(msg); } int k = 0; nDisks = stgInfo->getNumDisks(); //log disk one by one for(; k < nDisks ; k++ ) { diskInfo = stgInfo->getDisk(k); if(diskInfo == NULL) { msg = "diskInfo for disk: "; msg += Utils::int_to_char(tmp,10,(unsigned int*)&k); msg += " in (storage pool: "; msg += stgName; msg += ", fs: "; msg += fsName; msg += ") is NULL"; log_error(msg); continue; } diskName = diskInfo->getName(); msg = "Refresh disk: "; msg += diskName; msg += " in (storage pool: "; msg += stgName; msg += ", fs: "; msg += fsName; msg += ")"; log_debug(msg); ret = refreshDisk(diskInfo, clusterid); if(ret != TEAL_SUCCESS) { msg = "Refresh disk: "; msg += diskName; msg += " in (storage pool: "; msg += stgName; msg += ", fs: "; msg += fsName; msg += ") failed with "; msg += Utils::int_to_char(tmp,10,(unsigned int*)&ret); log_error(msg); } }//end of refresh disks }//end of refresh stgpool /* core dump in GPFS 3.4, only effective in 3.5 err = GPFSHandler::getPollHandler()->getFileSets((char*)fsName.c_str(), &fileSetList); if(err != M_OK) { msg = "update fileset info in (fs: "; msg += fsName; msg += ") failed with "; msg += Utils::int_to_char(tmp,10,(unsigned int*)&err); log_error(msg); nFsets = 0; fileSetList = NULL; continue; } //at first time to get nFsets but will not return M_OK */ err = GPFSHandler::getPollHandler()->getFileSets1((char*)fsName.c_str(), fileSetList, &nFsets); if(nFsets <= 0) { msg = "no fileset found in (fs: "; msg += fsName; msg += ")"; log_warn(msg); nFsets = 0; fileSetList = NULL; continue; } fileSetList = new FileSet[nFsets]; err = GPFSHandler::getPollHandler()->getFileSets1((char*)fsName.c_str(), fileSetList, &nFsets); if(err != M_OK) { msg = "update fileset info in (fs: "; msg += fsName; msg += ") failed with "; msg += Utils::int_to_char(tmp,10,(unsigned int*)&err); log_warn(msg); nFsets = 0; fileSetList = NULL; continue; } int l = 0; //log fileset one by one for(; l < nFsets; l++ ) { fsetInfo = &fileSetList[l]; if(fsetInfo == NULL) { msg = "fsetInfo for fset: "; msg += Utils::int_to_char(tmp,10,(unsigned int*)&i); msg += " in (fs: "; msg += fsName; msg += ") is NULL"; log_error(msg); continue; } fsetName = fsetInfo->getName(); msg = "Refresh fileset: "; msg += fsetName; msg += " in (fs: "; msg += fsName; msg += ")"; log_debug(msg); ret = refreshFset(fsetInfo, clusterid); if(ret != TEAL_SUCCESS) { msg = "Refresh file set: "; msg += fsetName; msg += " in (fs: "; msg += fsName; msg += ") failed with"; msg += Utils::int_to_char(tmp,10,(unsigned int*)&ret); log_error(msg); } }//end of refresh fset if(fileSetList) { delete []fileSetList; fileSetList = NULL; nFsets = 0; fsetInfo = NULL; } }//end of refresh fs nNodes = clusterInfo->getNumNodes(); // to get disk access info, place this here to update num_access_disk in nodeinfo and need to invoke updateStoragePool() prior to this API err = GPFSHandler::getPollHandler()->updateDiskAccessInfo(clusterInfo); if(err != M_OK) { msg = "update disk access info failed with "; msg += Utils::int_to_char(tmp,10,(unsigned int*)&err); log_warn(msg); /* Simply ignore this error to continue.... log_error(msg); return; */ } NodeInfo* nodeInfo = NULL; //log node one by one for( i = 0 ; i < nNodes; i++) { nodeInfo = clusterInfo->getNode(i); if (nodeInfo == NULL) { msg = "nodeInfo for node "; msg += Utils::int_to_char(tmp,10,(unsigned int*)&i); msg += "is NULL"; log_error(msg); continue; } nodeName = nodeInfo->getName(); msg = "Refresh node: "; msg += nodeName; log_debug(msg); ret = refreshNode(nodeInfo, clusterid); if(ret != TEAL_SUCCESS) { msg = "Refresh node: "; msg += nodeName; msg += " failed with "; msg += Utils::int_to_char(tmp,10,(unsigned int*)&ret); log_error(msg); continue; } }//end of refresh node //refresh free disks here since free disk number/info can only be got after invoking updateDiskInfo() to all fs/stgpool err = GPFSHandler::getPollHandler()->updateFreeDiskInfo(clusterInfo); if(err != M_OK) { msg = "update free disk info failed with "; msg += Utils::int_to_char(tmp,10,(unsigned int*)&err); msg += ", ignore it..."; log_warn(msg); } nDisks = clusterInfo->getNumFreeDisks(); int k = 0; for(; k < nDisks ; k++ ) { diskInfo = clusterInfo->getFreeDisk(k); if(diskInfo == NULL) { msg = "diskInfo for free disk: "; msg += Utils::int_to_char(tmp,10,(unsigned int*)&i); msg += " is NULL"; log_error(msg); continue; } diskName = diskInfo->getName(); int s; int nServers = diskInfo->getNumServerItems(); int nBacks = diskInfo->getNumBackupServerItems(); string node_name; for(s = 0; s < nServers; s++) { DiskServerInfo *ds = diskInfo->getServer(s); node_name += string(ds->getName()) + string(" "); } for(s = 0; s < nBacks; s++) { DiskServerInfo *ds = diskInfo->getBackupServer(s); node_name += string(ds->getName()) + string(" "); } msg = "Refresh free disk: "; msg += "("; msg += diskName; msg += ")"; log_debug(msg); char svrList[NAME_STRING_LEN] = {0}; strcpy(svrList,node_name.c_str()); ret = refreshDisk(diskInfo, clusterid, svrList); if(ret != TEAL_SUCCESS) { msg = "Refresh free disk: "; msg += "("; msg += diskName; msg += ") failed with "; msg += Utils::int_to_char(tmp,10,(unsigned int*)&ret); log_error(msg); } }//end of refresh free disks //refresh cluster here since free disk number/info can only be got after invoking updateDiskInfo() to all fs/stgpool msg = "Refresh cluster: "; msg += clusterName; log_debug(msg); ret = refreshCluster(clusterInfo,clusterStatus); if(ret != TEAL_SUCCESS) { msg = "Refresh cluster failed with "; msg += Utils::int_to_char(tmp,10,(unsigned int*)&err); log_error(msg); } log_info("##################Start to refresh perseus configuration###################"); int nRgAllocated = 6; /* number of rg slots allocated in the buffer in advance*/ char *bufP = NULL; int bufLen = 0; int rc = 0; int nPdisk = 0; int nVdisk = 0; int nRg = 0; int nDa = 0; string pdiskName; string vdiskName; string rgName; string daName; gpfsRecoveryGroupSdrInfo *rgSdrTableP = NULL; gpfsRecoveryGroupSdrInfo *rgSdrP = NULL; gpfsRecoveryGroup *rgTableP = NULL; gpfsRecoveryGroup *rgP = NULL; gpfsRecoveryGroupDeclusteredArray* daP = NULL; gpfsDeclusteredArrayPdisk* pdiskP = NULL; gpfsDeclusteredArrayVdisk* vdiskP = NULL; rgSdrTableP = new gpfsRecoveryGroupSdrInfo[nRgAllocated]; nRg = nRgAllocated; /* get initial info from SDR (all RG names) */ rc = getNsdRAIDSdrInfo(rgSdrTableP, &nRg); // retry if failed with ENOMEM if(rc == ENOMEM) { log_debug("Not enough memory allocated, reallocate..."); nRgAllocated = nRg > nRgAllocated ? nRg : nRgAllocated; delete[] rgSdrTableP; rgSdrTableP = NULL; rgSdrTableP = new gpfsRecoveryGroupSdrInfo[nRgAllocated]; nRg = nRgAllocated; rc = getNsdRAIDSdrInfo(rgSdrTableP, &nRg); } if (rc == M_OK) { if (nRg >= 1) { rgTableP = new gpfsRecoveryGroup[nRg]; if (rgTableP == NULL) { msg = "Initial RG table failed with "; msg += Utils::int_to_char(tmp,10,(unsigned int*)&rc); log_error(msg); return; } for (i = 0, rgSdrP = rgSdrTableP; i < nRg && i < nRgAllocated; i++, rgSdrP++) { rgP = rgTableP + i; rgP->updateRgSdrInfo(rgSdrP->getRecoveryGroupName(),rgSdrP->getRecoveryGroupServerList(),rgSdrP->getRecoveryGroupId()); rc = getRecoveryGroupSummary(rgP); //refresh rg info if (rc == 0) { rgName = rgP->getRecoveryGroupName(); rc = getRecoveryGroupDeclusteredArrays(rgP); // refresh da info if (rc == 0) { int l = 0; int nDa = rgP->getRecoveryGroupDeclusterArrays(); bool allDaOK = true; // is all DA ok? for(; l < nDa; l++) { daP = rgP->getDeclusteredArrayP(l); if(daP == NULL) { msg = "da: "; msg += Utils::int_to_char(tmp,10,(unsigned int*)&l); msg += "in (rg: "; msg += rgName; msg += ") is NULL"; log_error(msg); continue; } daName = daP->getDeclusteredArrayName(); msg = "Refresh da: "; msg += daName; msg += " in rg: "; msg += rgName; log_debug(msg); ret = refreshDa(daP, clusterid, rgName); if(ret != TEAL_SUCCESS) { msg = "Refresh declustered array: "; msg += daName; msg += " in (rg: "; msg += rgName; msg += ") failed with "; msg += Utils::int_to_char(tmp,10,(unsigned int*)&ret); log_error(msg); } int j = 0; int k = 0; nPdisk = daP->getDeclusteredArrayPdisks(); nVdisk = daP->getDeclusteredArrayVdisks(); for(; j < nPdisk; j++) { pdiskP = daP->getDeclusteredArrayPdiskP(j); if(pdiskP == NULL) { msg = "pdisk: "; msg += Utils::int_to_char(tmp,10,(unsigned int*)&j); msg += " in (rg: "; msg += rgName; msg += ", da: "; msg += daName; msg += ") is NULL"; log_error(msg); continue; } pdiskName = pdiskP->getPdiskName(); msg = "Refresh pdisk: "; msg += pdiskName; msg += " in (rg: "; msg += rgName; msg += ", da: "; msg += daName; msg += ")"; log_debug(msg); ret = refreshPdisk(pdiskP,clusterid,rgName,daName); if(ret != TEAL_SUCCESS) { msg = "Refresh pdisk: "; msg += pdiskName; msg += " in (rg: "; msg += rgName; msg += ", da: "; msg += daName; msg += Utils::int_to_char(tmp,10,(unsigned int*)&ret); log_error(msg); } } for(; k < nVdisk; k++) { vdiskP = daP->getDeclusteredArrayVdiskP(k); if(vdiskP == NULL) { msg = "vdisk: "; msg += Utils::int_to_char(tmp,10,(unsigned int*)&k); msg += " in (rg: "; msg += rgName; msg += ", da: "; msg += daName; msg += ") is NULL"; log_error(msg); continue; } vdiskName = vdiskP->getVdiskName(); msg = "Refresh vdisk: "; msg += vdiskName; msg += " in (rg: "; msg += rgName; msg += ", da: "; msg += daName; log_debug(msg); ret = refreshVdisk(vdiskP,clusterid,rgName,daName); if(ret != TEAL_SUCCESS) { msg = "Refresh vdisk: "; msg += vdiskName; msg += " in (rg: "; msg += rgName; msg += ", da: "; msg += daName; msg += ") failed with "; msg += Utils::int_to_char(tmp,10,(unsigned int*)&ret); log_error(msg); } } allDaOK &= strcmp(daP->getDeclusteredNeedsService(),"yes"); // check all DA's status } msg = "Refresh rg: "; msg += rgName; log_debug(msg); ret = refreshRg(rgP, clusterid,allDaOK); if(ret != TEAL_SUCCESS) { msg = "Refresh recovery group: "; msg += rgName; msg += " failed with "; msg += Utils::int_to_char(tmp,10,(unsigned int*)&ret); log_error(msg); } } else { msg = "get DA to refresh DA in RG: "; msg += rgName; msg += " failed with "; msg += Utils::int_to_char(tmp,10,(unsigned int*)&rc); log_warn(msg); continue; } } else { msg = "get RG summary to refresh RG: "; msg += Utils::int_to_char(tmp,10,(unsigned int*)&i); msg += " failed with "; msg += Utils::int_to_char(tmp,10,(unsigned int*)&rc); log_warn(msg); continue; } } } else { log_warn("No recovery group found!"); } } else if(rc == ENODEV) { msg = "No perseus configuration.."; log_info(msg); } else { msg = "Failed to getNsdRAIDSdrInfo with "; msg += Utils::int_to_char(tmp,10,(unsigned int*)&rc); log_warn(msg); } log_info("########################End of refresh all entities#########################################"); return; }
// it is running in decoder thread bool as_netstream::open_stream(const char* c_url) { // This registers all available file formats and codecs // with the library so they will be used automatically when // a file with the corresponding format/codec is opened // Open video file // The last three parameters specify the file format, buffer size and format parameters; // by simply specifying NULL or 0 we ask libavformat to auto-detect the format // and use a default buffer size if (av_open_input_file(&m_FormatCtx, c_url, NULL, 0, NULL) != 0) { // log_error("Couldn't open file '%s'\n", c_url); set_status(error, playStreamNotFound); return false; } // Next, we need to retrieve information about the streams contained in the file // This fills the streams field of the AVFormatContext with valid information if (av_find_stream_info(m_FormatCtx) < 0) { log_error("Couldn't find stream information from '%s'\n", c_url); return false; } // Find the first video & audio stream m_video_index = -1; m_audio_index = -1; for (int i = 0; i < m_FormatCtx->nb_streams; i++) { AVCodecContext* enc = m_FormatCtx->streams[i]->codec; switch (enc->codec_type) { default: break; case CODEC_TYPE_AUDIO: if (m_audio_index < 0) { m_audio_index = i; m_audio_stream = m_FormatCtx->streams[i]; } break; case CODEC_TYPE_VIDEO: if (m_video_index < 0) { m_video_index = i; m_video_stream = m_FormatCtx->streams[i]; } break; case CODEC_TYPE_DATA: case CODEC_TYPE_SUBTITLE: case CODEC_TYPE_UNKNOWN: break; } } if (m_video_index < 0) { log_error("Didn't find a video stream from '%s'\n", c_url); return false; } // Get a pointer to the codec context for the video stream m_VCodecCtx = m_FormatCtx->streams[m_video_index]->codec; // Find the decoder for the video stream AVCodec* pCodec = avcodec_find_decoder(m_VCodecCtx->codec_id); if (pCodec == NULL) { m_VCodecCtx = NULL; log_error("Decoder not found\n"); return false; } // Open codec if (avcodec_open(m_VCodecCtx, pCodec) < 0) { m_VCodecCtx = NULL; log_error("Could not open codec\n"); return false; } if (m_audio_index >= 0 && get_sound_handler() != NULL) { // Get a pointer to the audio codec context for the video stream m_ACodecCtx = m_FormatCtx->streams[m_audio_index]->codec; // Find the decoder for the audio stream AVCodec* pACodec = avcodec_find_decoder(m_ACodecCtx->codec_id); if (pACodec == NULL) { log_error("No available AUDIO decoder to process MPEG file: '%s'\n", c_url); return false; } // Open codec if (avcodec_open(m_ACodecCtx, pACodec) < 0) { log_error("Could not open AUDIO codec\n"); return false; } } m_convert_ctx = sws_getContext( m_VCodecCtx->width, m_VCodecCtx->height, m_VCodecCtx->pix_fmt, m_VCodecCtx->width, m_VCodecCtx->height, PIX_FMT_RGBA32, SWS_BICUBIC, NULL, NULL, NULL); assert(m_convert_ctx); return true; }
static void session_receive_from_backend(EV_P_ session_context *sc) { int ret; packet_data *pd; packet_data temp = { .length = sizeof(temp.payload) }; ret = mbedtls_ssl_read(&sc->ssl, temp.payload, temp.length); switch (ret) { case MBEDTLS_ERR_SSL_WANT_READ: case MBEDTLS_ERR_SSL_WANT_WRITE: case MBEDTLS_ERR_NET_RECV_FAILED: case MBEDTLS_ERR_SSL_TIMEOUT: session_mark_activity(EV_A_ sc); return; case MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY: log_info("(%s:%d) Backend asked to close DTLS session", sc->options->backend_host, sc->options->backend_port); ev_io_start(EV_A_ &sc->backend_wr_watcher); sc->step = GOLDY_SESSION_STEP_FLUSH_TO_CLIENT; return; default: if (ret < 0) { session_deferred_free_after_error(sc, ret, "session_receive_from_backend - unknwon error"); return; } /* ret is the number of plaintext bytes received */ log_debug("(%s:%d) %d bytes read from DTLS socket", sc->options->backend_host, sc->options->backend_port, ret); if (ret > PACKET_DATA_BUFFER_SIZE) { session_deferred_free_after_error(sc, 0, "session_receive_from_backend - packet payload too big"); return; } pd = calloc(1, sizeof(packet_data)); memcpy(pd->payload, temp.payload, ret); pd->length = ret; pd->next = 0; LL_APPEND(sc->from_backend, pd); session_mark_activity(EV_A_ sc); ev_io_start(EV_A_ &sc->client_wr_watcher); return; } } static void session_send_to_client(EV_P_ session_context *sc) { int ret; packet_data* head = sc->from_backend; if (!head) { ev_io_stop(EV_A_ &sc->client_wr_watcher); return; } ret = mbedtls_net_send(&sc->client_fd, head->payload, head->length); if (ret == MBEDTLS_ERR_SSL_WANT_WRITE) { session_mark_activity(EV_A_ sc); return; } if (ret < 0) { session_deferred_free_after_error(sc, ret, "session_send_to_client"); return; } log_debug("(%s:%d) %d bytes sent to client server", sc->client_ip_str, sc->client_port, ret); if ((size_t)ret != head->length) { log_error("Sent only %d bytes out of %d", ret, head->length); } session_mark_activity(EV_A_ sc); LL_DELETE(sc->from_backend, head); free(head); if (!sc->from_backend) { ev_io_stop(EV_A_ &sc->client_wr_watcher); } return; }
static rstatus_t stats_create_buf(struct stats *st) { uint32_t int64_max_digits = 20; /* INT64_MAX = 9223372036854775807 */ uint32_t key_value_extra = 8; /* "key": "value", */ uint32_t pool_extra = 8; /* '"pool_name": { ' + ' }' */ uint32_t server_extra = 8; /* '"server_name": { ' + ' }' */ uint32_t used_cpu_max_digits = 6; /* 100.00 */ size_t size = 0; uint32_t i; ASSERT(st->buf.data == NULL && st->buf.size == 0); /* header */ size += 1; size += st->service_str.len; size += st->service.len; size += key_value_extra; size += st->source_str.len; size += st->source.len; size += key_value_extra; size += st->version_str.len; size += st->version.len; size += key_value_extra; size += st->uptime_str.len; size += int64_max_digits; size += key_value_extra; size += st->timestamp_str.len; size += int64_max_digits; size += key_value_extra; size += st->used_cpu_user_str.len; size += used_cpu_max_digits; size += key_value_extra; size += st->used_cpu_sys_str.len; size += used_cpu_max_digits; size += key_value_extra; size += st->voluntary_switches_str.len; size += int64_max_digits; size += key_value_extra; size += st->involuntary_switches_str.len; size += int64_max_digits; size += key_value_extra; /* server pools */ for (i = 0; i < array_n(&st->sum); i++) { struct stats_pool *stp = array_get(&st->sum, i); uint32_t j; size += stp->name.len; size += pool_extra; for (j = 0; j < array_n(&stp->metric); j++) { struct stats_metric *stm = array_get(&stp->metric, j); size += stm->name.len; size += int64_max_digits; size += key_value_extra; } /* servers per pool */ for (j = 0; j < array_n(&stp->server); j++) { struct stats_server *sts = array_get(&stp->server, j); uint32_t k; size += sts->name.len; size += server_extra; for (k = 0; k < array_n(&sts->metric); k++) { struct stats_metric *stm = array_get(&sts->metric, k); size += stm->name.len; size += int64_max_digits; size += key_value_extra; } } } /* footer */ size += 2; size = NC_ALIGN(size, NC_ALIGNMENT); st->buf.data = nc_alloc(size); if (st->buf.data == NULL) { log_error("create stats buffer of size %zu failed: %s", size, strerror(errno)); return NC_ENOMEM; } st->buf.size = size; log_debug(LOG_DEBUG, "stats buffer size %zu", size); return NC_OK; }