/** * Adds the control value to a controller using wrapper apis * @param newcontroller the controller to be added the value to * @param control_file name of the control file of the controller * @param wr the name of wrapper api * @param value_type which value out of four types * @param struct cval the control value structure */ int add_control_value(struct cgroup_controller *newcontroller, char *control_file, char *wr, int value_type, struct cntl_val_t cval) { int retval; switch (value_type) { case BOOL: retval = cgroup_add_value_bool(newcontroller, control_file, cval.val_bool); snprintf(wr, SIZE, "add_value_bool()"); break; case INT64: retval = cgroup_add_value_int64(newcontroller, control_file, cval.val_int64); snprintf(wr, SIZE, "add_value_int64()"); break; case UINT64: retval = cgroup_add_value_uint64(newcontroller, control_file, cval.val_uint64); snprintf(wr, SIZE, "add_value_uint64()"); break; case STRING: retval = cgroup_add_value_string(newcontroller, control_file, cval.val_string); snprintf(wr, SIZE, "add_value_string()"); break; default: printf("ERROR: wrong value in add_control_value()\n"); return 1; break; } return retval; }
static int l_cgroup_add_value(lua_State *L) { struct u_cgroup_controller *uc = check_cgroup_controller(L, 1); const char *key = lua_tostring(L, 2); int rv; if(!uc) { lua_pushstring(L, "Not a valid cgroup"); lua_error (L); return 0; } if(lua_isstring(L, 3)) { rv = cgroup_add_value_string(uc->controller, key, lua_tostring(L, 3)); } else if(lua_isnumber(L, 3)) { rv = cgroup_add_value_int64(uc->controller, key, lua_tointeger(L, 3)); } else if(lua_isboolean(L, 3)) { rv = cgroup_add_value_bool(uc->controller, key, lua_toboolean(L, 3)); } else { lua_pushstring(L, "Not a valid type"); lua_error (L); } lua_pushinteger(L, rv); return 1; }