summaryrefslogtreecommitdiffstats
path: root/sys-utils/prlimit.c
diff options
context:
space:
mode:
authorBernhard Voelker2011-11-16 17:57:27 +0100
committerKarel Zak2011-11-23 12:11:46 +0100
commit53e1f461f9a86a4c979b2bd719b8ccd1b608980e (patch)
treebf5b04393c77b622a8a64fd3cf5455f5d283502a /sys-utils/prlimit.c
parentlibblkid: fix mac partition detection (diff)
downloadkernel-qcow2-util-linux-53e1f461f9a86a4c979b2bd719b8ccd1b608980e.tar.gz
kernel-qcow2-util-linux-53e1f461f9a86a4c979b2bd719b8ccd1b608980e.tar.xz
kernel-qcow2-util-linux-53e1f461f9a86a4c979b2bd719b8ccd1b608980e.zip
prlimit: add support for executing a command
prlimit.c: Alternatively to applying the limits to an existing process via the --pid option, allow a command to be executed. Adapted usage() accordingly. prlimit.1: mention new syntax. Signed-off-by: Bernhard Voelker <mail@bernhard-voelker.de>
Diffstat (limited to 'sys-utils/prlimit.c')
-rw-r--r--sys-utils/prlimit.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/sys-utils/prlimit.c b/sys-utils/prlimit.c
index bcbfb5a8f..846695b5a 100644
--- a/sys-utils/prlimit.c
+++ b/sys-utils/prlimit.c
@@ -152,7 +152,9 @@ static void __attribute__ ((__noreturn__)) usage(FILE * out)
fputs(USAGE_HEADER, out);
fprintf(out,
- _(" %s [options]\n"), program_invocation_short_name);
+ _(" %s [options] [-p PID]\n"), program_invocation_short_name);
+ fprintf(out,
+ _(" %s [options] COMMAND\n"), program_invocation_short_name);
fputs(_("\nGeneral Options:\n"), out);
fputs(_(" -p, --pid <pid> process id\n"
@@ -521,7 +523,7 @@ int main(int argc, char **argv)
assert(MAX_RESOURCES == STACK + 1);
while((opt = getopt_long(argc, argv,
- "c::d::e::f::i::l::m::n::q::r::s::t::u::v::x::y::p:o:vVh",
+ "+c::d::e::f::i::l::m::n::q::r::s::t::u::v::x::y::p:o:vVh",
longopts, NULL)) != -1) {
switch(opt) {
case 'c':
@@ -608,8 +610,9 @@ int main(int argc, char **argv)
break;
}
}
- if (argc > optind)
- usage(stderr);
+ if (argc > optind && pid)
+ errx(EXIT_FAILURE,
+ _("--pid option and COMMAND are mutually exclusive"));
if (!ncolumns) {
/* default columns */
@@ -633,5 +636,11 @@ int main(int argc, char **argv)
if (!list_empty(&lims))
show_limits(&lims, tt_flags);
+ if (argc > optind) {
+ /* prlimit [options] COMMAND */
+ execvp(argv[optind], &argv[optind]);
+ err(EXIT_FAILURE, _("executing %s failed"), argv[optind]);
+ }
+
return EXIT_SUCCESS;
}