예제 #1
0
파일: bridge.c 프로젝트: dieterdeyke/WAMPES
static void route_packet(struct connection *p)
{

    int multicast;
    struct connection *p1next;
    struct connection *p1;
    uint8 *ap;
    uint8 *dest;
    uint8 *src;

    if ((*p->buf & 0xf) != KISS_DATA)
        return;
    dest = p->buf + 1;
    ap = src = dest + AXALEN;
    while (!(ap[6] & E)) {
        ap += AXALEN;
        if (ap[6] & REPEATED)
            src = ap;
        else {
            dest = ap;
            break;
        }
    }
    memcpy(p->call, src, AXALEN);
    multicast = all || addreq(dest, ax25_bdcst) || addreq(dest, nr_bdcst);
    for (p1 = connections; p1; p1 = p1next) {
        p1next = p1->next;
        if (multicast || !*p1->call || addreq(dest, p1->call)) {
            if (write(p1->fd, p->buf, p->cnt) <= 0)
                close_connection(p1);
        }
    }
}
예제 #2
0
파일: t14.c 프로젝트: 00001/plan9port
void
t14init(void)
{
	addreq(L("tl"), r_warn, -1);
	addreq(L("pc"), r_nop, -1);	/* page number char */
	addreq(L("lt"), r_lt, -1);
}
예제 #3
0
파일: t6.c 프로젝트: 00001/plan9port
void
t6init(void)
{
	addreq(L("ll"), r_ll, -1);
	addreq(L("in"), r_in, -1);
	addreq(L("ti"), r_ti, 1);
	
	nr(L(".l"), eval(L("6.5i")));
}
예제 #4
0
파일: t20.c 프로젝트: 00001/plan9port
void
t20init(void)
{
	addreq(L("mc"), r_warn, -1);
	addraw(L("tm"), r_tm);
	addraw(L("ab"), r_ab);
	addreq(L("lf"), r_lf, -1);
	addreq(L("pm"), r_pm, -1);
	addreq(L("fl"), r_fl, 0);
}
예제 #5
0
파일: asrv.C 프로젝트: vonwenm/pbft
bool
svccb::operator== (const svccb &a) const
{
    return (xid () == a.xid () && prog () == a.prog ()
            && vers () == a.vers () && proc () == a.proc ()
            && addrlen == a.addrlen && addreq (addr, a.addr, addrlen));
}
예제 #6
0
void
rel_demux (const struct config_common *cc,
	   const struct sockaddr_storage *ss,
	   packet_t *pkt, size_t len)
{
    assert(cc);
    assert(ss);
    assert(pkt);
    assert(len >= 0);

    rel_t *r;
    for (r = rel_list; r != NULL; r = r->next) {
        if (addreq(ss, &r->ss)) {
            rel_recvpkt(r, pkt, len);
            return;
        }
    }
    
    /* Before we create a new rel_t, we need to check
     * that this packet has a seqno == 1, otherwise
     * we're starting a flow part way in, and that's 
     * against the rules. */

    if (ntohl(pkt->seqno) != 1) {
        return;
    }

    /* If we reach here, then we need a new rel_t
     * for this connection, so we add it at the
     * head of the linked list of rel_t objects. */

    rel_t *new_r = rel_create (NULL, ss, cc);
    rel_recvpkt(new_r, pkt, len);
}
bool
resolv_conf::bumpsock (bool failure)
{
  if (reload_lock)
    return false;
  if (timenow > last_reload + 60) {
    reload (failure);
    return false;
  }

  if (nbump >= _res.nscount) {
    cantsend ();
    return false;
  }

  ns_idx = (ns_idx + 1) % _res.nscount;
  if (failure
      && (!addr || addrlen != sizeof (srvaddr)
	  || !addreq (addr, (reinterpret_cast<sockaddr *>
			     (&_res.nsaddr_list[ns_idx])),
		      addrlen)))
    warn ("changing nameserver to %s\n",
	  inet_ntoa (_res.nsaddr_list[ns_idx].sin_addr));

  srvaddr = _res.nsaddr_list[ns_idx];
  if (!srvaddr.sin_addr.s_addr)
    srvaddr.sin_addr.s_addr = htonl (INADDR_LOOPBACK);

  addr = reinterpret_cast<sockaddr *> (&srvaddr);
  addrlen = sizeof (srvaddr);

  return true;
}
예제 #8
0
파일: reliable.c 프로젝트: nyn531/cs144
/* This function only gets called when the process is running as a
 * server and must handle connections from multiple clients.  You have
 * to look up the rel_t structure based on the address in the
 * sockaddr_storage passed in.  If this is a new connection (sequence
 * number 1), you will need to allocate a new conn_t using rel_create
 * ().  (Pass rel_create NULL for the conn_t, so it will know to
 * allocate a new connection.)
 */
void
rel_demux (const struct config_common *cc,
	   const struct sockaddr_storage *ss,
	   packet_t *pkt, size_t len)
{
  if (!check_valid(pkt, len)) return;

  rel_t * r = rel_list;
  
  while (r) {
    if (r->ss && addreq(ss, r->ss)) {
      break;
    }
    r = r->next; 
  }

  if (!r) {
    if (ntohl(pkt->seqno) == 1) {
      r = rel_create(NULL, ss, cc);
    } else {
      return;
    }
  }

  rel_recvpkt(r, pkt, len);
}
예제 #9
0
파일: t17.c 프로젝트: aahud/harvey
void
t17init(void)
{
	int i;
	
	for(i=0; i<nelem(env); i++)
		env[i] = defenv;

	addreq(L("ev"), r_ev, -1);
}
예제 #10
0
static void unifyiflist(void)
{
int d=0,s,i;

	for (s=0;s<broadnum;s++) {
		for (i=0;i<s;i++)
			if (addreq(broads[s],broads[i])) break;
		if (i>=s) broads[d++]=broads[s];
		}
	broadnum=d;
}
예제 #11
0
파일: ipx_udp.cpp 프로젝트: paud/d2x-xl
static int FindDestInList (struct sockaddr_in *destAddr)
{
	int i;

for (i = 0; i < destAddrNum; i++) 
	if ((i < masksNum) ?
		!addreqm (destAddr, &destList [i].addr, broadmasks + i) :
		!addreq (destAddr, &destList [i].addr)) 
	return i;
return destAddrNum;
}
예제 #12
0
파일: t3.c 프로젝트: 99years/plan9
void
t3init(void)
{
	nr(L(".o"), eval(L("1i")));
	nr(L(".o0"), eval(L("1i")));
	nr(L(".p"), eval(L("11i")));
	
	addreq(L("pl"), r_warn, -1);
	addreq(L("bp"), r_nop, -1);
	addreq(L("pn"), r_warn, -1);
	addreq(L("po"), r_po, -1);
	addreq(L("ne"), r_nop, -1);
	addreq(L("mk"), r_nop, -1);
	addreq(L("rt"), r_warn, -1);
}
예제 #13
0
파일: t5.c 프로젝트: dancrossnyc/harvey
void
t5init(void)
{
	addreq(L("vs"), r_vs, -1);
	addreq(L("ls"), r_ls, -1);
	addreq(L("sp"), r_sp, -1);
	addreq(L("sv"), r_sp, -1);
	addreq(L("os"), r_nop, -1);
	addreq(L("ns"), r_ns, 0);
	addreq(L("rs"), r_rs, 0);

	nr(L(".v"), eval(L("12p")));
	nr(L(".v0"), eval(L("12p")));
	nr(L(".ls"), 1);
	nr(L(".ls0"), 1);
}
예제 #14
0
파일: t10.c 프로젝트: 99years/plan9
void
t10init(void)
{
	addreq(L("ec"), r_ec, -1);
	addreq(L("eo"), r_eo, 0);
	addreq(L("lg"), r_nop, -1);
	addreq(L("cc"), r_cc, -1);
	addreq(L("c2"), r_c2, -1);
	addreq(L("tr"), r_warn, -1);
	addreq(L("ul"), r_nop, -1);
	addraw(L("\\\""), r_comment);
	
	addesc('!', e_bang, 0);
	addesc('X', e_X, 0);
	addesc('\"', e_quote, CopyMode|ArgMode);
	addesc('\n', e_newline, CopyMode|ArgMode|HtmlMode);
	addesc('e', e_e, 0);
}
예제 #15
0
파일: roff.c 프로젝트: AustenConrad/plan-9
void
run(void)
{
	t1init();
	t2init();
	t3init();
	t4init();
	t5init();
	t6init();
	t7init();
	t8init();
	/* t9init(); t9.c */
	t10init();
	t11init();
	/* t12init(); t12.c */
	t13init();
	t14init();
	t15init();
	t16init();
	t17init();
	t18init();
	t19init();
	t20init();
	htmlinit();
	hideihtml();
	
	addreq(L("margin"), r_margin, 1);
	nr(L(".margin"), 1);
	nr(L(".paragraph"), 1);

	runinput();
	while(popinput())
		;
	dot = '.';
	if(verbose)
		fprint(2, "eof\n");
	runmacro1(L("eof"));
	closehtml();
}
예제 #16
0
파일: ipx_udp.cpp 프로젝트: paud/d2x-xl
static int AddDestToList (struct sockaddr_in *destAddr)
{
	int				h, i;
	tDestListEntry	*pdl;

if (!destAddr->sin_addr.s_addr) 
	return -1;
if (destAddr->sin_addr.s_addr == htonl (INADDR_BROADCAST))
	return destAddrNum;

for (i = 0; i < destAddrNum; i++) {
	h = (i < masksNum) ?
		 addreqm (destAddr, &destList [i].addr, broadmasks + i) :
		 addreq (destAddr, &destList [i].addr);
	if (h < 2)
		break;
	}
if (i < destAddrNum) {
	if (h)
		destList [i].addr = *destAddr;
	return i;
	}
if (!ChkDestListSize ())
	return -1;
pdl = destList + destAddrNum++;
pdl->addr = *destAddr;
#if UDP_SAFEMODE
pdl->nSent = 0;
pdl->nReceived = 0;
pdl->firstPacket = 0;
pdl->numPackets = 0;
pdl->bSafeMode = -1;
pdl->bOurSafeMode = -1;
pdl->modeCountdown = 1;
#endif
return i;
}
예제 #17
0
파일: momctl.c 프로젝트: CESNET/torque
int do_mom(

    char *HPtr,
    int   MOMPort,
    int   CmdIndex)

{
    int sd;

    if ((sd = openrm(HPtr, MOMPort)) < 0)
    {
        /* FAILURE */

        extern char TRMEMsg[];

        fprintf(stderr, "cannot connect to MOM on node '%s', errno=%d (%s)\n",
                HPtr,
                pbs_errno,
                strerror(pbs_errno));

        if (TRMEMsg[0] != '\0')
        {
            fprintf(stderr, " %s\n",
                    TRMEMsg);
        }

        return(sd);
    }

    if (IsVerbose == TRUE)
    {
        fprintf(stderr, "INFO:     successfully connected to %s\n",
                HPtr);
    }

    switch (CmdIndex)
    {

    case momClear:

    {
        char tmpLine[1024];

        char *Value;

        snprintf(tmpLine, 1024, "clearjob=%s",
                 (JPtr != NULL) ? JPtr : "all");

        if (addreq(sd, tmpLine) != 0)
        {
            /* FAILURE */

            fprintf(stderr,"ERROR:    cannot request job clear on %s (errno=%d-%s: %d-%s)\n",
                    HPtr,
                    errno,
                    pbs_strerror(errno),
                    pbs_errno,
                    pbs_strerror(pbs_errno));

            closerm(sd);

            return(FAILURE);
        }

        if ((Value = (char *)getreq(sd)) == NULL)
        {
            /* FAILURE */

            fprintf(stderr,"ERROR:    job clear failed on %s (errno=%d-%s: %d-%s)\n",
                    HPtr,
                    errno,
                    pbs_strerror(errno),
                    pbs_errno,
                    pbs_strerror(pbs_errno));

            closerm(sd);

            return(FAILURE);
        }

        /* job cleared */

        fprintf(stdout,"job clear request successful on %s\n",
                HPtr);
        }  /* END BLOCK (case momClear) */

    break;

    case momShutdown:

    {
        int rc;

        rc = downrm(sd);

        if (rc != 0)
        {
            /* FAILURE */

            fprintf(stderr,"ERROR:    cannot shutdown mom daemon on %s (errno=%d-%s: %d-%s)\n",
                    HPtr,
                    errno,
                    pbs_strerror(errno),
                    pbs_errno,
                    pbs_strerror(pbs_errno));

            closerm(sd);

            exit(EXIT_FAILURE);
        }

        fprintf(stdout, "shutdown request successful on %s\n",
                HPtr);
        }    /* END BLOCK */

    break;

    case momReconfig:

    {
        int rc;

        rc = configrm(sd, ConfigBuf);

        if (rc != 0)
        {
            /* FAILURE */

            fprintf(stderr,"ERROR:    cannot reconfigure mom on %s (errno=%d-%s: %d-%s)\n",
                    HPtr,
                    errno,
                    pbs_strerror(errno),
                    pbs_errno,
                    pbs_strerror(pbs_errno));

            closerm(sd);

            return(FAILURE);
        }

        fprintf(stdout, "reconfig successful on %s\n",
                HPtr);
        }  /* END BLOCK (case momReconfig) */

    break;

    case momQuery:

    default:

    {
        char *ptr;

        int  rindex;

        char *Value;

        int was_error = 0;

        for (rindex = 0; rindex < QueryI; rindex++)
        {
            if (addreq(sd, Query[rindex]) != 0)
            {
                fprintf(stderr,"ERROR:    cannot add query for '%s' on %s (errno=%d-%s: %d-%s)\n",
                        Query[rindex],
                        HPtr,
                        errno,

                        pbs_strerror(errno),
                        pbs_errno,
                        pbs_strerror(pbs_errno));

                was_error = 1;
            }
        }

        for (rindex = 0; rindex < QueryI; rindex++)
        {
            if ((ptr = strchr(Query[rindex],'=')) != NULL)
            {
                *ptr = '\0';
            }

            if ((Value = (char *)getreq(sd)) == NULL)
            {
                fprintf(stderr, "ERROR:    query[%d] '%s' failed on %s (errno=%d-%s: %d-%s)\n",
                        rindex,
                        Query[rindex],
                        HPtr,
                        errno,
                        pbs_strerror(errno),
                        pbs_errno,
                        pbs_strerror(pbs_errno));

                was_error = 1;
            }
            else
            {
                if (!strncmp(Query[rindex], "diag", strlen("diag")))
                {
                    fprintf(stdout, "%s\n",
                            Value);
                }
                else if (!strncmp(Query[rindex], "cycle", strlen("cycle")))
                {
                    fprintf(stdout, "mom %s successfully cycled %s\n",
                            HPtr,
                            Value);
                }
                else
                {
                    fprintf(stdout, "%12s: %12s = '%s'\n",
                            HPtr,
                            Query[rindex],
                            Value);
                }
            }

            if (ptr != NULL)
            {
                *ptr = '=';
            }
        }  /* END for (rindex) */
        return (was_error);
        }    /* END BLOCK (case momQuery) */

    break;
    }  /* END switch(CmdIndex) */

    closerm(sd);

    return(0);
} /* END do_mom() */
예제 #18
0
파일: getrsrcs.c 프로젝트: CESNET/torque
/*
 * Find an entry for the resources for the requested host in the list of
 * existing resources, or create a new one for that host and return it.
 */
Resources *
schd_get_resources(char *exechost)
{
    char   *id = "schd_get_resources";
    Resources *rptr, *new_rsrcs;
    int     rm;

    char   *response = NULL;
    int     badreply   = 0;
    int     cpus_avail = 0;
    size_t  pmem_avail = 0;

    char    hpm_ctl[64];

    struct sigaction act, oact;

    unsigned int remain; /* Time remaining in any old alarm(). */
    time_t then;  /* When this alarm() was started. */

#ifdef NODEMASK
    Bitfield cpy;
    int     i, j;
#endif /* NODEMASK */

    /*
     * Check for a local copy of the resources being available already.
     * If so, just return a reference to that Resources structure.
     */

    if (schd_RsrcsList != NULL)
    {
        for (rptr = schd_RsrcsList; rptr != NULL; rptr = rptr->next)
            if (strcmp(rptr->exechost, exechost) == 0)
                return (rptr);
    }

    schd_timestamp("get_rsrcs");

    /*
     * No cached resource information for 'exechost'.  Need to query the
     * host for its information.
     */

    if ((new_rsrcs = (Resources *)malloc(sizeof(Resources))) == NULL)
    {
        (void)sprintf(log_buffer, "Unable to alloc space for Resources.");
        log_record(PBSEVENT_SYSTEM, PBS_EVENTCLASS_SERVER, id, log_buffer);
        DBPRT(("%s: %s\n", id, log_buffer));

        return (NULL); /* Can't get the information - nowhere to store it. */
    }

    memset((void *)new_rsrcs, 0, sizeof(Resources));

    act.sa_flags = 0;
    act.sa_handler = connect_interrupt;
    sigemptyset(&act.sa_mask);
    remain = 0;
    then = 0;

    /*
     * Set the alarm, and maintain some idea of how long was left on any
     * previously set alarm.
     */

    if (sigaction(SIGALRM, &act, &oact) == 0)
    {
        remain = alarm(GETRSRCS_CONNECT_TIME);
        then = time(NULL);
    }

    if ((rm = openrm(exechost, 0)) == -1)
    {
        (void)sprintf(log_buffer,
                      "Unable to contact resmom@%s (%d)", exechost, pbs_errno);
        log_record(PBSEVENT_SYSTEM, PBS_EVENTCLASS_SERVER, id, log_buffer);

        badreply = 1;
        goto bail;
    }

    /*
     * Turn off full response.  Responses will be received in the order in
     * which they are sent.
     */
    fullresp(0);

    /* Build a list of all the resources about which we want information. */

    addreq(rm, "loadave");

    addreq(rm, "availmem");

    addreq(rm, "physmem");

    addreq(rm, "ncpus");

#ifdef NODEMASK
    addreq(rm, "availmask");

#endif /* NODEMASK */

    if (schd_MANAGE_HPM)
    {
        (void)sprintf(hpm_ctl, HPM_CTL_FORMAT_STR, HPM_CTL_QUERY_STR);
        addreq(rm, hpm_ctl);
    }

    /* Get the values back from the resource monitor, and round up. */

    /* Receive LOADAVE response from resource monitor. */
    response = getreq(rm);

    if (response != NULL)
    {
        new_rsrcs->loadave = atof(response) * schd_FAKE_MACH_MULT;
        (void)free(response);
    }
    else
    {
        (void)sprintf(log_buffer, "bad return from getreq(loadave), %d, %d",
                      pbs_errno, errno);
        log_record(PBSEVENT_SYSTEM, PBS_EVENTCLASS_SERVER, id, log_buffer);
        badreply = 1;
        goto bail;
    }

    /* Receive AVAILMEM response from resource monitor. */
    response = getreq(rm);

    if (response != NULL)
    {
        new_rsrcs->freemem = schd_val2byte(response);
        new_rsrcs->freemem *= schd_FAKE_MACH_MULT;
        (void)free(response);
    }
    else
    {
        (void)sprintf(log_buffer, "bad return from getreq(freemem), %d, %d",
                      pbs_errno, errno);
        log_record(PBSEVENT_SYSTEM, PBS_EVENTCLASS_SERVER, id, log_buffer);
        badreply = 1;
        goto bail;
    }

    /* Receive PHYSMEM response from resource monitor. */
    response = getreq(rm);

    if (response != NULL)
    {
        pmem_avail = schd_val2byte(response);
        pmem_avail *= schd_FAKE_MACH_MULT;
        (void)free(response);
    }
    else
    {
        (void)sprintf(log_buffer, "bad return from getreq(realmem), %d, %d",
                      pbs_errno, errno);
        log_record(PBSEVENT_SYSTEM, PBS_EVENTCLASS_SERVER, id, log_buffer);
        badreply = 1;
        goto bail;
    }

    /* Receive NCPUS response from resource monitor. */
    response = getreq(rm);

    if (response != NULL)
    {
        cpus_avail = atoi(response) * schd_FAKE_MACH_MULT;
        (void)free(response);
    }
    else
    {
        (void)sprintf(log_buffer, "bad return from getreq(ncpus), %d, %d",
                      pbs_errno, errno);
        log_record(PBSEVENT_SYSTEM, PBS_EVENTCLASS_SERVER, id, log_buffer);
        badreply = 1;
        goto bail;
    }

#ifdef NODEMASK
    /* Receive available nodes from resource monitor. */
    response = getreq(rm);

    if (response == NULL)
    {
        (void)sprintf(log_buffer, "bad return from getreq(availmask), %d, %d",
                      pbs_errno, errno);
        log_record(PBSEVENT_SYSTEM, PBS_EVENTCLASS_SERVER, id, log_buffer);
        badreply = 1;
        goto bail;
    }
    else
    {
        if (schd_bits2mask(response, &new_rsrcs->availmask) != 0)
        {
            if (schd_str2mask(response, &new_rsrcs->availmask) != 0)
            {
                (void)sprintf(log_buffer, "can't parse availmask '%s'", response);
                log_record(PBSEVENT_SYSTEM, PBS_EVENTCLASS_SERVER, id, log_buffer);
                badreply = 1;
                goto bail;
            }
        }

        (void)free(response);
    }

#endif /* NODEMASK */

    if (schd_MANAGE_HPM)
    {
        /* Receive HPM_CTL response from resource monitor. */
        response = getreq(rm);

        if (response != NULL)
        {
            if (strcmp(response, HPM_CTL_USERMODE_STR) == 0)
                new_rsrcs->flags |= RSRCS_FLAGS_HPM_USER;
            else if (strcmp(response, HPM_CTL_GLOBALMODE_STR) == 0)
                new_rsrcs->flags &= ~RSRCS_FLAGS_HPM_USER;
            else
            {
                (void)sprintf(log_buffer, "bad response '%s' for '%s@%s'",
                              response, hpm_ctl, exechost);
                log_record(PBSEVENT_SYSTEM, PBS_EVENTCLASS_SERVER, id,
                           log_buffer);
                badreply = 1;
                goto bail;
            }
        }
        else
        {
            (void)sprintf(log_buffer, "bad return from getreq(%s), %d, %d",
                          hpm_ctl, pbs_errno, errno);
            log_record(PBSEVENT_SYSTEM, PBS_EVENTCLASS_SERVER, id, log_buffer);
            badreply = 1;
            goto bail;
        }
    }

    /*
     * NOTE: response will be free()'d in bail.  Be sure to explicitly free()
     * response if more getreq() calls are added before the code below.
     */

bail:
    if (response != NULL)
        (void)free(response);

    /* Disconnect from the resource monitor. */
    if (rm >= 0)  /* resmom handle "0" is valid in RPP. */
        closerm(rm);

    /* And unset the alarm and handler. */
    alarm(0);

    sigaction(SIGALRM, &oact, &act);

    /* Reset the old alarm, taking into account how much time has passed. */
    if (remain)
    {
        DBPRT(("%s: old alarm had %d secs remaining, %d elapsed, ", id,
               remain, (time(NULL) - then)));
        /* How much time remains even after the time spent above? */
        remain -= (time(NULL) - then);

        /*
         * Would the previous time have already expired?  If so, schedule
         * an alarm call in 1 second (close enough, hopefully).
         */

        if (remain < 1)
            remain = 1;

        DBPRT(("reset to %d secs\n", remain));

        alarm(remain);
    }

    /*
     * Verify all the data came back as expected; if not, abort this
     * iteration of the scheduler.
     */
    if (badreply)
    {
        (void)sprintf(log_buffer,
                      "Got bad info from mom@%s - aborting sched run", exechost);
        log_record(PBSEVENT_SYSTEM, PBS_EVENTCLASS_SERVER, id, log_buffer);
        DBPRT(("%s: %s\n", id, log_buffer));

        free(new_rsrcs);
        return (NULL);
    }

    /* Make a copy of the hostname for the resources struct. */
    new_rsrcs->exechost = schd_strdup(exechost);

    if (new_rsrcs->exechost == NULL)
    {
        (void)sprintf(log_buffer, "Unable to copy exechost %s to rsrcs",
                      exechost);
        log_record(PBSEVENT_SYSTEM, PBS_EVENTCLASS_SERVER, id, log_buffer);
        DBPRT(("%s: %s\n", id, log_buffer));

        free(new_rsrcs);
        return (NULL);
    }

    new_rsrcs->nodes_total = NODES_REQD(cpus_avail, pmem_avail);

#ifdef NODEMASK
    /* Copy the availmask schd_FAKE_MACH_MULT times to match avail cpus. */
    BITFIELD_CPY(&cpy, &(new_rsrcs->availmask));

    for (i = 2; i <= schd_FAKE_MACH_MULT; i++)
    {
        for (j = 0; j < (cpus_avail / schd_FAKE_MACH_MULT / 2); j++)
            BITFIELD_SHIFTL(&cpy);

        BITFIELD_SETM(&(new_rsrcs->availmask), &cpy);
    }

#endif /* NODEMASK */

    if (schd_RsrcsList == NULL)
    {
        schd_RsrcsList  = new_rsrcs; /* Start the list. */
    }
    else
    {
        for (rptr = schd_RsrcsList; rptr->next != NULL; rptr = rptr->next)
            /* Find the last element in the list. */ ;

        rptr->next = new_rsrcs;
    }

    /* Next pointer for the tail of the list points to nothing. */
    new_rsrcs->next = NULL;

    return (new_rsrcs);
}
예제 #19
0
파일: ipx_udp.c 프로젝트: paud/d2x-xl
static int UDPReceivePacket(ipx_socket_t *s, char *outbuf, int outbufsize, 
 struct ipx_recv_data *rd) {
	int size;
	struct sockaddr_in fromaddr;
	int fromaddrsize=sizeof(fromaddr);
	unsigned short ports;
	size_t offs;
	int i;

	if ((size=recvfrom(s->fd,outbuf,outbufsize,0,(struct sockaddr *)&fromaddr,&fromaddrsize))<0)
		return -1;
#ifndef _WIN32
#	ifdef UDPDEBUG
	////printf(MSGHDR "recvfrom((%d-8=%d),",size,size-8);
	dumpaddr(&fromaddr);
	//puts(").");
#	endif
#endif
	if (fromaddr.sin_family!=AF_INET) return -1;
	if (size<4) return -1;
	if (memcmp(outbuf+0,D1Xid,2)) {
		if (size<8 || memcmp(outbuf+0,D1Xudp,6)) return -1;
		if (!compatibility) {
			compatibility=1;
			fputs(MSGHDR "Received obsolete packet from ",stdout);
			dumpaddr(&fromaddr);
			//puts(", upgrade that machine.\n" MSGHDR "Turning on compatibility mode...");
			}
		offs=6;
		}
	else offs=2;

	/* Lace: (dst_socket & src_socket) should be network-byte-order by comment in include/ipx_drv.h */
	/*       This behaviour presented here is broken. It is not used anywhere, so why bother? */
	rd->src_socket = ntohs(*(unsigned short *)(outbuf+offs));
	if (rd->src_socket != s->socket) {
#ifdef UDPDEBUG
		msg(" - pkt was dropped (dst=%d,my=%d)",rd->src_socket,s->socket);
#endif
		return -1;
		}
	rd->dst_socket = s->socket;

	// check if we already have sender of this packet in broadcast list
	for (i=0;i<broadnum;i++) {
		if (i>=masksnum) {
			if (addreq(fromaddr,broads[i])) break; 
			}
		else {
			if (fromaddr.sin_port==broads[i].sin_port
			&&( fromaddr.sin_addr.s_addr & broadmasks[i].sin_addr.s_addr)
			==(broads[i].sin_addr.s_addr & broadmasks[i].sin_addr.s_addr)) break;
			}
		}
	if (i>=broadnum) { // we don't have sender of this packet in our broadcast list
		chkbroadsize();
		broads[broadnum++]=fromaddr;
		fputs(MSGHDR "Adding host ",stdout);
		dumpaddr(&fromaddr);
		//puts(" to broadcasting address list");
		}

	memmove(outbuf,outbuf+offs+2,size-(offs+2));
	size-=offs+2;

	memcpy(rd->src_node+0,&fromaddr.sin_addr,4);
	ports=htons(ntohs(fromaddr.sin_port)-UDP_BASEPORT);
	memcpy(rd->src_node+4,&ports,2);
	memset(rd->src_network, 0, 4);
	rd->pktType = 0;
#ifndef _WIN32
#	ifdef UDPDEBUG
	////printf(MSGHDR "ReceivePacket: size=%d,from=",size);
	dumpraddr(rd->src_node);
	////putchar('\n');
#	endif
#endif

	return size;
}
예제 #20
0
파일: t18.c 프로젝트: 99years/plan9
void
t18init(void)
{
	addreq(L("rd"), r_rd, -1);
	addreq(L("ex"), r_ex, 0);
}
예제 #21
0
파일: ipx_udp.cpp 프로젝트: paud/d2x-xl
/* Stolen from my GGN */
static int addiflist (void)
{
	unsigned 				cnt = MAX_BRDINTERFACES, i, j;
	struct ifconf 			ifconf;
	int 						sock;
#ifdef _DEBUG
	int						ioRes;
#endif
	struct sockaddr_in	*sinp, *sinmp;

D2_FREE (broads);
#ifdef __macosx__
/* This code is for Mac OS X, whose BSD layer does bizarre things with variable-length
* structures when calling ioctl using SIOCGIFCOUNT. Or any other architecture that
* has this call, for that matter, since it's much simpler than the other code below.
*/
	struct ifaddrs *ifap, *ifa;
	struct sockaddr *broadaddr, *dstaddr;

if (getifaddrs (&ifap) != 0)
	FAIL ("Getting list of interface addresses: %m");

// First loop to count the number of valid addresses and allocate enough memory
j = 0;
for (ifa = ifap; ifa != NULL; ifa = ifa->ifa_next) {
	// Only count the address if it meets our criteria.
	if (ifa->ifa_flags & IF_NOTFLAGS || !((ifa->ifa_flags & IF_REQFLAGS) && (ifa->ifa_addr->sa_family == AF_INET)))
		continue;
	j++;
	}
broadsize = j;
chk (broads = D2_ALLOC (j * sizeof (*broads)));
// Second loop to copy the addresses
j = 0;
for (ifa = ifap; ifa != NULL; ifa = ifa->ifa_next) {
	// Only copy the address if it meets our criteria.
	if ((ifa->ifa_flags & IF_NOTFLAGS) || !((ifa->ifa_flags & IF_REQFLAGS) && (ifa->ifa_addr->sa_family == AF_INET)))
		continue;
	j++;
	sinp = (struct sockaddr_in *) ifa->ifa_broadaddr;
	sinmp = (struct sockaddr_in *) ifa->ifa_dstaddr;
#else // non-getifaddrs () code for Linux variants
	sock = socket (AF_INET, SOCK_DGRAM, IPPROTO_UDP);
	if (sock < 0)
		FAIL ("Creating IP socket failed:\n%m");
#	ifdef SIOCGIFCOUNT
	if (!_IOCTL (sock, SIOCGIFCOUNT, &cnt))
		{ /* //msg ("Getting iterface count error: %m"); */ }
	else
		cnt = cnt * 2 + 2;
#	endif
	ifconf.ifc_len = cnt * sizeof (struct ifreq);
	chk (ifconf.ifc_req = (ifreq *) D2_ALLOC (ifconf.ifc_len));
#ifdef _DEBUG
	memset (ifconf.ifc_req, 0, ifconf.ifc_len);
	ioRes = ioctl (sock, SIOCGIFCONF, &ifconf);
	if (ioRes < 0) {
#else
	 if (!_IOCTL (sock, SIOCGIFCONF, &ifconf)) {
#endif
		close (sock);
		FAIL ("ioctl (SIOCGIFCONF)\nIP interface detection failed:\n%m");
		}
	if (ifconf.ifc_len % sizeof (struct ifreq)) {
		close (sock);
		FAIL ("ioctl (SIOCGIFCONF)\nIP interface detection failed:\n%m");
		}
cnt = ifconf.ifc_len / sizeof (struct ifreq);
chk (broads = (sockaddr_in *) D2_ALLOC (cnt * sizeof (*broads)));
broadsize = cnt;
for (i = j = 0; i < cnt; i++) {
	if (!_IOCTL (sock, SIOCGIFFLAGS, ifconf.ifc_req + i)) {
		close (sock);
		FAIL ("ioctl (UDP (%d),\"%s\",SIOCGIFFLAGS)\nerror: %m", i, ifconf.ifc_req [i].ifr_name);
		}
	if (((ifconf.ifc_req [i].ifr_flags & IF_REQFLAGS) != IF_REQFLAGS) ||
		  (ifconf.ifc_req [i].ifr_flags & IF_NOTFLAGS))
		continue;
	if (!_IOCTL (sock, (ifconf.ifc_req [i].ifr_flags & IFF_BROADCAST) ? SIOCGIFBRDADDR : SIOCGIFDSTADDR, ifconf.ifc_req + i)) {
		close (sock);
		FAIL ("ioctl (UDP (%d),\"%s\",SIOCGIF{DST/BRD}ADDR)\nerror: %m", i, ifconf.ifc_req [i].ifr_name);
		}
	sinp = (struct sockaddr_in *) &ifconf.ifc_req [i].ifr_broadaddr;
	if (!_IOCTL (sock, SIOCGIFNETMASK, ifconf.ifc_req + i)) {
		close (sock);
		FAIL ("ioctl (UDP (%d),\"%s\",SIOCGIFNETMASK)\nerror: %m", i, ifconf.ifc_req [i].ifr_name);
		}
	sinmp = (struct sockaddr_in *)&ifconf.ifc_req [i].ifr_addr;
	if (sinp->sin_family!=AF_INET || sinmp->sin_family!=AF_INET) 
		continue;
#endif // __macosx__
	// Code common to both getifaddrs () and ioctl () approach
	broads [j] = *sinp;
	broads [j].sin_port = UDP_BASEPORT; //FIXME: No possibility to override from cmdline
	broadmasks [j] = *sinmp;
	j++;
	}
#ifdef __macosx__
freeifaddrs (ifap);
#endif
broadnum = j;
masksnum = j;
return 0;
}

//------------------------------------------------------------------------------
/* Previous function addiflist () can (and probably will) report multiple
 * same addresses. On some Linux boxes is present both device "eth0" and
 * "dummy0" with the same IP addreesses - we'll filter it here.
 */

static void unifyiflist (void)
{
int d=0,s,i;

	for (s=0;s<broadnum;s++) {
		for (i=0;i<s;i++)
			if (addreq (broads + s, broads + i)) break;
		if (i>=s) broads [d++] = broads [s];
		}
	broadnum=d;
}

//------------------------------------------------------------------------------

/* Parse PORTSHIFT numeric parameter
 */

static void portshift (const char *cs)
{
long port;
unsigned short ports=0;

	port=atol (cs);
	if (port<-PORTSHIFT_TOLERANCE || port>+PORTSHIFT_TOLERANCE)
		//msg ("Invalid portshift in \"%s\", tolerance is +/-%d",cs,PORTSHIFT_TOLERANCE)
		;
	else ports=htons (port);
	memcpy (qhbuf+4,&ports,2);
}
예제 #22
0
파일: getrsrcs.c 프로젝트: gto11520/torque
/*
 * Find an entry for the resources for the requested host in the list of
 * existing resources, or create a new one for that host and return it.
 */
Resources *
schd_get_resources(char *exechost)
  {
  char *id = "schd_get_resources";
  Resources *rptr, *new_rsrcs;
  int  rm;
  char *response = NULL;
  int  badreply   = 0;
  int  local_errno = 0;

  struct sigaction act, oact;
  unsigned int remain;  /* Time remaining in any old alarm(). */
  time_t  then;  /* When this alarm() was started. */

  /*
   * Check for a local copy of the resources being available already.
   * If so, just return a reference to that Resources structure.
   */

  if (schd_RsrcsList != NULL)
    {
    for (rptr = schd_RsrcsList; rptr != NULL; rptr = rptr->next)
      if (strcmp(rptr->exechost, exechost) == 0)
        return (rptr);
    }

  schd_timestamp("get_rsrcs");

  /*
   * No cached resource information for 'exechost'.  Need to query the
   * host for its information.
   */

  if ((new_rsrcs = (Resources *)malloc(sizeof(Resources))) == NULL)
    {
    (void)sprintf(log_buffer, "Unable to alloc space for Resources.");
    log_record(PBSEVENT_SYSTEM, PBS_EVENTCLASS_SERVER, id, log_buffer);
    DBPRT(("%s: %s\n", id, log_buffer));

    return (NULL); /* Can't get the information - nowhere to store it. */
    }

  memset((void *)new_rsrcs, 0, sizeof(Resources));

  act.sa_flags = 0;
  act.sa_handler = connect_interrupt;
  sigemptyset(&act.sa_mask);
  remain = 0;
  then = 0;

  /*
   * Set the alarm, and maintain some idea of how long was left on any
   * previously set alarm.
   */

  if (sigaction(SIGALRM, &act, &oact) == 0)
    {
    remain = alarm(GETRSRCS_CONNECT_TIME);
    then = time(NULL);
    }

  if ((rm = openrm(exechost, 0)) == -1)
    {
    (void)sprintf(log_buffer,
                  "Unable to contact resmom@%s ", exechost);
    log_record(PBSEVENT_SYSTEM, PBS_EVENTCLASS_SERVER, id, log_buffer);

    badreply = 1;
    goto bail;
    }

  /*
   * Turn off full response.  Responses will be received in the order in
   * which they are sent.
   */
  fullresp(0);

  /* Build a list of all the resources about which we want information. */

  addreq(rm, "loadave");

  addreq(rm, "availmem");

  addreq(rm, "physmem");

  addreq(rm, "ncpus");

  addreq(rm, "tmpdir");

  addreq(rm, "arch");

  /* Get the values back from the resource monitor, and round up. */

  /* Receive LOADAVE response from resource monitor. */
  response = getreq_err(&local_errno, rm);

  if (response != NULL)
    {
    new_rsrcs->loadave = atof(response);
    (void)free(response);
    }
  else
    {
    (void)sprintf(log_buffer, "bad return from getreq(loadave), %d, %d",
                  local_errno, errno);
    log_record(PBSEVENT_SYSTEM, PBS_EVENTCLASS_SERVER, id, log_buffer);
    badreply = 1;
    goto bail;
    }

  /* Receive AVAILMEM response from resource monitor. */
  response = getreq_err(&local_errno, rm);

  if (response != NULL)
    {
    new_rsrcs->freemem = schd_val2byte(response);
    (void)free(response);
    }
  else
    {
    (void)sprintf(log_buffer, "bad return from getreq(freemem), %d, %d",
                  local_errno, errno);
    log_record(PBSEVENT_SYSTEM, PBS_EVENTCLASS_SERVER, id, log_buffer);
    badreply = 1;
    goto bail;
    }

  /* Receive PHYSMEM response from resource monitor. */
  response = getreq_err(&local_errno, rm);

  if (response != NULL)
    {
    new_rsrcs->mem_total = schd_val2byte(response);
    (void)free(response);
    }
  else
    {
    (void)sprintf(log_buffer, "bad return from getreq(realmem), %d, %d",
                  local_errno, errno);
    log_record(PBSEVENT_SYSTEM, PBS_EVENTCLASS_SERVER, id, log_buffer);
    badreply = 1;
    goto bail;
    }

  /* Receive NCPUS response from resource monitor. */
  response = getreq_err(&local_errno, rm);

  if (response != NULL)
    {
    new_rsrcs->ncpus_total = atoi(response);
    (void)free(response);
    }
  else
    {
    (void)sprintf(log_buffer, "bad return from getreq(ncpus), %d, %d",
                  local_errno, errno);
    log_record(PBSEVENT_SYSTEM, PBS_EVENTCLASS_SERVER, id, log_buffer);
    badreply = 1;
    goto bail;
    }

  /* Receive TMPDIR response from resource monitor. */
  response = getreq_err(&local_errno, rm);

  if (response != NULL)
    {
    new_rsrcs->tmpdir = schd_val2byte(response);
    (void)free(response);
    }
  else
    {
    (void)sprintf(log_buffer, "bad return from getreq(tmpdir), %d, %d",
                  local_errno, errno);
    log_record(PBSEVENT_SYSTEM, PBS_EVENTCLASS_SERVER, id, log_buffer);
    badreply = 1;
    goto bail;
    }

  /* Receive ARCH response from resource monitor. */
  response = getreq_err(&local_errno, rm);

  if (response != NULL)
    {
    new_rsrcs->arch = schd_strdup(response);
    (void)free(response);
    }
  else
    {
    (void)sprintf(log_buffer, "bad return from getreq(arch), %d, %d",
                  local_errno, errno);
    log_record(PBSEVENT_SYSTEM, PBS_EVENTCLASS_SERVER, id, log_buffer);
    badreply = 1;
    goto bail;
    }

bail:

  /* Disconnect from the resource monitor. */

  if (rm >= 0)  /* resmom handle "0" is valid in RPP. */
    closerm(rm);

  /* And unset the alarm and handler. */
  alarm(0);

  sigaction(SIGALRM, &oact, &act);

  /* Reset the old alarm, taking into account how much time has passed. */
  if (remain)
    {
    DBPRT(("%s: old alarm had %d secs remaining, %d elapsed, ", id,
           remain, (time(NULL) - then)));

    /* How much time remains even after the time spent above? */
    remain -= (time(NULL) - then);

    /*
     * Would the previous time have already expired?  If so, schedule
     * an alarm call in 1 second (close enough, hopefully).
     */

    if (remain < 1)
      remain = 1;

    DBPRT(("reset to %d secs\n", remain));

    alarm(remain);
    }

  /*
   * Verify all the data came back as expected; if not, abort this
   * iteration of the scheduler.
   */

  if (badreply)
    {
    (void)sprintf(log_buffer,
                  "Got bad info from mom@%s - skipping this node", exechost);
    log_record(PBSEVENT_SYSTEM, PBS_EVENTCLASS_SERVER, id, log_buffer);
    DBPRT(("%s: %s\n", id, log_buffer));
    free(new_rsrcs);
    return (NULL);
    }

  /* Make a copy of the hostname for the resources struct. */
  new_rsrcs->exechost = schd_strdup(exechost);

  if (new_rsrcs->exechost == NULL)
    {
    (void)sprintf(log_buffer, "Unable to copy exechost %s to rsrcs",
                  exechost);
    log_record(PBSEVENT_SYSTEM, PBS_EVENTCLASS_SERVER, id, log_buffer);
    DBPRT(("%s: %s\n", id, log_buffer));
    free(new_rsrcs);
    return (NULL);
    }

  if (schd_RsrcsList == NULL)
    {
    schd_RsrcsList  = new_rsrcs; /* Start the list. */
    }
  else
    {
    for (rptr = schd_RsrcsList; rptr->next != NULL; rptr = rptr->next)
      /* Find the last element in the list. */ ;

    rptr->next = new_rsrcs;
    }

  /* Next pointer for the tail of the list points to nothing. */
  new_rsrcs->next = NULL;

  return (new_rsrcs);
  }
예제 #23
0
파일: t7.c 프로젝트: 00001/plan9port
void
t7init(void)
{	
	addreq(L("de"), r_de, -1);
	addreq(L("am"), r_de, -1);
	addreq(L("ig"), r_de, -1);
	addraw(L("ds"), r_ds);
	addraw(L("as"), r_ds);
	addreq(L("rm"), r_rm, -1);
	addreq(L("rn"), r_rn, -1);
	addreq(L("di"), r_di, -1);
	addreq(L("da"), r_di, -1);
	addreq(L("it"), r_it, -1);
	addreq(L("em"), r_em, 1);
	addreq(L("wh"), r_wh, -1);
	addreq(L("ch"), r_ch, -1);
	addreq(L("dt"), r_dt, -1);
	
	addesc('$', e_dollar, CopyMode|ArgMode|HtmlMode);
	addesc('*', e_star, CopyMode|ArgMode|HtmlMode);
	addesc('t', e_t, CopyMode|ArgMode);
	addesc('a', e_a, CopyMode|ArgMode);
	addesc('\\', e_backslash, ArgMode|CopyMode);
	addesc('.', e_dot, CopyMode|ArgMode);
	
	ds(L("eof"), L(".sp 0.5i\n"));
	ds(L(".."), L(""));
}
예제 #24
0
파일: getrsrcs.c 프로젝트: Johnlihj/torque
/*
 * Find an entry for the resources for the requested host in the list of
 * existing resources, or create a new one for that host and return it.
 */
Resources *
schd_get_resources(char *exechost)
  {
  char   *id = "schd_get_resources";
  Resources *rptr, *new_rsrcs;
  int     rm;

  char   *response;
  int     badreply   = 0;
  int     cpus_avail = 0;
  int     cpus_tot   = 0;

  struct sigaction act, oact;

  unsigned int remain; /* Time remaining in any old alarm(). */
  time_t then;  /* When this alarm() was started. */

  /*
   * Check for a local copy of the resources being available already.
   * If so, just return a reference to that Resources structure.
   */

  if (schd_RsrcsList != NULL)
    {
    for (rptr = schd_RsrcsList; rptr != NULL; rptr = rptr->next)
      if (strcmp(rptr->exechost, exechost) == 0)
        return (rptr);
    }

  schd_timestamp("get_rsrcs");

  /*
   * No cached resource information for 'exechost'.  Need to query the
   * host for its information.
   */

  if ((new_rsrcs = (Resources *)malloc(sizeof(Resources))) == NULL)
    {
    (void)sprintf(log_buffer, "Unable to alloc space for Resources.");
    log_record(PBSEVENT_SYSTEM, PBS_EVENTCLASS_SERVER, id, log_buffer);
    DBPRT(("%s: %s\n", id, log_buffer));

    return (NULL); /* Can't get the information - nowhere to store it. */
    }

  memset((void *)new_rsrcs, 0, sizeof(Resources));

  act.sa_flags = 0;
  act.sa_handler = connect_interrupt;
  sigemptyset(&act.sa_mask);
  remain = 0;
  then = 0;

  /*
   * Set the alarm, and maintain some idea of how long was left on any
   * previously set alarm.
   */

  if (sigaction(SIGALRM, &act, &oact) == 0)
    {
    remain = alarm(GETRSRCS_CONNECT_TIME);
    then = time(NULL);
    }

  if ((rm = openrm(exechost, 0)) == -1)
    {
    (void)sprintf(log_buffer,
                  "Unable to contact resmom@%s (%d)", exechost, pbs_errno);
    log_record(PBSEVENT_SYSTEM, PBS_EVENTCLASS_SERVER, id, log_buffer);

    badreply = 1;
    goto bail;
    }

  /*
   * Turn off full response.  Responses will be received in the order in
   * which they are sent.
   */
  fullresp(0);

  /* Build a list of all the resources about which we want information. */

  addreq(rm, "mppe_app");

  addreq(rm, "mppe_avail");

  /* Get the values back from the resource monitor, and round up. */

  /* Receive MPPE_APP response from resource monitor. */
  /* returns the total number of Application PEs configured */
  response = getreq(rm);

  if (response != NULL)
    {
    cpus_tot = atoi(response) * schd_FAKE_MACH_MULT;
    }
  else
    {
    (void)sprintf(log_buffer, "bad return from getreq(ncpus), %d, %d",
                  pbs_errno, errno);
    log_record(PBSEVENT_SYSTEM, PBS_EVENTCLASS_SERVER, id, log_buffer);
    badreply = 1;
    goto bail;
    }

  /* Receive MPPE_AVAIL response from resource monitor. */
  /* returns the largest contiguous block of APP PEs */
  response = getreq(rm);

  if (response != NULL)
    {
    cpus_avail = atoi(response) * schd_FAKE_MACH_MULT;
    }
  else
    {
    (void)sprintf(log_buffer, "bad return from getreq(ncpus), %d, %d",
                  pbs_errno, errno);
    log_record(PBSEVENT_SYSTEM, PBS_EVENTCLASS_SERVER, id, log_buffer);
    badreply = 1;
    goto bail;
    }

  new_rsrcs->freemem = MB_PER_NODE * schd_FAKE_MACH_MULT;

bail:
  /* Disconnect from the resource monitor. */

  if (rm)
    closerm(rm);

  /* And unset the alarm and handler. */
  alarm(0);

  sigaction(SIGALRM, &oact, &act);

  /* Reset the old alarm, taking into account how much time has passed. */
  if (remain)
    {
    DBPRT(("%s: old alarm had %d secs remaining, %d elapsed, ", id,
           remain, (time(NULL) - then)));
    /* How much time remains even after the time spent above? */
    remain -= (time(NULL) - then);

    /*
     * Would the previous time have already expired?  If so, schedule
     * an alarm call in 1 second (close enough, hopefully).
     */

    if (remain < 1)
      remain = 1;

    DBPRT(("reset to %d secs\n", remain));

    alarm(remain);
    }

  /*
   * Verify all the data came back as expected; if not, abort this
   * iteration of the scheduler.
   */
  if (badreply)
    {
    (void)sprintf(log_buffer,
                  "Got bad info from mom@%s - aborting sched run", exechost);
    log_record(PBSEVENT_SYSTEM, PBS_EVENTCLASS_SERVER, id, log_buffer);
    DBPRT(("%s: %s\n", id, log_buffer));

    free(new_rsrcs);
    return (NULL);
    }

  /* Make a copy of the hostname for the resources struct. */
  new_rsrcs->exechost = schd_strdup(exechost);

  if (new_rsrcs->exechost == NULL)
    {
    (void)sprintf(log_buffer, "Unable to copy exechost %s to rsrcs",
                  exechost);
    log_record(PBSEVENT_SYSTEM, PBS_EVENTCLASS_SERVER, id, log_buffer);
    DBPRT(("%s: %s\n", id, log_buffer));

    free(new_rsrcs);
    return (NULL);
    }

  new_rsrcs->nodes_total = cpus_tot;

  new_rsrcs->nodes_alloc = cpus_tot - cpus_avail;

  if (schd_RsrcsList == NULL)
    {
    schd_RsrcsList  = new_rsrcs; /* Start the list. */
    }
  else
    {
    for (rptr = schd_RsrcsList; rptr->next != NULL; rptr = rptr->next)
      /* Find the last element in the list. */ ;

    rptr->next = new_rsrcs;
    }

  /* Next pointer for the tail of the list points to nothing. */
  new_rsrcs->next = NULL;

  return (new_rsrcs);
  }
예제 #25
0
파일: ipx_udp.cpp 프로젝트: paud/d2x-xl
static int addiflist (void)
{
	unsigned					i, cnt = MAX_BRDINTERFACES;
	struct ifconf 			ifconf;
	int 						sock;
#if DBG
	int						ioRes;
#endif
	unsigned 				j;
	struct sockaddr_in	*sinp, *sinmp;

D2_FREE (broads);
sock = socket (AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if (sock < 0)
	FAIL ("Creating IP socket failed:\n%m");
#	ifdef SIOCGIFCOUNT
if (!_IOCTL (sock, SIOCGIFCOUNT, &cnt))
	{ /* //msg ("Getting iterface count error: %m"); */ }
else
	cnt = cnt * 2 + 2;
#	endif
ifconf.ifc_len = cnt * sizeof (struct ifreq);
chk (ifconf.ifc_req = (ifreq *) D2_ALLOC (ifconf.ifc_len));
#	if DBG
memset (ifconf.ifc_req, 0, ifconf.ifc_len);
ioRes = ioctl (sock, SIOCGIFCONF, &ifconf);
if (ioRes < 0) {
#	else
 if (!_IOCTL (sock, SIOCGIFCONF, &ifconf)) {
#	endif
	close (sock);
	FAIL ("ioctl (SIOCGIFCONF)\nIP interface detection failed:\n%m");
	}
if (ifconf.ifc_len % sizeof (struct ifreq)) {
	close (sock);
	FAIL ("ioctl (SIOCGIFCONF)\nIP interface detection failed:\n%m");
	}
cnt = ifconf.ifc_len / sizeof (struct ifreq);
chk (broads = (sockaddr_in *) D2_ALLOC (cnt * sizeof (*broads)));
broadsize = cnt;
for (i = j = 0; i < cnt; i++) {
	if (!_IOCTL (sock, SIOCGIFFLAGS, ifconf.ifc_req + i)) {
		close (sock);
		FAIL ("ioctl (UDP (%d),\"%s\",SIOCGIFFLAGS)\nerror: %m", i, ifconf.ifc_req [i].ifr_name);
		}
	if (((ifconf.ifc_req [i].ifr_flags & IF_REQFLAGS) != IF_REQFLAGS) ||
		  (ifconf.ifc_req [i].ifr_flags & IF_NOTFLAGS))
		continue;
	if (!_IOCTL (sock, (ifconf.ifc_req [i].ifr_flags & IFF_BROADCAST) ? SIOCGIFBRDADDR : SIOCGIFDSTADDR, ifconf.ifc_req + i)) {
		close (sock);
		FAIL ("ioctl (UDP (%d),\"%s\",SIOCGIF{DST/BRD}ADDR)\nerror: %m", i, ifconf.ifc_req [i].ifr_name);
		}
	sinp = (struct sockaddr_in *) &ifconf.ifc_req [i].ifr_broadaddr;
	if (!_IOCTL (sock, SIOCGIFNETMASK, ifconf.ifc_req + i)) {
		close (sock);
		FAIL ("ioctl (UDP (%d),\"%s\",SIOCGIFNETMASK)\nerror: %m", i, ifconf.ifc_req [i].ifr_name);
		}
	sinmp = (struct sockaddr_in *)&ifconf.ifc_req [i].ifr_addr;
	if (sinp->sin_family!=AF_INET || sinmp->sin_family!=AF_INET) 
		continue;
	// Code common to both getifaddrs () and ioctl () approach
	broads [j] = *sinp;
	broads [j].sin_port = UDP_BASEPORT; //FIXME: No possibility to override from cmdline
	broadmasks [j] = *sinmp;
	j++;
	}
broadnum = j;
masksnum = j;
return 0;
}

#endif

//------------------------------------------------------------------------------
/* Previous function addiflist () can (and probably will) report multiple
 * same addresses. On some Linux boxes is present both device "eth0" and
 * "dummy0" with the same IP addreesses - we'll filter it here.
 */

static void unifyiflist (void)
{
	int d = 0, s, i;

for (s = 0; s < broadnum; s++) {
	for (i = 0; i < s; i++)
		if (addreq (broads + s, broads + i)) 
			break;
	if (i >= s) 
		broads [d++] = broads [s];
	}
broadnum = d;
}
예제 #26
0
int
main(int argc, char *argv[])
{
	int i;
	char mom_name[PBS_MAXHOSTNAME+1];
	int mom_port = 0;
	int c, rc;
	int mom_sd;
	char *req;

#ifdef WIN32
	if (winsock_init()) {
		return 1;
	}
#endif
	if (gethostname(mom_name, (sizeof(mom_name) - 1)) < 0  )
		mom_name[0] = '\0';

	while ((c = getopt(argc, argv, "m:p:")) != EOF) {
		switch (c) {
			case 'm':
				strcpy(mom_name, optarg);
				break;
			case 'p':
				mom_port = atoi(optarg);
				break;
			default:
				fprintf(stderr, "Bad option: %c\n", c);
		}
	}

	if (mom_name[0] == '\0' || optind == argc) {
		fprintf(stderr,
			"Error in usage: pbs_rmget [-m mom name] [-p mom port] <req1>...[reqN]\n");
		return 1;
	}

	if(set_msgdaemonname("pbs_rmget")) {
		fprintf(stderr, "Out of memory\n");
		return 1;
	}

	/* load the pbs conf file */
	if (pbs_loadconf(0) == 0) {
		fprintf(stderr, "%s: Configuration error\n", argv[0]);
		return (1);
	}

	if (pbs_conf.pbs_use_tcp == 1) {
		struct			tpp_config tpp_conf;
		fd_set 			selset;
		struct 			timeval tv;

		if (!pbs_conf.pbs_leaf_name) {
			char my_hostname[PBS_MAXHOSTNAME+1];
			if (gethostname(my_hostname, (sizeof(my_hostname) - 1)) < 0) {
				fprintf(stderr, "Failed to get hostname\n");
				return -1;
			}
			pbs_conf.pbs_leaf_name = get_all_ips(my_hostname, log_buffer, sizeof(log_buffer) - 1);
			if (!pbs_conf.pbs_leaf_name) {
				fprintf(stderr, "%s\n", log_buffer);
				fprintf(stderr, "%s\n", "Unable to determine TPP node name");
				return -1;
			}
		}

		/* We don't want to show logs related to connecting pbs_comm on console
		 * this set this flag to ignore it
		 */
		log_mask = SHOW_NONE;

		/* set tpp function pointers */
		set_tpp_funcs(log_tppmsg);

		/* call tpp_init */
		rc = 0;
#ifndef WIN32
		if (pbs_conf.auth_method == AUTH_MUNGE)
			rc = set_tpp_config(&pbs_conf, &tpp_conf, pbs_conf.pbs_leaf_name, -1, pbs_conf.pbs_leaf_routers,
								pbs_conf.pbs_use_compression,
								TPP_AUTH_EXTERNAL,
								get_ext_auth_data, validate_ext_auth_data);
		else
#endif
			rc = set_tpp_config(&pbs_conf, &tpp_conf, pbs_conf.pbs_leaf_name, -1, pbs_conf.pbs_leaf_routers,
								pbs_conf.pbs_use_compression,
								TPP_AUTH_RESV_PORT,
								NULL, NULL);
		if (rc == -1) {
			fprintf(stderr, "Error setting TPP config\n");
			return -1;
		}

		if ((rpp_fd = tpp_init(&tpp_conf)) == -1) {
			fprintf(stderr, "rpp_init failed\n");
			return -1;
		}

		/*
		 * Wait for net to get restored, ie, app to connect to routers
		 */
		FD_ZERO(&selset);
		FD_SET(rpp_fd, &selset);
		tv.tv_sec = 5;
		tv.tv_usec = 0;
		select(FD_SETSIZE, &selset, NULL, NULL, &tv);

		rpp_poll(); /* to clear off the read notification */

		/* Once the connection is established we can unset log_mask */
		log_mask &= ~SHOW_NONE;
	} else {
		/* set rpp function pointers */
		set_rpp_funcs(log_rppfail);
	}

	/* get the FQDN of the mom */
	c = get_fullhostname(mom_name, mom_name, (sizeof(mom_name) - 1));
	if (c == -1) {
		fprintf(stderr, "Unable to get full hostname for mom %s\n", mom_name);
		return -1;
	}

	if ((mom_sd = openrm(mom_name, mom_port)) < 0) {
		fprintf(stderr, "Unable to open connection to mom: %s:%d\n", mom_name, mom_port);
		return 1;
	}

	for (i = optind; i < argc; i++)
		addreq(mom_sd, argv[i]);

	for (i = optind; i < argc; i++) {
		req = getreq(mom_sd);
		if (req == NULL) {
			fprintf(stderr, "Error getting response %d from mom.\n", i - optind);
			return 1;
		}
		printf("[%d] %s\n", i - optind, req);
		free(req);
	}

	closerm(mom_sd);

	return 0;
}