示例#1
0
int
urlopen(Url *u)
{
	char buf[BUFSIZE];
	int cfd, fd, conn, n;

	urlconvience(u);
	snprint(buf, sizeof(buf), "%s/clone", webmountpt);
	cfd = open(buf, ORDWR);
	if(cfd < 0)
		error("can't open clone file");

	n = read(cfd, buf, sizeof(buf)-1);
	if(n <= 0)
		error("reading clone");

	buf[n] = '\0';
	conn = atoi(buf);

	snprint(buf, sizeof(buf), "url %S", u->src.r);
	if(write(cfd, buf, strlen(buf)) < 0){
//		fprint(2, "write: %s: %r\n", buf);
    Err:
		close(cfd);
		return -1;
	}
	if(u->method==HPost && u->post.r != nil){
		snprint(buf, sizeof(buf), "%s/%d/postbody", webmountpt, conn);
		fd = open(buf, OWRITE);
		if(fd < 0){
//			fprint(2, "urlopen: bad query: %s: %r\n", buf);
			goto Err;
		}
		snprint(buf, sizeof(buf), "%S", u->post.r);
		if(write(fd, buf, strlen(buf)) < 0)
			fprint(2, "urlopen: bad query: %s: %r\n", buf);

		close(fd);
	}
	snprint(buf, sizeof(buf), "%s/%d/body", webmountpt, conn);
	fd = open(buf, OREAD);
	if(fd < 0){
//		fprint(2, "open: %S: %r\n", u->src.r);
		goto Err;
	}
	u->ctype = getattr(conn, "contenttype");
	u->act = getattr(conn, "parsed/url");
	if(u->act.nr == 0)
		copyrunestr(&u->act, &u->src);
	close(cfd);
	return fd;
}
extent_protocol::status
extent_client::get(extent_protocol::extentid_t eid, std::string &buf) {
    decltype(cache_.begin()) iter;
    {
        std::unique_lock<std::mutex> m_(cache_mtx_);
        iter = cache_.find(eid);
        if (cache_.end() != iter && (iter->second.status == extent_protocol::ALL_CACHED) ) {
            buf = iter->second.buf;
            iter->second.attr.atime = std::time(nullptr);
            return extent_protocol::OK;
        }
    }

    cl->call(extent_protocol::get, eid, buf);

    {
        extent_protocol::attr attr;
        getattr(eid, attr);
        std::unique_lock<std::mutex> m_(cache_mtx_);
        if (cache_.end() != iter) {
            iter->second.buf = buf;
            iter->second.attr.atime = std::time(nullptr);
            iter->second.status = extent_protocol::ALL_CACHED;
        } else {
            cache_[eid] = {eid, attr, buf, false, extent_protocol::ALL_CACHED};
        }

    }


    return extent_protocol::OK;
}
示例#3
0
int CassandraFS::unlink(const char* path) {
    struct stat stat;
    struct cfs_attrs cfs_attrs;
    int attr_err = getattr(path, &stat, &cfs_attrs);

    if (attr_err) {
        return attr_err;
    }
    
    CassandraFutureSpool *spool = new CassandraFutureSpool(4);

    spool->append(remove_entry(path));
    spool->append(remove_sub_entry(path));
    spool->append(remove_sub_entries(path));
    
    if (!S_ISDIR(stat.st_mode)) {
        remove_physical_file(&stat, &cfs_attrs, spool);
    }

    spool->wait_all();
    int errors = spool->get_errors();
    delete spool;
    
    if (errors > 0) {
        return -EIO;
    }
    
    return 0;
}
char *OS_initialize() {

	struct CuAt* odm_object;
	int num_fetched;

	/* get the number of processors online */
	ncpus = sysconf(_SC_NPROCESSORS_ONLN);
	if( ncpus == -1 ) {		/* sysconf error */
		ncpus = 1;
	}

	/* get the page size in bytes */
	pagesize = getpagesize();

	/* get the amount of physical memory */
	if( 0 != odm_initialize() ) {
		/* fprintf(stderr, "cannot initialize ODM in Proc::ProcessTable::OS_initialize (AIX)!\n"); */
		ppt_warn("cannot initialize ODM in Proc::ProcessTable::OS_initialize (AIX)!");
	} else {
		odm_object = (struct CuAt*)getattr("sys0", "realmem", 0, &num_fetched);
		memory = strtoull(odm_object->value, 0, 10);
		odm_terminate();
	}

    memory = memory * 1024;

	return NULL;

}
示例#5
0
文件: console.c 项目: takuto-h/ruby
static int
set_ttymode(int fd, conmode *t, void (*setter)(conmode *, void *), void *arg)
{
    conmode r;
    if (!getattr(fd, t)) return 0;
    r = *t;
    setter(&r, arg);
    return setattr(fd, &r);
}
示例#6
0
boost::python::object PythonConfig::getattr(const boost::python::object &obj, const std::string &name, const bool abortOnNull)
{
	boost::python::object result = getattr(obj, name);
	if ((result.ptr() == Py_None) && abortOnNull)
	{
		std::cerr << "Error while accessing object '" << name << "'" << std::endl;
		exit(1);
	}
	return result;
}
示例#7
0
extern "C" PyObject* PyObject_GetAttrString(PyObject* o, const char* attr) {
    // TODO do something like this?  not sure if this is safe; will people expect that calling into a known function
    // won't end up doing a GIL check?
    // threading::GLDemoteRegion _gil_demote;

    try {
        return getattr(o, attr);
    } catch (Box* b) {
        Py_FatalError("unimplemented");
    }
}
示例#8
0
extern "C" PyObject* PyObject_GetAttrString(PyObject* o, const char* attr) noexcept {
    // TODO do something like this?  not sure if this is safe; will people expect that calling into a known function
    // won't end up doing a GIL check?
    // threading::GLDemoteRegion _gil_demote;

    try {
        return getattr(o, attr);
    } catch (ExcInfo e) {
        setCAPIException(e);
        return NULL;
    }
}
示例#9
0
int posixemu_access(const char *name, int mode)
{
	DWORD attr;

	if ((attr = getattr((char *) name,NULL,NULL)) == (DWORD)~0) return -1;

	if (attr & FILE_ATTRIBUTE_READONLY && (mode & W_OK)) {
		lasterror = ERROR_ACCESS_DENIED;
		return -1;
	}
	else return 0;
}
示例#10
0
文件: bind.c 项目: biddyweb/xwbot
/* matching function */
static BOOL
bind_match(x_object *o, x_obj_attr_t *_o)
{
  const char *xmlns;
  ENTER;

  xmlns = getattr("xmlns", _o);
  if (xmlns && EQ(xmlns,"urn:ietf:params:xml:ns:xmpp-bind"))
    return TRUE;
  else
    return FALSE;
}
示例#11
0
文件: console.c 项目: takuto-h/ruby
/*
 * call-seq:
 *   io.echo?       -> true or false
 *
 * Returns +true+ if echo back is enabled.
 *
 * You must require 'io/console' to use this method.
 */
static VALUE
console_echo_p(VALUE io)
{
    conmode t;
    rb_io_t *fptr;
    int fd;

    GetOpenFile(io, fptr);
    fd = GetReadFD(fptr);
    if (!getattr(fd, &t)) rb_sys_fail(0);
    return echo_p(&t) ? Qtrue : Qfalse;
}
示例#12
0
extern "C" PyObject* PyObject_GetAttr(PyObject* o, PyObject* attr_name) {
    if (!isSubclass(attr_name->cls, str_cls)) {
        PyErr_Format(PyExc_TypeError, "attribute name must be string, not '%.200s'", Py_TYPE(attr_name)->tp_name);
        return NULL;
    }

    try {
        return getattr(o, static_cast<BoxedString*>(attr_name)->s.c_str());
    } catch (Box* b) {
        Py_FatalError("unimplemented");
    }
}
示例#13
0
boost::python::object PythonConfig::getattr(const boost::python::object &obj, const std::string &name)
{
	if (in('.', name))
	{
		std::vector<std::string> tmp = split(name, ".", 1);
		return getattr(getattr(obj, tmp[0]), tmp[1]);
	}
	else
	{
		try
		{
			if (name == "")
				return obj;
			return obj.attr(boost::python::str(name));
		}
		catch(boost::python::error_already_set const &)
		{
			PyErr_Clear();
			return boost::python::object();
		}
	}
}
示例#14
0
文件: cmdapi.cpp 项目: biddyweb/xwbot
int
xcmdapi::equals(x_obj_attr_t *_o)
{
    const char *xmlns;
    ENTER;

    xmlns = getattr((KEY) "xmlns", _o);

    if ((x_strncasecmp(xmlns, xcmdapi::cmdXmlns, strlen(xcmdapi::cmdXmlns)) == 0))
        return (int) true;
    else
        return (int) false;
}
示例#15
0
文件: sem.c 项目: ajinkya93/OpenBSD
/*
 * Define a device.  This may (or may not) also define an interface
 * attribute and/or refer to existing attributes.
 */
void
defdev(struct devbase *dev, int ispseudo, struct nvlist *loclist,
    struct nvlist *attrs)
{
	struct nvlist *nv;
	struct attr *a;

	if (dev == &errdev)
		goto bad;
	if (dev->d_isdef) {
		error("redefinition of `%s'", dev->d_name);
		goto bad;
	}
	dev->d_isdef = 1;
	if (has_errobj(attrs, &errattr))
		goto bad;

	/*
	 * Handle implicit attribute definition from locator list.  Do
	 * this before scanning the `at' list so that we can have, e.g.:
	 *	device foo at other, foo { slot = -1 }
	 * (where you can plug in a foo-bus extender to a foo-bus).
	 */
	if (loclist != NULL) {
		nv = loclist;
		loclist = NULL;	/* defattr disposes of them for us */
		if (defattr(dev->d_name, nv))
			goto bad;
		attrs = newnv(dev->d_name, NULL, getattr(dev->d_name), 0,
		    attrs);
	}

	/* Committed!  Set up fields. */
	dev->d_ispseudo = ispseudo;
	dev->d_attrs = attrs;

	/*
	 * For each interface attribute this device refers to, add this
	 * device to its reference list.  This makes, e.g., finding all
	 * "scsi"s easier.
	 */
	for (nv = attrs; nv != NULL; nv = nv->nv_next) {
		a = nv->nv_ptr;
		if (a->a_iattr)
			a->a_refs = addtoattr(a->a_refs, dev);
	}
	return;
bad:
	nvfreel(loclist);
	nvfreel(attrs);
}
示例#16
0
void PythonConfig::loadConfig(const std::string &filename)
{
	try
	{
		exec_file(boost::python::str(filename), main_namespace);
	}
	catch(boost::python::error_already_set const &)
	{
		std::cerr << "Error while parsing config file: " << filename << std::endl;
		PyErr_Print();
		exit(1);
	}
	config = getattr(main_module, "config", true);
}
示例#17
0
std::vector<std::string> PythonConfig::dir(const std::string &name, const bool hide)
{
	boost::python::dict locals;
	locals["__introspection"] = getattr(config, name);
	boost::python::list tmp(eval("dir(__introspection)", main_namespace, locals));
	std::vector<std::string> result;
	for (int i = 0; i < len(tmp); ++i)
	{
		std::string item = boost::python::extract<std::string>(tmp[i]);
		if ((!startswith(item, "__")) || (!hide))
			result.push_back(item);
	}
	return result;
}
示例#18
0
文件: console.c 项目: takuto-h/ruby
/*
 * call-seq:
 *   io.cooked!
 *
 * Enables cooked mode.
 *
 * If the terminal mode needs to be back, use io.cooked { ... }.
 *
 * You must require 'io/console' to use this method.
 */
static VALUE
console_set_cooked(VALUE io)
{
    conmode t;
    rb_io_t *fptr;
    int fd;

    GetOpenFile(io, fptr);
    fd = GetReadFD(fptr);
    if (!getattr(fd, &t)) rb_sys_fail(0);
    set_cookedmode(&t, NULL);
    if (!setattr(fd, &t)) rb_sys_fail(0);
    return io;
}
示例#19
0
文件: console.c 项目: takuto-h/ruby
/*
 * call-seq:
 *   io.raw!(min: nil, time: nil)
 *
 * Enables raw mode.
 *
 * If the terminal mode needs to be back, use io.raw { ... }.
 *
 * You must require 'io/console' to use this method.
 */
static VALUE
console_set_raw(int argc, VALUE *argv, VALUE io)
{
    conmode t;
    rb_io_t *fptr;
    int fd;
    rawmode_arg_t opts, *optp = rawmode_opt(argc, argv, &opts);

    GetOpenFile(io, fptr);
    fd = GetReadFD(fptr);
    if (!getattr(fd, &t)) rb_sys_fail(0);
    set_rawmode(&t, optp);
    if (!setattr(fd, &t)) rb_sys_fail(0);
    return io;
}
示例#20
0
文件: console.c 项目: takuto-h/ruby
/*
 * call-seq:
 *   io.echo = flag
 *
 * Enables/disables echo back.
 * On some platforms, all combinations of this flags and raw/cooked
 * mode may not be valid.
 *
 * You must require 'io/console' to use this method.
 */
static VALUE
console_set_echo(VALUE io, VALUE f)
{
    conmode t;
    rb_io_t *fptr;
    int fd;

    GetOpenFile(io, fptr);
    fd = GetReadFD(fptr);
    if (!getattr(fd, &t)) rb_sys_fail(0);
    if (RTEST(f))
	set_echo(&t, NULL);
    else
	set_noecho(&t, NULL);
    if (!setattr(fd, &t)) rb_sys_fail(0);
    return io;
}
示例#21
0
文件: message.c 项目: biddyweb/xwbot
/** matching function */
static BOOL
msg_match(x_object *o, x_obj_attr_t *attrs)
{
  const char *from1, *from2;
  ENTER;

  from1 = getattr("from", attrs);
  from2 = x_object_getattr(o, "from");

  if (((from1 && from2) && !EQ(from1,from2)) || !(from1 && from2))
    {
      TRACE("FAIL: %s != %s, EXIT\n", from1, from2);
      return FALSE;
    }

  return TRUE;
}
示例#22
0
文件: cmdapi.cpp 项目: biddyweb/xwbot
int
xcmdapi::classmatch(x_obj_attr_t *attrs)
{
    const char *node;
    ENTER;
    if (attrs)
    {
        node = getattr((KEY) "node", attrs);
        if (node && EQ(node,xcmdapi::cmdName))
        {
            TRACE("OK. %s\n", node);
            return (int) true;
        }
    }
    EXIT;
    return (int) false;
}
示例#23
0
char* OS_initialize() {
  
  struct CuAt*      obj;
  int               how_many;
  

  Sysmem = 0;

  /*
   * Get the real memory size via ODM
   *
   */


  if (odm_initialize() == 0) {
    obj = (struct CuAt*)getattr ("sys0", "realmem", 0, &how_many);
    Sysmem = strtoull(obj->value, 0, 10);
    odm_terminate();
  }

  else {
    printf("BIG PROLEM !\n");
  }
  
  Sysmem = Sysmem * 1024;
  
  /*
   * Get The number of processors
   *
   */
   ProcessNumber = sysconf(_SC_NPROCESSORS_ONLN);
   if ( ProcessNumber == -1 ) {
     ProcessNumber = 1;
   }


  /*
   * Get the page size in bytes
   *
   */
  
  PageSize = getpagesize();
  
  return NULL;
}
示例#24
0
int posixemu_stat (const TCHAR *name, struct _stat64 *statbuf)
{
	DWORD attr;
	FILETIME ft, lft;

	if ((attr = getattr (name, &ft, &statbuf->st_size)) == (DWORD)~0) {
		return -1;
	} else {
		statbuf->st_mode = (attr & FILE_ATTRIBUTE_READONLY) ? FILEFLAG_READ : FILEFLAG_READ | FILEFLAG_WRITE;
		if (attr & FILE_ATTRIBUTE_ARCHIVE)
			statbuf->st_mode |= FILEFLAG_ARCHIVE;
		if (attr & FILE_ATTRIBUTE_DIRECTORY)
			statbuf->st_mode |= FILEFLAG_DIR;
		FileTimeToLocalFileTime (&ft,&lft);
		statbuf->st_mtime = (long)((*(__int64 *)&lft-((__int64)(369*365+89)*(__int64)(24*60*60)*(__int64)10000000))/(__int64)10000000);
	}
	return 0;
}
示例#25
0
文件: algo.c 项目: xieran1988/asys2
void decl_var_float(const char *name, float *p, float min, float max)
{
	if (mode == 'w') {
		startnode("float");
		attr("name", "%s", name);
		attr("max", "%f", max);
		attr("min", "%f", min);
		attr("val", "%f", *p);
		endnode();
	}
	if (mode == 'r' && 
			nodeis("float") && attris("name", name)) 
	{
		float v;
		if (getattr("val", "%f", &v) && 
				v >= min && v <= max) 
			*p = v;
	}
}
示例#26
0
static int
inbandshell_t_try_write(x_object *thiz_, void *buf, u_int32_t len,
                        x_obj_attr_t *attr)
{
    int err = -1;
    x_string_t xs;
    x_object *msg;
    x_object *tmp;
//    shell_transport_t *thiz = (shell_transport_t *) (void*) thiz_;

    if (attr)
        xs = getattr("iotype",attr);

    if(xs && EQ(xs,"out"))
    {
        TRACE("write in: %s\n", (char *)buf);
        msg = _GNEW("$message",NULL);
        x_object_set_content(msg, buf, len);
        _MCAST(thiz_,msg);
        _REFPUT(msg,NULL);
    }
    else
    {
        TRACE("write out: %s\n", (char *)buf);
        if (!thiz_->write_handler)
        {
            tmp = _CHLD(_PARNT(X_OBJECT(thiz_)), MEDIA_IN_CLASS_STR);
            thiz_->write_handler = tmp;
            if (!thiz_->write_handler)
            {
                TRACE("No valid media was found\n");
                ERROR;
                return -1;
            }
            else
            {
                _REFGET(thiz_->write_handler);
            }
        }
        err = _WRITE(thiz_->write_handler,buf,len,attr);
    }
    return err;
}
示例#27
0
文件: streams.c 项目: biddyweb/xwbot
static BOOL
iostream_equals(x_object *chan, x_obj_attr_t *attrs)
{
    const char *nama, *namo;
    ENTER;

    if (!attrs)
        return FALSE;

    nama = getattr("name", attrs);
    namo = _AGET(chan, "name");

    if ((nama && namo && NEQ(nama,namo)) || ((nama || namo) && !(nama && namo)))
    {
        TRACE("EXIT Not EQUAL '%s'!='%s'\n", nama, namo);
        return FALSE;
    }

    return TRUE;
}
示例#28
0
int CassandraFS::truncate(const char* path, off_t size) {
    CassStatement* statement = NULL;
    struct stat stat;
    struct cfs_attrs cfs_attrs;
    CassandraFutureSpool* spool = new CassandraFutureSpool(4);
    
    int err = getattr(path, &stat, &cfs_attrs);

    if (err != 0) {
        return -EIO;
    }

    statement = cass_statement_new("UPDATE physical_files SET size = ? WHERE id = ?", 2);
    cass_statement_bind_int64(statement, 0, size);
    cass_statement_bind_uuid(statement, 1, cfs_attrs.physical_file_id);
    spool->append(cass_session_execute(ctxt->session, statement));
    cass_statement_free(statement);
    
    off_t current_size = stat.st_size;
    int current_blocks = blocks_needed(current_size, cfs_attrs.block_size);
    int needed_blocks = blocks_needed(size, cfs_attrs.block_size);
    
    for (int a = needed_blocks; a<current_blocks; a++) {
        spool->append(delete_file_block(&stat, &cfs_attrs, a));
    }

    if (size % cfs_attrs.block_size > 0) {
        spool->append(truncate_block(&stat, &cfs_attrs, needed_blocks-1, size % cfs_attrs.block_size));
    }
    
    spool->wait_all();
    int errors = spool->get_errors();
    delete spool;
    
    if (errors>0) {
        return -EIO;
    }

    return 0;
}
 void
 configure(const tendrils& p, const tendrils& in, const tendrils& out)
 {
   ECTO_SCOPED_CALLPYTHON();
   bp::object subs = p.get<bp::object>("baggers");
   bp::list l = bp::dict(subs).items();
   for (int j = 0; j < bp::len(l); ++j)
   {
     bp::object key = l[j][0];
     bp::object value = l[j][1];
     std::string keystring = bp::extract<std::string>(key);
     bp::object cell_impl = getattr(value, "__impl");
     ecto::cell::ptr cell = bp::extract<ecto::cell::ptr>(cell_impl);
     std::string topic;
     cell->parameters["topic_name"] >> topic;
     Bagger_base::ptr bagger;
     cell->parameters["bagger"] >> bagger;
     topics_.push_back(topic);
     baggers_[topic] = std::make_pair(keystring, bagger);
   }
   p["bag"]->set_callback<std::string>(boost::bind(&BagReader::on_bag_name_change, this, _1));
 }
示例#30
0
int posixemu_stat(const char *name, struct stat *statbuf)
{
	char buf[1024];
	DWORD attr;
	FILETIME ft, lft;

	fname_atow(name,buf,sizeof buf);

	if ((attr = getattr(buf,&ft,(size_t*)&statbuf->st_size)) == (DWORD)~0)
	{
		lasterror = GetLastError();
		return -1;
	}
	else
	{
        statbuf->st_mode = (attr & FILE_ATTRIBUTE_READONLY) ? FILEFLAG_READ: FILEFLAG_READ | FILEFLAG_WRITE;
		if (attr & FILE_ATTRIBUTE_ARCHIVE) statbuf->st_mode |= FILEFLAG_ARCHIVE;
		if (attr & FILE_ATTRIBUTE_DIRECTORY) statbuf->st_mode |= FILEFLAG_DIR;
		FileTimeToLocalFileTime(&ft,&lft);
		statbuf->st_mtime = (*(__int64 *)&lft-((__int64)(369*365+89)*(__int64)(24*60*60)*(__int64)10000000))/(__int64)10000000;
	}

	return 0;
}