Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SPT_NOENV results in getproctitle missing last char #118

Open
elelayan opened this issue Sep 22, 2022 · 2 comments
Open

SPT_NOENV results in getproctitle missing last char #118

elelayan opened this issue Sep 22, 2022 · 2 comments

Comments

@elelayan
Copy link

elelayan commented Sep 22, 2022

OS: Linux xxx 5.10.0-16-amd64 #1 SMP Debian 5.10.127-1 (2022-06-30) x86_64 GNU/Linux
Python: Python 3.7.12 | packaged by conda-forge | (default, Oct 26 2021, 06:08:53) [GCC 9.4.0] on linux

py-setproctitle: 1.3.1 wheel from pypi or master compiled locally with pip install -e ./py-setproctitle --global-option --with-debugging-symbols --global-option --debug

test script:

#!/usr/bin/env python3

import setproctitle


if __name__ == '__main__':
    print("PROCTITLE:", setproctitle.getproctitle())

OUTPUT

$ SPT_NOENV=yes /tmp/hello.py 
PROCTITLE: /tmp/hello.p

EXPECTED OUTPUT (contains the last y)

$ SPT_NOENV=yes /tmp/hello.py 
PROCTITLE: /tmp/hello.py
@elelayan
Copy link
Author

I tracked it down to https://github.com/dvarrazzo/py-setproctitle/blob/master/src/spt_status.c#L349

    spt_strlcpy(ps_buffer + ps_buffer_fixed_size, activity,
            ps_buffer_size - ps_buffer_fixed_size);

ps_buffer_fixed_size=0, ps_buffer_size doesn't include the '\0' from the last argv, resulting in spt_strlcpy replacing 'y' with a new '\0'.

A blind fix in https://github.com/dvarrazzo/py-setproctitle/blob/master/src/spt_status.c#L231

            if (!noenv || !*noenv) {
                ....
            }
            else
            {
                end_of_area += 1;
            }

works but I'm not sure if end_of +1 should also be applied in the case when SPT_NOENV is set, getting us an additional character to set the activity...

@mattip
Copy link

mattip commented May 30, 2024

See also ray-project/ray#40289 where ray tests hit this problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants