diff --git a/kodak1400_print.c b/kodak1400_print.c index ec75c3d..6d45dbe 100644 --- a/kodak1400_print.c +++ b/kodak1400_print.c @@ -266,6 +266,13 @@ static int send_plane(struct libusb_device_handle *dev, uint8_t endp, return 0; } +static int terminate = 0; + +void sigterm_handler(int signum) { + terminate = 1; + INFO("Job Cancelled"); +} + int main (int argc, char **argv) { struct libusb_context *ctx; @@ -356,6 +363,7 @@ int main (int argc, char **argv) /* Ignore SIGPIPE */ signal(SIGPIPE, SIG_IGN); + signal(SIGTERM, sigterm_handler); /* Read in then validate header */ read(data_fd, &hdr, sizeof(hdr)); @@ -630,6 +638,10 @@ top: if (state != S_FINISHED) goto top; + /* Clean up */ + if (terminate) + copies = 1; + INFO("Print complete (%d remaining)\n", copies - 1); if (copies && --copies) { diff --git a/selphy_print.c b/selphy_print.c index ae7399a..79be239 100644 --- a/selphy_print.c +++ b/selphy_print.c @@ -524,6 +524,13 @@ static int find_and_enumerate(struct libusb_context *ctx, return found; } +static int terminate = 0; + +void sigterm_handler(int signum) { + terminate = 1; + INFO("Job Cancelled"); +} + int main (int argc, char **argv) { struct libusb_context *ctx; @@ -650,6 +657,7 @@ int main (int argc, char **argv) /* Ignore SIGPIPE */ signal(SIGPIPE, SIG_IGN); + signal(SIGTERM, sigterm_handler); /* Read in entire print job */ memcpy(header, buffer, header_len); @@ -876,6 +884,10 @@ top: if (state != S_FINISHED) goto top; + /* Clean up */ + if (terminate) + copies = 1; + INFO("Print complete (%d remaining)\n", copies - 1); if (copies && --copies) {