Opened 16 years ago

Last modified 4 years ago

#3353 assigned enhancement

resource.h broken (not implemented yet?)

Reported by: scottmc Owned by: nobody
Priority: normal Milestone: R1.1
Component: System/POSIX Version: R1/pre-alpha1
Keywords: Cc:
Blocked By: #7556, #14749 Blocking:
Platform: All

Description

May be related to ticket #2817 perhaps not, python's test_resource.py passes the first test, then fails the next 3 and then crashes on getrusage.

~/develop/python/Lib/test> python test_resource.py
test_args (__main__.ResourceTest) ... ok
test_fsize_enforced (__main__.ResourceTest) ... ERROR
test_fsize_ismax (__main__.ResourceTest) ... ERROR
test_fsize_toobig (__main__.ResourceTest) ... ERROR
test_getrusage (__main__.ResourceTest) ... Kill Thread
~/develop/python/Lib/test> 

Attachments (1)

0002-Implement-setrlimit-for-RLIMIT_AS-RLIMIT_DATA-and-RL.patch (1.4 KB ) - added by owenca 7 years ago.

Download all attachments as: .zip

Change History (22)

comment:1 by Timothy_Gu, 10 years ago

The first three errors are easily reproducible with

#include <errno.h>
#include <stdio.h>
#include <sys/resource.h>

int
main()
{
    struct rlimit rl = {0};
    int ret;
    ret = get_rlimit(RLIMIT_FSIZE, &rl);
    printf("%d %d %" __HAIKU_PRI_PREFIX_ADDR "d %" __HAIKU_PRI_PREFIX_ADDR "d\n", ret, errno, rl.rlim_cur, rl.rlim_max);
    return ret;
}
Last edited 10 years ago by Timothy_Gu (previous) (diff)

comment:2 by Timothy_Gu, 10 years ago

Apparently only part of POSIX spec for [gs]et_rlimit is implemented, and when it encounters an unimplemented property it just returns EINVAL.

See https://github.com/haiku/haiku/blob/449f7f5a7b9d381c1eeab3ddfbdba0db0ce05c22/src/system/kernel/thread.cpp#L1310-L1327

I'm not sure what the right thing to do is here. Should I make it return ENOSYS instead? But that would break a lot of apps relying on POSIX. Or I could make it return 0 as the values.

List of unimplemented properties:

  • RLIMIT_CPU: maximum amount of CPU time, in seconds, used by a process
  • RLIMIT_DATA: maximum size of a process' data segment, in bytes
  • RLIMIT_FSIZE: maximum size of a file, in bytes, that may be created by a process
  • RLIMIT_STACK (implemented in get_rlimit() but not in set): maximum size of the initial thread's stack, in bytes
  • RLIMIT_AS: maximum size of a process' total available memory, in bytes

I will investigate the getrusage() failure soon.

comment:3 by Timothy_Gu, 10 years ago

The getrusage() function itself works fairly well, from my standalone test program. I believe the issue is in one of the patches applied to get python to build, as the segfault seems to be from the python internals. I will try to confirm.

comment:4 by Timothy_Gu, 10 years ago

Interestingly, the getrusage() issue only seems to be reproducible on x86_gcc2. x86_64 does not have this issue. I will test pure x86 soon.

comment:5 by Timothy_Gu, 10 years ago

My program used to test getrusage():

#include <errno.h>
#include <stdio.h>
#include <sys/resource.h>

// From https://github.com/python/cpython/blob/2.7/Modules/resource.c#L20
#define doubletime(TV) ((double)(TV).tv_sec + (TV).tv_usec * 0.000001)

int
main()
{
    struct rusage ru = {0};
    int ret;
    ret = getrusage(RUSAGE_SELF, &ru);
    printf("%d %d %f %f\n", ret, errno, doubletime(ru.ru_utime), doubletime(ru.ru_stime));
    return ret;
}

It prints something like this:

0 0 0.1034 0.1620

The first two 0's indicate that there is no error (ret and errno resp.).

comment:6 by Timothy_Gu, 10 years ago

Unfortunately no, getrusage() doesn't work on x86_gcc4 either.

comment:7 by Timothy_Gu, 10 years ago

Hah found where the issue is. It is in a patch in Python. Will submit a PR to haikuports soon.

comment:8 by pulkomandy, 10 years ago

Please include a link to your PR so we can check and close this. Thanks for investigating!

in reply to:  8 comment:9 by Timothy_Gu, 10 years ago

Replying to pulkomandy:

Please include a link to your PR so we can check and close this. Thanks for investigating!

Here: https://bitbucket.org/haikuports/haikuports/pull-request/453/fix-python-resource-module/diff

comment:10 by pulkomandy, 10 years ago

Type: bugenhancement

Ok, PR is merged. It would still be nice to actually implement things so we don't have to hack around it in Python sources, but at least the crash is fixed now.

comment:11 by axeld, 8 years ago

Component: - GeneralSystem/POSIX
Owner: changed from axeld to nobody
Status: newassigned

comment:12 by owenca, 7 years ago

Added RLIMIT_AS, RLIMIT_DATA, and RLIMIT_STACK for setrlimit() to match getrlimit(). Please see the attached patch.

comment:13 by owenca, 7 years ago

patch: 01

comment:14 by pulkomandy, 7 years ago

I don't think this is the right way to go about it. Either we don't support changing the values, and we always return EINVAL (this is what happens now). Or, we do support setting them, and by this I mean also setting them to a value other than the default.

With your changes, the function now returns "ok" in some cases, which makes it harder to check wether actually changing the value is possible, but no functionality is gained. This is not of much use.

comment:15 by owenca, 7 years ago

Because the existing code doesn't support RLIMIT_CORE and doesn't always return EINVAL in common_setrlimit, I made the other rlimits to match the behavior. So the current way of handling RLIMIT_CORE in common_setrlimit is also wrong?

comment:16 by pulkomandy, 7 years ago

patch: 10

comment:17 by pulkomandy, 7 years ago

Patch migrated to Gerrit: https://review.haiku-os.org/79

comment:18 by pulkomandy, 6 years ago

Blocked By: 7556 added

comment:19 by pulkomandy, 6 years ago

Blocked By: 14749 added

comment:20 by cocobean, 5 years ago

Checked header with POSIX.1-2017 spec. PASSES.

Last edited 5 years ago by cocobean (previous) (diff)

comment:21 by pulkomandy, 4 years ago

Milestone: R1R1.1
Note: See TracTickets for help on using tickets.