Skip to content

Commit 148556b

Browse files
committed
Catching SIGCONT correctly
1 parent 6ffafcd commit 148556b

File tree

4 files changed

+29
-15
lines changed

4 files changed

+29
-15
lines changed

src/libltfs/ltfs.c

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,29 @@ bool ltfs_caught_sigcont(void)
222222
return caught_sigcont;
223223
}
224224

225+
int ltfs_extra_signal_handlers(void)
226+
{
227+
ltfs_sighandler_t ret;
228+
ret = signal(SIGCONT, _ltfs_sigcont);
229+
if (ret == SIG_ERR) {
230+
return -LTFS_SIG_HANDLER_ERR;
231+
}
232+
233+
return 0;
234+
}
235+
236+
int ltfs_unset_extra_signal_handler(void)
237+
{
238+
ltfs_sighandler_t rc;
239+
int ret = 0;
240+
241+
rc = signal(SIGCONT, SIG_DFL);
242+
if (rc == SIG_ERR)
243+
ret = -LTFS_SIG_HANDLER_ERR;
244+
245+
return ret;
246+
}
247+
225248
/**
226249
* This function can be used to enable libltfs signal handler
227250
* to kill ltfs, mkltfs, ltfsck cleanly
@@ -266,15 +289,6 @@ int ltfs_set_signal_handlers(void)
266289
return -LTFS_SIG_HANDLER_ERR;
267290
}
268291

269-
ret = signal(SIGCONT, _ltfs_sigcont);
270-
if (ret == SIG_ERR) {
271-
signal(SIGINT, SIG_DFL);
272-
signal(SIGHUP, SIG_DFL);
273-
signal(SIGQUIT, SIG_DFL);
274-
signal(SIGTERM, SIG_DFL);
275-
return -LTFS_SIG_HANDLER_ERR;
276-
}
277-
278292
return 0;
279293
}
280294
#endif
@@ -309,10 +323,6 @@ int ltfs_unset_signal_handlers(void)
309323
if (rc == SIG_ERR)
310324
ret = -LTFS_SIG_HANDLER_ERR;
311325

312-
rc = signal(SIGCONT, SIG_DFL);
313-
if (rc == SIG_ERR)
314-
ret = -LTFS_SIG_HANDLER_ERR;
315-
316326
return ret;
317327
}
318328
#endif

src/libltfs/ltfs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,8 @@ bool ltfs_caught_sigcont(void);
596596
void ltfs_sigcont_set(bool sig_val);
597597
int ltfs_set_signal_handlers(void);
598598
int ltfs_unset_signal_handlers(void);
599+
int ltfs_extra_signal_handlers(void);
600+
int ltfs_unset_extra_signal_handler(void);
599601
int ltfs_finish();
600602

601603
/* Public wrappers for tape_* functions */

src/libltfs/tape.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,15 +1245,13 @@ ssize_t tape_write(struct device_data *dev, const char *buf, size_t count, bool
12451245
}
12461246

12471247
if (ltfs_caught_sigcont()) {
1248-
ltfsmsg(LTFS_DEBUG, 16503D, "ltfs_caught_sigcont", "tape_write");
12491248
ret_for_update_position = tape_get_position_from_drive(dev, &current_position);
12501249
if (ret_for_update_position) {
12511250
/* Return error since the current tape position was unable to be determined, so there could be an undetected position mismatch */
12521251
ltfsmsg(LTFS_ERR, 11081E, ret);
12531252
return -LTFS_WRITE_ERROR;
12541253
}
12551254

1256-
ltfsmsg(LTFS_INFO, 11334I, "compare offset in tape_write", (unsigned long long)dev->position.block, (unsigned long long)current_position.block);
12571255
diff = ((unsigned long long)dev->position.block - (unsigned long long)current_position.block);
12581256
if (diff) {
12591257
/* Position mismatch, diff not equal zero */

src/main.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,10 +1241,14 @@ int single_drive_main(struct fuse_args *args, struct ltfs_fuse_data *priv)
12411241
ltfsmsg(LTFS_INFO, 14111I);
12421242
ltfsmsg(LTFS_INFO, 14112I);
12431243
ltfsmsg(LTFS_INFO, 14113I);
1244+
/* Set handlers for signals that need to be caught while fuse main is running*/
1245+
ltfs_extra_signal_handlers();
12441246
ret = fuse_main(args->argc, args->argv, &ltfs_ops, priv);
12451247
if (ret != 0) {
12461248
ltfsmsg(LTFS_WARN, 14123W, ret);
12471249
}
1250+
/* Unset extra handlers once fuse main exits */
1251+
ltfs_unset_extra_signal_handler();
12481252

12491253
/* Setup signal handler again to terminate cleanly */
12501254
ret = ltfs_set_signal_handlers();

0 commit comments

Comments
 (0)