nima / python-dmidecode

Python DMI-Decode
39 stars 27 forks source link

fix bug: Failed to open memory buffer (/dev/mem): Permission denied #37

Closed HuO50 closed 2 years ago

HuO50 commented 2 years ago

Default use /dev/mem dump dmidecode info. Add collecting info method from DMI instead /dev/mem. Issue address:https://github.com/nima/python-dmidecode/issues/15

lian-bo commented 2 years ago

Hi, Zhongze Thank you for the fix. As we discussed offline, I will merge it into the devel branch: smbios-3.3.0. And then we will test all changes, once the devel branch is ready, we can switch to the master branch. Thanks.

lian-bo commented 2 years ago
Hi, Zhongze Can you check it again? I got the following compilation errors: $ sudo make python3.10 src/setup.py build /home/lijiang/src/python-dmidecode/src/setup.py:29: DeprecationWarning: The distutils package is deprecated and slated for removal in Python 3.12. Use setuptools or check PEP 632 for potential alternatives from distutils.core import setup, Extension running build running build_py running build_ext building 'dmidecodemod' extension gcc -Wno-unused-result -Wsign-compare -DDYNAMIC_ANNOTATIONS_ENABLED=1 -DNDEBUG -O2 -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fstack-protector-strong -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE -fPIC -fwrapv -O2 -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fstack-protector-strong -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE -fPIC -fwrapv -O2 -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fstack-protector-strong -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE -fPIC -fwrapv -fPIC -UNDEBUG -I/usr/include/libxml2 -I/usr/include/python3.10 -c src/dmidecode.c -o build/temp.linux-x86_64-3.10/src/dmidecode.o src/dmidecode.c: In function ‘dmi_additional_info’: src/dmidecode.c:3907:42: warning: variable ‘str_n’ set but not used [-Wunused-but-set-variable] 3907 xmlNode data_n = NULL, str_n = NULL, *val_n = NULL; ^~~~~ gcc -Wno-unused-result -Wsign-compare -DDYNAMIC_ANNOTATIONS_ENABLED=1 -DNDEBUG -O2 -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fstack-protector-strong -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE -fPIC -fwrapv -O2 -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fstack-protector-strong -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE -fPIC -fwrapv -O2 -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fstack-protector-strong -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE -fPIC -fwrapv -fPIC -UNDEBUG -I/usr/include/libxml2 -I/usr/include/python3.10 -c src/dmidecodemodule.c -o build/temp.linux-x86_64-3.10/src/dmidecodemodule.o In file included from src/dmidecodemodule.c:47: src/dmidecodemodule.h:71:12: error: conflicting types for ‘smbios_decode’; have ‘int(Log_t , int, u8 , const char , u32, xmlNode )’ {aka ‘int(struct _Log_t , int, unsigned char , const char , unsigned int, struct _xmlNode )’} 71 extern int smbios_decode(Log_t logp, int type, u8 buf, const char devmem, u32 flags, xmlNode node); ^~~~~ In file included from src/dmidecodemodule.h:58: src/dmidecode.h:39:5: note: previous declaration of ‘smbios_decode’ with type ‘int(Log_t , int, u8 , const char , xmlNode )’ {aka ‘int(struct _Log_t , int, unsigned char , const char , struct _xmlNode )’} 39 int smbios_decode(Log_t logp, int type, u8 buf, const char devmem, xmlNode xmlnode); ^~~~~ src/dmidecodemodule.h:72:12: error: conflicting types for ‘legacy_decode’; have ‘int(Log_t , int, u8 , const char , u32, xmlNode )’ {aka ‘int(struct _Log_t , int, unsigned char , const char , unsigned int, struct _xmlNode )’} 72 extern int legacy_decode(Log_t logp, int type, u8 buf, const char devmem, u32 flags, xmlNode node); ^~~~~ src/dmidecode.h:40:5: note: previous declaration of ‘legacy_decode’ with type ‘int(Log_t , int, u8 , const char , xmlNode )’ {aka ‘int(struct _Log_t , int, unsigned char , const char , struct _xmlNode )’} 40 int legacy_decode(Log_t logp, int type, u8 buf, const char devmem, xmlNode xmlnode); ^~~~~ src/dmidecodemodule.c: In function ‘init’: src/dmidecodemodule.c:90:31: error: ‘SYS_TABLE_FILE’ undeclared (first use in this function) 90 opt->devmem = SYS_TABLE_FILE; ^~~~~~ src/dmidecodemodule.c:90:31: note: each undeclared identifier is reported only once for each function it appears in src/dmidecodemodule.c: In function ‘dmidecode_get_version’: src/dmidecodemodule.c:150:39: error: ‘SYS_TABLE_FILE’ undeclared (first use in this function) 150 opt->devmem = SYS_TABLE_FILE; ^~~~~~ src/dmidecodemodule.c:164:33: warning: implicit declaration of function ‘smbios3_decode_get_version’; did you mean ‘smbios_decode_get_version’? [-Wimplicit-function-declaration] 164 ver_n = smbios3_decode_get_version(buf, opt->dumpfile); ^~~~~~ smbios_decode_get_version src/dmidecodemodule.c:164:31: warning: assignment to ‘xmlNode ’ {aka ‘struct _xmlNode ’} from ‘int’ makes pointer from integer without a cast [-Wint-conversion] 164 ver_n = smbios3_decode_get_version(buf, opt->dumpfile); ^ src/dmidecodemodule.c:195:54: error: ‘SYS_ENTRY_FILE’ undeclared (first use in this function) 195 if ((buf = read_file(opt->logdata, 0, &size, SYS_ENTRY_FILE)) != NULL) ^~~~~~ src/dmidecodemodule.c:199:31: warning: assignment to ‘xmlNode ’ {aka ‘struct _xmlNode ’} from ‘int’ makes pointer from integer without a cast [-Wint-conversion] 199 ver_n = smbios3_decode_get_version(buf, opt->devmem); ^ src/dmidecodemodule.c:235:17: warning: assignment to ‘u8 ’ {aka ‘unsigned char ’} from ‘int’ makes pointer from integer without a cast [-Wint-conversion] 235 if (buf = mem_chunk(opt->logdata, fp, 0x20, opt->devmem) == NULL) ^ src/dmidecodemodule.c:235:13: warning: suggest parentheses around assignment used as truth value [-Wparentheses] 235 if (buf = mem_chunk(opt->logdata, fp, 0x20, opt->devmem) == NULL) ^~~ src/dmidecodemodule.c:243:23: warning: assignment to ‘xmlNode ’ {aka ‘struct _xmlNode ’} from ‘int’ makes pointer from integer without a cast [-Wint-conversion] 243 ver_n = smbios3_decode_get_version(buf, opt->devmem); ^ src/dmidecodemodule.c:270:31: warning: assignment to ‘xmlNode ’ {aka ‘struct _xmlNode ’} from ‘int’ makes pointer from integer without a cast [-Wint-conversion] 270 ver_n = smbios3_decode_get_version(buf + fp, opt->devmem); ^ src/dmidecodemodule.c: In function ‘dmidecode_get_xml’: src/dmidecodemodule.c:352:29: warning: implicit declaration of function ‘smbios3_decode’; did you mean ‘smbios_decode’? [-Wimplicit-function-declaration] 352 if (smbios3_decode(opt->logdata, opt->type, buf, opt->dumpfile, 0, dmixml_n)) ^~~~~~ smbios_decode src/dmidecodemodule.c:375:54: error: ‘SYS_ENTRY_FILE’ undeclared (first use in this function) 375 if ((buf = read_file(opt->logdata, 0, &size, SYS_ENTRY_FILE)) != NULL) ^~~~~~ src/dmidecodemodule.c:379:74: error: ‘SYS_TABLE_FILE’ undeclared (first use in this function) 379 if (smbios3_decode(opt->logdata, opt->type, buf, SYS_TABLE_FILE, FLAG_NO_FILE_OFFSET, dmixml_n)) ^~~~~~ src/dmidecodemodule.c:379:90: error: ‘FLAG_NO_FILE_OFFSET’ undeclared (first use in this function) 379 if (smbios3_decode(opt->logdata, opt->type, buf, SYS_TABLE_FILE, FLAG_NO_FILE_OFFSET, dmixml_n)) ^~~~~~~ src/dmidecodemodule.c:412:17: warning: assignment to ‘u8 ’ {aka ‘unsigned char ’} from ‘int’ makes pointer from integer without a cast [-Wint-conversion] 412 if (buf = mem_chunk(opt->logdata, fp, 0x20, opt->devmem) == NULL) ^ src/dmidecodemodule.c:412:13: warning: suggest parentheses around assignment used as truth value [-Wparentheses] 412 if (buf = mem_chunk(opt->logdata, fp, 0x20, opt->devmem) == NULL) ^~~ src/dmidecodemodule.c: In function ‘__dmidecode_xml_getsection’: src/dmidecodemodule.c:569:90: warning: passing argument 3 of ‘_pyReturnError’ makes integer from pointer without a cast [-Wint-conversion] 569 _pyReturnError(PyExc_RuntimeError, "Invalid type id '%s' -- %s", typeid, err); ^~
char *
In file included from src/dmidecode.h:24: src/dmierror.h:38:65: note: expected ‘int’ but argument is of type ‘char *’ 38 void _pyReturnError(PyObject exception, const char fname, int line, const char *msgfmt, ...); ~~^~ src/dmidecodemodule.c: In function ‘dmidecode_get_group’: src/dmidecodemodule.c:607:39: error: ‘SYS_TABLE_FILE’ undeclared (first use in this function) 607 opt->devmem = SYS_TABLE_FILE; ^~~~~~ src/dmidecodemodule.c: In function ‘__dmidecode_xml_gettypeid’: src/dmidecodemodule.c:656:39: error: ‘SYS_TABLE_FILE’ undeclared (first use in this function) 656 opt->devmem = SYS_TABLE_FILE; ^~~~~~ src/dmidecodemodule.c: In function ‘dmidecode_get_section’: src/dmidecodemodule.c:764:25: warning: assignment discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers] 764 section = PyUnicode_AsUTF8(args); ^ src/dmidecodemodule.c: In function ‘dmidecode_dump’: src/dmidecodemodule.c:893:26: error: ‘SYS_TABLE_FILE’ undeclared (first use in this function) 893 if (dump(SYS_TABLE_FILE, f)) ^~~~~~ src/dmidecodemodule.c:884:13: warning: unused variable ‘ret’ [-Wunused-variable] 884 int ret; ^~~ src/dmidecodemodule.c: In function ‘dmidecode_set_dev’: src/dmidecodemodule.c:916:19: warning: assignment discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers] 916 f = PyUnicode_AsUTF8(arg); ^ src/dmidecodemodule.c: In function ‘dmidecode_set_pythonxmlmap’: src/dmidecodemodule.c:978:23: warning: assignment discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers] 978 fname = PyUnicode_AsUTF8(arg); ^ src/dmidecodemodule.c: At top level: src/dmidecodemodule.c:1057:24: warning: initialization of ‘PyObject ()(PyObject , PyObject )’ {aka ‘struct _object ()(struct _object , struct _object )’} from incompatible pointer type ‘PyObject ()(PyObject , PyObject , PyObject )’ {aka ‘struct _object ()(struct _object , struct _object , struct _object )’} [-Wincompatible-pointer-types] 1057 {(char *)"xmlapi", dmidecode_xmlapi, METH_VARARGS METH_KEYWORDS, ^~~~ src/dmidecodemodule.c:1057:24: note: (near initialization for ‘DMIDataMethods[16].ml_meth’) src/dmidecodemodule.c: In function ‘PyInit_dmidecodemod’: src/dmidecodemodule.c:1171:72: warning: passing argument 3 of ‘PyCapsule_New’ from incompatible pointer type [-Wincompatible-pointer-types] 1171 PyModule_AddObject(module, "options", PyCapsule_New(opt, NULL, destruct_options)); ^~~~
void ()(void )

In file included from /usr/include/python3.10/Python.h:102, from src/dmidecodemodule.c:42: /usr/include/python3.10/pycapsule.h:31:26: note: expected ‘PyCapsule_Destructor’ {aka ‘void ()(struct _object )’} but argument is of type ‘void ()(void )’ 31 | PyCapsule_Destructor destructor); | ~~~~~^~~~~~ error: command '/usr/bin/gcc' failed with exit code 1 make: *** [Makefile:65: build/lib.linux-x86_64-3.10/dmidecodemod.cpython-310-x86_64-linux-gnu.so] Error 1

lian-bo commented 2 years ago

I have reverted the pull request from the devel branch: smbion-3.3.0. Thanks.

HuO50 commented 2 years ago

Sorry for committing wrong code! I will check the code again.