Example #1
0
int
main (void)
{
  tests_start ();
  
  check_rand ();

  tests_end ();
  exit (0);
}
Example #2
0
int
main (int argc, char **argv)
{
  tests_start ();
  mp_trace_base = -16;

  check_rand ();

  tests_end ();
  exit (0);
}
Example #3
0
int
main (int argc, char **argv)
{
    tests_start ();

    check_data ();
    check_rand (argc, argv);

    tests_end ();
    exit (0);
}
Example #4
0
int
main (void)
{
  tests_start ();

  check_various ();
  check_rand ();
  check_reuse_three ();

  tests_end ();
  exit (0);
}
Example #5
0
int
main (void)
{
  tests_start ();
  mp_trace_base = -16;

  check_twobits ();
  check_rand ();

  tests_end ();
  exit (0);
}
Example #6
0
int
main (void)
{
  tests_start ();
  mp_trace_base = -16;

  check_onebit ();
  check_twobit ();
  check_inf ();
  check_underflow ();
  check_ieee_denorm ();
  check_ieee_overflow ();
  check_0x81c25113 ();
  check_rand ();

  tests_end ();
  exit (0);
}
Example #7
0
void
do_command(char **argv, int allrun, char *username)
{
    FILE *fd, *fda, *in;
    char buf[MAXBUF], cbuf[MAXBUF], pipebuf[2048];
    int status, i, piping, pollret, nrofargs, arg, fdf;
    char *p, *command, **rsh, *cd, **q, *rshstring, **cmd;
    node_t *nodeptr;
    size_t maxnodelen;
    struct pollfd fds[2];

    i = 0;
    piping = 0;
    in = NULL;
    maxnodelen = 0;

    for (nodeptr = nodelink; nodeptr != NULL; nodeptr = nodeptr->next)
	if (strlen(nodeptr->name) > maxnodelen)
	    maxnodelen = strlen(nodeptr->name);

    if (debug && username != NULL)
	(void)printf("As User: %s\n", username);

    /* construct the command from the remains of argv */
    for (i=0, p=*argv, q=argv; p != NULL; p = *++q)
	i += (strlen(p)+1);
    command = (char *)calloc(i+1, sizeof(char));
    for (p = *argv; p != NULL; p = *++argv ) {
	strcat(command, p);
	strcat(command, " ");
    }
    if (debug)
	(void)printf("\nDo Command: %s\n", command);

    if (strcmp(command,"") == 0) {
	piping = 1;

	/* are we a terminal?  then go interactive! */
	if (isatty(STDIN_FILENO) && piping)
	    (void)printf("%s>", progname);
	in = fdopen(STDIN_FILENO, "r");

	/* start reading stuff from stdin and process */
	free(command);
	command = fgets(cbuf, sizeof(cbuf), in);
	if (command != NULL)
	    if (strcmp(command,"\n") == 0)
		command = NULL;
    }
    if (allrun) {
	nodeptr = check_rand();
	if (testflag && rshport > 0 && porttimeout > 0) {
	    while (!test_node_connection(rshport, porttimeout, nodeptr)) {
		    fprintf(stderr, "Skipping down node %s.\n", nodeptr->name);
		    nodeptr = check_rand();
	    }
        }
    }

    rsh = parse_rcmd("RCMD_CMD", "RCMD_CMD_ARGS", &nrofargs);
    rshstring = build_rshstring(rsh, nrofargs);
    
    /* begin the processing loop */
    while (command != NULL) {
	if (!allrun) {
		nodeptr = check_rand();
		if (testflag && rshport > 0 && porttimeout > 0) {
			while (!test_node_connection(rshport, porttimeout,
				nodeptr)) {
				fprintf(stderr, "Skipping down node %s.\n",
				    nodeptr->name);
				nodeptr = check_rand();
			}
		}
	}
	if (debug)
	    printf("Working node: %s\n", nodeptr->name);
	/* we set up pipes for each node, to prepare
	 * for the oncoming barrage of data.
	 */
	if (pipe(nodeptr->out.fds) != 0)
	    bailout();
	if (pipe(nodeptr->err.fds) != 0)
	    bailout();
	nodeptr->childpid = fork();
	/* its the ol fork and switch routine eh? */
	switch (nodeptr->childpid) {
	case -1:
	    bailout();
	    break;
	case 0: 
	    /* stupid unix tricks vol 1 */
	    if (dup2(nodeptr->out.fds[1], STDOUT_FILENO) != STDOUT_FILENO)
		bailout();
	    if (dup2(nodeptr->err.fds[1], STDERR_FILENO) != STDERR_FILENO)
		bailout();
	    if (close(nodeptr->out.fds[0]) != 0)
		bailout();
	    if (close(nodeptr->err.fds[0]) != 0)
		bailout();
	    /* stdin & stderr non-blocking */
	    fdf = fcntl(nodeptr->out.fds[0], F_GETFL);
	    fcntl(nodeptr->out.fds[0], F_SETFL, fdf|O_NONBLOCK);
	    fdf = fcntl(nodeptr->err.fds[0], F_GETFL);
	    fcntl(nodeptr->err.fds[0], F_SETFL, fdf|O_NONBLOCK);
	    
	    if (username != NULL)
		(void)snprintf(buf, MAXBUF, "%s@%s", username, nodeptr->name);
	    else
		(void)snprintf(buf, MAXBUF, "%s", nodeptr->name);
	    if (debug)
		(void)printf("%s %s %s\n", rshstring, buf, command);
	    cmd = calloc(nrofargs+1, sizeof(char *));
	    arg = 0;
	    while (rsh[arg] != NULL) {
		    cmd[arg] = rsh[arg];
		    arg++;
	    }
	    cmd[arg++] = buf;
	    cmd[arg++] = command;
	    cmd[arg] = (char *)0;
	    execvp(rsh[0], cmd);
	    bailout();
	} /* end switch */
	/* now close off the useless stuff, and read the goodies */
	if (close(nodeptr->out.fds[1]) != 0)
	    bailout();
	if (close(nodeptr->err.fds[1]) != 0)
	    bailout();
	fda = fdopen(nodeptr->out.fds[0], "r"); /* stdout */
	if (fda == NULL)
	    bailout();
	fd = fdopen(nodeptr->err.fds[0], "r"); /* stderr */
	if (fd == NULL)
	    bailout();
	fds[0].fd = nodeptr->out.fds[0];
	fds[1].fd = nodeptr->err.fds[0];
	fds[0].events = POLLIN|POLLPRI;
	fds[1].events = POLLIN|POLLPRI;
	pollret = 1;
	while (pollret >= 0) {
	    int gotdata;

	    pollret = poll(fds, 2, 5);
	    gotdata = 0;
	    if ((fds[0].revents&POLLIN) == POLLIN ||
		(fds[0].revents&POLLHUP) == POLLHUP ||
		(fds[0].revents&POLLPRI) == POLLPRI) {
#ifdef __linux__
		cd = fgets(pipebuf, sizeof(pipebuf), fda);
		if (cd != NULL) {
#else
		while ((cd = fgets(pipebuf, sizeof(pipebuf), fda))) {
#endif
		    (void)printf("%*s: %s", -maxnodelen,
			nodeptr->name, cd);
		    gotdata++;
		}
	    }
	    if ((fds[1].revents&POLLIN) == POLLIN ||
		(fds[1].revents&POLLHUP) == POLLHUP ||
		(fds[1].revents&POLLPRI) == POLLPRI) {
#ifdef __linux__
		cd = fgets(pipebuf, sizeof(pipebuf), fd);
		if (cd != NULL) {
#else
		while ((cd = fgets(pipebuf, sizeof(pipebuf), fd))) {
#endif
		    if (errorflag) 
			(void)printf("%*s: %s", -maxnodelen,
			    nodeptr->name, cd);
		    gotdata++;
		}
	    }
	    if (!gotdata)
		if (((fds[0].revents&POLLHUP) == POLLHUP ||
		     (fds[0].revents&POLLERR) == POLLERR ||
		     (fds[0].revents&POLLNVAL) == POLLNVAL) &&
		    ((fds[1].revents&POLLHUP) == POLLHUP ||
		     (fds[1].revents&POLLERR) == POLLERR ||
		     (fds[1].revents&POLLNVAL) == POLLNVAL))
		    break;
	}
	fclose(fda);
	fclose(fd);
	(void)wait(&status);

	/* yes, this is code repetition, no need to adjust your monitor */
	if (piping) {
	    if (isatty(STDIN_FILENO) && piping)
		(void)printf("%s>", progname);
	    command = fgets(cbuf, sizeof(cbuf), in);
	    if (command != NULL)
		if (strcmp(command,"\n") == 0)
		    command = NULL;
	} else
	    command = NULL;
    } /* while loop */
    if (piping) {  /* I learned this the hard way */
	fflush(in);
	fclose(in);
    } else
	    free(command);
    free(rshstring);
    for (i=0; rsh[i] != NULL; i++)
	    free(rsh[i]);
    free(rsh);
}