Date: Tue, 24 Mar 2009 01:35:59 +0000 (UTC) From: "David E. O'Brien" <obrien@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-7@freebsd.org Subject: svn commit: r190356 - stable/7/usr.sbin/burncd Message-ID: <200903240135.n2O1ZxP4027999@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: obrien Date: Tue Mar 24 01:35:58 2009 New Revision: 190356 URL: http://svn.freebsd.org/changeset/base/190356 Log: MFC: r186337/r186444/186784: burncd(8) doesn't handle signals and interrupting burncd during operation. Add signal handling by doing a CDRIOCFLUSH ioctl to attempt to leave burner in a sane state when burning is interrupted with SIGHUP, SIGINT, SIGTERM, or in case an I/O error occurs during write. Modified: stable/7/usr.sbin/burncd/ (props changed) stable/7/usr.sbin/burncd/Makefile stable/7/usr.sbin/burncd/burncd.c Modified: stable/7/usr.sbin/burncd/Makefile ============================================================================== --- stable/7/usr.sbin/burncd/Makefile Tue Mar 24 01:31:42 2009 (r190355) +++ stable/7/usr.sbin/burncd/Makefile Tue Mar 24 01:35:58 2009 (r190356) @@ -3,6 +3,6 @@ PROG= burncd MAN= burncd.8 -WARNS?= 5 +WARNS?= 6 .include <bsd.prog.mk> Modified: stable/7/usr.sbin/burncd/burncd.c ============================================================================== --- stable/7/usr.sbin/burncd/burncd.c Tue Mar 24 01:31:42 2009 (r190355) +++ stable/7/usr.sbin/burncd/burncd.c Tue Mar 24 01:35:58 2009 (r190356) @@ -29,6 +29,7 @@ */ #include <unistd.h> +#include <signal.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> @@ -57,7 +58,8 @@ struct track_info { int addr; }; static struct track_info tracks[100]; -static int global_fd_for_cleanup, quiet, verbose, saved_block_size, notracks; +static int quiet, verbose, saved_block_size, notracks; +static volatile sig_atomic_t global_fd_for_cleanup; void add_track(char *, int, int, int); void do_DAO(int fd, int, int); @@ -67,6 +69,8 @@ int write_file(int fd, struct track_info int roundup_blocks(struct track_info *); void cue_ent(struct cdr_cue_entry *, int, int, int, int, int, int, int); void cleanup(int); +void cleanup_flush(void); +void cleanup_signal(int); void usage(void); int @@ -157,6 +161,9 @@ main(int argc, char **argv) global_fd_for_cleanup = fd; err_set_exit(cleanup); + signal(SIGHUP, cleanup_signal); + signal(SIGINT, cleanup_signal); + signal(SIGTERM, cleanup_signal); for (arg = 0; arg < argc; arg++) { if (!strcasecmp(argv[arg], "fixate")) { @@ -319,6 +326,10 @@ main(int argc, char **argv) if (eject) if (ioctl(fd, CDIOCEJECT) < 0) err(EX_IOERR, "ioctl(CDIOCEJECT)"); + + signal(SIGHUP, SIG_DFL); + signal(SIGINT, SIG_DFL); + signal(SIGTERM, SIG_DFL); close(fd); exit(EX_OK); } @@ -469,8 +480,10 @@ do_DAO(int fd, int test_write, int multi err(EX_IOERR, "ioctl(CDRIOCSENDCUE)"); for (i = 0; i < notracks; i++) { - if (write_file(fd, &tracks[i])) + if (write_file(fd, &tracks[i])) { + cleanup_flush(); err(EX_IOERR, "write_file"); + } } ioctl(fd, CDRIOCFLUSH); @@ -499,8 +512,10 @@ do_TAO(int fd, int test_write, int preem if (!quiet) fprintf(stderr, "next writeable LBA %d\n", tracks[i].addr); - if (write_file(fd, &tracks[i])) + if (write_file(fd, &tracks[i])) { + cleanup_flush(); err(EX_IOERR, "write_file"); + } if (ioctl(fd, CDRIOCFLUSH) < 0) err(EX_IOERR, "ioctl(CDRIOCFLUSH)"); } @@ -630,9 +645,11 @@ write_file(int fd, struct track_info *tr track_info->block_size; } if ((res = write(fd, buf, count)) != count) { - if (res == -1) - fprintf(stderr, "\n%s\n", strerror(errno)); - else + if (res == -1) { + fprintf(stderr, "\n"); + close(track_info->file); + return errno; + } else fprintf(stderr, "\nonly wrote %d of %jd" " bytes\n", res, (intmax_t)count); break; @@ -693,6 +710,22 @@ cleanup(int dummy __unused) } void +cleanup_flush(void) +{ + if (ioctl(global_fd_for_cleanup, CDRIOCFLUSH) < 0) + err(EX_IOERR, "ioctl(CDRIOCFLUSH)"); +} + +void +cleanup_signal(int sig) +{ + signal(sig, SIG_IGN); + ioctl(global_fd_for_cleanup, CDRIOCFLUSH); + write(STDERR_FILENO, "\nAborted\n", 10); + _exit(EXIT_FAILURE); +} + +void usage(void) { fprintf(stderr,
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200903240135.n2O1ZxP4027999>