Comparison

util-src/pposix.c @ 865:2dce34e9182d

pposix: Standardize error messages
author Matthew Wild <mwild1@gmail.com>
date Tue, 03 Mar 2009 17:25:20 +0000
parent 864:416c812acde5
child 896:2c0b9e3c11c3
comparison
equal deleted inserted replaced
864:416c812acde5 865:2dce34e9182d
320 int hardlimit = -1; 320 int hardlimit = -1;
321 const char *resource = NULL; 321 const char *resource = NULL;
322 int rid = -1; 322 int rid = -1;
323 if(arguments < 1 || arguments > 3) { 323 if(arguments < 1 || arguments > 3) {
324 lua_pushboolean(L, 0); 324 lua_pushboolean(L, 0);
325 lua_pushstring(L, "Wrong number of arguments"); 325 lua_pushstring(L, "incorrect-arguments");
326 } 326 }
327 327
328 resource = luaL_checkstring(L, 1); 328 resource = luaL_checkstring(L, 1);
329 softlimit = luaL_checkinteger(L, 2); 329 softlimit = luaL_checkinteger(L, 2);
330 hardlimit = luaL_checkinteger(L, 3); 330 hardlimit = luaL_checkinteger(L, 3);
335 struct rlimit lim_current; 335 struct rlimit lim_current;
336 336
337 if (softlimit < 0 || hardlimit < 0) { 337 if (softlimit < 0 || hardlimit < 0) {
338 if (getrlimit(rid, &lim_current)) { 338 if (getrlimit(rid, &lim_current)) {
339 lua_pushboolean(L, 0); 339 lua_pushboolean(L, 0);
340 lua_pushstring(L, "getrlimit() failed."); 340 lua_pushstring(L, "getrlimit-failed");
341 return 2; 341 return 2;
342 } 342 }
343 } 343 }
344 344
345 if (softlimit < 0) lim.rlim_cur = lim_current.rlim_cur; 345 if (softlimit < 0) lim.rlim_cur = lim_current.rlim_cur;
347 if (hardlimit < 0) lim.rlim_max = lim_current.rlim_max; 347 if (hardlimit < 0) lim.rlim_max = lim_current.rlim_max;
348 else lim.rlim_max = hardlimit; 348 else lim.rlim_max = hardlimit;
349 349
350 if (setrlimit(rid, &lim)) { 350 if (setrlimit(rid, &lim)) {
351 lua_pushboolean(L, 0); 351 lua_pushboolean(L, 0);
352 lua_pushstring(L, "setrlimit() failed."); 352 lua_pushstring(L, "setrlimit-failed");
353 return 2; 353 return 2;
354 } 354 }
355 } else { 355 } else {
356 lua_pushboolean(L, 0); 356 /* Unsupported resoucrce. Sorry I'm pretty limited by POSIX standard. */
357 lua_pushstring(L, "Unsupported resoucrce. Sorry I'm pretty limited by POSIX standard."); 357 lua_pushboolean(L, 0);
358 lua_pushstring(L, "invalid-resource");
358 return 2; 359 return 2;
359 } 360 }
360 lua_pushboolean(L, 1); 361 lua_pushboolean(L, 1);
361 return 1; 362 return 1;
362 } 363 }
367 int rid = -1; 368 int rid = -1;
368 struct rlimit lim; 369 struct rlimit lim;
369 370
370 if (arguments != 1) { 371 if (arguments != 1) {
371 lua_pushboolean(L, 0); 372 lua_pushboolean(L, 0);
372 lua_pushstring(L, "I expect one argument only, the resource string."); 373 lua_pushstring(L, "invalid-arguments");
373 return 2; 374 return 2;
374 } 375 }
375 376
376 resource = luaL_checkstring(L, 1); 377 resource = luaL_checkstring(L, 1);
377 rid = string2resource(resource); 378 rid = string2resource(resource);
378 if (rid != -1) { 379 if (rid != -1) {
379 if (getrlimit(rid, &lim)) { 380 if (getrlimit(rid, &lim)) {
380 lua_pushboolean(L, 0); 381 lua_pushboolean(L, 0);
381 lua_pushstring(L, "getrlimit() failed."); 382 lua_pushstring(L, "getrlimit-failed.");
382 return 2; 383 return 2;
383 } 384 }
384 } else { 385 } else {
385 lua_pushboolean(L, 0); 386 /* Unsupported resoucrce. Sorry I'm pretty limited by POSIX standard. */
386 lua_pushstring(L, "Unsupported resoucrce. Sorry I'm pretty limited by POSIX standard."); 387 lua_pushboolean(L, 0);
388 lua_pushstring(L, "invalid-resource");
387 return 2; 389 return 2;
388 } 390 }
389 lua_pushboolean(L, 1); 391 lua_pushboolean(L, 1);
390 lua_pushnumber(L, lim.rlim_cur); 392 lua_pushnumber(L, lim.rlim_cur);
391 lua_pushnumber(L, lim.rlim_max); 393 lua_pushnumber(L, lim.rlim_max);