Ejemplo n.º 1
0
Archivo: client.c Proyecto: hpc/Spindle
void parse_python_prefixes(int fd)
{
   char *path;
   int i, j;
   int num_pythonprefixes;

   if (pythonprefixes)
      return;
   get_python_prefix(fd, &path);

   num_pythonprefixes = (path[0] == '\0') ? 0 : 1;
   for (i = 0; path[i] != '\0'; i++) {
      if (path[i] == ':')
         num_pythonprefixes++;
   }   

   debug_printf3("num_pythonprefixes = %d in %s\n", num_pythonprefixes, path);
   pythonprefixes = (python_path_t *) spindle_malloc(sizeof(python_path_t) * (num_pythonprefixes+1));
   for (i = 0, j = 0; j < num_pythonprefixes; j++) {
      char *cur = path+i;
      char *next = strchr(cur, ':');
      if (next != NULL)
         *next = '\0';
      pythonprefixes[j].path = cur;
      pythonprefixes[j].pathsize = strlen(cur);
      i += pythonprefixes[j].pathsize+1;
   }
   pythonprefixes[num_pythonprefixes].path = NULL;
   pythonprefixes[num_pythonprefixes].pathsize = 0;

   for (i = 0; pythonprefixes[i].path != NULL; i++)
      debug_printf3("Python path # %d = %s\n", i, pythonprefixes[i].path);
}
Ejemplo n.º 2
0
int ldcs_open_server_connections_pipe(int fd, int nc, int *more_avail) {
  int  fifoid, inout, connfd;
  char fifo[MAX_PATH_LEN];
  char *fifo_file;
  int  pid;
  
  if ((fd<0) || (fd>fdlist_pipe_size) )  _error("wrong fd");
  

  /* wait until a <pid>-1 fifo is created */
  for (;;) {
    fifo_file=ldcs_notify_get_next_file(fdlist_pipe[fd].notify_fd);
    if(fifo_file) {
       inout = 0; pid = 0;
       sscanf(fifo_file, "fifo-%d-%d", &pid, &inout);
       free(fifo_file);
       if(inout==1) {
          break;
       }
    }
  }

  connfd=get_new_fd_pipe();
  if(connfd<0) return(-1);
  fdlist_pipe[connfd].serverfd=fd;
  fdlist_pipe[connfd].type=LDCS_PIPE_FD_TYPE_CONN;

  sprintf(fifo, "%s/fifo-%d-0", fdlist_pipe[fd].path , pid );
  fdlist_pipe[connfd].out_fn = strdup(fifo);

  sprintf(fifo, "%s/fifo-%d-1", fdlist_pipe[fd].path , pid );
  fdlist_pipe[connfd].in_fn = strdup(fifo);

  debug_printf3("before open fifo '%s'\n",fdlist_pipe[connfd].out_fn);
  if (-1 == (fifoid = open(fdlist_pipe[connfd].out_fn, O_WRONLY))) _error("open fifo failed");
  debug_printf3("after open fifo (out): -> fifoid=%d\n",fifoid);
  fdlist_pipe[connfd].out_fd=fifoid;

  debug_printf3("before open fifo '%s'\n",fdlist_pipe[connfd].in_fn);
  if (-1 == (fifoid = open(fdlist_pipe[connfd].in_fn, O_RDONLY|O_NONBLOCK)))  _error("open fifo failed");
  /* if (-1 == (fifoid = open(fdlist_pipe[connfd].in_fn, O_RDONLY)))  _error("open fifo failed"); */
  debug_printf3("after open fifo (in) : -> fifoid=%d\n",fifoid);
  fdlist_pipe[connfd].in_fd=fifoid;

  /* add info to server fd data structure */
  fdlist_pipe[fd].conn_list_used++;
  if (fdlist_pipe[fd].conn_list_used > fdlist_pipe[fd].conn_list_size) {
    fdlist_pipe[fd].conn_list = realloc(fdlist_pipe[fd].conn_list, 
					     (fdlist_pipe[fd].conn_list_used + 15) * sizeof(int)
					     );
    fdlist_pipe[fd].conn_list_size = fdlist_pipe[fd].conn_list_used + 15;
  }
  fdlist_pipe[fd].conn_list[fdlist_pipe[fd].conn_list_used-1]=connfd;

  *more_avail=ldcs_notify_more_avail(fdlist_pipe[fd].notify_fd);

  return(connfd);
};
int ldcs_audit_server_md_msocket_deserialize_bootstrap(char *data, int datasize, ldcs_msocket_bootstrap_t **rbootstrap) {
  int rc=0;
  ldcs_msocket_bootstrap_t *bootstrap;
  int size;
  int i,o;

  /* check that we have some entries */
  if (datasize <= 0) {
    return (-1);
  }
  
  o=0;
  size=((int*)data)[o];  o++;

  debug_printf3("deserialize: size = %d\n",size);
  
  /* check again i we have some entries */
  if (size <= 0) {
    return (-1);
  }

  bootstrap=ldcs_audit_server_md_msocket_new_bootstrap(size);

  /* allocate bootstrap data structure */
  bootstrap->size=size;
  bootstrap->allocsize=((int*)data)[o]; o++;

  for (i=0; i < bootstrap->size; i++) {
    bootstrap->fromlist[i]=((int*)data)[o]; o++;
    debug_printf3("deserialize: from[%d] = %d\n",i,bootstrap->fromlist[i]);
  }

  for (i=0; i < bootstrap->size; i++) {
    bootstrap->tolist[i]=((int*)data)[o]; o++;
    debug_printf3("deserialize: to[%d] = %d\n",i,bootstrap->tolist[i]);
  }

  for (i=0; i < bootstrap->size; i++) {
    bootstrap->toportlist[i]=((int*)data)[o]; o++;
    debug_printf3("deserialize: toport[%d] = %d\n",i,bootstrap->toportlist[i]);
  }

  /* copy the strings in and fill in the offsets */
  int offset = o * sizeof(int) + bootstrap->size * sizeof(int);
  for (i=0; i < bootstrap->size; i++) {
    offset=((int*)data)[o+i];
    bootstrap->tohostlist[i]=strdup((char*)(data + offset));
    debug_printf3("deserialize: tohost[%d] = %s\n",i,bootstrap->tohostlist[i]);
  }

  ldcs_audit_server_md_msocket_dump_bootstrap(bootstrap);

  *rbootstrap=bootstrap;

  return(rc);

}
Ejemplo n.º 4
0
int ldcs_audit_server_md_is_responsible ( ldcs_process_data_t *ldcs_process_data, char *filename ) {
   /* current implementation: only MD rank does file operations  */
   if(ldcs_process_data->md_rank == 0) { 
      debug_printf3("Decided I am responsible for file %s\n", filename);
      return 1;
   } else {
      debug_printf3("Decided I am not responsible for file %s\n", filename);
      return 0;
   }
}
Ejemplo n.º 5
0
int filemngt_stat(char *pathname, struct stat *buf)
{
   int result;
   if (*pathname == '*') {
      result = stat(pathname+1, buf);
      debug_printf3("stat(%s) = %d\n", pathname, result);
   }
   else {
      result = lstat(pathname, buf);
      debug_printf3("lstat(%s) = %d\n", pathname, result);
   }
   return result;
}
Ejemplo n.º 6
0
static ssize_t readlink_worker(const char *path, char *buf, size_t bufsiz,
                               char *newbuf, ssize_t rl_result)
{
   char newpath[MAX_PATH_LEN+1];
   char spindle_id[32];
   int location_len;

   location_len = strlen(location);   
   snprintf(spindle_id, sizeof(spindle_id), "spindle.%d", number);

   if (!strstr(newbuf, spindle_id) ||
       strncmp(location, newbuf, location_len) != 0) {
      debug_printf3("readlink not intercepting, %s not prefixed by %s\n", newbuf, location);
      int len = strlen(newbuf);
      if (len > bufsiz)
         len = bufsiz;
      memcpy(buf, newbuf, len);
      return len;
   }

   send_orig_path_request(ldcsid, newbuf+location_len+1, newpath);
   int len = strlen(newpath);
   if (len > bufsiz)
      len = bufsiz;
   memcpy(buf, newpath, len);
   debug_printf2("readlink translated %s to %s to %s\n", path, newbuf, newpath);
   return len;
}
Ejemplo n.º 7
0
static int ldso_metadata_run(char *pathname, ldso_info_t *ldsoinfo)
{
   FILE *f;
   char *cmdline;
   unsigned int cmdline_size;
   int error, result;
   unsigned long resolve_offset, profile_offset;

   cmdline_size = 2 * (strlen(pathname) + strlen(LIBEXECDIR) + strlen("/print_ldso_entry") + 2) + 1;
   cmdline = (char *) malloc(cmdline_size);

   debug_printf3("Running '%s' to get ldso offsets\n", cmdline);
   snprintf(cmdline, cmdline_size, "%s %s %s %s", 
            pathname, LIBEXECDIR "/print_ldso_entry",
            pathname, LIBEXECDIR "/print_ldso_entry");
   f = popen(cmdline, "r");
   if (f == NULL) {
      error = errno;
      err_printf("Failed to run '%s' to get loader offets: %s\n", cmdline, strerror(error));
      free(cmdline);
      return -1;
   }
   free(cmdline);

   result = fscanf(f, "%lu\n%lu\n", &resolve_offset, &profile_offset);
   pclose(f);
   if (result != 2) {
      err_printf("Failed to read offsets from print_ldso_entry\n");
      return -1;
   }

   ldsoinfo->binding_offset = (signed long) (resolve_offset - profile_offset);
   return 0;
}
Ejemplo n.º 8
0
int client_recv_msg_static_socket(int fd, ldcs_message_t *msg,  ldcs_read_block_t block) {
  char help[41];
  int rc=0;
  int n, connfd;
  if ((fd<0) || (fd>MAX_FD) )  _error("wrong fd");
  connfd=ldcs_socket_fdlist[fd].fd;


  n = _ldcs_read_socket(connfd,&msg->header,sizeof(msg->header), block);
  if (n == 0) return(rc);
  if (n < 0) _error("ERROR reading header from socket");

  if(msg->header.len>0) {

    msg->data = (char *) spindle_malloc(msg->header.len);
    if (!msg)  _error("could not allocate memory for message data");
    
    n = _ldcs_read_socket(connfd,msg->data,msg->header.len, LDCS_READ_BLOCK);
    if (n == 0) return(rc);
    if (n < 0) _error("ERROR reading message data from socket");
    if (n != msg->header.len) _error("received different number of bytes for message data");

  } else {
    msg->data = NULL;
  }

  bzero(help,41);if(msg->data) strncpy(help,msg->data,40);
  debug_printf3("received message of type: %s len=%d data=%s ...\n",
	       _message_type_to_str(msg->header.type),
	       msg->header.len,help );
  
  return(0);
}
Ejemplo n.º 9
0
ldcs_message_t * ldcs_recv_msg_pipe(int fd, ldcs_read_block_t block ) {
  ldcs_message_t *msg;
  int n;

  if ((fd<0) || (fd>fdlist_pipe_size) )  _error("wrong fd");

  msg = (ldcs_message_t *) malloc(sizeof(ldcs_message_t));
  if (!msg)  _error("could not allocate memory for message");

  n = _ldcs_read_pipe(fdlist_pipe[fd].in_fd,&msg->header,sizeof(msg->header), block);
  if (n == 0) {
    free(msg);
    return(NULL);
  }
  if (n < 0) _error("ERROR reading header from connection");

  if(msg->header.len>0) {

    msg->data = (char *) malloc(msg->header.len);
    if (!msg)  _error("could not allocate memory for message data");

    n = _ldcs_read_pipe(fdlist_pipe[fd].in_fd,msg->data,msg->header.len, LDCS_READ_BLOCK);
    if (n < 0) _error("ERROR reading message data from socket");
    if (n != msg->header.len) _error("received different number of bytes for message data");

  } else {
    msg->data = NULL;
  }

  debug_printf3("received message of type: %s len=%d data=%s ...\n",
	       _message_type_to_str(msg->header.type),
	       msg->header.len, msg->data );

  return(msg);
}
Ejemplo n.º 10
0
int ldcs_close_server_connection_pipe(int fd) {
  int rc=0, serverfd, c;
  int result;
  struct stat st;

  if ((fd<0) || (fd>fdlist_pipe_size) )  _error("wrong fd");
  
  debug_printf3(" closing fd %d for conn %d, closing connection\n",fdlist_pipe[fd].in_fd,fd);
  close(fdlist_pipe[fd].in_fd);
  debug_printf3(" closing fd %d for conn %d, closing connection\n",fdlist_pipe[fd].out_fd,fd);
  close(fdlist_pipe[fd].out_fd);


  result = stat(fdlist_pipe[fd].in_fn, &st);
  if (result == -1) 
     err_printf("stat of %s failed: %s\n", fdlist_pipe[fd].in_fn, strerror(errno));
  if (S_ISFIFO(st.st_mode)) {
     result = unlink(fdlist_pipe[fd].in_fn); 
     if(result != 0) {
        debug_printf3("error while unlink fifo %s errno=%d (%s)\n", fdlist_pipe[fd].in_fn, 
                      errno, strerror(errno));
     }
  }
  
  result = stat(fdlist_pipe[fd].out_fn, &st);
  if (result == -1)
     err_printf("stat of %s failed: %s\n", fdlist_pipe[fd].out_fn, strerror(errno));
  if (S_ISFIFO(st.st_mode)) {
     result = unlink(fdlist_pipe[fd].out_fn); 
     if(result != 0) {
        debug_printf3("error while unlink fifo %s errno=%d (%s)\n", fdlist_pipe[fd].out_fn, 
                      errno, strerror(errno));
     }
  }
  
  /* remove connection from server list */
  serverfd=fdlist_pipe[fd].serverfd;
  for(c=0;c<fdlist_pipe[serverfd].conn_list_used;c++) {
    if(fdlist_pipe[serverfd].conn_list[c]==fd) {
      fdlist_pipe[serverfd].conn_list[c]=-1;
    }
  }

  free_fd_pipe(fd);

  return(rc);
};
Ejemplo n.º 11
0
void spindle_la_activity (uintptr_t *cookie, unsigned int flag)
{
   debug_printf3("la_activity(): cookie = %p; flag = %s\n", cookie,
                 (flag == LA_ACT_CONSISTENT) ? "LA_ACT_CONSISTENT" :
                 (flag == LA_ACT_ADD) ?        "LA_ACT_ADD" :
                 (flag == LA_ACT_DELETE) ?     "LA_ACT_DELETE" :
                 "???");
   return;
}
Ejemplo n.º 12
0
int client_open_connection_socket(char* hostname, int portno)
{
   int sockfd, fd;
   struct sockaddr_in serv_addr;
   struct hostent *server;

   fd=get_new_fd_socket();
   if(fd<0) return(-1);
   ldcs_socket_fdlist[fd].type=LDCS_SOCKET_FD_TYPE_CONN;

   sockfd = socket(AF_INET, SOCK_STREAM, 0);
   if (sockfd < 0) _error("ERROR opening socket");

   debug_printf3("after socket: -> sockfd=%d\n",sockfd);

   server = gethostbyname(hostname);
   debug_printf3("after gethostbyname: -> server=%p\n",server);
   if (server == NULL) {
      fprintf(stderr,"ERROR, no such host\n");
      exit(0);
   }

   debug_printf3("after gethostbyname: -> hostname=%s\n",server->h_name);

   bzero((char *) &serv_addr, sizeof(serv_addr));
   serv_addr.sin_family = AF_INET;
   bcopy((char *)server->h_addr, 
         (char *)&serv_addr.sin_addr.s_addr,
         server->h_length);
   serv_addr.sin_port = htons(portno);
   debug_printf3("after port: -> port=%d\n",portno);

   ldcs_socket_fdlist[fd].fd=sockfd;


   if (connect(sockfd,(struct sockaddr *) &serv_addr,sizeof(serv_addr)) < 0) {
      return(-1);
   }
  
   debug_printf3("after connect: -> port=%d\n",portno);
  
   return(fd);
  
}
Ejemplo n.º 13
0
int ldcs_audit_server_fe_md_preload ( char *filename, void *data  ) {
  int rc=0;
  char buffer[MAX_PATH_LEN];
  ldcs_msocket_fe_data_t *fe_data=(ldcs_msocket_fe_data_t *) data;
  FILE * fp;
  char * line = NULL, *p;
  size_t len = 0;
  ssize_t read;
  ldcs_message_t out_msg;
  ldcs_message_t *in_msg;
  
  fprintf(stderr,"SERVERFE: open file for list of library for preload: '%s'\n",filename); 
  fp = fopen(filename, "r");  
  if (fp == NULL)  {
    fprintf(stderr,"SPINDLE FE: preloadfile not found: '%s' ... skipping \n",filename); 
    return(rc);
  }

  out_msg.header.type=LDCS_MSG_PRELOAD_FILE;
  out_msg.alloclen=MAX_PATH_LEN;  out_msg.data=buffer;

  while( (read = getline(&line, &len, fp)) >= 0) {
    
    if( (p=strchr(line,'\n')) ) *p='\0';
    if( (p=strchr(line,' ')) ) *p='\0';
    strcpy(buffer,line);

    fprintf(stderr,"SERVERFE: found library for preload: '%s'\n",line); 
    if( buffer[0]=='#') continue;

    if ( strlen(buffer)==0 ) {
      fprintf(stderr,"SERVERFE: unknown line: '%s'\n",buffer);
      continue;
    }
    out_msg.header.len=strlen(buffer)+1;
    
    debug_printf3("SERVERFE: sent preload msg(%s)  to tree root connid=%d\n",out_msg.data, fe_data->connid);
    ldcs_send_msg_socket(fe_data->connid,&out_msg);
    
    fprintf(stderr, "SERVERFE: sent preload msg(%s)  to tree root\n",out_msg.data);

    /* receive msg from root node */
    in_msg=ldcs_recv_msg_socket(fe_data->connid, LDCS_READ_BLOCK);
    if(in_msg->header.type==LDCS_MSG_PRELOAD_FILE_OK) {
      fprintf(stderr, "SERVERFE:   --> successful\n");
    } else {
      fprintf(stderr, "SERVERFE:   --> not successful\n");
    }
    ldcs_msg_free(&in_msg);
    
  }
  fclose(fp);
  if (line) free(line);

  return(rc);
}
Ejemplo n.º 14
0
ElfX_Addr redirect_fork(const char *symname, ElfX_Addr value)
{
   if (strcmp(symname, "vfork") == 0) {
      return (ElfX_Addr) vfork_wrapper;
   }
   else {
      debug_printf3("Not translating fork call %s\n", symname);
      return (ElfX_Addr) value;
   }
}
int ldcs_audit_server_md_msocket_dump_bootstrap(ldcs_msocket_bootstrap_t *bootstrap) {
  int rc=0;
  int i;
  for (i=0; i < bootstrap->size; i++) {
    debug_printf3("DUMP bootstrap: %2d -> %2d (%s,%d)\n",
		 bootstrap->fromlist[i],bootstrap->tolist[i],
		 bootstrap->tohostlist[i],bootstrap->toportlist[i]);
  }
  return(rc);
}
Ejemplo n.º 16
0
int ldcs_notify_get_fd(int fd) {
  int realfd=-1;
  if ((fd<0) || (fd>MAX_FD) )  _error("wrong fd");

  if(ldcs_fdlist_nt[fd].inuse) {
    realfd=ldcs_fdlist_nt[fd].ntfd;
  }
  debug_printf3("return ntfd=%d\n",realfd);

  return(realfd);
}
Ejemplo n.º 17
0
/* write size bytes from buf into fd, retry if necessary */
static int ldcs_cobo_write_fd_w_suppress(int fd, void* buf, int size, int suppress)
{
    int rc;
    int n = 0;
    char* offset = (char*) buf;

    while (n < size) {
	rc = write(fd, offset, size - n);

	if (rc < 0) {
	    if(errno == EINTR || errno == EAGAIN) { continue; }
            if (!suppress) {
                err_printf("Writing to file descriptor (write(fd=%d,offset=%p,size=%d) %m errno=%d)\n",
                           fd, offset, size-n, errno);
            } else {
                debug_printf3("Writing to file descriptor (write(fd=%d,offset=%p,size=%d) %m errno=%d)\n",
                           fd, offset, size-n, errno);
            }
	    return rc;
	} else if(rc == 0) {
            if (!suppress) {
                err_printf("Unexpected return code of 0 from write to file descriptor (write(fd=%d,offset=%p,size=%d))\n",
                           fd, offset, size-n);
            } else {
                debug_printf3("Unexpected return code of 0 from write to file descriptor (write(fd=%d,offset=%p,size=%d))\n",
                           fd, offset, size-n);
            }
	    return -1;
	}

	offset += rc;
	n += rc;
    }

    return n;
}
Ejemplo n.º 18
0
unsigned int spindle_la_version(unsigned int version)
{
   int result;
   int binding_offset = 0;

   result = get_ldso_metadata(&binding_offset);
   if (result == -1) {
      err_printf("Unable to lookup binding offset\n");
      return -1;
   }
   debug_printf3("Updating subaudit bindings with offset %d\n", binding_offset);
   init_plt_binding_func(binding_offset);

   return 1;
}
Ejemplo n.º 19
0
static int _ldcs_read_socket(int fd, void *data, int bytes, ldcs_read_block_t block) {

  int         left,bsumread;
  ssize_t      btoread, bread;
  char       *dataptr;
  
  left      = bytes;
  bsumread  = 0;
  dataptr   = (char*) data;

  while (left > 0)  {
    btoread    = left;
    bread      = read(fd, dataptr, btoread);
    if(bread<0) {
      if( (errno==EAGAIN) || (errno==EWOULDBLOCK) ) {
	debug_printf3("read from socket: got EAGAIN or EWOULDBLOCK\n");
	if(block==LDCS_READ_NO_BLOCK) return(0);
	else continue;
      } else { 
         debug_printf3("read from socket: %ld bytes ... errno=%d (%s)\n",bread,errno,strerror(errno));
      }
    } else {
      debug_printf3("read from socket: %ld bytes ...\n",bread);
    }

    if(bread>0) {
      left      -= bread;
      dataptr   += bread;
      bsumread  += bread;
    } else {
      if(bread==0) return(bsumread);
      else         return(bread);
    }
  }
  return (bsumread);
}
Ejemplo n.º 20
0
int ldcs_recv_msg_static_pipe(int fd, ldcs_message_t *msg, ldcs_read_block_t block) {
  int n;
  int rc=0;
  msg->header.type=LDCS_MSG_UNKNOWN;
  msg->header.len=0;
  if ((fd<0) || (fd>fdlist_pipe_size) )  _error("wrong fd");

  n = _ldcs_read_pipe(fdlist_pipe[fd].in_fd,&msg->header,sizeof(msg->header), block);
  if (n == 0) {
     /* Disconnect.  Return an artificial client end message */
     debug_printf2("Client disconnected.  Returning END message\n");
     msg->header.type = LDCS_MSG_END;
     msg->header.len = 0;
     msg->data = NULL;
     return(rc);
  }
  if (n < 0) _error("ERROR reading header from connection");

  if(msg->header.len>0) {
    n = _ldcs_read_pipe(fdlist_pipe[fd].in_fd,msg->data,msg->header.len, LDCS_READ_BLOCK);
    if (n == 0) 
       return(rc);
    if (n < 0) {
       int error = errno;
       err_printf("Error during read of pipe: %s (%d)\n", strerror(error), error);
       return -1;
    }
    if (n != msg->header.len) {
       int error = errno;
       err_printf("Partial read on pipe.  Got %u / %u: %s (%d)\n",
                  (unsigned) n, (unsigned) msg->header.len,
                  strerror(error), error);
       return -1;
    }

  } else {
    *msg->data = '\0';
  }

  debug_printf3("received message of type: %s len=%d data=%s ...\n",
	       _message_type_to_str(msg->header.type),
	       msg->header.len, msg->data );

  return(rc);
}
Ejemplo n.º 21
0
int ldcs_audit_server_md_init(unsigned int port, unsigned int num_ports, 
                              unique_id_t unique_id, ldcs_process_data_t *data)
{
   int rc=0;
   unsigned int *portlist;
   int my_rank, ranks, fanout;
   int i;

   portlist = malloc(sizeof(unsigned int) * (num_ports + 1));
   for (i = 0; i < num_ports; i++) {
      portlist[i] = port + i;
   }
   portlist[num_ports] = 0;

   /* initialize the client (read environment variables) */
   debug_printf2("Opening cobo with port %d - %d\n", portlist[0], portlist[num_ports-1]);
   if (cobo_open(unique_id, (int *) portlist, num_ports, &my_rank, &ranks) != COBO_SUCCESS) {
      printf("Failed to init\n");
      exit(1);
   }
   debug_printf2("cobo_open complete. Cobo rank %d/%d\n", my_rank, ranks);
   free(portlist);

   data->server_stat.md_rank = data->md_rank = my_rank;
   data->server_stat.md_size = data->md_size = ranks;
   data->md_listen_to_parent = 0;

   cobo_get_num_childs(&fanout);
   data->server_stat.md_fan_out = data->md_fan_out = fanout;

   cobo_barrier();

   /* send ack about being ready */
   if (data->md_rank == 0) { 
      int root_fd, ack=13;

      /* send fe client signal to stop (ack)  */
      cobo_get_parent_socket(&root_fd);
    
      ldcs_cobo_write_fd(root_fd, &ack, sizeof(ack));
      debug_printf3("sent FE client signal that server are ready %d\n",ack);
   }
  
   return(rc);
}
Ejemplo n.º 22
0
int ll_read(int fd, void *buf, size_t count)
{
   int result;
   size_t pos = 0;

   while (pos < count) {
      result = read(fd, ((char *) buf) + pos, count - pos);
      debug_printf3("Read %d bytes from network: %d %d %d...\n", result, (int) ((char *)buf)[pos],
                    (int) ((char *)buf)[pos+1], (int) ((char *)buf)[pos+2]);
      if (result == -1 || result == 0) {
         if (errno == EINTR || errno == EAGAIN)
            continue;
         err_printf("Error reading from cobo FD %d\n", fd);
         return -1;
      }
      pos += result;
   }
   return 0;
}
Ejemplo n.º 23
0
/* ************************************************************** */
int ldcs_send_msg_pipe(int fd, ldcs_message_t * msg) {

  int n;

  if ((fd<0) || (fd>fdlist_pipe_size) )  _error("wrong fd");
  
  debug_printf3("sending message of type: %s len=%d data=%s ...\n",
	       _message_type_to_str(msg->header.type),
	       msg->header.len,msg->data );  

  n = _ldcs_write_pipe(fdlist_pipe[fd].out_fd,&msg->header,sizeof(msg->header));
  if (n < 0) _error("ERROR writing header to pipe");

  if(msg->header.len>0) {
    n = _ldcs_write_pipe(fdlist_pipe[fd].out_fd,(void *) msg->data,msg->header.len);
    if (n < 0) _error("ERROR writing data to pipe");
    if (n != msg->header.len) _error("sent different number of bytes for message data");
  }
    
  return(0);
}
Ejemplo n.º 24
0
int ll_write(int fd, void *buf, size_t count)
{
   int result, error;
   size_t pos = 0;

   while (pos < count) {
      result = write(fd, ((char *) buf) + pos, count - pos);
      debug_printf3("Wrote %d bytes to network: %d %d %d...\n", result, (int) ((char *)buf)[pos],
                    (int) ((char *)buf)[pos+1], (int) ((char *)buf)[pos+2]);

      if (result == -1 || result == 0) {
         if (errno == EINTR || errno == EAGAIN)
            continue;
         error = errno;
         err_printf("Error writing to cobo FD %d: %s\n", fd, strerror(error));
         return -1;
      }
      pos += result;
   }
   return 0;
}
Ejemplo n.º 25
0
int ldcs_dump_memmaps(int pid) {
  int rc=0;
  char filename[MAX_PATH_LEN];
  FILE * fp;
  char * line = NULL;
  size_t len = 0;
  ssize_t read;

  sprintf(filename,"/proc/%d/maps",pid);

  fp = fopen(filename, "r");   if (fp == NULL)  perror("could not open proc maps file");
  
  while( (read = getline(&line, &len, fp)) >= 0) {
    debug_printf3("%s: %s",filename,line);
    printf("%s: %s",filename,line);
  }
  fclose(fp);
  if (line) free(line);
  
  return(rc);
}
Ejemplo n.º 26
0
int ldcs_audit_server_md_register_fd ( ldcs_process_data_t *ldcs_process_data ) {
   int rc=0, i;
   int parent_fd, child_fd;
   int num_childs;

   if(cobo_get_parent_socket(&parent_fd)!=COBO_SUCCESS) {
      err_printf("Error, could not get parent socket\n");
      assert(0);
   }

   debug_printf3("Registering fd %d for cobo parent connection\n",parent_fd);
   ldcs_listen_register_fd(parent_fd, 0, &ldcs_audit_server_md_cobo_CB, (void *) ldcs_process_data);
   ldcs_process_data->md_listen_to_parent=1;
   
   cobo_get_num_childs(&num_childs);
   for (i = 0; i<num_childs; i++) {
      cobo_get_child_socket(i, &child_fd);
      ldcs_listen_register_fd(child_fd, 0, &ldcs_audit_server_md_cobo_CB, (void *) ldcs_process_data);
   }
   
   return(rc);
}
Ejemplo n.º 27
0
int client_send_msg_socket(int fd, ldcs_message_t * msg) {

  char help[41];
  int n, connfd;
  if ((fd<0) || (fd>MAX_FD) )  _error("wrong fd");
  connfd=ldcs_socket_fdlist[fd].fd;

  bzero(help,41);if(msg->data) strncpy(help,msg->data,40);
  debug_printf3("sending message of type: %s len=%d data=%s ...\n",
	       _message_type_to_str(msg->header.type),
	       msg->header.len,help );

  n = _ldcs_write_socket(connfd,&msg->header,sizeof(msg->header));
  if (n < 0) _error("ERROR writing header to socket");

  if(msg->header.len>0) {
    n = _ldcs_write_socket(connfd,(void *) msg->data,msg->header.len);
    if (n < 0) _error("ERROR writing data to socket");
  }
  
  
  return(0);
}
Ejemplo n.º 28
0
/**
 * Clear files from the local ramdisk
 **/
int ldcs_audit_server_filemngt_clean()
{
#if !defined(USE_CLEANUP_PROC)
   DIR *tmpdir;
   struct dirent *dp;
   char path[MAX_PATH_LEN];
   struct stat finfo;
   int result;

   debug_printf("Cleaning tmpdir %s\n", _ldcs_audit_server_tmpdir);

   tmpdir = opendir(_ldcs_audit_server_tmpdir);
   if (!tmpdir) {
      err_printf("Failed to open %s for cleaning: %s\n", _ldcs_audit_server_tmpdir,
                 strerror(errno));
      return -1;
   }
   
   while ((dp = readdir(tmpdir))) {
      snprintf(path, MAX_PATH_LEN, "%s/%s", _ldcs_audit_server_tmpdir, dp->d_name);
      result = lstat(path, &finfo);
      if (result == -1) {
         err_printf("Failed to stat %s\n", path);
         continue;
      }
      if (!S_ISREG(finfo.st_mode)) {
         debug_printf3("Not cleaning file %s\n", path);
         continue;
      }
      unlink(path);
   }

   closedir(tmpdir);
   rmdir(_ldcs_audit_server_tmpdir);
#endif
   return 0;
}
Ejemplo n.º 29
0
int ldcs_notify_init(char *path) {
  int fd=-1;

  fd=nt_get_new_fd();
  if(fd<0) return(-1);
  
  ldcs_fdlist_nt[fd].inuse= 1;
  ldcs_fdlist_nt[fd].ntfd = inotify_init();
  if (ldcs_fdlist_nt[fd].ntfd < 0) {        
    _error("failure while running inotify_init");
  }
  
  debug_printf3("add watch: ntfd=%d dir=%s\n",ldcs_fdlist_nt[fd].ntfd, path);
  ldcs_fdlist_nt[fd].wd = inotify_add_watch(ldcs_fdlist_nt[fd].ntfd, path, IN_CREATE);
  if (ldcs_fdlist_nt[fd].wd < 0) {
    _error ("inotify_add_watch");  
  }

  ldcs_fdlist_nt[fd].buffer_len=BUF_LEN;
  ldcs_fdlist_nt[fd].buffer=malloc(ldcs_fdlist_nt[fd].buffer_len);
  ldcs_fdlist_nt[fd].buffer_next=-1; 	/* nothing read */

   return(fd);
 }
Ejemplo n.º 30
0
char *ldcs_notify_get_next_file(int fd) {
  char* result=NULL;

  struct inotify_event *event;

  if ((fd<0) || (fd>MAX_FD) )  _error("wrong fd");

  if ((ldcs_fdlist_nt[fd].buffer_next<0) 
      || (ldcs_fdlist_nt[fd].buffer_next>=ldcs_fdlist_nt[fd].buffer_enddata)) {
    ldcs_fdlist_nt[fd].buffer_next = 0;
    debug_printf3("read new events ...\n");
    ldcs_fdlist_nt[fd].buffer_enddata = 
      read (ldcs_fdlist_nt[fd].ntfd, ldcs_fdlist_nt[fd].buffer, ldcs_fdlist_nt[fd].buffer_len);
    debug_printf3("read new events ... %d bytes read\n",ldcs_fdlist_nt[fd].buffer_enddata);

    if (ldcs_fdlist_nt[fd].buffer_enddata < 0) {
      if (errno == EINTR) {
	/* need to reissue system call */
      } else {
	_error ("read on notify failed");
      }
    } else if (!ldcs_fdlist_nt[fd].buffer_enddata) {
      /* BUF_LEN too small? */
    }
  }
  
  debug_printf3("scan for next events ... buffer_next=%d\n",ldcs_fdlist_nt[fd].buffer_next);
  event = (struct inotify_event *) &ldcs_fdlist_nt[fd].buffer[ldcs_fdlist_nt[fd].buffer_next];

  debug_printf3("got event... wd=%d mask=%u cookie=%u len=%u \n",
	       event->wd, event->mask,event->cookie, event->len);

  if (event->len) {
    result=strdup(event->name);
    debug_printf3("          name=%s \n",event->name);
  }
    
  ldcs_fdlist_nt[fd].buffer_next += EVENT_SIZE + event->len;
  debug_printf3("shift buffer buffer_next=%d of enddata=%d event_size=%ld event_len=%u\n",
	       ldcs_fdlist_nt[fd].buffer_next,ldcs_fdlist_nt[fd].buffer_enddata,EVENT_SIZE,event->len);
  
  return(result);
}