Пример #1
0
int main(int argc, char *argv[])
{
	bencode_list *list;
	bencode_integer *integer;
	bencode_string *string;
	char *str = "5:cameli5ee";
	int n;
	int i;
	io_buf buf;
	io_reader r;

	memset(&buf, 0, sizeof(buf));
	memset(&r, 0, sizeof(r));

	buf.buf = str;
	buf.len = strlen(str);
	r.data = &buf;
	r.read = io_bufread;

	list = parselist('l', &r, &n);
	assert(list != NULL);
	assert(list->nvals == 2);

	assert(list->vals != NULL);

	assert(list->vals[0] != NULL);
	assert(list->vals[0]->type == BENCODE_STRING);

	assert(list->vals[1] != NULL);
	assert(list->vals[1]->type == BENCODE_INTEGER);

	assert(n == strlen(str) + 1);

	exit(EXIT_SUCCESS);
}
Пример #2
0
Файл: ace.c Проект: nopy4869/ACE
int main(int argc, char** argv)
{
	int x;
	int ret;
	printf("Advance Copying Executable!\nUsage: ace [file to copy] [-d [name of output filename list]] [output filename(s)]\n");
	ret = read(argv[1]);
	if(ret != 0)
	{
		printf("Failed intial load\n");
		printf("%s", errorcodes[ret]);
		return ret;
	}
	else
	{
		for(x = 2; x < argc; x++)
		{
			if(strncmp(argv[x], "-d", 2) == 0)
			{
				x++;
				ret = parselist(argv[x]);
				if(ret != 0)
					printf("%s", errorcodes[ret]);
			}
			else
			{
				ret = write(argv[x]);
				if(ret != 0)
				{
					printf("Error writing %s to %s: %s",argv[1], argv[x], errorcodes[ret]);
				}
			}
		}
	}
	return 0;
};
Пример #3
0
/* parse.c 612d */
static Exp parseexp(Par p) {
    switch (p->alt) {
    case ATOM:
        /* parseexp [[atom]] and return the result 612e */
        {
            const char *s = nametostr(p->u.atom);
            char *t;
            long l = strtol(s, &t, 10);
            if (*t == '\0') /* the number is the whole string */
                return mkLiteral(l);
            else
                return mkVar(p->u.atom);
        }
    case LIST:
        /* parseexp [[list]] and return the result 613a */
        {
            Parlist pl;
            Name first;
            Explist argl;

            pl = p->u.list;
            if (pl == NULL)
                error("%p: empty list in input", p);
            if (pl->hd->alt != ATOM)
                error("%p: first item of list not name", p);

            first = pl->hd->u.atom;
            argl  = parselist(pl->tl);
            if (first == strtoname("begin")) {
                /* parseexp [[begin]] and return the result 613b */
                return mkBegin(argl);
            } else if (first == strtoname("if")) {
                /* parseexp [[if]] and return the result 613c */
                if (lengthEL(argl) != 3)
                    error("%p: usage: (if cond true false)", p);
                return mkIfx(nthEL(argl, 0), nthEL(argl, 1), nthEL(argl, 2));
            } else if (first == strtoname("set")) {
                /* parseexp [[set]] and return the result 613e */
                if (lengthEL(argl) != 2)
                    error("%p: usage: (set var exp)", p);
                if (nthEL(argl, 0)->alt != VAR)
                    error("%p: set needs variable as first param", p);
                return mkSet(nthEL(argl, 0)->u.var, nthEL(argl, 1));
            } else if (first == strtoname("while")) {
                /* parseexp [[while]] and return the result 613d */
                if (lengthEL(argl) != 2)
                    error("%p: usage: (while cond body)", p);
                return mkWhilex(nthEL(argl, 0), nthEL(argl, 1));
            } else {
                /* parseexp function application and return the result 614a */
                return mkApply(first, argl);
            }
        }
    default:
        assert(0);
        return NULL;
    }
}
/* parse.c 720d */
Explist parselist(Parlist pl) {
    Exp e;

    if (pl == NULL)
        return NULL;

    e = parseexp(pl->hd);
    return mkEL(e, parselist(pl->tl));
}
Пример #5
0
/*
 * Now we can move on to parsing [[Exp]]s. The
 * [[parselist]] helper function repeatedly calls
 * [[parseexp]] to parse a list of [[Par]] expressions,
 * eventually returning a list of [[Exp]]s.
 * <parse.c>=
 */
static Explist parselist(Parlist pl) {
    Exp e;

    if (pl == NULL)
        return NULL;

    e = parseexp(pl->hd); /* force pl->hd to be parsed first */
    return mkEL(e, parselist(pl->tl));
}
Пример #6
0
void IFCParser::parseargs(wistream& is, Attribute& args)
{
	args.clear();

	wstring tok = gettok(is);	// '('

	parselist(is, args);

	tok = gettok(is);					// ')'	
}
bool
str2logentry (sfsauth_logentry *li, str s)
{
  vec<str> lv;
  if (split (&lv, colon, s, 4, true) != 3)
    return false;
  if (!convertint (lv[0], &li->vers)
      || !parselist (&li->members, lv[1], parsemember))
    return false;
  li->audit = lv[2];
  return true;
}
bool
str2groupinfo (sfsauth_groupinfo *gi, str s)
{
  vec<str> gv;
  if (split (&gv, colon, s, 8, true) != 7)
    return false;
  if (!namerx.match (gv[0])
      || badcharrx.search (gv[5]))
    return false;
  gi->name = gv[0];
  if (!convertint (gv[1], &gi->id)
      || !convertint (gv[2], &gi->vers)
      || !parselist (&gi->owners, gv[3], parsemember)
      || !parselist (&gi->members, gv[4], parsemember)
      // || !convertint (gv[5], &gi->refresh)
      // || !convertint (gv[6], &gi->timeout)
      )
    return false;
  gi->properties = gv[5];
  gi->audit = gv[6];
  // gi->audit = gv[7];
  return true;
}
bool
str2cacheentry (sfsauth_cacheentry *ci, str s)
{
  vec<str> cv;
  if (split (&cv, colon, s, 7, true) != 6)
    return false;
  ci->key = single_char_sub (cv[0], '$', ",");
  if (!parselist (&ci->values, cv[1], parsemember)
      || !convertint (cv[2], &ci->vers)
      || !convertint (cv[3], &ci->refresh)
      || !convertint (cv[4], &ci->timeout)
      || !convertint (cv[5], &ci->last_update))
    return false;
  return true;
}
Пример #10
0
int
main(int argc, char *argv[])
{
	FILE *fp;
	int ret = 0;
	char *tl = "8";

	ARGBEGIN {
	case 't':
		tl = EARGF(usage());
		if (!*tl)
			eprintf("tablist cannot be empty\n");
		/* Fallthrough: -t implies -a */
	case 'a':
		aflag = 1;
		break;
	default:
		usage();
	} ARGEND

	tablistlen = parselist(tl);

	if (!argc) {
		unexpand("<stdin>", stdin);
	} else {
		for (; *argv; argc--, argv++) {
			if (!strcmp(*argv, "-")) {
				*argv = "<stdin>";
				fp = stdin;
			} else if (!(fp = fopen(*argv, "r"))) {
				weprintf("fopen %s:", *argv);
				ret = 1;
				continue;
			}
			unexpand(*argv, fp);
			if (fp != stdin && fshut(fp, *argv))
				ret = 1;
		}
	}

	ret |= fshut(stdin, "<stdin>") | fshut(stdout, "<stdout>");

	return ret;
}
Пример #11
0
/* Replace the query */
int
ncurisetquery(NCURI* duri,const char* query)
{
    int ret = NCU_OK;
    freestringvec(duri->querylist);    
    nullfree(duri->query);
    duri->query = NULL;
    duri->querylist = NULL;
    if(query != NULL && strlen(query) > 0) {
	NClist* params = nclistnew();
	duri->query = strdup(query);
	ret = parselist(duri->query,params);
	if(ret != NCU_OK)
	    {THROW(NC_EURL);}
	nclistpush(params,NULL);
	duri->querylist = nclistextract(params);
	nclistfree(params);
    }
done:
    return ret;
}
Пример #12
0
/* Do a simple uri parse: return NCU_OK if success, NCU_XXX if failed */
int
ncuriparse(const char* uri0, NCURI** durip)
{
    int ret = NCU_OK;
    NCURI tmp;
    char* p;
    char* q;
    int isfile;
    int hashost;
    char* uri = NULL;
    NCURI* duri = NULL;
    char* prefix = NULL;
    char* next = NULL;
    NClist* params = nclistnew();
    NClist* querylist = nclistnew();
    size_t len0;
    int pathchar;

    if(uri0 == NULL)
	{THROW(NCU_EBADURL);}

    len0 = strlen(uri0);
    if(len0 == 0)
	{THROW(NCU_EBADURL);}

    /* Create a local NCURI instance to hold
       pointers into the parsed string
    */
    memset(&tmp,0,sizeof(tmp));

    /* make mutable copy. Add some extra space
       because we will need to null terminate the host section
       without losing the first character of the path section.
    */
    uri = (char*)malloc(len0+1+1); /* +2 for nul term and for host section terminator */
    if(uri == NULL)
	{THROW(NCU_ENOMEM);}
    strncpy(uri,uri0,len0+1);

    /* Walk the uri and do the following:
	1. remove leading and trailing whitespace
	2. convert all '\\' -> '\' (Temp hack to remove escape characters
                                    inserted by Windows or MinGW)
    */
    for(q=uri,p=uri;*p;p++) {if((*p == '\\' && p[1] == '\\') || *p < ' ') {continue;} else {*q++ = *p;}}
    *q = '\0';

    p = uri;

    /* break up the url into coarse pieces */
    if(*p == LBRACKET) {
        prefix = p;
        ret = collectprefixparams(p,&next); /* collect the prefix */
        if(ret != NCU_OK)
            {THROW(NCU_EBADURL);}
         p = next;
    } else {
	prefix = NULL;
    }
    tmp.uri = p; /* will be the core */
    /* Skip past the core of the url */
    next = nclocate(p,"?#");
    if(next != NULL) {
	int c = *next;
	terminate(next);
	next++;
	if(c == '?') {
	    tmp.query = next;
	    next = nclocate(next,"#");
	    if(next == NULL)
		tmp.fragment = NULL;
	    else {
		terminate(next);
		next++;
	        tmp.fragment = next;
	    }
	} else { /*c == '#'*/
	    tmp.fragment = next;
	}	    
    }

    /* Parse the prefix parameters */
    if(prefix != NULL) {
        if(parselist(prefix,params) != NCU_OK)
            {THROW(NCU_EBADURL);}
    }
    /* Parse the fragment parameters */
    if(tmp.fragment != NULL) {
        if(parselist(tmp.fragment,params) != NCU_OK)
            {THROW(NCU_EBADURL);}
    }
    if(nclistlength(params) > 0) {
	nclistpush(params,NULL);
        tmp.fraglist = nclistextract(params);
    } else
	tmp.fraglist = NULL;
    /* Parse the query */
    if(tmp.query != NULL) {
        if(parselist(tmp.query,querylist) != NCU_OK)
            {THROW(NCU_EBADURL);}
        if(nclistlength(querylist) > 0) {
	    nclistpush(querylist,NULL);
            tmp.querylist = nclistextract(querylist);
	}
    }    

    /* Now parse the core of the url */
    p = tmp.uri;

    /* Mark the protocol */
    tmp.protocol = p;
    p = strchr(p,':');
    if(!p)
	{THROW(NCU_EBADURL);}
    terminate(p); /*overwrite colon*/
    p++; /* skip the colon */
    if(strlen(tmp.protocol)==0)
	{THROW(NCU_EBADURL);}
    /*
       The legal formats for file: urls are a problem since
       many variants are often accepted.
       By RFC, the proper general format is: file://host/path,
       where the 'host' can be omitted and defaults to 'localhost'.
       and the path includes the leading '/'.
       So, assuming no host, the format is: "file:///path".
       Some implementations, however, ignore the host, and allow
       the format: file:/path.
       We also simplify things by assuming the host part is always empty.
       which means we can have file:///path, but not file://..../path.
       Note in all cases, the leading '/' is considered part of the path,
       which is then assumed to be an absolute path. But also note that
       the windows drive letter has to be taken into account. Our rule is that
       if the path looks like D:..., 
       where D is a single alphabetic letter (a-z or A-Z),
       then it is a windows path and can be use in place of a /path.
       The rules implemented here (for file:) are then as follows
       1. file:D:... : assume D: is a windows drive letter and treat D:... as the path
       2. file:/X, where X does not start with a slash: treat /X as the path.
       3. file://D:... : assume D: is a windows drive letter and treat as the path
       4. file:///X, where X does not start with a slash: treat /X as the path.
       All other cases are disallowed: specifically including file://X.
    */

    isfile = (strcmp(tmp.protocol,"file")==0);
    if(isfile) {
	int l = strlen(p); /* to test if we have enough characters */
	hashost = 0; /* always */
	if(l >= 2 && p[1] == ':' && strchr(DRIVELETTERS,p[0]) != NULL) { /* case 1 */
	    p = p; /* p points to the start of the path */
        } else if(l >= 2 && p[0] == '/' && p[1] != '/') { /* case 2 */
	    p = p; /* p points to the start of the path */
	} else if(l >= 4 && p[0] == '/' && p[1] == '/'
		&& p[3] == ':' && strchr(DRIVELETTERS,p[2]) != NULL) { /* case 3 */
	    p = p+2; /* points to the start of the windows path */
        } else if(l >= 4 && p[0] == '/' && p[1] == '/' && p[2] == '/' && p[3] != '/') { /* case 4 */
	    p += 2; /* points to the start of the path */
        } else /* everything else is illegal */
	    {THROW(NCU_EPATH);}
    } else {
        if(p[0] != '/' || p[1] != '/') /* must be proto:// */
	    {THROW(NCU_EPATH);}
	p += 2;
        hashost = 1; /* Assume we have a hostname */
    }
    if(!hashost) {
        tmp.path = p;
	pathchar = EOFCHAR;
    } else { /* assume there should be a host section */
	/* We already extracted the query and/or fragment sections above,
           splocate the end of the host section and therefore the start
           of the path.
        */
	tmp.host = p;
        p  = nclocate(p,"/");
	if(p == NULL) { /* no path */
	    tmp.path = NULL; /* default */
	    pathchar = EOFCHAR;
	} else {
	    tmp.path = p; /* save ptr to rest of the path */
	    pathchar = *p; /* save leading char of the path */
	    terminate(p); /* overwrite the leading char of the path; restored below */
	}
    }
    /* Nullify tmp.host for consistency */
    if(tmp.host != NULL && strlen(tmp.host)==0) {tmp.host = NULL;}

    if(tmp.host != NULL) {/* Parse the host section */
        char* pp;
	/* Check for leading user:pwd@ */
        char* newhost = strchr(tmp.host,'@');
        if(newhost != NULL) {
	    size_t rem;
	    if(newhost == tmp.host)
		{THROW(NCU_EUSRPWD);} /* we have proto://@ */
	    terminate(newhost); /* overwrite '@' */
	    newhost++; /* should point past usr+pwd */
	    tmp.user = tmp.host;
	    /* Break user+pwd into two pieces */
	    pp = strchr(tmp.user,':');
	    if(pp == NULL)
		{THROW(NCU_EUSRPWD);} /* we have user only */
	    terminate(pp); /* overwrite ':' */
	    pp++;
	    if(strlen(tmp.user)==0)
		{THROW(NCU_EUSRPWD);} /* we have empty user */
	    if(strlen(pp)==0)
		{THROW(NCU_EUSRPWD);} /* we have empty password */
	    tmp.password = pp;	    
	    tmp.host = newhost;
	}
	/* Breakup host into host + port */
	pp = tmp.host;
        pp = strchr(pp,':');
        if(pp != NULL) { /* there is a port */
	    terminate(pp); /* overwrite ':' */
	    pp++; /* skip colon */
	    if(strlen(tmp.host) == 0)
		{THROW(NCU_EBADURL);} /* empty host */
	    if(strlen(pp)==0)
		{THROW(NCU_EBADURL);} /* empty port */
	    tmp.port = pp;
	    /* The port must look something like a number */
	    for(pp=tmp.port;*pp;pp++) {
	        if(strchr("0123456789-",*pp) == NULL)
		    {THROW(NCU_EPORT);}  /* probably not a real port, fail */
	    }
	} /* else no port */
    }

    /* Fill in duri from tmp */
    duri = (NCURI*)calloc(1,sizeof(NCURI));
    if(duri == NULL)
      {THROW(NCU_ENOMEM);}
    /* save original uri */
    duri->uri = strdup(uri0);
    duri->protocol = nulldup(tmp.protocol);
    /* before saving, we need to decode the user+pwd */
    duri->user = NULL;
    duri->password = NULL;
    if(tmp.user != NULL) 
        duri->user = ncuridecode(tmp.user);
    if(tmp.password != NULL)
        duri->password = ncuridecode(tmp.password);
    duri->host = nulldup(tmp.host);
    duri->port = nulldup(tmp.port);
    if(tmp.path != NULL) {
	/* We need to add back the previously overwritten path lead char (if necessary);
           this must be done after all host section related pieces have been captured */
	if(pathchar != EOFCHAR)
	    *tmp.path = pathchar;
        duri->path = nulldup(tmp.path);
    }
    duri->query = nulldup(tmp.query);
    duri->fragment = nulldup(tmp.fragment);
    duri->fraglist = tmp.fraglist; tmp.fraglist = NULL;
    duri->querylist = tmp.querylist; tmp.querylist = NULL;
    if(durip) *durip = duri;

#ifdef NCXDEBUG
	{
        fprintf(stderr,"duri:");
	fprintf(stderr," protocol=|%s|",FIX(duri->protocol));
	fprintf(stderr," user=|%s|",FIX(duri->user));
	fprintf(stderr," password=|%s|",FIX(duri->password));
	fprintf(stderr," host=|%s|",FIX(duri->host));
	fprintf(stderr," port=|%s|",FIX(duri->port));
	fprintf(stderr," path=|%s|",FIX(duri->path));
	fprintf(stderr," query=|%s|",FIX(duri->query));
	fprintf(stderr," fragment=|%s|",FIX(duri->fragment));
        fprintf(stderr,"\n");
    }
#endif

done:
    if(uri != NULL)
	free(uri);
    freestringlist(params);
    freestringlist(querylist);
    freestringvec(tmp.fraglist);
    freestringvec(tmp.querylist);
    return ret;
}
Пример #13
0
/*
 * <parse.c>=
 */
static Exp parseexp(Par p) {
    switch (p->alt) {
    case ATOM:
        /*
         * If we have a name, it must be either a literal value
         * or a variable.
         * <parseexp [[atom]] and return the result>=
         */
        {
            const char *s = nametostr(p->u.atom);
            char *t;
            long l = strtol(s, &t, 10);
            if (*t == '\0') /* the number is the whole string */
                return mkLiteral(l);
            else
                return mkVar(p->u.atom);
        }
    case LIST:
        /*
         * If we have a list, we need to look at the first
         * element, which must be a name.
         * <parseexp [[list]] and return the result>=
         */
        {
            Parlist pl;
            Name first;
            Explist argl;

            pl = p->u.list;
            if (pl == NULL)
                error("%p: empty list in input", p);
            if (pl->hd->alt != ATOM)
                error("%p: first item of list not name", p);

            first = pl->hd->u.atom;
            argl  = parselist(pl->tl);
            if (first == strtoname("begin")) {
                /*
                 * A [[begin]] expression can have any number of
                 * parameters.
                 * <parseexp [[begin]] and return the result>=
                 */
                return mkBegin(argl);
            } else if (first == strtoname("if")) {
                /*
                 * An [[if]] expression needs three parameters.
                 * <parseexp [[if]] and return the result>=
                 */
                if (lengthEL(argl) != 3)
                    error("%p: usage: (if cond true false)", p);
                return mkIfx(nthEL(argl, 0), nthEL(argl, 1), nthEL(argl, 2));
            } else if (first == strtoname("set")) {
                /*
                 * A [[set]] expression requires a variable and a value.
                 * <parseexp [[set]] and return the result>=
                 */
                if (lengthEL(argl) != 2)
                    error("%p: usage: (set var exp)", p);
                if (nthEL(argl, 0)->alt != VAR)
                    error("%p: set needs variable as first param", p);
                return mkSet(nthEL(argl, 0)->u.var, nthEL(argl, 1));
            } else if (first == strtoname("while")) {
                /*
                 * A [[while]] loop needs two.
                 * <parseexp [[while]] and return the result>=
                 */
                if (lengthEL(argl) != 2)
                    error("%p: usage: (while cond body)", p);
                return mkWhilex(nthEL(argl, 0), nthEL(argl, 1));
            } else {
                /*
                 * Anything else must be a function application. We
                 * can't check the number of parameters here, because
                 * the function definition might change before
                 * evaluation, or might not be present yet (as occurs,
                 * for example, when defining recursive functions).
                 * <parseexp function application and return the result>=
                 */
                return mkApply(first, argl);
            }
        }
    default:
        assert(0);
        return NULL;
    }
}
Пример #14
0
int bind( int sockfd, const struct sockaddr *my_addr, socklen_t addrlen)
{
#ifdef SO_REUSEPORT
   // parse environment property (just once)
   if (reuse_ports.count < 0){
     char *env_reuse = getenv("PRIVBIND_REUSE_PORTS");
     if (env_reuse == NULL){
       reuse_ports.count = 0;
     }else{
       if (parselist(env_reuse, &reuse_ports, 1, 65535) != 0){
         reuse_ports.count = -1;
         return -1;
       }
     }
   }
   
   // get bind port
   int port = -1;
   if (my_addr->sa_family==AF_INET)
      port = (int) ntohs(((struct sockaddr_in *) my_addr)->sin_port);
   else if (my_addr->sa_family==AF_INET6)
      port = (int) ntohs(((struct sockaddr_in6 *) my_addr)->sin6_port);
   
   // check if we should setup SO_REUSEPORT for this port
   if (port != -1 && is_in_list(&reuse_ports, port)){
      int optval = 1;
      int retval = setsockopt(sockfd, SOL_SOCKET, SO_REUSEPORT, &optval, sizeof(optval));
      if (retval != 0)
        return retval;
   }
#endif
  
   /* First of all, attempt the bind. We only need the socket if it fails with access denied */

   int oret=_bind( sockfd, my_addr, addrlen );
   if( oret==0 || errno!=EACCES )
      return oret;

   /* In most cases, we can let the bind go through as is */
   if( master_quit || (my_addr->sa_family!=AF_INET && my_addr->sa_family!=AF_INET6) 
       || (my_addr->sa_family==AF_INET && addrlen<sizeof(struct sockaddr_in)) 
       || (my_addr->sa_family==AF_INET6 && addrlen<sizeof(struct sockaddr_in6))  
     ) { 
      errno=EACCES;
      return oret;
   }

   /* Prepare the ancillary data for passing the actual FD */
   struct msghdr msghdr={.msg_name=NULL};
   struct cmsghdr *cmsg;
   char buf[CMSG_SPACE(sizeof(int))];
   int *fdptr;

    msghdr.msg_control=buf;
    msghdr.msg_controllen=sizeof(buf);

    cmsg=CMSG_FIRSTHDR(&msghdr);
    cmsg->cmsg_level=SOL_SOCKET;
    cmsg->cmsg_type=SCM_RIGHTS;
    cmsg->cmsg_len=CMSG_LEN(sizeof(int));

    /* Initialize the payload */
    fdptr=(int *)CMSG_DATA(cmsg);
    fdptr[0]=sockfd;
    msghdr.msg_controllen=cmsg->cmsg_len;

    /* Don't forget the data component */
    struct ipc_msg_req request;
    struct iovec iov;

    msghdr.msg_iov=&iov;
    msghdr.msg_iovlen=1;

    iov.iov_base=&request;
    iov.iov_len=sizeof(request);

    request.type=MSG_REQ_BIND;

    /* Check family of the request, only INET and INET6 should make it here */
    if (my_addr->sa_family==AF_INET)
      request.data.bind4.addr=*(struct sockaddr_in *) my_addr;
    else if (my_addr->sa_family==AF_INET6)
      request.data.bind6.addr=*(struct sockaddr_in6 *) my_addr;

    int retval=oret;

    if( acquire_lock(1) ) {
       if( sendmsg( COMM_SOCKET, &msghdr, MSG_NOSIGNAL )>0 ) {
          /* Request was sent - wait for reply */
          struct ipc_msg_reply reply;

          if( recv( COMM_SOCKET, &reply, sizeof(reply), 0 )>0 ) {
             retval=reply.data.stat.retval;
             if( retval<0 )
                errno=reply.data.stat.error;
          } else {
             /* It would appear that the other process has closed, just return the original retval */
             master_cleanup();
          }
       } else {
          /* An error has occured! */
          if( errno==EPIPE || errno==ENOTCONN || errno==EBADF ) {
             master_cleanup();
          } else {
             perror("privbind communication socket error");
             master_cleanup();
          }
       }

       acquire_lock(0);
    }

    /* Make sure we return the original errno, regardless of what caused us to fail */
    if( retval!=0 )
        errno=EACCES;

    return retval;
}
/* parse.c 720f */
Exp parseexp(Par p) {
    switch (p->alt) {
    case ATOM:
        /* parseexp [[ATOM]] and return 721 */
        {
            Name n = p->u.atom;
            const char *s; /* string form of n */
            char *t;       /* nondigits in s, if any */
            long l;        /* number represented by s, if any */

            if (n == strtoname("#t"))
                return mkLiteral(truev);
            else if (n == strtoname("#f"))
                return mkLiteral(falsev);

            s = nametostr(n);
            l = strtol(s, &t, 10);
            if (*t == '\0' && *s != '\0')
                                /* all the characters in s are digits base 10 */
                return mkLiteral(mkNum(l));
            else
                return mkVar(n);
        }
    case LIST:
        /* parseexp [[LIST]] and return 722a */
        {
            Parlist pl;                /* parenthesized list we are parsing */
            Name first;
                            /* first element, as a name (or NULL if not name) */
            Explist el;                /* remaining elements, as expressions */
            Exp rv;                    /* result of parsing */

            pl = p->u.list;
            if (pl == NULL)
                error("%p: empty list in input", p);

            first = pl->hd->alt == ATOM ? pl->hd->u.atom : NULL;
            if (first == strtoname("lambda")) {
                /* parseexp [[lambda]] and put the result in [[rv]] 722b */
                Par q;

                if (lengthPL(pl->tl) != 2)
                    error("%p: usage: (lambda (formals) exp)", p);
                q = nthPL(pl->tl, 0);
                if (q->alt != LIST)
                    error("%p: usage: (lambda (formals) exp)", p);
                rv = mkLambdax(mkLambda(getnamelist(p, q->u.list), parseexp(
                                                            nthPL(pl->tl, 1))));
            } else if (first == strtoname("let")
                   ||  first == strtoname("let*")
                   ||  first == strtoname("letrec")) {
                /* parseexp let and put the result in [[rv]] 723a */
                Letkeyword letword;
                Par letbindings;

                if (first == strtoname("let"))
                    letword = LET;
                else if (first == strtoname("let*"))
                    letword = LETSTAR;
                else if (first == strtoname("letrec"))
                    letword = LETREC;
                else
                    assert(0);

                if (lengthPL(pl->tl) != 2)
                    error("%p: usage: (%n (letlist) exp)", p, first);

                letbindings = nthPL(pl->tl, 0);
                if (letbindings->alt != LIST)
                    error("%p: usage: (%n (letlist) exp)", p, first);

                rv = mkLetx(letword, NULL, NULL, parseexp(nthPL(pl->tl, 1)));

                parseletbindings(p, letbindings->u.list, rv);
            } else if (first == strtoname("quote")) {
                /* parseexp [[quote]] and put the result in [[rv]] 723d */
                {
                    if (lengthPL(pl) != 2)
                        error("%p: quote needs exactly one argument", p);
                    rv = mkLiteral(parsesx(nthPL(pl, 1)));
                }
            } else {
                el = parselist(pl->tl);
                if (first == strtoname("begin")) {
                    /* parseexp [[begin]] and put the result in [[rv]] 724e */
                    rv = mkBegin(el);
                } else if (first == strtoname("if")) {
                    /* parseexp [[if]] and put the result in [[rv]] 724f */
                    if (lengthEL(el) != 3)
                        error("%p: usage: (if cond true false)", p);
                    rv = mkIfx(nthEL(el, 0), nthEL(el, 1), nthEL(el, 2));
                } else if (first == strtoname("set")) {
                    /* parseexp [[set]] and put the result in [[rv]] 725b */
                    if (lengthEL(el) != 2)
                        error("%p: usage: (set var exp)", p);
                    if (nthEL(el, 0)->alt != VAR)
                        error("%p: set needs variable as first param", p);
                    rv = mkSet(nthEL(el, 0)->u.var, nthEL(el, 1));
                } else if (first == strtoname("while")) {
                    /* parseexp [[while]] and put the result in [[rv]] 725a */
                    if (lengthEL(el) != 2)
                        error("%p: usage: (while cond body)", p);
                    rv = mkWhilex(nthEL(el, 0), nthEL(el, 1));

 /* [[RBR else LBR]] possibly parse expressions that are in \uschemeplus 723e */
                  /* nothing happens */
                } else {
                   /* parseexp application and put the result in [[rv]] 724d */
                   rv = mkApply(parseexp(pl->hd), el);
                }
            }
            return rv;
        }
    default:
        assert(0);
        return NULL;
    }
}
Пример #16
0
int
main(int argc, char *argv[])
{
	cpusetid_t setid;
	cpuset_t mask;
	lwpid_t tid;
	pid_t pid;
	int ch;

	CPU_ZERO(&mask);
	level = CPU_LEVEL_WHICH;
	which = CPU_WHICH_PID;
	id = pid = tid = setid = -1;
	while ((ch = getopt(argc, argv, "Ccgij:l:p:rs:t:x:")) != -1) {
		switch (ch) {
		case 'C':
			Cflag = 1;
			break;
		case 'c':
			if (rflag)
				usage();
			cflag = 1;
			level = CPU_LEVEL_CPUSET;
			break;
		case 'g':
			gflag = 1;
			break;
		case 'i':
			iflag = 1;
			break;
		case 'j':
			jflag = 1;
			which = CPU_WHICH_JAIL;
			id = atoi(optarg);
			break;
		case 'l':
			lflag = 1;
			parselist(optarg, &mask);
			break;
		case 'p':
			pflag = 1;
			which = CPU_WHICH_PID;
			id = pid = atoi(optarg);
			break;
		case 'r':
			if (cflag)
				usage();
			level = CPU_LEVEL_ROOT;
			rflag = 1;
			break;
		case 's':
			sflag = 1;
			which = CPU_WHICH_CPUSET;
			id = setid = atoi(optarg);
			break;
		case 't':
			tflag = 1;
			which = CPU_WHICH_TID;
			id = tid = atoi(optarg);
			break;
		case 'x':
			xflag = 1;
			which = CPU_WHICH_IRQ;
			id = atoi(optarg);
			break;
		default:
			usage();
		}
	}
	argc -= optind;
	argv += optind;
	if (gflag) {
		if (argc || Cflag || lflag)
			usage();
		/* Only one identity specifier. */
		if (jflag + xflag + sflag + pflag + tflag > 1)
			usage();
		if (iflag)
			printsetid();
		else
			printaffinity();
		exit(EXIT_SUCCESS);
	}
	if (iflag)
		usage();
	/*
	 * The user wants to run a command with a set and possibly cpumask.
	 */
	if (argc) {
		if (Cflag | pflag | rflag | tflag | xflag | jflag)
			usage();
		if (sflag) {
			if (cpuset_setid(CPU_WHICH_PID, -1, setid))
				err(argc, "setid");
		} else {
			if (cpuset(&setid))
				err(argc, "newid");
		}
		if (lflag) {
			if (cpuset_setaffinity(level, CPU_WHICH_PID,
			    -1, sizeof(mask), &mask) != 0)
				err(EXIT_FAILURE, "setaffinity");
		}
		errno = 0;
		execvp(*argv, argv);
		err(errno == ENOENT ? 127 : 126, "%s", *argv);
	}
	/*
	 * We're modifying something that presently exists.
	 */
	if (Cflag && (sflag || rflag || !pflag || tflag || xflag || jflag))
		usage();
	if (!lflag && (cflag || rflag))
		usage();
	if (!lflag && !(Cflag || sflag))
		usage();
	/* You can only set a mask on a thread. */
	if (tflag && (sflag | pflag | xflag | jflag))
		usage();
	/* You can only set a mask on an irq. */
	if (xflag && (jflag | pflag | sflag | tflag))
		usage();
	if (Cflag) {
		/*
		 * Create a new cpuset and move the specified process
		 * into the set.
		 */
		if (cpuset(&setid) < 0)
			err(EXIT_FAILURE, "newid");
		sflag = 1;
	}
	if (pflag && sflag) {
		if (cpuset_setid(CPU_WHICH_PID, pid, setid))
			err(EXIT_FAILURE, "setid");
		/*
		 * If the user specifies a set and a list we want the mask
		 * to effect the pid and not the set.
		 */
		which = CPU_WHICH_PID;
		id = pid;
	}
	if (lflag) {
		if (cpuset_setaffinity(level, which, id, sizeof(mask),
		    &mask) != 0)
			err(EXIT_FAILURE, "setaffinity");
	}

	exit(EXIT_SUCCESS);
}
Пример #17
0
static void parseterm(void)
{
  int count;
  switch(tokentype)
  {
    case NUMBER:
      if(strchr(tokenval, '.') == NULL)
        makeINT(atol(tokenval));
      else
        makeREAL(atof(tokenval));
      gettoken();
      break;
    case IDENTIFIER:
      parsename();
      break;
    case TYPEID:
      push(gettemplate(tokenval));
      makecompound(STRUCT, 1);
      gettoken();
      break;
    case CHARACTER:
      makeconstant(CHAR, tokenval[0]);
      gettoken();
      break;
    case STRING:
      buildstring(tokenval);
      gettoken();
      break;
    case LPAR:
      gettoken();
      if(tokentype == OPERATOR && strcmp(tokenval, "-") != 0)
      {
        parsename();
        if(tokentype != RPAR)
        {
          parseexpression(MAXPRIO);
          rotatestack();
          push(gettemplate("_section"));
          make(APPLY);
          make(APPLY);
        }
      }
      else if(tokentype == RPAR)
        makeconstant(NULLTUPLE, 0);
      else
      {
        parseexpression(MAXPRIO);
        if(tokentype == COMMA)
        {
          count = 1;
          while(tokentype == COMMA)
          {
            gettoken();
            parseexpression(MAXPRIO);
            count++;
          }
          makecompound(PAIR, count);
        }
      }
      if(tokentype != RPAR) parseerror(2);
      gettoken();
      break;
    case LBRACK:
      parselist();
      break;
    case LACC:
      count = 0;
      do
      {
        gettoken();
        if(tokentype != IDENTIFIER) parseerror(25);
        push(gettemplate(tokenval));
        gettoken();
        if(strcmp(tokenval, "=") != 0) parseerror(5);
        gettoken();
        parseexpression(MAXPRIO);
        makeinverse(ALIAS);
        count++;
      }
      while(tokentype == COMMA);
      makecompound(RECORD, count);
      if(tokentype != RACC) parseerror(33);
      gettoken();
      break;
    default:
      parseerror(3);
  }
}