Changeset 3648
- Timestamp:
- Apr 1, 2005, 6:32:51 PM (21 years ago)
- Location:
- trunk/Ohana/src
- Files:
-
- 3 deleted
- 11 edited
-
elixir/src/DumpStatus.c (modified) (3 diffs)
-
elixir/src/LoadPending.c (modified) (4 diffs)
-
elixir/src/MachineOps.c (modified) (2 diffs)
-
elixir/src/MsgOps.c (modified) (6 diffs)
-
imregister/base/WriteFIFO.c (modified) (1 diff)
-
imregister/detrend/entry.c (modified) (3 diffs)
-
imregister/src/imstatreg.c (modified) (2 diffs)
-
libohana/src/glockfile.c (modified) (8 diffs)
-
misc/Makefile (modified) (1 diff)
-
misc/src/dbtest.c (deleted)
-
misc/src/glock.c (deleted)
-
misc/src/glockfile.c (modified) (3 diffs)
-
misc/src/glockfile2.c (deleted)
-
opihi/dvo/elixir.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/elixir/src/DumpStatus.c
r2428 r3648 4 4 5 5 FILE *f; 6 int i, fd,state, total, mode;6 int i, state, total, mode; 7 7 Process *global, **process; 8 8 int Nprocess, Nobject, Dynamic; … … 16 16 } else { 17 17 /* lock file */ 18 fd = setlockfile2 (filename, 0.1, LCK_XCLD, &state); 19 if (fd == -1) return (2); 20 f = fdopen (fd, "r+"); 21 if (f == (FILE *) NULL) { 22 mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH; 23 fchmod (fd, mode); 24 clearlockfile2 (filename, fd, LCK_XCLD, &state); 25 return (2); 26 } 18 f = fsetlockfile (filename, 0.1, LCK_XCLD, &state); 19 if (f == NULL) return (2); 27 20 fseek (f, 0, SEEK_END); 28 21 } … … 51 44 if (f != stderr) { 52 45 mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH; 53 fchmod (fd, mode); 54 clearlockfile2 (filename, fd, LCK_XCLD, &state); 55 fclose (f); 46 chmod (filename, mode); 47 fclearlockfile (filename, f, LCK_XCLD, &state); 56 48 } 57 49 return (TRUE); -
trunk/Ohana/src/elixir/src/LoadPending.c
r2428 r3648 15 15 16 16 int i, status, depend, Nobjects; 17 int fd,lockstate, mode;17 int lockstate, mode; 18 18 FILE *f; 19 19 char name[7][256], line[1024]; … … 33 33 34 34 /* check lockfile - don't remove list if locked */ 35 fd = setlockfile2 (filename, 1.0, LCK_XCLD, &lockstate); 36 if (fd == -1) { 37 *state = 1; 38 return (Nobjects); 39 } 40 f = fdopen (fd, "r+"); 41 if (f == (FILE *) NULL) { 42 clearlockfile2 (filename, fd, LCK_XCLD, &lockstate); 35 f = fsetlockfile (filename, 1.0, LCK_XCLD, &lockstate); 36 if (f == NULL) { 43 37 *state = 1; 44 38 return (Nobjects); … … 113 107 escape: 114 108 if (*dynamic) { 115 if ( ftruncate (fd, 0)) {109 if (truncate (filename, 0)) { 116 110 fprintf (stderr, "failed to clear source %s (errno %d)\n", filename, errno); 117 111 Shutdown (1); … … 120 114 /* clean up fifo - set mode to 666, unlock */ 121 115 mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH; 122 fchmod (fd, mode); 123 clearlockfile2 (filename, fd, LCK_XCLD, &lockstate); 116 chmod (filename, mode); 117 fclearlockfile (filename, f, LCK_XCLD, &lockstate); 118 } else { 119 fclose (f); 124 120 } 125 fclose (f);126 121 127 122 if ((*state == 2) && *dynamic) { -
trunk/Ohana/src/elixir/src/MachineOps.c
r3400 r3648 443 443 int DumpProcessTimes (char *filename) { 444 444 445 int i, j, fd,state, mode;445 int i, j, state, mode; 446 446 FILE *f; 447 447 double dt; 448 448 449 fd = 0;450 449 if (filename == (char *) NULL) { 451 450 system ("tput clear"); 452 451 f = stderr; 453 452 } else { 454 455 453 /* check lockfile */ 456 fd = setlockfile2 (filename, 0.1, LCK_XCLD, &state); 457 if (fd == -1) return (2); 458 f = fdopen (fd, "r+"); 459 if (f == (FILE *) NULL) { 460 mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH; 461 fchmod (fd, mode); 462 clearlockfile2 (filename, fd, LCK_XCLD, &state); 463 return (2); 464 } 454 f = fsetlockfile (filename, 0.1, LCK_XCLD, &state); 455 if (f == NULL) return (2); 465 456 fseek (f, 0, SEEK_END); 466 457 } … … 486 477 if (f != stderr) { 487 478 mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH; 488 fchmod (fd, mode); 489 clearlockfile2 (filename, fd, LCK_XCLD, &state); 490 fclose (f); 479 chmod (filename, mode); 480 fclearlockfile (filename, f, LCK_XCLD, &state); 491 481 } 492 482 return (1); -
trunk/Ohana/src/elixir/src/MsgOps.c
r2428 r3648 1 1 # include "controller.h" 2 3 /*** this file should be updated to use fsetlockfile / fclearlockfile ***/4 2 5 3 int WaitMsg (char *fifo, char **message, double maxdelay) { … … 42 40 43 41 /* check lockfile */ 44 fd = setlockfile2 (fifo, 0.1, LCK_XCLD, &state); 45 if (fd == -1) return (2); 46 f = fdopen (fd, "r+"); 47 if (f == (FILE *) NULL) { 48 mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH; 49 fchmod (fd, mode); 50 clearlockfile2 (fifo, fd, LCK_XCLD, &state); 51 return (2); 52 } 42 f = fsetlockfile (fifo, 0.1, LCK_XCLD, &state); 43 if (f == NULL) return (2); 53 44 54 45 /* if file is empty, return 0 */ 55 46 if (state == LCK_EMPTY) { 56 47 mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH; 57 fchmod (fd, mode); 58 clearlockfile2 (fifo, fd, LCK_XCLD, &state); 59 fclose (f); 48 chmod (fifo, mode); 49 fclearlockfile (fifo, f, LCK_XCLD, &state); 60 50 return (0); 61 51 } … … 80 70 /* file will remain until unlocked and fclosed below, 81 71 but cannot be written to because it is locked */ 82 if ( ftruncate (fd, 0)) {72 if (truncate (fifo, 0)) { 83 73 fprintf (stderr, "failed to clear fifo file %s (errno: %d)\n", fifo, errno); 84 74 Shutdown (1); … … 86 76 87 77 mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH; 88 fchmod (fd, mode); 89 clearlockfile2 (fifo, fd, LCK_XCLD, &state); 90 fclose (f); 78 chmod (f, mode); 79 fclearlockfile (fifo, f, LCK_XCLD, &state); 91 80 92 81 if (Nbytes == 0) { … … 106 95 107 96 /* check lockfile */ 108 fd = setlockfile2 (fifo, 0.1, LCK_XCLD, &state); 109 if (fd == -1) return (2); 110 f = fdopen (fd, "r+"); 111 if (f == (FILE *) NULL) { 112 mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH; 113 fchmod (fd, mode); 114 clearlockfile2 (fifo, fd, LCK_XCLD, &state); 115 return (2); 116 } 97 f = fsetlockfile (fifo, 0.1, LCK_XCLD, &state); 98 if (f == NULL) return (2); 117 99 118 100 /* write message to end of file */ … … 121 103 122 104 mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH; 123 fchmod (fd, mode); 124 clearlockfile2 (fifo, fd, LCK_XCLD, &state); 125 fclose (f); 126 105 chmod (fifo, mode); 106 fclearlockfile (fifo, f, LCK_XCLD, &state); 127 107 return (1); 128 129 108 } 130 109 131 132 110 /* possible return states: 133 134 111 0 - no message (fifo file empty or non-existent) 135 112 1 - message received 136 113 2 - busy (fifo file locked) 137 138 114 */ -
trunk/Ohana/src/imregister/base/WriteFIFO.c
r3 r3648 1 1 # include "imregister.h" 2 3 static char retchar[] = "\n";4 2 5 3 int WriteFIFO (char *filename, char *line) { 6 4 7 5 int state, mode; 8 int fd;6 FILE *f; 9 7 10 f d = setlockfile2(filename, 20.0, LCK_XCLD, &state);11 if (f d == -1) {12 fprintf (stderr, "ERROR: can't lock fifo %s\n", filename);13 return (FALSE);8 f = fsetlockfile (filename, 20.0, LCK_XCLD, &state); 9 if (f == NULL) { 10 fprintf (stderr, "ERROR: can't lock fifo %s\n", filename); 11 return (FALSE); 14 12 } 15 13 16 lseek (fd, 0, SEEK_END); 17 write (fd, line, strlen (line)); 18 write (fd, retchar, 1); 14 fseek (f, 0, SEEK_END); 15 fprintf (f, "%s\n", line); 19 16 20 17 mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH; 21 fchmod (fd, mode);22 clearlockfile2 (filename, fd, LCK_XCLD, &state);18 chmod (filename, mode); 19 fclearlockfile (filename, f, LCK_XCLD, &state); 23 20 24 21 return (TRUE); 22 } 25 23 26 } -
trunk/Ohana/src/imregister/detrend/entry.c
r3319 r3648 30 30 31 31 int status; 32 int found, Ntry, f d, filestate;32 int found, Ntry, filestate; 33 33 char path[256], fullpath[256], filename[256], rootname[256], fullname[256], line[512]; 34 34 char *dBPath; 35 35 char *filter_basename; 36 36 struct stat statbuf; 37 FILE *f; 37 38 38 39 filter_basename = filterhash[newdata[0].filter]; … … 75 76 sprintf (filename, "%s/%s.%02d.fits", path, rootname, Ntry); 76 77 sprintf (fullname, "%s/%s", dBPath, filename); 77 f d = setlockfile2(fullname, 2.0, LCK_XCLD, &filestate);78 f = fsetlockfile (fullname, 2.0, LCK_XCLD, &filestate); 78 79 if (filestate == LCK_EMPTY) { 79 80 found = TRUE; … … 105 106 exit (1); 106 107 } 107 clearlockfile2 (fullname, fd, LCK_XCLD, &filestate);108 fclearlockfile2 (fullname, f, LCK_XCLD, &filestate); 108 109 109 110 return (TRUE); -
trunk/Ohana/src/imregister/src/imstatreg.c
r3646 r3648 1 1 # include "imregister.h" 2 2 # include "imreg.h" 3 static char *version = "imstatreg $Revision: 3.1 0$";3 static char *version = "imstatreg $Revision: 3.11 $"; 4 4 5 5 int main (int argc, char **argv) { … … 12 12 get_version (argc, argv, version); 13 13 args (argc, argv); 14 init_db();14 SetSignals (); 15 15 16 16 if (CLIENT) imregclient (argv[1], argv[2], argv[3]); 17 18 SetSignals ();19 17 20 18 /* fork in background */ -
trunk/Ohana/src/libohana/src/glockfile.c
r3538 r3648 1 1 # include <ohana.h> 2 2 3 /* set a lock on the given file */4 3 FILE *fsetlockfile (char *filename, double timeout, int type, int *state) { 5 6 int fd;7 FILE *f;8 9 fd = setlockfile2 (filename, timeout, type, state);10 if (fd == -1) return ((FILE *) NULL);11 12 /* setlockfile2 returns a pointer to a vile open for update */13 f = fdopen (fd, "r+");14 if (f == (FILE *) NULL) {15 clearlockfile2 (filename, fd, type, state);16 fprintf (stderr, "can't make stream from descriptor\n");17 return ((FILE *) NULL);18 }19 return (f);20 }21 22 /* clears lock. removes hardlock even if file pointer is not supplied */23 int fclearlockfile (char *filename, FILE *f, int type, int *state) {24 25 int fd, status;26 27 fd = -1;28 if (f != NULL) {29 fflush (f);30 fd = fileno (f);31 }32 status = clearlockfile2 (filename, fd, type, state);33 if (f != NULL) fclose (f);34 return (status);35 }36 37 /* should eventually rewrite these two to use a stream as the basic38 element and only grab the fileno when needed by fcntl39 (fileno cannot fail) */40 41 int setlockfile2 (char *filename, double timeout, int type, int *state) {42 4 43 5 int i, done, nbytes, status; 44 6 char *lockname, buffer[64]; 45 7 char *file, *path; 46 int fd , flock;47 int filemode;8 int fd; 9 FILE *f, flock; 48 10 struct stat filestat; 49 11 struct flock filelock; … … 51 13 52 14 /* initial values at -1, close if the are set to another value */ 53 fd = flock = -1;54 filemode = S_IRUSR | S_IRGRP | S_IROTH;55 15 file = path = lockname = (char *) NULL; 56 gettimeofday (&then, (void *) NULL);57 16 58 17 /* define lock type */ … … 65 24 case LCK_XCLD: 66 25 filelock.l_type = F_WRLCK; /* set an exclusive lock */ 67 filemode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;68 26 break; 69 27 case LCK_SOFT: 70 28 filelock.l_type = F_RDLCK; /* set a shared lock */ 71 filemode = S_IRUSR | S_IRGRP | S_IROTH;72 29 break; 73 30 default: … … 85 42 } 86 43 87 /* try to open file */88 f d = open (filename, O_RDWR | O_CREAT, filemode);89 if (f d == -1) {44 /* try to open file (create if it does not exist) */ 45 f = fopen (filename, "w+"); 46 if (f == NULL) { 90 47 *state = LCK_ACCESS; 91 48 goto failure; 92 49 } 50 fd = fileno (f); 93 51 94 52 /* we first try to set a FS level lock on the file */ 95 for (done = 0; !done; ) { 53 gettimeofday (&then, (void *) NULL); 54 while (1) { 55 /* try to lock file */ 56 if (fcntl (fd, F_SETLK, &filelock) != -1) goto got_lock; 96 57 97 58 /* check for timeout */ … … 101 62 goto failure; 102 63 } 103 usleep (10000); /* 10 ms is min */ 104 105 /* try to lock file */ 106 if (fcntl (fd, F_SETLK, &filelock) != -1) done = 1; 107 } 64 usleep (10000); /* 10 ms is min utime */ 65 } 66 got_lock: 108 67 109 68 if (type == LCK_HARD) { 110 /* we've locked filename, now check lockname */ 111 112 /* locking the lockfile before checking / setting contents will 113 ensure the data is synced across NFS */ 114 69 /* we've locked filename, now check lockfile */ 70 115 71 /* set up name to lockfile */ 116 72 path = pathname (filename); … … 120 76 121 77 /* try to open lockfile */ 122 flock = open (lockname, O_RDWR | O_CREAT, filemode);123 if (flock == -1) {78 flock = fopen (lockname, "w+"); 79 if (flock == NULL) { 124 80 *state = LCK_HARDLCK; 125 81 goto failure; 126 } 127 128 /* try a few times to lock lockfile */ 129 for (i = 0; (i < 20) && (fcntl (flock, F_SETLK, &filelock) == -1); i++) { 130 usleep (10000); 131 } 82 /***** this one has left the file locked ****/ 83 } 84 fd = fileno (flock); 85 86 /* try a few times to lock lockfile (locking the lockfile before checking 87 the contents will ensure the data is synced across NFS) */ 88 for (i = 0; (i < 20) && (fcntl (fd, F_SETLK, &filelock) == -1); i++) usleep (10000); 132 89 if (i == 20) { 133 90 *state = LCK_HARDLCK + 10; 134 91 goto failure; 135 } 136 137 /* we've locked the file, now read the contents */ 138 nbytes = read (flock, buffer, 4); 92 /***** this one has left the file locked ****/ 93 } 94 95 /* we've locked the lockfile, now read the contents */ 96 nbytes = fread (buffer, 1, 4, flock); 139 97 if (nbytes == 4) { /* lock file has a word in it */ 140 98 buffer[4] = 0; … … 142 100 *state = LCK_HARDLCK + 20; 143 101 goto failure; 102 /*** lock file is still 144 103 } 104 /* note that we don't care if the lockfile has random garbage */ 145 105 } 146 106 … … 187 147 } 188 148 149 /* clears lock. removes hardlock even if file pointer is not supplied */ 150 int fclearlockfile (char *filename, FILE *f, int type, int *state) { 151 152 int fd, status; 153 154 fd = -1; 155 if (f != NULL) { 156 fflush (f); 157 fd = fileno (f); 158 } 159 status = clearlockfile2 (filename, fd, type, state); 160 if (f != NULL) fclose (f); 161 return (status); 162 } 163 189 164 /* if we pass in -1, all we can do is clear the hardlock */ 190 165 int clearlockfile2 (char *filename, int fd, int type, int *state) { -
trunk/Ohana/src/misc/Makefile
r2510 r3648 44 44 for i in $(PROGRAMS); do make $$i.install; done 45 45 46 # special rules for specific targets47 dbtest: src/dbtest.$(ARCH).o src/glockfile2.$(ARCH).o48 $(CC) -o dbtest src/dbtest.$(ARCH).o src/glockfile2.$(ARCH).o $(LIBS) $(CCFLAGS)49 50 46 FAKESRC = $(SRC)/fakestars.$(ARCH).o $(SRC)/random.$(ARCH).o 51 47 -
trunk/Ohana/src/misc/src/glockfile.c
r2417 r3648 5 5 char *filename; 6 6 double timeout; 7 int holdtime, state, type, fd; 7 int holdtime, state, type; 8 FILE *f; 8 9 9 10 if (argc != 4) { … … 28 29 } 29 30 30 f d = setlockfile2(filename, timeout, type, &state);31 if (fd == -1) {31 f = fsetlockfile (filename, timeout, type, &state); 32 if (fd == NULL) { 32 33 fprintf (stderr, "ERROR: can't lock file %s\n", filename); 33 34 exit (1); … … 35 36 36 37 sleep (holdtime); 37 38 clearlockfile2 (filename, fd, type, &state); 39 38 fclearlockfile (filename, f, type, &state); 40 39 exit (0); 41 40 } -
trunk/Ohana/src/opihi/dvo/elixir.c
r3462 r3648 62 62 int WriteMsg (char *fifo, char *message) { 63 63 64 int fd,state, mode;64 int state, mode; 65 65 FILE *f; 66 66 67 67 /* check lockfile */ 68 fd = setlockfile2 (fifo, 2.0, LCK_XCLD, &state); 69 if (fd == -1) return (0); 70 f = fdopen (fd, "r+"); 71 if (f == (FILE *) NULL) { 72 mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH; 73 fchmod (fd, mode); 74 clearlockfile2 (fifo, fd, LCK_XCLD, &state); 75 return (0); 76 } 68 f = fsetlockfile (fifo, 2.0, LCK_XCLD, &state); 69 if (f == NULL) return (0); 77 70 78 71 /* write message to end of file */ … … 81 74 82 75 mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH; 83 fchmod (fd, mode);76 chmod (fifo, mode); 84 77 85 clearlockfile2 (fifo, fd, LCK_XCLD, &state); 86 fclose (f); 87 78 fclearlockfile (fifo, f, LCK_XCLD, &state); 88 79 return (1); 89 90 80 } 91 81 … … 94 84 int i, nbytes, Nbytes, NBYTES; 95 85 char *buffer; 96 int fd,state, mode;86 int state, mode; 97 87 FILE *f; 98 88 struct stat filestat; … … 108 98 109 99 /* check lockfile */ 110 f d = setlockfile2(fifo, 2.0, LCK_XCLD, &state);111 if (f d == -1) {100 f = fsetlockfile (fifo, 2.0, LCK_XCLD, &state); 101 if (f == NULL) { 112 102 fprintf (stderr, "message locked (%d)\n", state); 113 return (0);114 }115 f = fdopen (fd, "r+");116 if (f == (FILE *) NULL) {117 fprintf (stderr, "message blocked\n");118 mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;119 fchmod (fd, mode);120 clearlockfile2 (fifo, fd, LCK_XCLD, &state);121 103 return (0); 122 104 } … … 125 107 if (state == LCK_EMPTY) { 126 108 mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH; 127 fchmod (fd, mode); 128 clearlockfile2 (fifo, fd, LCK_XCLD, &state); 129 fclose (f); 109 chmod (fifo, mode); 110 fclearlockfile (fifo, f, LCK_XCLD, &state); 130 111 return (0); 131 112 } … … 148 129 149 130 mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH; 150 fchmod (fd, mode); 151 clearlockfile2 (fifo, fd, LCK_XCLD, &state); 152 fclose (f); 131 chmod (f, mode); 132 fclearlockfile (fifo, f, LCK_XCLD, &state); 153 133 154 134 if (Nbytes == 0) {
Note:
See TracChangeset
for help on using the changeset viewer.
