1: /*
   2:  *	Create a bid for the command on the command line
   3:  */
   4: #include <stdio.h>
   5: #include <sys/types.h>
   6: #include <sys/socket.h>
   7: #include <netinet/in.h>
   8: #include <sys/stat.h>
   9: #include <errno.h>
  10: #include <pwd.h>
  11: #include "dsh.h"
  12: #include "dbid.h"
  13: 
  14: #define TOKENSIZE 120
  15: 
  16: /*
  17:  *	Get the next token
  18:  */
  19: char *
  20: nexttoken (p, token)
  21: char    *p;
  22: char    *token;
  23: {
  24:     while (*p == ' ' || *p == '\t')
  25:     p++;
  26:     while (*p != ' ' && *p != '\t' && *p != 0)
  27:     *token++ = *p++;
  28:     *token = 0;
  29:     return (p);
  30: }
  31: 
  32: main (argc, argv)
  33: int argc;
  34: char    *argv[];
  35: {
  36:     char    token[TOKENSIZE];
  37:     char    *p;
  38:     bool    allfound;
  39:     double  la[3];
  40:     int     fd, rv;
  41:     int     pid, port;
  42:     struct bidmsg   b;
  43:     struct passwd   *pwd;
  44:     struct passwd   *getpwuid();
  45: 
  46:     if (argc != 5) {
  47:     fprintf (stderr, "dbid usage: dbid <command> <host> <port#> <host>\n");
  48:     for (rv = 0; rv <argc; rv++) {
  49:         fprintf (stderr, "%s || ", argv[rv]);
  50:     }
  51:     fprintf (stderr, "\n");
  52:     exit (-1);
  53:     }
  54: 
  55:     /* find the elements of a pipe */
  56:     getpath ();
  57:     p = argv[1];
  58:     strcpy (token, "|");
  59:     allfound = TRUE;
  60:     while (*p != 0) {
  61:     if (*p != 0 && strcmp ("|", token) == 0) {
  62:         p = nexttoken (p, token);
  63:         if (*token != 0) {
  64:         if (findcmd (token) != 0) {
  65:             allfound = FALSE;
  66:             break;
  67:         }
  68:         }
  69:     }
  70:     p = nexttoken (p, token);
  71:     }
  72: 
  73:     /* get the load average */
  74:     getloadave (la);
  75: 
  76:     /* simple bidding */
  77:     if (allfound) {
  78:     b.bm_bid = 10.0 / la[0];
  79:     } else {
  80:     b.bm_bid = NOBID;
  81:     }
  82:     strcpy (b.bm_host, argv[4]);
  83: 
  84:     /* get the directory to use */
  85:     pwd = getpwuid (getuid());
  86:     pid = getpid();
  87:     rv = getstringrc (".dshrc", "dir", token);
  88:     if (rv < 0) {
  89:     sprintf (b.bm_dir, "%s/dsh%d", pwd->pw_dir, pid);
  90:     } else {
  91:     if (token[0] == '/' || token[0] == '~') {
  92:         /* this is an absolute path */
  93:         sprintf (b.bm_dir, "%s/dsh%d", token, pid);
  94:     } else {
  95:         /* a relative path */
  96:         sprintf (b.bm_dir, "%s/%s/dsh%d", pwd->pw_dir, token, pid);
  97:     }
  98:     }
  99: 
 100:     /* return bid */
 101:     port = 0;               /* no particular port */
 102:     fd = makedgsocket (&port);
 103:     if (fd < 0) {
 104:     error ("dbid: couldn't open socket to send over");
 105:     }
 106:     /*
 107:     fprintf (stderr, "senddg (%d, %x, %d, %s, %d)\n",
 108:         fd, &b, sizeof (struct bidmsg), argv[2], atoi(argv[3]));
 109:     */
 110:     rv = senddg (fd, &b, sizeof (struct bidmsg), argv[2], atoi(argv[3]));
 111:     if (rv < 0) {
 112:     error ("dbid: couldn't send bid");
 113:     }
 114: }

Defined functions

main defined in line 32; never used
nexttoken defined in line 19; used 2 times

Defined macros

TOKENSIZE defined in line 14; used 1 times
  • in line 36
Last modified: 1983-07-21
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 935
Valid CSS Valid XHTML 1.0 Strict