示例#1
0
int
tcsetattr(int fd, int optactions, const struct termios *t)
{
	int n, i;
	char buf[100];

	if(!isptty(fd)) {
		if(!isatty(fd)) {
			errno = ENOTTY;
			return -1;
		} else
			return 0;
	}
	n = sprintf(buf, "IOW %4.4x %4.4x %4.4x %4.4x ",
		t->c_iflag, t->c_oflag, t->c_cflag, t->c_lflag);

	for(i = 0; i < NCCS; i++)
		n += sprintf(buf+n, "%2.2x ", t->c_cc[i]);

	if(_SEEK(fd, -2, 0) != -2) {
		_syserrno();
		return -1;
	}

	n = _WRITE(fd, buf, n);
	if(n < 0) {
		_syserrno();
		return -1;
	}

	return 0;
}
示例#2
0
void
_fdinit(char *s, char *se)
{
	int i, usedproc;
	Fdinfo *fi;
	struct stat sbuf;

	usedproc = 0;
	if(readprocfdinit() == 0)
		usedproc = 1;
else
_WRITE(2, "FAILED\n", 7);
	if(s)
		sfdinit(usedproc, s, se);
	if(!s && !usedproc)
		defaultfdinit();

	for(i = 0; i < OPEN_MAX; i++) {
		fi = &_fdinfo[i];
		if(fi->flags&FD_ISOPEN){
			if(fstat(i, &sbuf) >= 0) {
				fi->uid = sbuf.st_uid;
				fi->gid = sbuf.st_gid;
			}
		}
	}
}
示例#3
0
int
tcsetpgrp(int fd, pid_t pgrpid)
{
	int n;
	char buf[30];

	if(!isptty(fd)) {
		if(!isatty(fd)) {
			errno = ENOTTY;
			return -1;
		} else
			return 0;
	}
	n = sprintf(buf, "IOW note %d", pgrpid);

	if(_SEEK(fd, -2, 0) != -2) {
		_syserrno();
		return -1;
	}

	n = _WRITE(fd, buf, n);
	if(n < 0) {
		_syserrno();
		return -1;
	}
}
示例#4
0
static __inline void
sendMouseEvent(droid_hid *thiz, int *_dat)
{
    x_object *tmp;
    char buf[64];

    TRACE("[GobeeHid] sendMouseEvent()1: this(%p) {%d::%d:%dx%d} EXIT\n",
             thiz,_dat[0],_dat[1],_dat[2],_dat[3]);

    if (!thiz->xobj.write_handler)
    {
        tmp = _CHLD(_PARNT(thiz),"out$media");
        if (!tmp)
        {

            TRACE("No output channel... Decreasing camera status...\n");
            ERROR;
            return;
        }

        tmp = _CHLD(tmp,"101");
        if (!tmp)
        {
            TRACE("No output channel... Decreasing camera status...\n");
            ERROR;
            return;
        }
        else
        {
            thiz->xobj.write_handler = X_OBJECT(tmp);
            _REFGET(thiz->xobj.write_handler);
        }
    }
    else
    {
        TRACE("Handler OK\n");
    }

//    TRACE("[GobeeHid] sendMouseEvent()2: {%d::%d:%dx%d} EXIT\n",
//             _dat[0],_dat[1],_dat[2],_dat[3]);
//
    if (thiz->xobj.write_handler)
      {
        TRACE("[GobeeHid] sendMouseEvent()2: %s, {%d::%d:%dx%d} EXIT\n",
                 _GETNM(thiz->xobj.write_handler),
                 _dat[0],_dat[1],_dat[2],_dat[3]);
          _WRITE(thiz->xobj.write_handler, _dat, 4*sizeof(int), NULL);
      }
    else
      {
        TRACE("[GobeeHid] ERROR!! sendMouseEvent()2: {%d::%d:%dx%d} EXIT\n",
                 _dat[0],_dat[1],_dat[2],_dat[3]);
      }

    TRACE("[GobeeHid] sendMouseEvent()3: {%d::%d:%dx%d} EXIT\n",
             _dat[0],_dat[1],_dat[2],_dat[3]);
}
示例#5
0
static void
__vcam_periodic_cb(struct ev_loop *loop, struct ev_periodic *w, int revents)
{
  int ofd;
  int granule;
  x_object *tmp;
  virtual_camera_t *_vcam = w->data;

  TRACE("\n");

  if (!(granule++ % 200))
    {
//      gobee_theora_resize(cdata->w, cdata->h, cdata->w, sock,
//          (struct sockaddr *) &cli, sizeof(cli));
    }
  if (v4l2_next_frame(_vcam->vfd) == 0)
    {
      if (!_vcam->xobj.write_handler)
        {
          tmp = _CHLD(_PARNT(X_OBJECT(_vcam)), "out$media");
          tmp = _CHLD(tmp,NULL);
          if (!tmp)
            {
              TRACE("No output channel... Decreasing camera status...\n");
              ERROR;
              return;
            }
          else
            {
              _vcam->xobj.write_handler = tmp;
              _REFGET(_vcam->xobj.write_handler);
            }
        }

      /**
       * @todo Make length correct here!!!!
       */
      // convert first
      YUYV_to_i420p(&_vcam->_framebuf[0], &_vcam->framebuf[0], _vcam->w,
          _vcam->h);

      _WRITE(_vcam->xobj.write_handler, _vcam->framebuf, _vcam->w*_vcam->h*3/2,
          NULL);

#ifdef DEBUG
      ofd = open("yuv.out.dump", O_WRONLY | O_APPEND);
      write(ofd,_vcam->_framebuf,_vcam->w*_vcam->h*2);
      close(ofd);
#endif

    }
}
示例#6
0
文件: write.c 项目: 99years/plan9
ssize_t
write(int d, const void *buf, size_t nbytes)
{
	int n;

	if(d<0 || d>=OPEN_MAX || !(_fdinfo[d].flags&FD_ISOPEN)){
		errno = EBADF;
		return -1;
	}
	if(_fdinfo[d].oflags&O_APPEND)
		_SEEK(d, 0, 2);
	n = _WRITE(d, buf, nbytes);
	if(n < 0)
		_syserrno();
	return n;
}
示例#7
0
文件: message.c 项目: biddyweb/xwbot
static void
msg_exit(x_object *o)
{
  x_object *outchan;
  x_object *out;
  x_object *body;
  struct msg_object *msgo = (struct msg_object *) (void *) o;
  ENTER;

  printf("%s:%s():%d\n", __FILE__, __FUNCTION__, __LINE__);

//  x_object_print_path(o, 0);

  body = x_object_get_child(o, "body");

  if (body && msgo->iosession)
    {
      if (body->content.pos)
        {
          TRACE("BODY = %s\n", body->content.cbuf);

          /* now write message out */
          outchan = x_session_channel_open2(X_OBJECT(msgo->iosession), "msg");
          if (outchan)
            {
              TRACE("\n");
              if ((out = _CHLD(outchan, _XS("transport"))))
                {
                  TRACE("%s\n",body->content.cbuf);
                  _WRITE(out, body->content.cbuf, body->content.pos, NULL);
                }
              else
                {
                  TRACE("No output found\n");
                }
            }
          else
            {
              TRACE("No channel found\n");
            }
          x_string_rew(&body->content);
        }
    }

  EXIT;
}
示例#8
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;
}
示例#9
0
文件: rename.c 项目: Earnestly/plan9
int
rename(const char *from, const char *to)
{
	int n;
	char *f, *t;
	Dir *d, nd;

	if(access(to, 0) >= 0){
		if(_REMOVE(to) < 0){
			_syserrno();
			return -1;
		}
	}
	if((d = _dirstat(to)) != nil){
		free(d);
		errno = EEXIST;
		return -1;
	}
	if((d = _dirstat(from)) == nil){
		_syserrno();
		return -1;
	}
	f = strrchr(from, '/');
	t = strrchr(to, '/');
	f = f? f+1 : (char *)from;
	t = t? t+1 : (char *)to;
	n = 0;
	if(f-from==t-to && strncmp(from, to, f-from)==0){
		/* from and to are in same directory (we miss some cases) */
		_nulldir(&nd);
		nd.name = t;
		if(_dirwstat(from, &nd) < 0){
			_syserrno();
			n = -1;
		}
	}else{
		/* different directories: have to copy */
		int ffd, tfd;
		char buf[8192];

		tfd = -1;
		if((ffd = _OPEN(from, 0)) < 0 ||
		   (tfd = _CREATE(to, 1, d->mode)) < 0){
			_CLOSE(ffd);
			_syserrno();
			n = -1;
		}
		while(n>=0 && (n = _READ(ffd, buf, 8192)) > 0)
			if(_WRITE(tfd, buf, n) != n){
				_syserrno();
				n = -1;
			}
		_CLOSE(ffd);
		_CLOSE(tfd);
		if(n>0)
			n = 0;
		if(n == 0) {
			if(_REMOVE(from) < 0){
				_syserrno();
				return -1;
			}
		}
	}
	free(d);
	return n;
}
示例#10
0
文件: execve.c 项目: Earnestly/plan9
int
execve(const char *name, const char *argv[], const char *envp[])
{
	int n, f, i;
	char **e, *ss, *se;
	Fdinfo *fi;
	unsigned long flags;
	char nam[256+5];
	char buf[1000];

	_RFORK(RFCENVG);
	/*
	 * To pass _fdinfo[] across exec, put lines like
	 *   fd flags oflags
	 * in $_fdinfo (for open fd's)
	 */

	f = _CREATE("#e/_fdinfo", OWRITE, 0666);
	ss = buf;
	for(n = 0; n<OPEN_MAX; n++){
		fi = &_fdinfo[n];
		flags = fi->flags;
		if(flags&FD_CLOEXEC){
			_CLOSE(n);
			fi->flags = 0;
			fi->oflags = 0;
		}else if(flags&FD_ISOPEN){
			ss = _ultoa(ss, n);
			*ss++ = ' ';
			ss = _ultoa(ss, flags);
			*ss++ = ' ';
			ss = _ultoa(ss, fi->oflags);
			*ss++ = '\n';
			if(ss-buf < sizeof(buf)-50){
				_WRITE(f, buf, ss-buf);
				ss = buf;
			}
		}
	}
	if(ss > buf)
		_WRITE(f, buf, ss-buf);
	_CLOSE(f);
	/*
	 * To pass _sighdlr[] across exec, set $_sighdlr
	 * to list of blank separated fd's that have
	 * SIG_IGN (the rest will be SIG_DFL).
	 * We write the variable, even if no signals
	 * are ignored, in case the current value of the
	 * variable ignored some.
	 */
	f = _CREATE("#e/_sighdlr", OWRITE, 0666);
	if(f >= 0){
		ss = buf;
		for(i = 0; i <=MAXSIG && ss < &buf[sizeof(buf)]-5; i++) {
			if(_sighdlr[i] == SIG_IGN) {
				ss = _ultoa(ss, i);
				*ss++ = ' ';
			}
		}
		_WRITE(f, buf, ss-buf);
		_CLOSE(f);
	}
	if(envp){
		strcpy(nam, "#e/");
		for(e = (char **)envp; (ss = *e); e++) {
			se = strchr(ss, '=');
			if(!se || ss==se)
				continue;	/* what is name? value? */
			n = se-ss;
			if(n >= sizeof(nam)-3)
				n = sizeof(nam)-3-1;
			memcpy(nam+3, ss, n);
			nam[3+n] = 0;
			f = _CREATE(nam, OWRITE, 0666);
			if(f < 0)
				continue;
			se++; /* past = */
			n = strlen(se);
			/* temporarily decode nulls (see _envsetup()) */
			for(i=0; i < n; i++)
				if(se[i] == 1)
					se[i] = 0;
			_WRITE(f, se, n);
			/* put nulls back */
			for(i=0; i < n; i++)
				if(se[i] == 0)
					se[i] = 1;
			_CLOSE(f);
		}
	}
	n = _EXEC(name, argv);
	_syserrno();
	return n;
}
示例#11
0
int
execve(const char *name, const char *argv[], const char *envp[])
{
	int n, f, i;
	char **e, *ss, *se;
	Fdinfo *fi;
	unsigned long flags;
	char buf[1024];

	_RFORK(RFCENVG);
	/*
	 * To pass _fdinfo[] across exec, put lines like
	 *   fd flags oflags
	 * in $_fdinfo (for open fd's)
	 */

	f = _CREATE("/env/_fdinfo", OWRITE, 0666);
	ss = buf;
	for(i = 0; i<OPEN_MAX; i++){
		if(i == f)
			continue;
		fi = &_fdinfo[i];
		flags = fi->flags;
		if(flags&FD_CLOEXEC){
			_CLOSE(i);
			fi->flags = 0;
			fi->oflags = 0;
		}else if(flags&FD_ISOPEN){
			if(f < 0)
				continue;
			ss = _ultoa(ss, i);
			*ss++ = ' ';
			ss = _ultoa(ss, flags);
			*ss++ = ' ';
			ss = _ultoa(ss, fi->oflags);
			*ss++ = '\n';
			n = ss-buf;
			if(n > sizeof(buf)-50){
				if(_WRITE(f, buf, n) != n)
					break;
				ss = buf;
			}
		}
	}
	if(f >= 0){
		if(ss > buf)
			_WRITE(f, buf, ss-buf);
		_CLOSE(f);
	}

	/*
	 * To pass _sighdlr[] across exec, set $_sighdlr
	 * to list of blank separated fd's that have
	 * SIG_IGN (the rest will be SIG_DFL).
	 * We write the variable, even if no signals
	 * are ignored, in case the current value of the
	 * variable ignored some.
	 */
	f = _CREATE("/env/_sighdlr", OWRITE, 0666);
	if(f >= 0){
		ss = buf;
		for(i = 0; i <=MAXSIG; i++) {
			if(_sighdlr[i] == SIG_IGN) {
				ss = _ultoa(ss, i);
				*ss++ = ' ';
				n = ss-buf;
				if(n > sizeof(buf)-20){
					if(_WRITE(f, buf, n) != n)
						break;
					ss = buf;
				}
			}
		}
		if(ss > buf)
			_WRITE(f, buf, ss-buf);
		_CLOSE(f);
	}
	if(envp){
		for(e = envp; (ss = *e); e++) {
			se = strchr(ss, '=');
			if(!se || ss==se)
				continue;	/* what is name? value? */
			n = se-ss;
			if(n >= sizeof(buf)-5)
				continue;	/* name too long */
			strcpy(buf, "/env/");
			memcpy(buf+5, ss, n);
			buf[5+n] = 0;
			f = _CREATE(buf, OWRITE, 0666);
			if(f < 0)
				continue;
			ss = ++se;	/* past = */
			se += strlen(ss);
			while((n = (se - ss)) > 0){
				if(n > sizeof(buf))
					n = sizeof(buf);
				/* decode nulls (see _envsetup()) */
				for(i=0; i<n; i++)
					if((buf[i] = ss[i]) == 1)
						buf[i] = 0;
				if(_WRITE(f, buf, n) != n)
					break;
				ss += n;
			}
			_CLOSE(f);
		}
	}
	n = _EXEC(name, argv);
	_syserrno();
	return n;
}