chiark
/
gitweb
/
~mdw
/
mLib
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
0f2a884
)
Fix signal handling.
author
mdw
<mdw>
Sun, 6 Jun 1999 01:23:00 +0000
(
01:23
+0000)
committer
mdw
<mdw>
Sun, 6 Jun 1999 01:23:00 +0000
(
01:23
+0000)
lock.c
patch
|
blob
|
blame
|
history
diff --git
a/lock.c
b/lock.c
index 9dfabab6f715ec0ef8e2cd232c6c624f8ae2dc51..445e43de71c4bec5d4dd2d9d57773aa793f382f0 100644
(file)
--- a/
lock.c
+++ b/
lock.c
@@
-1,6
+1,6
@@
/* -*-c-*-
*
/* -*-c-*-
*
- * $Id: lock.c,v 1.
2 1999/05/26 20:53:4
0 mdw Exp $
+ * $Id: lock.c,v 1.
3 1999/06/06 01:23:0
0 mdw Exp $
*
* Simplified POSIX locking interface
*
*
* Simplified POSIX locking interface
*
@@
-30,6
+30,9
@@
/*----- Revision history --------------------------------------------------*
*
* $Log: lock.c,v $
/*----- Revision history --------------------------------------------------*
*
* $Log: lock.c,v $
+ * Revision 1.3 1999/06/06 01:23:00 mdw
+ * Fix signal handling.
+ *
* Revision 1.2 1999/05/26 20:53:40 mdw
* Fixes for stupid bugs.
*
* Revision 1.2 1999/05/26 20:53:40 mdw
* Fixes for stupid bugs.
*
@@
-88,7
+91,7
@@
static void lock_alarm(int sig) { ; }
int lock_file(int fd, unsigned how)
{
struct flock fk;
int lock_file(int fd, unsigned how)
{
struct flock fk;
-
void (*alrm)(int)
;
+
struct sigaction sa, oldsa
;
int e;
/* --- Fill in the easy bits --- */
int e;
/* --- Fill in the easy bits --- */
@@
-104,7
+107,7
@@
int lock_file(int fd, unsigned how)
return (fcntl(fd, F_SETLK, &fk));
}
return (fcntl(fd, F_SETLK, &fk));
}
- /* ---
Set an alarm handler
--- */
+ /* ---
Decide how to do the locking
--- */
if (how == LOCK_EXCL)
fk.l_type = F_WRLCK;
if (how == LOCK_EXCL)
fk.l_type = F_WRLCK;
@@
-115,14
+118,26
@@
int lock_file(int fd, unsigned how)
return (-1);
}
return (-1);
}
- alrm = signal(SIGALRM, lock_alarm);
+ /* --- Set up the alarm --- */
+
+ sa.sa_handler = lock_alarm;
+ sa.sa_flags = 0;
+ sigemptyset(&sa.sa_mask);
+ if (sigaction(SIGALRM, &sa, &oldsa))
+ return (-1);
+
+ /* --- Do it --- */
+
alarm(LOCK_TIMEOUT);
if ((e = fcntl(fd, F_SETLKW, &fk)) != 0) {
if (errno == EINTR)
errno = EAGAIN;
}
alarm(LOCK_TIMEOUT);
if ((e = fcntl(fd, F_SETLKW, &fk)) != 0) {
if (errno == EINTR)
errno = EAGAIN;
}
+
+ /* --- Remove the alarm handling --- */
+
alarm(0);
alarm(0);
- sig
nal(SIGALRM, alrm
);
+ sig
action(SIGALRM, &oldsa, 0
);
return (e);
}
return (e);
}