From de989d76fc888e2c1701a95974919a82a3386dd1 Mon Sep 17 00:00:00 2001 From: Jung-uk Kim Date: Wed, 3 Jun 2009 20:24:28 +0000 Subject: [PATCH] Fix acpidump(8) disassmebly with option -d. iasl(8) creates disassembled output file from input file name as a template. Honor TMPDIR environment variable while I am here. --- usr.sbin/acpi/acpidump/acpi.c | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/usr.sbin/acpi/acpidump/acpi.c b/usr.sbin/acpi/acpidump/acpi.c index fed0fb2fb59..30ed43f9daa 100644 --- a/usr.sbin/acpi/acpidump/acpi.c +++ b/usr.sbin/acpi/acpidump/acpi.c @@ -34,7 +34,9 @@ #include #include #include +#include #include +#include #include #include @@ -803,11 +805,26 @@ dsdt_save_file(char *outfile, struct ACPIsdt *rsdt, struct ACPIsdt *dsdp) void aml_disassemble(struct ACPIsdt *rsdt, struct ACPIsdt *dsdp) { - char tmpstr[32], buf[256]; + char buf[PATH_MAX], tmpstr[PATH_MAX]; + const char *tmpdir; + char *tmpext; FILE *fp; - int fd, len; - - strcpy(tmpstr, "/tmp/acpidump.XXXXXX"); + size_t len; + int fd; + + tmpdir = getenv("TMPDIR"); + if (tmpdir == NULL) + tmpdir = _PATH_TMP; + strncpy(tmpstr, tmpdir, sizeof(tmpstr)); + strncat(tmpstr, "/acpidump.", sizeof(tmpstr) - strlen(tmpdir)); + if (realpath(tmpstr, buf) == NULL) { + perror("realpath tmp file"); + return; + } + strncpy(tmpstr, buf, sizeof(tmpstr)); + len = strlen(buf); + tmpext = tmpstr + len; + strncpy(tmpext, "XXXXXX", sizeof(tmpstr) - len); fd = mkstemp(tmpstr); if (fd < 0) { perror("iasl tmp file"); @@ -821,7 +838,7 @@ aml_disassemble(struct ACPIsdt *rsdt, struct ACPIsdt *dsdp) close(STDOUT_FILENO); if (vflag == 0) close(STDERR_FILENO); - execl("/usr/sbin/iasl", "iasl", "-d", tmpstr, (char *) 0); + execl("/usr/sbin/iasl", "iasl", "-d", tmpstr, NULL); err(1, "exec"); } @@ -829,8 +846,9 @@ aml_disassemble(struct ACPIsdt *rsdt, struct ACPIsdt *dsdp) unlink(tmpstr); /* Dump iasl's output to stdout */ - fp = fopen("acpidump.dsl", "r"); - unlink("acpidump.dsl"); + strncpy(tmpext, "dsl", sizeof(tmpstr) - len); + fp = fopen(tmpstr, "r"); + unlink(tmpstr); if (fp == NULL) { perror("iasl tmp file (read)"); return; -- 2.45.0