Initial version of a utility to shove castors load into condor
authorDiane Trout <diane@caltech.edu>
Wed, 4 Apr 2012 21:51:38 +0000 (14:51 -0700)
committerDiane Trout <diane@caltech.edu>
Wed, 4 Apr 2012 21:51:38 +0000 (14:51 -0700)
CMakeLists.txt [new file with mode: 0644]
src/castor_load.c [new file with mode: 0644]

diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644 (file)
index 0000000..54f2c7b
--- /dev/null
@@ -0,0 +1,4 @@
+cmake_minimum_required(VERSION 2.6)
+project(condor-woldlab)
+add_executable(castor_load src/castor_load.c)
+
diff --git a/src/castor_load.c b/src/castor_load.c
new file mode 100644 (file)
index 0000000..3c46e15
--- /dev/null
@@ -0,0 +1,66 @@
+#define _POSIX_SOURCE 1
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netdb.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+
+#define BUF_SIZE 512
+
+int main(int argc, char **argv) {
+  int sock = 0;
+  int rv = 0;
+  int nread = 0;
+  struct addrinfo hints;
+  struct addrinfo *address;
+  struct addrinfo *addr_ptr;
+  char buf[BUF_SIZE];
+  
+  memset(buf, 0, BUF_SIZE);
+  memset(&hints, 0, sizeof(struct addrinfo));
+  hints.ai_family = AF_INET;
+  hints.ai_socktype = SOCK_STREAM;
+
+  
+  rv = getaddrinfo("castor-pvt", "1210", &hints, &address);
+  if (rv != 0) {
+    fprintf(stderr, "Error looking up hostname, %d\n", errno);
+    exit(-1);
+  }
+
+  
+  for (addr_ptr = address; addr_ptr != NULL; addr_ptr = addr_ptr->ai_next) {
+    sock = socket(addr_ptr->ai_family, 
+                 addr_ptr->ai_socktype,
+                 addr_ptr->ai_protocol);
+    if (sock == -1) {
+      continue;
+    }
+    
+    rv = connect(sock, addr_ptr->ai_addr, addr_ptr->ai_addrlen);
+    if (rv != -1) {
+      break;
+    }
+    close(sock);
+  }
+  if (addr_ptr == NULL) {
+    fprintf(stderr, "Could not connect\n");
+    exit(-1);
+  }
+
+  freeaddrinfo(address);
+
+  nread = read(sock, buf, BUF_SIZE-1);
+  if (nread == -1) {
+    fprintf(stderr, "read error");
+    exit(-1);
+  }
+  fprintf(stdout, "castor_load = %s", buf);
+  fprintf(stdout, "--\n");
+
+  exit(0);
+}