Skip to content

Commit c89ef57

Browse files
committed
Protecting LE agains error caused by SIGSTOP and SIGCONT
1 parent 33807bf commit c89ef57

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

src/libltfs/ltfs.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,18 @@ bool ltfs_is_interrupted(void)
207207
return interrupted;
208208
}
209209

210+
bool caught_sigcont = false;
211+
void _ltfs_sigcont(int signal)
212+
{
213+
ltfsmsg(LTFS_DEBUG, 16503D, "_ltfs_sigcont", "");
214+
caught_sigcont = true;
215+
}
216+
217+
bool ltfs_caught_sigcont(void)
218+
{
219+
return caught_sigcont;
220+
}
221+
210222
/**
211223
* This function can be used to enable libltfs signal handler
212224
* to kill ltfs, mkltfs, ltfsck cleanly
@@ -251,6 +263,15 @@ int ltfs_set_signal_handlers(void)
251263
return -LTFS_SIG_HANDLER_ERR;
252264
}
253265

266+
ret = signal(SIGCONT, _ltfs_sigcont);
267+
if (ret == SIG_ERR) {
268+
signal(SIGINT, SIG_DFL);
269+
signal(SIGHUP, SIG_DFL);
270+
signal(SIGQUIT, SIG_DFL);
271+
signal(SIGTERM, SIG_DFL);
272+
return -LTFS_SIG_HANDLER_ERR;
273+
}
274+
254275
return 0;
255276
}
256277
#endif
@@ -285,6 +306,10 @@ int ltfs_unset_signal_handlers(void)
285306
if (rc == SIG_ERR)
286307
ret = -LTFS_SIG_HANDLER_ERR;
287308

309+
rc = signal(SIGCONT, SIG_DFL);
310+
if (rc == SIG_ERR)
311+
ret = -LTFS_SIG_HANDLER_ERR;
312+
288313
return ret;
289314
}
290315
#endif

src/libltfs/ltfs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,7 @@ int ltfs_fs_init(void);
586586
void ltfs_set_log_level(int log_level);
587587
void ltfs_set_syslog_level(int syslog_level);
588588
bool ltfs_is_interrupted(void);
589+
bool ltfs_caught_sigcont(void);
589590
int ltfs_set_signal_handlers(void);
590591
int ltfs_unset_signal_handlers(void);
591592
int ltfs_finish();

src/libltfs/tape.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,6 +1187,9 @@ int tape_spacefm(struct device_data *dev, int count)
11871187
ssize_t tape_write(struct device_data *dev, const char *buf, size_t count, bool ignore_less, bool ignore_nospc)
11881188
{
11891189
ssize_t ret;
1190+
struct tc_position current_position;
1191+
int ret_for_update_position = 0;
1192+
unsigned long long diff = 0;
11901193

11911194
CHECK_ARG_NULL(dev, -LTFS_NULL_ARG);
11921195
CHECK_ARG_NULL(buf, -LTFS_NULL_ARG);
@@ -1241,6 +1244,19 @@ ssize_t tape_write(struct device_data *dev, const char *buf, size_t count, bool
12411244
count = -LTFS_LESS_SPACE;
12421245
}
12431246

1247+
if (ltfs_caught_sigcont()) {
1248+
ltfsmsg(LTFS_DEBUG, 16503D, "ltfs_caught_sigcont", "tape_write");
1249+
ret_for_update_position = tape_update_position(dev, &current_position);
1250+
if (ret_for_update_position) {
1251+
// Implement the error handling
1252+
}
1253+
ltfsmsg(LTFS_INFO, 11334I, "compare offset in tape_write", (unsigned long long)dev->position.block, (unsigned long long)current_position.block);
1254+
diff = ((unsigned long long)dev->position.block - (unsigned long long)current_position.block);
1255+
if (diff) {
1256+
return -LTFS_WRITE_ERROR;
1257+
}
1258+
}
1259+
12441260
ltfs_mutex_lock(&dev->append_pos_mutex);
12451261
dev->append_pos[dev->position.partition] = dev->position.block;
12461262
ltfs_mutex_unlock(&dev->append_pos_mutex);

0 commit comments

Comments
 (0)