acpi.c (173726) | acpi.c (193531) |
---|---|
1/*- 2 * Copyright (c) 1998 Doug Rabson 3 * Copyright (c) 2000 Mitsuru IWASAKI <iwasaki@FreeBSD.org> 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 10 unchanged lines hidden (view full) --- 19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 * | 1/*- 2 * Copyright (c) 1998 Doug Rabson 3 * Copyright (c) 2000 Mitsuru IWASAKI <iwasaki@FreeBSD.org> 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 10 unchanged lines hidden (view full) --- 19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 * |
27 * $FreeBSD: head/usr.sbin/acpi/acpidump/acpi.c 173726 2007-11-18 09:13:08Z jb $ | 27 * $FreeBSD: head/usr.sbin/acpi/acpidump/acpi.c 193531 2009-06-05 18:50:45Z jkim $ |
28 */ 29 30#include <sys/param.h> 31#include <sys/endian.h> 32#include <sys/stat.h> 33#include <sys/wait.h> 34#include <assert.h> 35#include <err.h> 36#include <fcntl.h> | 28 */ 29 30#include <sys/param.h> 31#include <sys/endian.h> 32#include <sys/stat.h> 33#include <sys/wait.h> 34#include <assert.h> 35#include <err.h> 36#include <fcntl.h> |
37#include <paths.h> |
|
37#include <stdio.h> | 38#include <stdio.h> |
39#include <stdlib.h> |
|
38#include <string.h> 39#include <unistd.h> 40 41#include "acpidump.h" 42 43#define BEGIN_COMMENT "/*\n" 44#define END_COMMENT " */\n" 45 --- 752 unchanged lines hidden (view full) --- 798 } 799 write_dsdt(fd, rsdt, dsdp); 800 close(fd); 801} 802 803void 804aml_disassemble(struct ACPIsdt *rsdt, struct ACPIsdt *dsdp) 805{ | 40#include <string.h> 41#include <unistd.h> 42 43#include "acpidump.h" 44 45#define BEGIN_COMMENT "/*\n" 46#define END_COMMENT " */\n" 47 --- 752 unchanged lines hidden (view full) --- 800 } 801 write_dsdt(fd, rsdt, dsdp); 802 close(fd); 803} 804 805void 806aml_disassemble(struct ACPIsdt *rsdt, struct ACPIsdt *dsdp) 807{ |
806 char tmpstr[32], buf[256]; | 808 char buf[PATH_MAX], tmpstr[PATH_MAX]; 809 const char *tmpdir; 810 char *tmpext; |
807 FILE *fp; | 811 FILE *fp; |
808 int fd, len; | 812 size_t len; 813 int fd; |
809 | 814 |
810 strcpy(tmpstr, "/tmp/acpidump.XXXXXX"); | 815 tmpdir = getenv("TMPDIR"); 816 if (tmpdir == NULL) 817 tmpdir = _PATH_TMP; 818 strncpy(tmpstr, tmpdir, sizeof(tmpstr)); 819 strncat(tmpstr, "/acpidump.", sizeof(tmpstr) - strlen(tmpdir)); 820 if (realpath(tmpstr, buf) == NULL) { 821 perror("realpath tmp file"); 822 return; 823 } 824 strncpy(tmpstr, buf, sizeof(tmpstr)); 825 len = strlen(buf); 826 tmpext = tmpstr + len; 827 strncpy(tmpext, "XXXXXX", sizeof(tmpstr) - len); |
811 fd = mkstemp(tmpstr); 812 if (fd < 0) { 813 perror("iasl tmp file"); 814 return; 815 } 816 write_dsdt(fd, rsdt, dsdp); 817 close(fd); 818 819 /* Run iasl -d on the temp file */ 820 if (fork() == 0) { 821 close(STDOUT_FILENO); 822 if (vflag == 0) 823 close(STDERR_FILENO); | 828 fd = mkstemp(tmpstr); 829 if (fd < 0) { 830 perror("iasl tmp file"); 831 return; 832 } 833 write_dsdt(fd, rsdt, dsdp); 834 close(fd); 835 836 /* Run iasl -d on the temp file */ 837 if (fork() == 0) { 838 close(STDOUT_FILENO); 839 if (vflag == 0) 840 close(STDERR_FILENO); |
824 execl("/usr/sbin/iasl", "iasl", "-d", tmpstr, (char *) 0); | 841 execl("/usr/sbin/iasl", "iasl", "-d", tmpstr, NULL); |
825 err(1, "exec"); 826 } 827 828 wait(NULL); 829 unlink(tmpstr); 830 831 /* Dump iasl's output to stdout */ | 842 err(1, "exec"); 843 } 844 845 wait(NULL); 846 unlink(tmpstr); 847 848 /* Dump iasl's output to stdout */ |
832 fp = fopen("acpidump.dsl", "r"); 833 unlink("acpidump.dsl"); | 849 strncpy(tmpext, "dsl", sizeof(tmpstr) - len); 850 fp = fopen(tmpstr, "r"); 851 unlink(tmpstr); |
834 if (fp == NULL) { 835 perror("iasl tmp file (read)"); 836 return; 837 } 838 while ((len = fread(buf, 1, sizeof(buf), fp)) > 0) 839 fwrite(buf, 1, len, stdout); 840 fclose(fp); 841} --- 57 unchanged lines hidden --- | 852 if (fp == NULL) { 853 perror("iasl tmp file (read)"); 854 return; 855 } 856 while ((len = fread(buf, 1, sizeof(buf), fp)) > 0) 857 fwrite(buf, 1, len, stdout); 858 fclose(fp); 859} --- 57 unchanged lines hidden --- |