コード例 #1
0
ファイル: tid.c プロジェクト: georgemarselis/openlava-macosx
int
tid_register (int taskid, int socknum, u_short taskPort, char *host,
	      bool_t doTaskInfo)
{
  struct tid *tidp;
  int i;

  if ((tidp = (struct tid *) malloc (sizeof (struct tid))) ==
      (struct tid *) NULL)
    {
      lserrno = LSE_MALLOC;
      return (-1);
    }

  tidp->rtid = taskid;
  tidp->sock = socknum;
  tidp->taskPort = taskPort;

  tidp->host = putstr_ (host);

  i = tid_index (taskid);
  tidp->link = tid_buckets[i];
  tid_buckets[i] = tidp;


  if (doTaskInfo)
    {
      lsQueueInit_ (&tidp->tMsgQ, NULL, tMsgDestroy_);
      if (tidp->tMsgQ == NULL)
	{
	  return (-1);
	}
    }
  else
    tidp->tMsgQ = NULL;


  tidp->refCount = (doTaskInfo) ? 2 : 1;
  tidp->isEOF = (doTaskInfo) ? FALSE : TRUE;

  return (0);

}
コード例 #2
0
ファイル: lib.init.c プロジェクト: ReiAyanamiQH/jhlava
int
ls_initrex(int num, int options)
{
    struct servent *sv;

    if (geteuid() == 0)
       rootuid_ = TRUE;

    if (initenv_(NULL, NULL)<0) {
        if (rootuid_ && !(options & KEEPUID))
            lsfSetUid(getuid());
        return(-1);
    }

    inithostsock_();
    lsQueueInit_(&requestQ, lsReqCmp_, NULL);
    if (requestQ == NULL) {
        lserrno = LSE_MALLOC;
        return(-1);
    }

    res_addr_.sin_family = AF_INET;

    if (genParams_[LSF_RES_PORT].paramValue) {
        if ((res_addr_.sin_port = atoi(genParams_[LSF_RES_PORT].paramValue))
            != 0)
            res_addr_.sin_port = htons(res_addr_.sin_port);
        else
            goto res_init_fail;
    } else if (genParams_[LSF_RES_DEBUG].paramValue) {
        res_addr_.sin_port = htons(RES_PORT);
    } else {
#  if defined(_COMPANY_X_)
        if ((res_addr_.sin_port =
                 get_port_number(RES_SERVICE,(char *)NULL)) == -1) {
#  else
        if ((sv = getservbyname("res", "tcp")) != NULL)
            res_addr_.sin_port = sv->s_port;
        else {
#  endif
res_init_fail:
            lserrno = LSE_RES_NREG;
            if (rootuid_ && !(options & KEEPUID))
                lsfSetUid(getuid());
            return (-1);
        }
    }

    initconntbl_();
    FD_ZERO(&connection_ok_);

    if ((rootuid_) && (genParams_[LSF_AUTH].paramValue == NULL)) {
        int i;
        i = opensocks_(num);
        if (!(options & KEEPUID))
            lsfSetUid(getuid());
        return (i);
    } else {
        return (num);
    }
}

int
opensocks_(int num)
{
    static char fname[] = "opensocks_";
    int s;
    int nextdescr;
    int i;

    totsockets_ = (num <= 0 || num > MAXCONNECT) ? LSF_DEFAULT_SOCKS : num;

    if (logclass & LC_COMM)
       ls_syslog(LOG_DEBUG,"%s: try to allocate num <%d> of socks",fname,num);

    nextdescr = FIRST_RES_SOCK;
    for (i = 0; i < totsockets_; i++) {
        if ((s = CreateSock_(SOCK_STREAM)) < 0) {
            if (logclass & LC_COMM)
                ls_syslog(LOG_DEBUG,
                   "%s: CreateSock_ failed, iter:<%d> %s",
                    fname,i,strerror(errno));
            totsockets_ = i;
            if (i > 0) {
                break;
            } else {
               return(-1);
            }
        }

        if (s != nextdescr) {
            if (dup2(s,nextdescr) < 0) {
                if (logclass & LC_COMM)
                    ls_syslog(LOG_DEBUG,
                    "%s: dup2() failed, old:<%d>, new<%d>, iter:<%d>  %s",
                               fname,s,nextdescr,i,strerror(errno));
                close(s);
                lserrno = LSE_SOCK_SYS;
                totsockets_ = i;
                if (i > 0)
                   break;
                else
                   return (-1);
            }

#if defined(FD_CLOEXEC)
            fcntl(nextdescr, F_SETFD, (fcntl(nextdescr, F_GETFD)
                       | FD_CLOEXEC)) ;
#else
#if defined(FIOCLEX)
            (void)ioctl(nextdescr, FIOCLEX, (char *)NULL);
#endif
#endif

            close(s);
        }
        nextdescr++;
    }

    currentsocket_ = FIRST_RES_SOCK;

    if (logclass & LC_COMM)
       ls_syslog(LOG_DEBUG,"%s: returning num=<%d>",fname,totsockets_);

    return (totsockets_);

}

/* ls_fdbusy()
 */
int
ls_fdbusy(int fd)
{
    sTab   hashSearchPtr;
    hEnt   *hEntPtr;

    if (fd == chanSock_(limchans_[PRIMARY])
        || fd == chanSock_(limchans_[MASTER])
        || fd == chanSock_(limchans_[UNBOUND]))
        return TRUE;

    if (fd == cli_nios_fd[0])
        return TRUE;

    hEntPtr = h_firstEnt_(&conn_table, &hashSearchPtr);
    while (hEntPtr) {
        int   *pfd;

        pfd = hEntPtr->hData;
        if (fd == pfd[0]
            || fd == pfd[1])
            return (TRUE);

        hEntPtr = h_nextEnt_(&hashSearchPtr);
    }

    if (rootuid_
        && fd >= currentsocket_
        && fd < FIRST_RES_SOCK + totsockets_)
        return TRUE;

    return FALSE;
}