Пример #1
0
static int packed_read_raw_ref(struct ref_store *ref_store,
			       const char *refname, struct object_id *oid,
			       struct strbuf *referent, unsigned int *type)
{
	struct packed_ref_store *refs =
		packed_downcast(ref_store, REF_STORE_READ, "read_raw_ref");
	struct snapshot *snapshot = get_snapshot(refs);
	const char *rec;

	*type = 0;

	rec = find_reference_location(snapshot, refname, 1);

	if (!rec) {
		/* refname is not a packed reference. */
		errno = ENOENT;
		return -1;
	}

	if (get_oid_hex(rec, oid))
		die_invalid_line(refs->path, rec, snapshot->eof - rec);

	*type = REF_ISPACKED;
	return 0;
}
Пример #2
0
ENTRYPOINT void init_antspotlight(ModeInfo *mi)
{
  double rot_speed = 0.3;

  antspotlightstruct *mp;
  
  if(!antspotlight) {
    if((antspotlight = (antspotlightstruct *) 
	calloc(MI_NUM_SCREENS(mi), sizeof (antspotlightstruct))) == NULL)
      return;
  }
  mp = &antspotlight[MI_SCREEN(mi)];
  mp->rot = make_rotator (rot_speed, rot_speed, rot_speed, 1, 0, True);
  mp->trackball = gltrackball_init ();

  if((mp->glx_context = init_GL(mi)) != NULL) {
    reshape_antspotlight(mi, MI_WIDTH(mi), MI_HEIGHT(mi));
    glDrawBuffer(GL_BACK);
    pinit();
  }
  else
    MI_CLEARWINDOW(mi);

  glGenTextures(1, &mp->screentexture);
  glBindTexture(GL_TEXTURE_2D, mp->screentexture);
  get_snapshot(mi);

  build_ant(mp);
  mp->mono = MI_IS_MONO(mi);
  mp->wire = MI_IS_WIREFRAME(mi);
  mp->boardsize = 8.0;
  mp->mag = 1;
}
Пример #3
0
int backtrace_snapshot(int pid, int *tids, int *index, int nr_tids)
{
    int i, rc = 0;
    struct snapshot *snap;

    if ((snap = get_snapshot(pid, tids, index, nr_tids)) == NULL)
        return -1;

    for (i = 0; i < snap->num_threads; ++i) {
        int x;
        char comm[16];
        char end_pad[25] = "------------------------";

        x = get_thread_comm(snap->tids[i], comm, sizeof(comm));
        if (x > 0 && x <= sizeof(end_pad))
        {
            end_pad[sizeof(end_pad) - x] = '\0';
            printf("-------------- thread %d (%d) (%s) %s\n", (index != NULL ? index[i] : i+1), snap->tids[i], comm, end_pad);
        }

        snap->cur_thr = i;
        if (backtrace_thread(&snapshot_addr_space_accessors, snap) < 0)
            rc = -1;
    }

    snapshot_destroy(snap);
    return rc;
}
Пример #4
0
int
main(int argc, char *argv[])
{
	int ii;
	int jj;

#define TXN_COUNT		10000
#define LOOP_COUNT		10
	
	GlobalTransactionId gxid[TXN_COUNT];
	GTM_Conn *conn;
	char connect_string[100];

	sprintf(connect_string, "host=localhost port=6666 node_name=one remote_type=%d", GTM_NODE_COORDINATOR);

	conn = PQconnectGTM(connect_string);
	if (conn == NULL)
	{
		client_log(("Error in connection\n"));
		exit(1);
	}

	for (jj = 0; jj < LOOP_COUNT; jj++)
	{
		for (ii = 0; ii < TXN_COUNT; ii++)
		{
			int kk;
			GTM_Snapshot snapshot;

			gxid[ii] = begin_transaction(conn, GTM_ISOLATION_RC);
			if (gxid[ii] != InvalidGlobalTransactionId)
				client_log(("Started a new transaction (GXID:%u)\n", gxid[ii]));
			else
				client_log(("BEGIN transaction failed for ii=%d\n", ii));
			snapshot = get_snapshot(conn, gxid[ii], true);


			if (ii % 2 == 0)
			{
				if (!abort_transaction(conn, gxid[ii]))
					client_log(("ROLLBACK successful (GXID:%u)\n", gxid[ii]));
				else
					client_log(("ROLLBACK failed (GXID:%u)\n", gxid[ii]));
			}
			else
			{
				if (!commit_transaction(conn, gxid[ii]))
					client_log(("COMMIT successful (GXID:%u)\n", gxid[ii]));
				else
					client_log(("COMMIT failed (GXID:%u)\n", gxid[ii]));
			}
		}
	}

	GTMPQfinish(conn);
	return 0;
}
Пример #5
0
GTM_Snapshot
GetSnapshotGTM(GlobalTransactionId gxid, bool canbe_grouped)
{
	GTM_Snapshot ret_snapshot = NULL;
	CheckConnection();
	if (conn)
		ret_snapshot = get_snapshot(conn, gxid, canbe_grouped);
	if (ret_snapshot == NULL)
	{
		CloseGTM();
		InitGTM();
#ifdef XCP
		if (conn)
			ret_snapshot = get_snapshot(conn, gxid, canbe_grouped);
#endif
	}
	return ret_snapshot;
}
Пример #6
0
//replaces current state with a copy of snapshot
entry* checkout(int id, entry *entryHead, snapshot *snapHead) {
	snapshot *chosenSnap = get_snapshot(snapHead, id);
	
	if (chosenSnap == NULL) {
		printf("no such snapshot\n");
		return entryHead;
	}
	
	printf("ok\n");
	free_entrylist_space(entryHead);
	return get_reversed_entrylist_copy(chosenSnap->entries);
}
Пример #7
0
//removes a snapshot with the given id from the list
snapshot* drop(snapshot *snapHead, int id) {
	snapshot *unwantedSnap = get_snapshot(snapHead, id);
	
	if (unwantedSnap == NULL) {
		printf("no such snapshot\n");
		return snapHead;
	}
	else {
		printf("ok\n");
		return snapshot_delete(snapHead, unwantedSnap);	
	}
}
Пример #8
0
QVariant vogleditor_apiCallTreeItem::columnData(int column, int role) const
{
   if (column >= VOGL_MAX_ACTC)
   {
      return QVariant();
   }

   if (role == Qt::DecorationRole)
   {
       // handle flags
       if (column == VOGL_ACTC_FLAGS)
       {
           if (has_snapshot())
           {
               if (get_snapshot()->is_outdated())
               {
                   // snapshot was dirtied due to an earlier edit
                   return QColor(200, 0, 0);
               }
               else if (get_snapshot()->is_edited())
               {
                   // snapshot has been edited
                   return QColor(200, 102, 0);
               }
               else
               {
                   // snapshot is good
                   return QColor(0, 0, 255);
               }
           }
       }
   }

   if (role == Qt::DisplayRole)
   {
       return m_columnData[column];
   }

   return QVariant();
}
Пример #9
0
static struct ref_iterator *packed_ref_iterator_begin(
		struct ref_store *ref_store,
		const char *prefix, unsigned int flags)
{
	struct packed_ref_store *refs;
	struct snapshot *snapshot;
	const char *start;
	struct packed_ref_iterator *iter;
	struct ref_iterator *ref_iterator;
	unsigned int required_flags = REF_STORE_READ;

	if (!(flags & DO_FOR_EACH_INCLUDE_BROKEN))
		required_flags |= REF_STORE_ODB;
	refs = packed_downcast(ref_store, required_flags, "ref_iterator_begin");

	/*
	 * Note that `get_snapshot()` internally checks whether the
	 * snapshot is up to date with what is on disk, and re-reads
	 * it if not.
	 */
	snapshot = get_snapshot(refs);

	if (!snapshot->buf)
		return empty_ref_iterator_begin();

	iter = xcalloc(1, sizeof(*iter));
	ref_iterator = &iter->base;
	base_ref_iterator_init(ref_iterator, &packed_ref_iterator_vtable, 1);

	iter->snapshot = snapshot;
	acquire_snapshot(snapshot);

	if (prefix && *prefix)
		start = find_reference_location(snapshot, prefix, 0);
	else
		start = snapshot->buf + snapshot->header_len;

	iter->pos = start;
	iter->eof = snapshot->eof;
	strbuf_init(&iter->refname_buf, 0);

	iter->base.oid = &iter->oid;

	iter->flags = flags;

	if (prefix && *prefix)
		/* Stop iteration after we've gone *past* prefix: */
		ref_iterator = prefix_ref_iterator_begin(ref_iterator, prefix, 0);

	return ref_iterator;
}
Пример #10
0
int packed_refs_lock(struct ref_store *ref_store, int flags, struct strbuf *err)
{
	struct packed_ref_store *refs =
		packed_downcast(ref_store, REF_STORE_WRITE | REF_STORE_MAIN,
				"packed_refs_lock");
	static int timeout_configured = 0;
	static int timeout_value = 1000;

	if (!timeout_configured) {
		git_config_get_int("core.packedrefstimeout", &timeout_value);
		timeout_configured = 1;
	}

	/*
	 * Note that we close the lockfile immediately because we
	 * don't write new content to it, but rather to a separate
	 * tempfile.
	 */
	if (hold_lock_file_for_update_timeout(
			    &refs->lock,
			    refs->path,
			    flags, timeout_value) < 0) {
		unable_to_lock_message(refs->path, errno, err);
		return -1;
	}

	if (close_lock_file_gently(&refs->lock)) {
		strbuf_addf(err, "unable to close %s: %s", refs->path, strerror(errno));
		rollback_lock_file(&refs->lock);
		return -1;
	}

	/*
	 * Now that we hold the `packed-refs` lock, make sure that our
	 * snapshot matches the current version of the file. Normally
	 * `get_snapshot()` does that for us, but that function
	 * assumes that when the file is locked, any existing snapshot
	 * is still valid. We've just locked the file, but it might
	 * have changed the moment *before* we locked it.
	 */
	validate_snapshot(refs);

	/*
	 * Now make sure that the packed-refs file as it exists in the
	 * locked state is loaded into the snapshot:
	 */
	get_snapshot(refs);
	return 0;
}
Пример #11
0
//removes all snapshots from the list that were taken after the one with the given id
snapshot* remove_snapshots(int id, snapshot *snapHead) {
	snapshot *chosenSnap = get_snapshot(snapHead, id);
	snapshot *newSnapHead = snapHead;
	if (chosenSnap == NULL) {
		return newSnapHead;	
	}
	
	chosenSnap = chosenSnap->prev;
	while (chosenSnap != NULL) {
		snapshot *temp = chosenSnap->prev;
		newSnapHead = snapshot_delete(newSnapHead, chosenSnap);
		chosenSnap = temp;
	}	
	
	return newSnapHead;
}
Пример #12
0
void
vca_manager::handle_vca_colorfulness ( vca_info& info )
{
    string url = get_mjpeg_url ( *info.device );

    ostringstream cmdline;
    uint16_t httpport = global::config()->get(info.name + ".httpport", 4001);
    cmdline << "vca/vca -i " << url
            << " " << info.params
            << " --httpport " << httpport;

    LOG ( INFO ) << info.name << ": " << cmdline.str();

    redi::ipstream in ( cmdline.str() );
    string line;
    while ( std::getline ( in, line ) )
    {
        auto evt = Q_NEW ( gevt, EVT_VCA_EVENT );
        evt->args.put ( "description", line );
        ptime timestamp ( microsec_clock::universal_time() );
        evt->args.put ( "timestamp", common::get_utc_string ( timestamp ) );

        path local_folder ( global::config()->get ( "vca.snapshot_dir", "snapshots" ) );
        path local_file ( info.name + " " + common::get_utc_string ( timestamp ) + ".jpg" );
        path absolute=operator/ ( local_folder, local_file );
        evt->args.put ( "snapshot_path", absolute.string() );

        ostringstream url;
        url << "http://localhost:" << httpport << "/frame.jpg";

        get_snapshot ( url.str(), absolute );

        this->postFIFO ( evt );
    }

    boost::this_thread::sleep_for ( boost::chrono::seconds ( 3 ) );

    auto evt = Q_NEW ( gevt, EVT_VCA_STOPPED );
    evt->args.put ( "name", info.name );
    this->postFIFO ( evt );

}
Пример #13
0
int backtrace_snapshot(int pid, int *tids, int *index, int nr_tids)
{
    int i, rc = 0;
    struct snapshot *snap;
    
    if ((snap = get_snapshot(pid, tids, index, nr_tids)) == NULL)
        return -1;

    for (i = 0; i < snap->num_threads; ++i) {
        printf("--------------------  thread %d (%d)  --------------------\n",
               (index != NULL ? index[i] : i+1), snap->tids[i]);

        snap->cur_thr = i;
        if (backtrace_thread(&snapshot_addr_space_accessors, snap) < 0)
            rc = -1;
    }

    snapshot_destroy(snap);
    return rc;
}
Пример #14
0
int main(int argc, string argv[])
{
  string *produce, snap_tags[MaxBodyFields], frame_tags[MaxBodyFields];
  snapshot *snaplist = NULL, *ssp, frame = { NULL, 0, 0.0, NULL };
  stream instr, outstr;
  int n, nbody, i;
  bodyptr btab, bp, sp;
  bool roff, voff;

  initparam(argv, defv);
  produce = burststring(getparam("produce"), ", ");
  layout_body(produce, Precision, NDIM);
  instr = stropen(getparam("in"), "r");
  get_history(instr);
  snaplist = ssp = (snapshot *) allocate(sizeof(snapshot));
  n = nbody = 0;
  while (get_snapshot(instr, *ssp, snap_tags, FALSE)) {
    if (! set_equal(snap_tags, produce))
      error("%s: input file lacks required items\n", getprog());
    n++;
    nbody += ssp->nbody;
    get_history(instr);
    ssp->link = (snapshot *) allocate(sizeof(snapshot));
    ssp = ssp->link;
  }
  strclose(instr);
  eprintf("[%s: read %d frames, %d bodies]\n", getprog(), n, nbody);
  if (! strnull(getparam("frame"))) {
    instr = stropen(getparam("frame"), "r");
    get_history(instr);
    if (! get_snapshot(instr, frame, frame_tags, FALSE))
      error("%s: no snapshot in frame file\n", getprog());
    strclose(instr);
    if (frame.nbody < n)
      error("%s: need at least %d points in frame\n", getprog(), n);
  }
  roff = (frame.nbody > 0) && set_member(frame_tags, PosTag);
  voff = (frame.nbody > 0) && set_member(frame_tags, VelTag);
  bp = btab = (bodyptr) allocate(nbody * SizeofBody);
  ssp = snaplist;
  for (i = 0; i < n; i++) {
    sp = ssp->bodies;
    while (sp < NthBody(ssp->bodies, ssp->nbody)) {
      memmove((void *) bp, (void *) sp, (size_t) SizeofBody);
      if (roff) {
	ADDV(Pos(bp), Pos(bp), Pos(NthBody(frame.bodies, i)));
      }
      if (voff) {
	ADDV(Vel(bp), Vel(bp), Vel(NthBody(frame.bodies, i)));
      }
      bp = NextBody(bp);
      sp = NextBody(sp);
    }
    ssp = ssp->link;
  }
  outstr = stropen(getparam("out"), "w");
  put_history(outstr);
  put_snap(outstr, &btab, &nbody, &frame.time, produce);
  strclose(outstr);
  return (0);
}
Пример #15
0
/*
 * Entity (service or instance): If there are -p options,
 * display_{pg,prop}() the named property groups and/or properties.  Otherwise
 * display_pg() all property groups.
 */
static void
process_ent(scf_entityp_t ent)
{
	scf_snapshot_t *snap = NULL;
	scf_propertygroup_t *pg;
	scf_property_t *prop;
	scf_iter_t *iter;
	svcprop_prop_node_t *spn;
	int ret, err;

	if (uu_list_numnodes(prop_list) == 0) {
		if (quiet)
			return;

		if ((pg = scf_pg_create(hndl)) == NULL ||
		    (iter = scf_iter_create(hndl)) == NULL)
			scfdie();

		if (cflag || Cflag || ent.type != ENT_INSTANCE) {
			if (scf_iter_entity_pgs(iter, ent) == -1)
				scfdie();
		} else {
			if (snapshot != NULL)
				snap = get_snapshot(ent.u.inst, snapshot);

			if (scf_iter_instance_pgs_composed(iter, ent.u.inst,
			    snap) == -1)
				scfdie();
			if (snap)
				scf_snapshot_destroy(snap);
		}

		while ((ret = scf_iter_next_pg(iter, pg)) == 1)
			display_pg(pg);
		if (ret == -1)
			scfdie();

		/*
		 * In normal usage, i.e. against the running snapshot,
		 * we must iterate over the current non-persistent
		 * pg's.
		 */
		if (sflag == 0 && snap != NULL) {
			scf_iter_reset(iter);
			if (scf_iter_instance_pgs_composed(iter, ent.u.inst,
			    NULL) == -1)
				scfdie();
			while ((ret = scf_iter_next_pg(iter, pg)) == 1) {
				uint32_t flags;

				if (scf_pg_get_flags(pg, &flags) == -1)
					scfdie();
				if (flags & SCF_PG_FLAG_NONPERSISTENT)
					display_pg(pg);
			}
		}
		if (ret == -1)
			scfdie();

		scf_iter_destroy(iter);
		scf_pg_destroy(pg);

		return;
	}

	if ((pg = scf_pg_create(hndl)) == NULL ||
	    (prop = scf_property_create(hndl)) == NULL)
		scfdie();

	if (ent.type == ENT_INSTANCE && snapshot != NULL)
		snap = get_snapshot(ent.u.inst, snapshot);

	for (spn = uu_list_first(prop_list);
	    spn != NULL;
	    spn = uu_list_next(prop_list, spn)) {
		if (ent.type == ENT_INSTANCE) {
			if (Cflag)
				ret = scf_instance_get_pg(ent.u.inst,
				    spn->spn_comp1, pg);
			else
				ret = scf_instance_get_pg_composed(ent.u.inst,
				    snap, spn->spn_comp1, pg);
			err = scf_error();

			/*
			 * If we didn't find it in the specified snapshot, use
			 * the current values if the pg is nonpersistent.
			 */
			if (ret == -1 && !Cflag &&snap != NULL && err ==
			    SCF_ERROR_NOT_FOUND) {
				ret = scf_instance_get_pg_composed(
				    ent.u.inst, NULL, spn->spn_comp1,
				    pg);

				if (ret == 0) {
					uint32_t flags;

					if (scf_pg_get_flags(pg, &flags) == -1)
						scfdie();
					if ((flags & SCF_PG_FLAG_NONPERSISTENT)
					    == 0) {
						ret = -1;
					}
				}
			}
		} else {
			/*
			 * If we are displaying properties for a service,
			 * treat it as though it were a composed, current
			 * lookup. (implicit cflag) However, if a snapshot
			 * was specified, fail.
			 */
			if (sflag)
				die(gettext("Only instances have "
				    "snapshots.\n"));
			ret = scf_entity_get_pg(ent, spn->spn_comp1, pg);
			err = scf_error();
		}
		if (ret == -1) {
			if (err != SCF_ERROR_NOT_FOUND)
				scfdie();

			if (PRINT_NOPROP_ERRORS) {
				char *buf;

				buf = safe_malloc(max_scf_fmri_length + 1);
				if (scf_entity_to_fmri(ent, buf,
				    max_scf_fmri_length + 1) == -1)
					scfdie();

				uu_warn(gettext("Couldn't find property group "
				    "`%s' for %s `%s'.\n"), spn->spn_comp1,
				    SCF_ENTITY_TYPE_NAME(ent), buf);

				free(buf);
			}

			noprop_common_action();

			continue;
		}

		if (spn->spn_comp2 == NULL) {
			if (!quiet)
				display_pg(pg);
			continue;
		}

		if (scf_pg_get_property(pg, spn->spn_comp2, prop) == -1) {
			if (scf_error() != SCF_ERROR_NOT_FOUND)
				scfdie();

			if (PRINT_NOPROP_ERRORS) {
				char *buf;

				buf = safe_malloc(max_scf_fmri_length + 1);
				if (scf_entity_to_fmri(ent, buf,
				    max_scf_fmri_length + 1) == -1)
					scfdie();

				/* FMRI syntax knowledge */
				uu_warn(gettext("Couldn't find property "
				    "`%s/%s' for %s `%s'.\n"), spn->spn_comp1,
				    spn->spn_comp2, SCF_ENTITY_TYPE_NAME(ent),
				    buf);

				free(buf);
			}

			noprop_common_action();

			continue;
		}

		if (!quiet)
			display_prop(pg, prop);
	}

	scf_property_destroy(prop);
	scf_pg_destroy(pg);
	if (snap)
		scf_snapshot_destroy(snap);
}
Пример #16
0
int
main(int argc, char *argv[])
{
	int ii;
	GlobalTransactionId gxid[4000];
	GTM_Conn *conn;
	char connect_string[100];

	for (ii = 0; ii < 3; ii++)
		fork();

	sprintf(connect_string, "host=localhost port=6666 node_name=one remote_type=%d", GTM_NODE_COORDINATOR);

	conn = PQconnectGTM(connect_string);
	if (conn == NULL)
	{
		client_log(("Error in connection\n"));
		exit(1);
	}

	for (ii = 0; ii < 20; ii++)
	{
		gxid[ii] = begin_transaction(conn, GTM_ISOLATION_RC);
		if (gxid[ii] != InvalidGlobalTransactionId)
			client_log(("Started a new transaction (GXID:%u)\n", gxid[ii]));
		else
			client_log(("BEGIN transaction failed for ii=%d\n", ii));
	}

	for (ii = 0; ii < 5; ii++)
	{
		int jj;
		GTM_Snapshot snapshot = get_snapshot(conn, gxid[ii], true);
		if (snapshot != NULL)
		{
			client_log(("Snapshot: GXID %u, xmin=%u, xmax=%u\n", gxid[ii],
					snapshot->sn_xmin, snapshot->sn_xmax));
			client_log(("xcnt=%d %s", snapshot->sn_xcnt,
					snapshot->sn_xcnt > 0 ? "xip=(" : ""));
			for (jj = 0; jj < snapshot->sn_xcnt; jj++)
				client_log(("%d%c ", snapshot->sn_xip[jj],
						((jj + 1) == snapshot->sn_xcnt) ? ')' : ','));
			client_log(("\n"));
		}
	}

	for (ii = 0; ii < 20; ii++)
	{
		if (!prepare_transaction(conn, gxid[ii]))
			client_log(("PREPARE successful (GXID:%u)\n", gxid[ii]));
		else
			client_log(("PREPARE failed (GXID:%u)\n", gxid[ii]));
	}

	for (ii = 0; ii < 20; ii++)
	{
		if (ii % 2 == 0)
		{
			if (!abort_transaction(conn, gxid[ii]))
				client_log(("ROLLBACK successful (GXID:%u)\n", gxid[ii]));
			else
				client_log(("ROLLBACK failed (GXID:%u)\n", gxid[ii]));
		}
		else
		{
			if (!commit_transaction(conn, gxid[ii]))
				client_log(("COMMIT successful (GXID:%u)\n", gxid[ii]));
			else
				client_log(("COMMIT failed (GXID:%u)\n", gxid[ii]));
		}
	}

	GTMPQfinish(conn);
	return 0;
}