X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=src%2Fvdlimit.c;h=3df67ba44bcb6baf0ec2690978fb18c7dad13d06;hb=95e2774070e989fe9cf9f48dae5fa054e55e2a3e;hp=fc287e9619f5cd098c32b5d01b095124d898c2b9;hpb=2822ba293eb308225c50d346930c47bf98d9927b;p=util-vserver.git diff --git a/src/vdlimit.c b/src/vdlimit.c index fc287e9..3df67ba 100644 --- a/src/vdlimit.c +++ b/src/vdlimit.c @@ -1,4 +1,4 @@ -// $Id: vdlimit.c,v 1.2 2005/08/21 22:16:22 mlhuang Exp $ --*- c -*-- +// $Id: vdlimit.c,v 1.5 2007/06/28 15:20:30 dhozac Exp $ --*- c -*-- // Copyright (C) 2005 Enrico Scholz // @@ -21,7 +21,6 @@ #endif #include "util.h" -#include #include #include @@ -85,14 +84,24 @@ showVersion() static void setDlimit(char const *filename, xid_t xid, uint32_t flags, struct vc_ctx_dlimit const *limit) { + bool was_added = false; + if (vc_get_dlimit(filename, xid, flags, 0) == -1) { if (vc_add_dlimit(filename, xid, flags) == -1) { perror(ENSC_WRAPPERS_PREFIX "vc_add_dlimit()"); exit(wrapper_exit_code); } + + was_added = true; } + if (vc_set_dlimit(filename, xid, flags, limit) == -1) { perror(ENSC_WRAPPERS_PREFIX "vc_set_dlimit()"); + + if (was_added && + vc_rem_dlimit(filename, xid, flags)==-1) + perror(ENSC_WRAPPERS_PREFIX "vc_rem_dlimit()"); + exit(wrapper_exit_code); } } @@ -200,6 +209,14 @@ setDLimitField(struct vc_ctx_dlimit *dst, char const *opt) return true; } +bool +isHigherLimit(uint_least32_t lhs, uint_least32_t rhs) +{ + if (lhs==VC_CDLIM_KEEP || rhs==VC_CDLIM_KEEP) return false; + + return lhs > rhs; +} + int main(int argc, char *argv[]) { bool do_set = false; @@ -261,6 +278,10 @@ int main(int argc, char *argv[]) WRITE_MSG(2, "No mount point specified; try '--help' for more information\n"); else if (xid==VC_NOCTX) WRITE_MSG(2, "No xid specified; try '--help' for more information\n"); + else if (isHigherLimit(limit.space_used, limit.space_total)) + WRITE_MSG(2, "invalid parameters: 'space_used' is larger than 'space_total'\n"); + else if (isHigherLimit(limit.inodes_used, limit.inodes_total)) + WRITE_MSG(2, "invalid parameters: 'inodes_used' is larger than 'inodes_total'\n"); else { for (; optind < argc; ++optind) { if (do_set) setDlimit(argv[optind], xid, flags, &limit);