updated the 3.0 branch from the head branch - ready for alpha18
[tprouty/samba.git] / source / lib / util_file.c
index e80267f84b5536fd2ebbcc2411308948398f4ed4..611e0e40be9deff25681ffc8fe51e09826d16bc1 100644 (file)
@@ -40,9 +40,10 @@ BOOL do_file_lock(int fd, int waitsecs, int type)
 {
   SMB_STRUCT_FLOCK lock;
   int             ret;
+  void (*oldsig_handler)(int);
 
   gotalarm = 0;
-  CatchSignal(SIGALRM, SIGNAL_CAST gotalarm_sig);
+  oldsig_handler = CatchSignal(SIGALRM, SIGNAL_CAST gotalarm_sig);
 
   lock.l_type = type;
   lock.l_whence = SEEK_SET;
@@ -51,9 +52,10 @@ BOOL do_file_lock(int fd, int waitsecs, int type)
   lock.l_pid = 0;
 
   alarm(waitsecs);
+  /* Note we must *NOT* use sys_fcntl here ! JRA */
   ret = fcntl(fd, SMB_F_SETLKW, &lock);
   alarm(0);
-  CatchSignal(SIGALRM, SIGNAL_CAST SIG_IGN);
+  CatchSignal(SIGALRM, SIGNAL_CAST oldsig_handler);
 
   if (gotalarm) {
     DEBUG(0, ("do_file_lock: failed to %s file.\n",
@@ -448,7 +450,8 @@ void *map_file(char *fname, size_t size)
 #endif
        if (!p) {
                p = file_load(fname, &s2);
-               if (!p || s2 != size) {
+               if (!p) return NULL;
+               if (s2 != size) {
                        DEBUG(1,("incorrect size for %s - got %d expected %d\n",
                                 fname, s2, size));
                        if (p) free(p);