Exemplo n.º 1
0
//******************************************************************************
//*preclone stuff (if too much, will go away in another source file)
//*fds mapping:
//* - 0 connexion socket
//* - 1 connexion socket
//* - 2 parent stderr
//* - 3 epoll
//* - 4 signalfd fd
//* - 5 parent unix socket for receiving connexion socket
//******************************************************************************
static void preclone_sigs_setup(void)
{
  //cannot change SIGKILL, neither SIGSTOP
  ul mask=(~0);
  l r=rt_sigprocmask(SIG_BLOCK,&mask,0,sizeof(mask));
  if(ISERR(r)){
    PERR("FATAL:child:preclone:%d:error blocking mostly all signals (%ld)\n",
                                                               preclone_slot,r);
    exit(-1);
  }

  mask=SIGBIT(SIGTERM);
  i sigs_fd=(i)signalfd4(-1,&mask,sizeof(mask),SFD_NONBLOCK);
  if(ISERR(r)){
    PERR("FATAL:child:preclone:%d:error setting up fd for signals (%d)\n",
                                                         preclone_slot,sigs_fd);
    exit(-1);
  }

  if(sigs_fd!=4){//moving signalfd fd to 4, if required
    r=dup2(sigs_fd,4);
    if(ISERR(r)){
      PERR("FATAL:child:preclone:%d:unable to move signalfd fd (%ld)\n",
                                                               preclone_slot,r);
      exit(-1);
    }
    do r=close(sigs_fd); while(r==-EINTR);
  }
}
Exemplo n.º 2
0
static void srv_sock_create(void)
{
  //TCP on IPv4... erk!
  srv_sock=(i)socket(PF_INET,SOCK_STREAM|SOCK_NONBLOCK,0);
  if(ISERR(srv_sock)){
    PERR("FATAL:unable to create the server listening socket:%d\n",srv_sock);
    kill(0,SIGTERM);
    exit(-1);
  }

  l bool_true=1;
  l r=setsockopt(srv_sock,SOL_SOCKET,SO_REUSEADDR,&bool_true,sizeof(bool_true));
  if(ISERR(r)){
    PERR("FATAL:unable to turn on socket rebinding option:%ld\n",r);
    kill(0,SIGTERM);
    exit(-1);
  }

  r=bind(srv_sock,&srv_addr,sizeof(srv_addr));
  if(ISERR(r)){
    PERR("FATAL:unable to bind address/port on server listening socket:%ld\n",r);
    kill(0,SIGTERM);
    exit(-1);
  }

  r=listen(srv_sock,0);
  if(ISERR(r)){
    PERR("FATAL:unable to flag server listening socket:%ld\n",r);
    kill(0,SIGTERM);
    exit(-1);
  }
}
Exemplo n.º 3
0
Arquivo: match.c Projeto: sylware/lwl
//based on the ep type, we may need to book enough room to put a worst case
//scenario of a concatenated sub-p with the ep p rem
static s8 ep_p_new(struct ep *ep,void *p_str,u64 p_sz)
{
  //We will do some p concatenation for the following p types. Then book room
  //for the worst case scenario.
  u64 str_sz=ep->type=='?'||ep->type=='@'?ep->full_p_sz:p_sz;

  l addr;
  u64 map_sz;
  if(!ep->ps){//first allocation
    map_sz=sizeof(*ep->ps)+str_sz+1;//count the 0 terminating char
    addr=mmap(map_sz,RD|WR,PRIVATE|ANONYMOUS);
    if(!addr||ISERR(addr)) return ERR_NOMEM;

    ep->last=0;
  }else{
    u64 new_p_sz=sizeof(*ep->ps)+str_sz+1;//count the 0 terminating char
    map_sz=ep->sz+new_p_sz;
    addr=mremap(ep->ps,ep->sz,map_sz);
    if(!addr||ISERR(addr)) return ERR_NOMEM;//ep is unmapped elsewhere

    struct p *p_last=(struct p*)((u8*)(ep->ps)+ep->last);
    ep->last+=sizeof(*p_last)+p_last->sz+1;//count the 0 terminating char
  }
  ep->ps=(struct p*)addr;
  ep->sz=map_sz;
  struct p *p=(struct p*)((u8*)(ep->ps)+ep->last);
  p->sz=str_sz;
  memcpy(&p->str[0],p_str,p_sz);//copy only p_sz chars
  p->str[p_sz]=0;//set the 0 terminating char
  return OK;
}
Exemplo n.º 4
0
static void channel_update (channel_t *c)
{
    DEBUG("   %s %x/%x/%x (%d) %s", c->which, c->status, c->flags, c->events, count_epoll, __FUNCTION__);
    ASSERT(!ISLISTED(c));

    channel_patch(c);
    channel_patch(c->peer);
    if (ISSHUT(c) && ISSHUT(c->peer))
        return tunnel_release(c->tunnel);
    if (ISERR(c))
        return tunnel_abort(c->tunnel, "Peer error: %s", c->which);
    if (ISERR(c->peer))
        return tunnel_abort(c->tunnel, "Peer error: %s", c->which);

    uint32_t evt = channel_events(c);
    if (c->events & BOTH) {
        c->events = evt;
        c->flags = SETACT(c->flags) & ~FLAG_ACTIVITY;
        PREPEND_STRUCT(ACTIVE_STRUCT_NAME(channel_t),c);
    } else
        channel_rearm(c, evt);

    DEBUG("   %s %x/%x/%x DONE (%d) %s", c->which, c->status, c->flags, c->events, count_epoll, __FUNCTION__);
    channel_update_listed(c->peer);
}
Exemplo n.º 5
0
//XXX:carefull, the dentry type is not supported by all fs
static void dir_parse(i parent_fd)
{
  ++depth;
  u8 dirents[DIRENTS_BUF_SZ];
  while(1){
    l r=getdents64(parent_fd,dirents,DIRENTS_BUF_SZ);
    if(ISERR(r)){
      PERR("ERROR(%ld):getdents error\n",r);
      exit(-1);
    }
    if(!r) break;
    l j=0;
    while(j<r){
      struct dirent64 *d=(struct dirent64*)(dirents+j);

      dout(d);

      if(d->type==DT_DIR&&!is_current(d->name)&&!is_parent(d->name)){
        i dir_fd;
        do
          dir_fd=(i)openat(parent_fd,d->name,RDONLY|NONBLOCK);
        while(dir_fd==-EINTR);
        if(ISERR(dir_fd))
          PERR("ERROR(%d):unable to open subdir:%s\n",dir_fd,d->name);
        else{
          dir_parse(dir_fd);
          l r1;
          do r1=close(dir_fd); while(r1==-EINTR);
        }
      }
      j+=d->rec_len;
    }
  }
  depth--;
}
Exemplo n.º 6
0
Arquivo: dce.c Projeto: sylware/lwl
s8 dce_mode_program(s32 output_name)
{
  struct output *o=&registry[output_name].output;
  void *sysname=(void*)udev_device_get_sysname(o->d);

  //----------------------------------------------------------------------------
  //alloc a properly sized double buffered frame buffer
  o->fb.align=PAGE_SZ;//align on a cpu memory page
  u64 sz=2*(o->current->h*o->current->v*alga_pixel_fmts_sz[o->pixel_fmt]);
  o->fb.sz=sz;
  ul req=IOWR('d',SI_MEM_ALLOC,o->fb);
  l r=ioctl(o->fd,req,(l)&o->fb);
  if(ISERR(r)){
    PERR("output:%s:dce:unable to allocate proper vram for a frame buffer of"
                                         " size %llu bytes\n",sysname,o->fb.sz);
    goto err;
  }

  LOG("output:%s:dce:double buffered frame buffer of %llu bytes allocated\n",
                                                                    sysname,sz);
  //----------------------------------------------------------------------------

  //----------------------------------------------------------------------------
  //program synchronously the video mode
  struct si_dce_dp_set dp_set;
  dp_set.idx=o->blk_idx;
  dp_set.primary=o->fb.gpu_addr;
  dp_set.secondary=o->fb.gpu_addr+sz/2;
  dp_set.pixel_fmt=o->pixel_fmt;
  dp_set.timing=*(o->current);
  dp_set.pitch=o->current->h;
  req=IOW('d',SI_DCE_DP_SET,dp_set);
  r=ioctl(o->fd,req,(l)&dp_set);
  if(ISERR(r)){
    PERR("output:%s:dce:%ux%u@%u: unable to program\n",sysname,o->current->h,
                                         o->current->v,v_refresh(o->current));
    goto err_free_fb;
  }
  //----------------------------------------------------------------------------

  LOG("output:%s:dce:%ux%u@%u:programmed successfully\n",sysname,o->current->h,
                                         o->current->v,v_refresh(o->current));
  return LWL_OK;

err_free_fb:
  req=IOW('d',SI_MEM_FREE,o->fb.gpu_addr);
  r=ioctl(o->fd,req,&o->fb.gpu_addr);
  if(ISERR(r))
    PERR("output:%s:dce:unable to free frame buffer memory (LEAK!)\n",sysname);
err:
  return LWL_ERR; 
}
Exemplo n.º 7
0
static i preclone_spawn(s16 slot)
{
  atomic_u8_set(preclones_states+slot,PRECLONE_BUSY);

  i sockets[2];
  preclone_ctl_socket(sockets);

  l r=clone(SIGCHLD,0,0,0,0);
  if(ISERR(r)){
    PERR("FATAL:error precloning process slot %d with error %ld\n",slot,r);
    return -1;
  }
  if(r==0) goto preclone_entry_setup;
 
  preclones[slot].sock=sockets[1];
  do r=close(sockets[0]); while(r==-EINTR);
  preclones[slot].pid=(i)r; 
  return 0;

preclone_entry_setup:
  preclone_slot=slot;
  do r=close(sockets[1]); while(r==-EINTR);//close parent unix socket
  preclone_parent_sock=sockets[0];

  do r=close(0); while(r==-EINTR);//for the connexion socket
  do r=close(1); while(r==-EINTR);//for the connexion socket
  //keep stderr

  do r=close(sigs_fd); while(r==-EINTR);//don't care of parent signal
  do r=close(epfd); while(r==-EINTR);//don't use parent epoll

  preclone_entry();
  return -1;
}
Exemplo n.º 8
0
static void clone_spawn(void)
{
  l r;
  if(ps_n<ps_max){
    r=clone(SIGCHLD,0,0,0,0);
    if(ISERR(r)){
      PERR("FATAL:error cloning %ld\n",r);
      kill(0,SIGTERM);
      exit(-1);
    }
    if(r==0) goto clone_entry_setup;
 
    ++ps_n;
  }
  return;

clone_entry_setup:
  do r=close(0); while(r==-EINTR);//for the connexion socket
  do r=close(1); while(r==-EINTR);//for the connexion socket
  //keep stderr

  do r=close(sigs_fd); while(r==-EINTR);//don't care of parent signal
  do r=close(epfd); while(r==-EINTR);//don't use parent epoll

  clone_entry();
  return;
}
int convert_e2prom_args(const char *e2prom_args, unsigned int *device_code, 
								unsigned int *addr, unsigned int *value)
{
	int i=0, err = 0;
	int pos[3]={0};
	int data[3]={0};
	char temp[3];
	for(; i<2; i++)
	{
		pos[i] += 1;
		pos[i+1] = find_symble(e2prom_args, pos[i]);
		ISERR(pos[i+1], "args format error\n");
		get_string_from_string(temp, e2prom_args, pos[i], pos[i+1]-pos[i]);
//		BRIGHT_DBG("temp = %s\n", temp);
		err = sscanf(temp, "%d", data+i);
//		BRIGHT_DBG("data[%d] hex = %x\n", i, data[i]);
	}
	get_string_from_string(temp, e2prom_args,  pos[2]+1, VALUE_BYTES);
//	BRIGHT_DBG("temp = %s\n", temp);
	err = sscanf(temp, "%x", data+2);
//	BRIGHT_DBG("data[%d] hex = %x\n", 2, data[2]);
	*device_code = data[0];
	*addr = data[1];
	*value = data[2];
	return 0;	
}
Exemplo n.º 10
0
Arquivo: regexec.c Projeto: nawawi/tcl
/*
 - complicatedFind - find a match for the main NFA (with complications)
 ^ static int complicatedFind(struct vars *, struct cnfa *, struct colormap *);
 */
static int
complicatedFind(
    struct vars *const v,
    struct cnfa *const cnfa,
    struct colormap *const cm)
{
    struct dfa *s, *d;
    chr *cold = NULL; /* silence gcc 4 warning */
    int ret;

    s = newDFA(v, &v->g->search, cm, &v->dfa1);
    NOERR();
    d = newDFA(v, cnfa, cm, &v->dfa2);
    if (ISERR()) {
	assert(d == NULL);
	freeDFA(s);
	return v->err;
    }

    ret = complicatedFindLoop(v, cnfa, cm, d, s, &cold);

    freeDFA(d);
    freeDFA(s);
    NOERR();
    if (v->g->cflags&REG_EXPECT) {
	assert(v->details != NULL);
	if (cold != NULL) {
	    v->details->rm_extend.rm_so = OFF(cold);
	} else {
	    v->details->rm_extend.rm_so = OFF(v->stop);
	}
	v->details->rm_extend.rm_eo = OFF(v->stop);	/* unknown */
    }
    return ret;
}
Exemplo n.º 11
0
/*
 * altdissect - determine alternative subexpression matches (uncomplicated)
 */
static int						/* regexec return code */
altdissect(struct vars * v,
           struct subre * t,
           chr *begin,			/* beginning of relevant substring */
           chr *end)			/* end of same */
{
    struct dfa *d;
    int			i;

    assert(t != NULL);
    assert(t->op == '|');

    for (i = 0; t != NULL; t = t->right, i++)
    {
        MDEBUG(("trying %dth\n", i));
        assert(t->left != NULL && t->left->cnfa.nstates > 0);
        d = newdfa(v, &t->left->cnfa, &v->g->cmap, &v->dfa1);
        if (ISERR())
            return v->err;
        if (longest(v, d, begin, end, (int *) NULL) == end)
        {
            MDEBUG(("success\n"));
            freedfa(d);
            return dissect(v, t->left, begin, end);
        }
        freedfa(d);
    }
    return REG_ASSERT;			/* none of them matched?!? */
}
Exemplo n.º 12
0
static void sigs_setup(void)
{//synchronous treatement of signals with signalfd
  //cannot change SIGKILL, neither SIGSTOP
  ul mask=(~0);
  l r=rt_sigprocmask(SIG_BLOCK,&mask,0,sizeof(mask));
  if(ISERR(r)){
    PERR("FATAL:error blocking mostly all signals (%ld)\n",r);
    exit(-1);
  }

  mask=SIGBIT(SIGTERM)|SIGBIT(SIGCHLD);
  sigs_fd=(i)signalfd4(-1,&mask,sizeof(mask),SFD_NONBLOCK);
  if(ISERR(sigs_fd)){
    PERR("FATAL:error setting up fd for signals (%d)\n",sigs_fd);
    exit(-1);
  }
}
Exemplo n.º 13
0
static void epoll_sigs_setup(void)
{
  epfd=(i)epoll_create1(0);
  if(ISERR(epfd)){
    PERR("FATAL:unable to create epoll fd (%d)\n",epfd);
    exit(-1);
  }
  struct epoll_event ep_evt;
  memset(&ep_evt,0,sizeof(ep_evt));
  ep_evt.events=EPOLLET|EPOLLIN;
  ep_evt.data.fd=sigs_fd;
  l r=epoll_ctl(epfd,EPOLL_CTL_ADD,sigs_fd,&ep_evt);
  if(ISERR(r)){
    PERR("FATAL:unable to register signal fd to epoll (%ld)\n",r);
    exit(-1);
  }
}
Exemplo n.º 14
0
Arquivo: regexec.c Projeto: dgsb/tcl
/*
 - complicatedAlternationDissect - determine alternative subexpression matches (w.
 - complications)
 ^ static int complicatedAlternationDissect(struct vars *, struct subre *, chr *, chr *);
 */
static int			/* regexec return code */
complicatedAlternationDissect(
    struct vars *const v,
    struct subre *t,
    chr *const begin,		/* beginning of relevant substring */
    chr *const end)		/* end of same */
{
    int er;
#define	UNTRIED	0		/* not yet tried at all */
#define	TRYING	1		/* top matched, trying submatches */
#define	TRIED	2		/* top didn't match or submatches exhausted */

#ifndef COMPILER_DOES_TAILCALL_OPTIMIZATION
    if (0) {
    doRight:
	t = t->right;
    }
#endif
    if (t == NULL) {
	return REG_NOMATCH;
    }
    assert(t->op == '|');
    if (v->mem[t->retry] == TRIED) {
	goto doRight;
    }

    MDEBUG(("cAlt n%d\n", t->retry));
    assert(t->left != NULL);

    if (v->mem[t->retry] == UNTRIED) {
	struct dfa *d = newDFA(v, &t->left->cnfa, &v->g->cmap, DOMALLOC);

	if (ISERR()) {
	    return v->err;
	}
	if (longest(v, d, begin, end, NULL) != end) {
	    freeDFA(d);
	    v->mem[t->retry] = TRIED;
	    goto doRight;
	}
	freeDFA(d);
	MDEBUG(("cAlt matched\n"));
	v->mem[t->retry] = TRYING;
    }

    er = complicatedDissect(v, t->left, begin, end);
    if (er != REG_NOMATCH) {
	return er;
    }

    v->mem[t->retry] = TRIED;
#ifndef COMPILER_DOES_TAILCALL_OPTIMIZATION
    goto doRight;
#else
  doRight:
    return complicatedAlternationDissect(v, t->right, begin, end);
#endif
}
Exemplo n.º 15
0
Arquivo: dce.c Projeto: sylware/lwl
void dce_dpm_on(struct output *o)
{
  void *sysname=(void*)udev_device_get_sysname(o->d);

  ul req=IOR('d',SI_DCE_DP_DPM,o->blk_idx);
  l r=ioctl(o->fd,req,&o->blk_idx);
  if(ISERR(r)) PERR("output:%s:dce:unable to swich dpm to on\n",sysname);
  else LOG("output:%s:dce:dpm on successfully\n",sysname);
}
Exemplo n.º 16
0
static void clone_setup(void)
{
  clone_sigs_setup();

  l r=dup2(cnx_sock,0);
  if(ISERR(r)){
    PERR("FATAL:child:clone:unable to make stdin the connexion socket (%ld)\n",
                                                                             r);
    exit(-1);
  }

  r=dup2(cnx_sock,1);
  if(ISERR(r)){
    PERR("FATAL:child:clone:unable to make stdout the connexion socket (%ld)\n",
                                                                             r);
    exit(-1);
  }
}
Exemplo n.º 17
0
static void preclone_ctl_socket(i sockets[2])
{
  l r=socketpair(AF_UNIX,SOCK_DGRAM,0,sockets);
  if(ISERR(r)){
    PERR("FATAL:error creating preclone socket pair (%ld)\n",r);
    kill(0,SIGTERM);
    exit(-1);
  }
}
Exemplo n.º 18
0
void main(int argc, char *argv[]) {
	func() ? 1 : 0;

#ifdef QUEUE
    DC_thread_t t;
    time_t tm;

    DC_queue_init (&queue, 100, 0);
    DC_thread_create (&t, print_func, NULL);
    signal (SIGALRM, sig);
    //signal (SIGINT, sig);
    alarm (1);

    usleep (1);
    while (!ext) {
        tm = (time(NULL)/1000);
        //fprintf (stderr, "Writing : %u\n", t);
        if (ISERR (DC_queue_add (&queue, (OBJ_t)tm, TRUE, 0))) {
            fprintf (stderr, "Queue is error\n");
            break;
        }
        x++;
    }

    sleep (100);
#elif defined (CONF)
    exit(DC_read_ini (argv[1], print_conf));
#elif defined (LIST)
    int i = 0;
    DC_list_t list;

    DC_list_init (&list, (OBJ_t)0);

    printf ("Insert 10 numbers (from 1-10):\n");
    for (i=0; i<10; i++) {
        DC_list_add (&list, i+1);
    }

    print_list(&list);

    printf ("Insert 22 at index of 2\n");
    DC_list_insert_at_index (&list, 22, 2);
    print_list (&list);

    printf ("Remove the number at index of 1\n");
    DC_list_remove_at_index (&list, 1);
    print_list (&list);

    printf ("Print the number at index of 8\n");
    printf ("%d\n", (int)DC_list_get_at_index (&list, 8));

    DC_list_clean (&list);
    print_list (&list);

    DC_list_destroy (&list);
#endif
}
Exemplo n.º 19
0
//******************************************************************************
//*clone stuff
//******************************************************************************
static void clone_sigs_setup(void)
{
  //cannot change SIGKILL, neither SIGSTOP
  u64 mask=(~0);
  l r=rt_sigprocmask(SIG_BLOCK,&mask,0,sizeof(mask));
  if(ISERR(r)){
    PERR("FATAL:child:clone:error blocking mostly all signals (%ld)\n",r);
    exit(-1);
  }
}
Exemplo n.º 20
0
Arquivo: dce.c Projeto: sylware/lwl
void dce_double_frame_buffer_free(struct output *o)
{
  void *sysname=(void*)udev_device_get_sysname(o->d);

  ul req=IOR('d',SI_MEM_FREE,o->fb.gpu_addr);
  l r=ioctl(o->fd,req,&o->fb.gpu_addr);
  if(ISERR(r))
    PERR("output:%s:dce:unable to free frame buffer memory (LEAK!)\n",sysname);
  else LOG("output:%s:dce:double frame buffer freed successfully\n",sysname);
}
Exemplo n.º 21
0
Arquivo: regexec.c Projeto: nawawi/tcl
/*
 - getsubdfa - create or re-fetch the DFA for a subre node
 * We only need to create the DFA once per overall regex execution.
 * The DFA will be freed by the cleanup step in exec().
 */
static struct dfa *
getsubdfa(struct vars * v,
	  struct subre * t)
{
    if (v->subdfas[t->id] == NULL) {
	v->subdfas[t->id] = newDFA(v, &t->cnfa, &v->g->cmap, DOMALLOC);
	if (ISERR())
	    return NULL;
    }
    return v->subdfas[t->id];
}
Exemplo n.º 22
0
static s8 file_close(struct ctx *c)
{
  s8 r0=CONF_INI_OK;

  l r=munmap(c->m,c->sz);
  if(ISERR(r)){
    PERR("file:error(%ld):unable to munmap conf file\n",r);
    r0=CONF_INI_ERR;goto exit;
  }

  do r=close(c->fd); while(r==-EINTR);
  if(ISERR(r)){
    PERR("file:error(%ld):closing conf file gone wrong\n",r);
    r0=CONF_INI_ERR;goto exit;
  }

  POUTC("file:conf file unmapped and closed\n");
exit:
  return r0;
}
Exemplo n.º 23
0
static void preclone_epoll_setup(void)
{
  i epfd=(i)epoll_create1(0);
  if(ISERR(epfd)){
    PERR("FATAL:child:preclone:%d:unable to create epoll fd (%d)\n",
                                                            preclone_slot,epfd);
    exit(-1);
  }

  if(epfd!=3){//moving epoll fd to 3, if required
    l r=dup2(epfd,3);
    if(ISERR(r)){
      PERR("FATAL:child:preclone:%d:unable to move epoll fd (%ld)\n",
                                                               preclone_slot,r);
      exit(-1);
    }
    do r=close(epfd); while(r==-EINTR);
  }

  struct epoll_event ep_evt;
  memset(&ep_evt,0,sizeof(ep_evt));
  ep_evt.events=EPOLLET|EPOLLIN;

  ep_evt.data.fd=4;
  l r=epoll_ctl(3,EPOLL_CTL_ADD,4,&ep_evt);
  if(ISERR(r)){
    PERR("FATAL:child:preclone:%d:unable to register signal fd to epoll (%ld)\n",
                                                               preclone_slot,r);
    exit(-1);
  }

  ep_evt.data.fd=5;
  ep_evt.events=EPOLLIN|EPOLLPRI;
  r=epoll_ctl(3,EPOLL_CTL_ADD,5,&ep_evt);
  if(ISERR(r)){
    PERR("FATAL:child:preclone:%d:unable to register parent socket to epoll"
                                                    " (%ld)\n",preclone_slot,r);
    exit(-1);
  }
}
Exemplo n.º 24
0
static void mem_allocate(void)
{
  if(!preclones_n) return;//nothing to allocate

  l r=mmap(0,(preclones_n)*sizeof(&preclones),PROT_READ|PROT_WRITE,
                                    MAP_PRIVATE|MAP_ANONYMOUS|MAP_POPULATE,0,0);
  if(!r||ISERR(r)){
    PERR("FATAL:unable to allocate children infos memory:%ld\n",r);
    exit(-1);
  }
  preclones=(struct preclone *)r;

  r=mmap(0,(preclones_n)*sizeof(&preclones_states),PROT_READ|PROT_WRITE,
                                     MAP_SHARED|MAP_ANONYMOUS|MAP_POPULATE,0,0);
  if(!r||ISERR(r)){
    PERR("FATAL:unable to allocate children shared memory:%ld\n",r);
    exit(-1);
  }
  preclones_states=(atomic_u8_t *)r;
  for(s16 slot=0;slot<preclones_n;++slot)
    atomic_u8_set(preclones_states+slot,PRECLONE_AVAILABLE);
}
Exemplo n.º 25
0
Arquivo: client.c Projeto: sylware/lwl
static void client_so_setup(i so,s32 slot)
{
  struct epoll_event ep_evt;
  memset(&ep_evt,0,sizeof(ep_evt));
  ep_evt.events=EPOLLIN|EPOLLHUP|EPOLLPRI;//*level* triggered
  ep_evt.data._32=(u32)slot;

  l r=epoll_ctl(ep_fd,EPOLL_CTL_ADD,so,&ep_evt);
  if(ISERR(r)){
    PERR("fatal(%ld):unable to register client socket(%d) to epoll\n",r,so);
    exit(LWL_ERR);
  }
}
Exemplo n.º 26
0
static void epoll_srv_sock_setup(void)
{
  struct epoll_event ep_evt;
  memset(&ep_evt,0,sizeof(ep_evt));
  ep_evt.events=EPOLLIN|EPOLLPRI;
  ep_evt.data.fd=srv_sock;
  l r=epoll_ctl(epfd,EPOLL_CTL_ADD,srv_sock,&ep_evt);
  if(ISERR(r)){
    PERR("FATAL:unable to register server socket to epoll (%ld)\n",r);
    kill(0,SIGTERM);
    exit(-1);
  }
}
Exemplo n.º 27
0
Arquivo: client.c Projeto: sylware/lwl
s8 client_rd(struct client *c)
{
  static struct msg m;
  memset(&m,0,sizeof(m));
  for(u32 j=0;j<MSG_FDS_MAX;++j) m.fds[j]=-1;

  struct io_vec iov;
  iov.base=&m.buf[0];
  iov.len=MSG_BUF_SZ;
  m.hdr.iov=&iov;
  m.hdr.iov_len=1;
 
  //use a control message for file descriptors
  m.hdr.ctl=&m.cm_buf[0];
  m.hdr.ctl_len=sizeof(m.cm_buf);
  struct cmsg_hdr *cm_hdr=CMSG_FIRSTHDR(&m.hdr);
  cm_hdr->lvl=SOL_SOCKET;
  cm_hdr->type=SCM_RIGHTS;
  cm_hdr->len=CMSG_LEN(sizeof(i));

  l r;//client *blocking* socket
  while(1){r=recvmsg(c->so,&m.hdr,0); if(r!=-EINTR) break;}
  if(ISERR(r)){
    PERR("client(%d):fatal(%ld):error receiving request\n",c->so,r);
    r=LWL_ERR;goto exit;
  }

  if(m.hdr.flgs&MSG_CTRUNC){
    PERR("client(%d):fatal:error receiving request file descriptor\n",c->so); 
    r=LWL_ERR;goto exit;
  }

  if(r&0x3){//payload must be padded on 32 bits words
    PERR("client(%d):fatal:receiving request has a payload size not 32 bits"
                                                       " word aligned\n",c->so);
    r=LWL_ERR;goto exit;
  }

  if(!r){
    PERR("client(%d):fatal:received empty request\n",c->so);
    r=LWL_ERR;goto exit;
  }

  m.dws=r>>2;

  r=msg_demux(c,&m);//message size is at least 1 dw 

exit:
  if(r==LWL_ERR) cm_fds_close(c,&m);
  return (s8)r;
}
Exemplo n.º 28
0
void ulinux_start(l argc,void **argv)
{
  u8 _dprintf_buf[DPRINTF_BUF_SZ];
  dprintf_buf=&_dprintf_buf[0];

  if(argc!=2){
    PERR("ERROR:wrong number of command arguments(%d)\n",argc);
    exit(-1);
  }

  i fd;
  do fd=(i)open(argv[1],RDONLY,0); while(fd==-EINTR);
  if(ISERR(fd)){
    PERR("ERROR(%ld):unable to open module %s\n",fd,argv[1]);
    exit(-1);
  }

  struct stat m_stat;
  l r=fstat(fd,&m_stat);
  if(ISERR(r)){
    PERR("ERROR(%ld):unable to stat module\n",r);
    exit(-1);
  }
  POUT("size=%lu\n",m_stat.sz);

  l addr=mmap(0,m_stat.sz,PROT_READ,MAP_PRIVATE|MAP_POPULATE,fd,0);
  if(!addr||ISERR(addr)){
    PERR("ERROR(%ld):unable to mmap module file\n",addr);
    exit(-1);
  }

  r=init_module(addr,m_stat.sz,"");
  if(ISERR(r)){
    PERR("ERROR(%ld):unable init module\n",r);
    exit(-1);
  }
  exit(0);
}
Exemplo n.º 29
0
int Tree_Construct (root_t** new_tree)
{
    ASSERT (new_tree);

    *new_tree = (root_t*) calloc (1, sizeof (new_tree));

    (*new_tree)->size = 1;

    ISERR (Node_Construct (&(*new_tree)->root), (*new_tree)->root);

    TREE_CHECK (*new_tree);

    return TREE_OK;
}
Exemplo n.º 30
0
Arquivo: dce.c Projeto: sylware/lwl
s8 dce_info_get(s32 output_name)
{
  struct output *o=&registry[output_name].output;

  ul req=IOR('d',SI_DCE_DPS_INFO,o->dce_info);
  l r=ioctl(o->fd,req,&o->dce_info);
  if(ISERR(r)){
    DCE_ERR("unable to get info\n");
    return LWL_ERR;
  }

  DCE_LOG("got information from the driving hardware\n");
  return LWL_OK;
}