Handle SIGTERM cleanly by finishing up current print, but no more.

This commit is contained in:
Solomon Peachy 2013-05-03 07:42:23 -04:00
parent ed27b59441
commit e280fbc060
2 changed files with 24 additions and 0 deletions

View File

@ -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) {

View File

@ -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) {