pkgsrc-Changes archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: psutil.Process(pid).as_dict() Memory Error (was: CVS commit: pkgsrc/x11/py-terminator)



Hello Kamil,
just an update about that, TLDR; py-psutil-5.6.2nb2 should no longer
have this issue.

Leonardo Taccari writes:
> [...]
>
> JFTR, it seems that the problem is not specific to py-terminator
> but a sysutils/py-psutil one.
>
> E.g.:
>
>  | % python3.7
>  | Python 3.7.3 (default, May  3 2019, 17:54:14)
>  | [GCC 7.4.0] on netbsd8
>  | Type "help", "copyright", "credits" or "license" for more information.
>  | >>> import psutil
>  | >>> psutil.Process(1).as_dict()
>  | Traceback (most recent call last):
>  |   File "<stdin>", line 1, in <module>
>  |   File "/usr/pkg/lib/python3.7/site-packages/psutil/__init__.py", line 638, in as_dict
>  |     ret = meth()
>  |   File "/usr/pkg/lib/python3.7/site-packages/psutil/__init__.py", line 790, in cmdline
>  |     return self._proc.cmdline()
>  |   File "/usr/pkg/lib/python3.7/site-packages/psutil/_psbsd.py", line 562, in wrapper
>  |     return fun(self, *args, **kwargs)
>  |   File "/usr/pkg/lib/python3.7/site-packages/psutil/_psbsd.py", line 666, in cmdline
>  |     return cext.proc_cmdline(self.pid)
>  | MemoryError
>
> The MemoryError is from
> psutil/arch/netbsd/specific.c:psutil_get_cmd_args() (that is called
> via psutil_proc_cmdline() -> psutil_get_cmdline() ->
> psutil_get_cmd_args()) and, unfortunately, adding debugging printf()
> seems to interfere with that (i.e. calling .as_dict() succeed).
>
> Attaching `gdb' against the Python process and trying to set a
> `breakpoint' unfortunately doesn't work (i.e. the breakpoint to
> psutil_get_cmd_args is set but never hit).
>
> If anyone has any idea how to debug this further or can spot anything
> please let me know!

The problem was in psutil_get_cmd_args():

 [...]

 char *
 psutil_get_cmd_args(pid_t pid, size_t *argsize) {
     int mib[4];
     ssize_t st;
     size_t argmax;
     size_t size;
     char *procargs = NULL;
 
     mib[0] = CTL_KERN;
     mib[1] = KERN_ARGMAX;
 
     size = sizeof(argmax);
     st = sysctl(mib, 2, &argmax, &size, NULL, 0);
     if (st == -1) {
         PyErr_SetFromErrno(PyExc_OSError);
         return NULL;
     }
 
     procargs = (char *)malloc(argmax);
     if (procargs == NULL) {
         PyErr_NoMemory();
         return NULL;
     }

 [...]

After the sysctl() call, size was `4' and the extra bytes in argmax
lead to a too big malloc() and so ended up inside the if calling
PyErr_NoMemory() (MemoryError) that we saw.

py-psutil-5.6.2nb2 should be fixed and I think that the patch in
x11/py-terminator can be removed.


Please let me know if there is any problem!



Home | Main Index | Thread Index | Old Index