diff options
author | H. Peter Anvin <hpa@linux.intel.com> | 2010-07-19 16:56:35 -0700 |
---|---|---|
committer | H. Peter Anvin <hpa@linux.intel.com> | 2010-07-19 16:56:35 -0700 |
commit | 04485f48391455fbd528640eff54ab09c23f8d93 (patch) | |
tree | c3b7ced66c5a0f2e571625da64af0b52a05c4c5d /mtools | |
parent | 9b18ab6c1019239a19160290775460601c569357 (diff) | |
parent | 9b30e3868cc76c13766bb686024832f274d97c45 (diff) | |
download | syslinux-04485f48391455fbd528640eff54ab09c23f8d93.tar.gz |
Merge branch 'master' into libinstaller_dos_wip
Resolved Conflicts:
libinstaller/syslxopt.c
mtools/syslinux.c
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
Diffstat (limited to 'mtools')
-rwxr-xr-x | mtools/syslinux.c | 44 |
1 files changed, 35 insertions, 9 deletions
diff --git a/mtools/syslinux.c b/mtools/syslinux.c index 937f6b87..ac189c61 100755 --- a/mtools/syslinux.c +++ b/mtools/syslinux.c @@ -1,6 +1,7 @@ /* ----------------------------------------------------------------------- * * * Copyright 1998-2008 H. Peter Anvin - All Rights Reserved + * Copyright 2010 Intel Corporation; author: H. Peter Anvin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -18,8 +19,7 @@ * We need device write permission anyway. */ -#define _XOPEN_SOURCE 500 /* Required on glibc 2.x */ -#define _BSD_SOURCE +#define _GNU_SOURCE #include <alloca.h> #include <errno.h> #include <fcntl.h> @@ -51,6 +51,12 @@ void __attribute__ ((noreturn)) die(const char *msg) exit(1); } +void __attribute__ ((noreturn)) die_err(const char *msg) +{ + fprintf(stderr, "%s: %s: %s\n", program, msg, strerror(errno)); + exit(1); +} + /* * read/write wrapper functions */ @@ -124,7 +130,8 @@ int main(int argc, char *argv[]) int dev_fd; struct stat st; int status; - char mtools_conf[] = "/tmp/syslinux-mtools-XXXXXX"; + const char *tmpdir; + char *mtools_conf; int mtc_fd; FILE *mtc, *mtp; struct libfat_filesystem *fs; @@ -155,12 +162,26 @@ int main(int argc, char *argv[]) } /* + * Temp directory of choice... + */ + tmpdir = getenv("TMPDIR"); + if (!tmpdir) { +#ifdef P_tmpdir + tmpdir = P_tmpdir; +#elif defined(_PATH_TMP) + tmpdir = _PATH_TMP; +#else + tmpdir = "/tmp"; +#endif + } + + /* * First make sure we can open the device at all, and that we have * read/write permission. */ dev_fd = open(opt.device, O_RDWR); if (dev_fd < 0 || fstat(dev_fd, &st) < 0) { - perror(opt.device); + die_err(opt.device); exit(1); } @@ -183,11 +204,14 @@ int main(int argc, char *argv[]) /* * Create an mtools configuration file */ + if (asprintf(&mtools_conf, "%s//syslinux-mtools-XXXXXX", tmpdir) < 0 || + !mtools_conf) + die_err(tmpdir); + mtc_fd = mkstemp(mtools_conf); - if (mtc_fd < 0 || !(mtc = fdopen(mtc_fd, "w"))) { - perror(program); - exit(1); - } + if (mtc_fd < 0 || !(mtc = fdopen(mtc_fd, "w"))) + die_err(mtools_conf); + fprintf(mtc, /* These are needed for some flash memories */ "MTOOLS_SKIP_CHECK=1\n" @@ -197,7 +221,9 @@ int main(int argc, char *argv[]) " offset=%llu\n", (unsigned long)mypid, dev_fd, (unsigned long long)opt.offset); - fclose(mtc); + + if (ferror(mtc) || fclose(mtc)) + die_err(mtools_conf); /* * Run mtools to create the LDLINUX.SYS file |