Skip to content

Commit 4f50835

Browse files
Copilotkrlmlr
andcommitted
Fix itimer state restoration in filelock-unix.c
- Add global variable filelock_old_timer to store previous timer state - Modify setitimer call to save old timer state before setting new one - Modify alarm callback to restore both signal handler and timer state - Verified package builds and installs correctly - Tested functionality with multiple scenarios Co-authored-by: krlmlr <1741643+krlmlr@users.noreply.github.com>
1 parent f945a73 commit 4f50835

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/filelock-unix.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#define FILELOCK_INTERRUPT_INTERVAL 200
1616

1717
struct sigaction filelock_old_sa;
18+
struct itimerval filelock_old_timer;
1819

1920
void filelock__finalizer(SEXP x) {
2021
filelock__list_t *ptr = (filelock__list_t*) R_ExternalPtrAddr(x);
@@ -33,6 +34,8 @@ void filelock__finalizer(SEXP x) {
3334
void filelock__alarm_callback (int signum) {
3435
/* Restore signal handler */
3536
sigaction(SIGALRM, &filelock_old_sa, 0);
37+
/* Restore timer state */
38+
setitimer(ITIMER_REAL, &filelock_old_timer, 0);
3639
}
3740

3841
int filelock__interruptible(int filedes, struct flock *lck,
@@ -63,7 +66,7 @@ int filelock__interruptible(int filedes, struct flock *lck,
6366
sa.sa_handler = &filelock__alarm_callback;
6467
sigaction(SIGALRM, &sa, &filelock_old_sa);
6568

66-
setitimer(ITIMER_REAL, &timer, 0);
69+
setitimer(ITIMER_REAL, &timer, &filelock_old_timer);
6770
ret = fcntl(filedes, F_SETLKW, lck);
6871

6972
/* We need to remove the timer here, to avoid getting a signal

0 commit comments

Comments
 (0)