Changeset 33240
- Timestamp:
- Feb 10, 2012, 1:54:34 PM (14 years ago)
- Location:
- branches/eam_branches/ipp-20111122/Ohana/src/photdbc
- Files:
-
- 3 edited
-
Makefile (modified) (2 diffs)
-
include/dvodist.h (modified) (3 diffs)
-
src/HostTableLoad.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20111122/Ohana/src/photdbc/Makefile
r33218 r33240 1 default: photdbc 1 default: photdbc dvodist 2 2 help: 3 3 @echo "make options: photdbc (default)" … … 36 36 $(SRC)/Shutdown_dvodist.$(ARCH).o \ 37 37 $(SRC)/SetSignals.$(ARCH).o \ 38 $(SRC)/rconnect.$(ARCH).o \39 38 $(SRC)/md5_ops.$(ARCH).o \ 40 39 $(SRC)/md5.$(ARCH).o \ -
branches/eam_branches/ipp-20111122/Ohana/src/photdbc/include/dvodist.h
r33223 r33240 5 5 # include <unistd.h> // needed? 6 6 7 # define myAssert(LOGIC,MSG) { if (!(LOGIC)) { fprintf (stderr, "%s\n", MSG); abort(); } }8 9 7 // used by the md5 stuff 10 8 # define NDIGEST 16 11 12 typedef enum {13 MODE_NONE = 0,14 MODE_OUT = 1,15 MODE_IN = 2,16 } ModeType;17 18 typedef struct {19 char *hostname;20 char *pathname;21 int hostID;22 } HostInfo;23 24 typedef struct {25 int Nhosts;26 HostInfo *hosts;27 unsigned short *index;28 } HostTable;29 30 // these should be moved to dvo.h?31 # define DATA_ON_TGT 0x0132 # define DATA_COPY_FAILURE 0x0233 9 34 10 /* global variables */ … … 42 18 43 19 void LockDatabase (char *catdir); 44 HostTable *HostTableLoad (char *catdir, char *rootname);45 20 int CheckHostsAndPaths (HostTable *table); 46 21 … … 54 29 void SetProtect (int mode); 55 30 int SetSignals (void); 56 int rconnect (char *command, char *hostname, char *shell, int *stdio);57 31 58 int write_fmt (int fd, char *format, ...);59 char *memstr (char *m1, char *m2, int n);60 32 int get_md5_with_copy (char *input, char *output, md5_byte_t *digest); -
branches/eam_branches/ipp-20111122/Ohana/src/photdbc/src/HostTableLoad.c
r33223 r33240 1 1 # include "dvodist.h" 2 2 # define DEBUG 1 3 4 void InitHosts (HostInfo *hosts, int Nhosts, int NHOSTS) {5 6 int i;7 for (i = Nhosts; i < NHOSTS; i++) {8 hosts[i].hostname = NULL;9 hosts[i].pathname = NULL;10 }11 return;12 }13 14 void FreeHosts (HostInfo *hosts, int Nhosts) {15 16 int i;17 for (i = 0; i < Nhosts; i++) {18 free (hosts[i].hostname);19 free (hosts[i].pathname);20 }21 free (hosts);22 return;23 }24 25 HostTable *HostTableLoad (char *catdir, char *rootname) {26 27 int i, Nline;28 29 char *filename = NULL;30 31 ALLOCATE (filename, char, strlen(catdir) + strlen(rootname) + 2); // one slash and one EOL32 sprintf (filename, "%s/%s", catdir, rootname);33 34 FILE *f = fopen (filename, "r");35 if (!f) {36 fprintf (stderr, "failed to open host table %s\n", filename);37 return NULL;38 }39 40 // simple format: ID hostname pathname41 42 int NHOSTS = 16;43 int Nhosts = 0;44 HostInfo *hosts = NULL;45 ALLOCATE (hosts, HostInfo, NHOSTS);46 InitHosts (hosts, Nhosts, NHOSTS);47 48 int maxID = 0;49 50 for (Nline = 0; TRUE; Nline ++) {51 int ID;52 char tmphost[1024];53 char tmppath[1024];54 char line[1024];55 56 // XXXX use this for safety: int status = scan_line_maxlen (f, line, 1024);57 int status = scan_line (f, line);58 if (status == EOF) break;59 60 // find first non-whitespace char & skip commented lines61 for (i = 0; OHANA_WHITESPACE (line[i]); i++);62 if (line[i] == '#') continue;63 64 status = sscanf (line, "%d %1023s %1023s", &ID, tmphost, tmppath);65 if (status != 3) {66 fprintf (stderr, "error reading line %d of host table %s\n", Nline, filename);67 FreeHosts (hosts, Nhosts);68 return NULL;69 }70 71 // check the validity of ID (0 < ID < MAX_SHORT)72 73 if (ID < 1) {74 fprintf (stderr, "invalid host ID %d\n", ID);75 exit (1);76 }77 if (ID > 255) {78 fprintf (stderr, "invalid host ID %d\n", ID);79 exit (1);80 }81 maxID = MAX(maxID, ID);82 83 hosts[Nhosts].hostID = ID;84 hosts[Nhosts].hostname = strcreate(tmphost);85 hosts[Nhosts].pathname = strcreate(tmppath);86 87 Nhosts ++;88 if (Nhosts >= NHOSTS) {89 NHOSTS += 16;90 REALLOCATE (hosts, HostInfo, NHOSTS);91 InitHosts (hosts, Nhosts, NHOSTS);92 }93 }94 95 HostTable *table = NULL;96 ALLOCATE (table, HostTable, 1);97 table->Nhosts = Nhosts;98 table->hosts = hosts;99 100 ALLOCATE (table->index, unsigned short, maxID + 1);101 for (i = 0; i <= maxID; i++) table->index[i] = -1;102 103 for (i = 0; i < table->Nhosts; i++) {104 if (table->index[table->hosts[i].hostID] == -1) {105 fprintf (stderr, "error: duplicate hostID %d\n", table->hosts[i].hostID);106 exit (1);107 }108 table->index[table->hosts[i].hostID] = i;109 }110 111 return table;112 }113 3 114 4 int CheckHostsAndPaths (HostTable *table) { … … 127 17 if (DEBUG) fprintf (stderr, "starting host within thread\n"); 128 18 129 int pid = rconnect (command, table->hosts[i].hostname, shell, stdio); 19 int errorInfo; 20 int pid = rconnect (command, table->hosts[i].hostname, shell, stdio, &errorInfo, TRUE); 130 21 if (!pid) { 131 22 /** failure to start: extend retry period **/ 132 if (DEBUG) fprintf (stderr, "failure to start %s \n", table->hosts[i].hostname);23 if (DEBUG) fprintf (stderr, "failure to start %s (error %d)\n", table->hosts[i].hostname, errorInfo); 133 24 exit (1); 134 25 }
Note:
See TracChangeset
for help on using the changeset viewer.
