giampaolo / psutil

Cross-platform lib for process and system monitoring in Python
BSD 3-Clause "New" or "Revised" License
10.32k stars 1.39k forks source link

Include <unistd.h> to avoid implicit-function-declaration for close and syscall #2321

Closed hroncok closed 1 year ago

hroncok commented 1 year ago

Summary

Description

See https://docs.python.org/3.13/whatsnew/3.13.html

Python.h no longer includes the standard header file. If needed, it should now be included explicitly. For example, it provides the functions: read(), write(), close(), isatty(), lseek(), getpid(), getcwd(), sysconf() and getpagesize().

giampaolo commented 1 year ago

Can you paste the compilation error? We don't use those functions in _psutil_linux.c, but perhaps we do in arch/linux/*.c files, so that should be added to those files, not _psutil_linux.c (and perhaps other files in arch/{OS}/*.c).

hroncok commented 1 year ago

Ah, sorry, should have pasted that in the first place:

Those were the errors I started with in 5.9.6:

      psutil/_psutil_linux.c: In function ‘ioprio_get’:
      psutil/_psutil_linux.c:73:12: error: implicit declaration of function ‘syscall’ [-Werror=implicit-function-declaration]
         73 |     return syscall(__NR_ioprio_get, which, who);
            |            ^~~~~~~
      psutil/_psutil_linux.c: In function ‘psutil_net_if_duplex_speed’:
      psutil/_psutil_linux.c:488:5: error: implicit declaration of function ‘close’; did you mean ‘clone’? [-Werror=implicit-function-declaration]
        488 |     close(sock);
            |     ^~~~~
            |     clone

Then I checked on the master branch and haven't noticed the error is a tad different:

      psutil/arch/linux/net.c: In function ‘psutil_net_if_duplex_speed’:
      psutil/arch/linux/net.c:112:5: error: implicit declaration of function ‘close’; did you mean ‘pclose’? [-Werror=implicit-function-declaration]
        112 |     close(sock);
            |     ^~~~~
            |     pclose

Will move the include to psutil/arch/linux/net.c and amend the commit message.

hroncok commented 1 year ago

And the other one is:

      psutil/arch/linux/proc.c: In function ‘ioprio_get’:
      psutil/arch/linux/proc.c:22:12: error: implicit declaration of function ‘syscall’ [-Werror=implicit-function-declaration]
         22 |     return syscall(__NR_ioprio_get, which, who);
            |            ^~~~~~~
giampaolo commented 1 year ago

While you're at it, can you also update these guys?

psutil/arch/solaris/environ.c
psutil/_psutil_sunos.c
hroncok commented 1 year ago

Done.

hroncok commented 1 year ago

Thanks for merging.