Ticket #1492: sge-loadsensor.patch

File sge-loadsensor.patch, 3.2 KB (added by opoplawski, 5 years ago)

sge-loadsensor.patch

  • sge-8.1.6/source/daemons/execd/sge_load_sensor.c

    diff -up sge-8.1.6/source/daemons/execd/sge_load_sensor.c.loadsensor sge-8.1.6/source/daemons/execd/sge_load_sensor.c
    old new static int sge_ls_start_ls(const char *q 
    270270   DPRINTF(("%s: successfully started load sensor \"%s\"\n",
    271271            SGE_FUNC, lGetString(this_ls, LS_command)));
    272272
    273    /* request first load report after starting */
    274    ls_send_command(this_ls, "\n");
    275 
    276273   return LS_OK;
    277274}
    278275
    static int read_ls(void) 
    438435   char value[1000];
    439436   lListElem *ls_elem;
    440437   bool flag = true;
     438   fd_set readfds;
     439   struct timeval timeleft;
     440   int wait = 1;
     441   int highest_fd;
     442   int ret;
    441443
    442444   DENTER(TOP_LAYER, "read_ls");
    443445
    static int read_ls(void) 
    448450         continue;
    449451      }
    450452
     453      /* request load report from ls */
     454      ls_send_command(ls_elem, "\n");
     455
    451456      DPRINTF(("receiving from %s\n", lGetString(ls_elem, LS_command)));
    452457
     458      highest_fd = fileno(file);
    453459      while (flag) {
    454460         if (fscanf(file, "%[^\n]\n", input) != 1) {
     461            FD_ZERO(&readfds);
     462            FD_SET(highest_fd, &readfds);
     463     
     464            /* wait up to 1 second per line for reading report */
     465            timeleft.tv_sec = wait;
     466            timeleft.tv_usec = 0;
     467            ret = select(highest_fd + 1, &readfds, NULL, NULL, &timeleft);
     468            if (ret == -1) {
     469               switch (errno) {
     470               case EINTR:
     471                  DPRINTF(("select failed with EINTR\n"));
     472                  WARNING((SGE_EVENT, "[load_sensor %s] read select failed with EINTR", lGetString(ls_elem, LS_pid)));
     473                  break;
     474               case EBADF:
     475                  DPRINTF(("select failed with EBADF\n"));
     476                  WARNING((SGE_EVENT, "[load_sensor %s] read select failed with EBADF", lGetString(ls_elem, LS_pid)));
     477                  break;
     478               case EINVAL:
     479                  DPRINTF(("select failed with EINVAL\n"));
     480                  WARNING((SGE_EVENT, "[load_sensor %s] read select failed with EINVAL", lGetString(ls_elem, LS_pid)));
     481                  break;
     482               default:
     483                  DPRINTF(("select failed with unexpected errno %d", errno));
     484                  WARNING((SGE_EVENT, "[load_sensor %s] read select failed with [%s]", lGetString(ls_elem, LS_pid), strerror(errno)));
     485               }
     486               DRETURN(-1);
     487            }
     488
     489            /* if something is there now, go back and read it */
     490            if (ret) continue;
     491 
     492            /* nothing to read, so exit */
    455493            break;
    456494         }
    457495#ifdef INTERIX
    static int read_ls(void) 
    474512            lXchgList(ls_elem, LS_complete, &tmp_list);
    475513            lFreeList(&tmp_list);
    476514
    477             /* request next load report from ls */
    478             ls_send_command(ls_elem, "\n");
    479             break;
     515            /* see without waiting if there is any backlog to process, we'll exit if fscanf fails */
     516            wait = 0;
     517            continue;
    480518         }
    481519
    482520         /* add a newline for pattern matching in sscanf */