Skip to content

Add {get,set}rlimit and getrusage to libc #23457

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

Merged
merged 1 commit into from
Mar 19, 2015

Conversation

nagisa
Copy link
Member

@nagisa nagisa commented Mar 17, 2015

Hopefully didn’t miss or mess up anything.

EDIT: ah, as usual, just didn’t bother running build before pushing a submit request button. Build pending.

@rust-highfive
Copy link
Contributor

r? @huonw

(rust_highfive has picked a reviewer for you, use r? to override)

@nagisa nagisa force-pushed the get-set-resources branch 2 times, most recently from 5412b51 to 5055fbc Compare March 17, 2015 21:38
@huonw
Copy link
Member

huonw commented Mar 17, 2015

I have no idea about how stable these are across platforms. Are the rlimit/rusage structs standardised?

@nagisa
Copy link
Member Author

nagisa commented Mar 17, 2015

from man 0p sys_resource.h:

The <sys/resource.h> header shall define the following type through typedef:

rlim_t          Unsigned integer type used for limit values.

The <sys/resource.h> header shall define the following symbolic constants, which shall have values suitable for use in #if preprocessing directives:

RLIM_INFINITY   A value of rlim_t indicating no limit.
RLIM_SAVED_MAX  A value of type rlim_t indicating an unrepresentable saved hard limit.
RLIM_SAVED_CUR  A value of type rlim_t indicating an unrepresentable saved soft limit.

On implementations where all resource limits are representable in an object of type rlim_t, RLIM_SAVED_MAX and RLIM_SAVED_CUR need not be distinct from RLIM_INFINITY.
The <sys/resource.h> header shall define the following symbolic constants as possible values of the who parameter of getrusage():

RUSAGE_SELF     Returns information about the current process.
RUSAGE_CHILDREN Returns information about children of the current process.

The <sys/resource.h> header shall define the rlimit structure, which shall include at least the following members:

rlim_t rlim_cur  The current (soft) limit.
rlim_t rlim_max  The hard limit.

The <sys/resource.h> header shall define the rusage structure, which shall include at least the following members:

struct timeval ru_utime  User time used.
struct timeval ru_stime  System time used.

The <sys/resource.h> header shall define the timeval structure as described in <sys/time.h>.
The <sys/resource.h> header shall define the following symbolic constants as possible values for the resource argument of getrlimit() and setrlimit():

RLIMIT_CORE     Limit on size of core file.
RLIMIT_CPU      Limit on CPU time per process.
RLIMIT_DATA     Limit on data segment size.
RLIMIT_FSIZE    Limit on file size.
RLIMIT_NOFILE   Limit on number of open files.
RLIMIT_STACK    Limit on stack size.
RLIMIT_AS       Limit on address space size.

The following shall be declared as functions and may also be defined as macros. Function prototypes shall be provided.

int  getpriority(int, id_t);
int  getrlimit(int, struct rlimit *);
int  getrusage(int, struct rusage *);
int  setpriority(int, id_t, int);
int  setrlimit(int, const struct rlimit *);

The values and structs are included here from corresponding OS’s header files (except for OS X/iOS rusage which is comes from iOS docs) with all the extensions they provide.

@nagisa
Copy link
Member Author

nagisa commented Mar 17, 2015

Ok, apparently this rusage conforms to SVr4, 4.3BSD, rather than POSIX 2001.

@alexcrichton alexcrichton assigned alexcrichton and unassigned huonw Mar 17, 2015
@alexcrichton
Copy link
Member

This looks good to me (it will be used in an upcoming patch of yours, right?). Feel free to ping once you've gone through the final update.

We should always be able to fix these in the future as well, so tweaks here and there should be fine.

@nagisa nagisa force-pushed the get-set-resources branch from 5055fbc to 2d701e6 Compare March 18, 2015 11:10
@nagisa
Copy link
Member Author

nagisa commented Mar 18, 2015

it will be used in an upcoming patch of yours, right?

At least a part of it, yes. I decided that if I’m binding a function in liblibc, I could as well just bind the related functions as well.
Also, since I’m not really sure what I’m doing here, I thought it would be better to submit this as a separate PR so this gets more eyes on it.

Moved rusage struct to bsd43.

@alexcrichton
Copy link
Member

In general this crate is currently a bit of a dumping ground and I'm not sure how well the organization has been maintained over time. We generally are not adding many new additions to it but instead binding them locally at (e.g. sys::c), but if you've already gone through the trouble of adding the definitions for all platforms then I think it's fine to go ahead and merge

@bors: r+

@bors
Copy link
Collaborator

bors commented Mar 18, 2015

📌 Commit 2d701e6 has been approved by alexcrichton

Manishearth added a commit to Manishearth/rust that referenced this pull request Mar 19, 2015
…chton

 Hopefully didn’t miss or mess up anything.

~~EDIT: ah, as usual, just didn’t bother running build before pushing a submit request button. Build pending.~~
@bors bors merged commit 2d701e6 into rust-lang:master Mar 19, 2015
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

Successfully merging this pull request may close these issues.

5 participants