|
|
|
@ -2,51 +2,65 @@
|
|
|
|
|
#define SAVE_H
|
|
|
|
|
#include "save.h"
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
char* template_format_save(config_all* _all_config, char* source_set_cmd) {
|
|
|
|
|
char* save_str_users(config_u_g_p* config, int index) {
|
|
|
|
|
char* cmd = yon_char_new("");
|
|
|
|
|
char split_simvol[2] = {0};
|
|
|
|
|
split_simvol[0] = 0;
|
|
|
|
|
split_simvol[1] = 0;
|
|
|
|
|
vector* vec_actors = &config->actors;
|
|
|
|
|
char* str_actors = NULL;
|
|
|
|
|
if (vec_actors->vectorList.total> 0) {
|
|
|
|
|
for (int i = 0; i < vec_actors->vectorList.total; i++) {
|
|
|
|
|
str_actors = (char*)vec_actors->pfVectorGet(vec_actors, i);
|
|
|
|
|
cmd = yon_char_unite(",", str_actors, NULL);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char* template_format_save(vector* vec_temp) {
|
|
|
|
|
char* cmd = yon_char_new("");
|
|
|
|
|
for (int i = 0; i < _all_config->v_u_g_p.pfVectorTotal(&_all_config->v_u_g_p); i++) {
|
|
|
|
|
config_u_g_p* _config = (config_u_g_p*)_all_config->v_u_g_p.pfVectorGet(&_all_config->v_u_g_p, i);
|
|
|
|
|
char* key = save_format_key(_config, i);
|
|
|
|
|
char* value = save_format_str_value(_config, i);
|
|
|
|
|
//char* value_status = save_format_status_cmd(_config, i);
|
|
|
|
|
if (key!= NULL) {
|
|
|
|
|
// key = yon_char_unite(cmd, " " , key, "=\"" , value, "\" ", NULL);
|
|
|
|
|
cmd = yon_char_unite(cmd, key, "=" , value, " ", NULL);
|
|
|
|
|
//cmd = yon_char_unite(cmd, key, "=" , value_status, " ", NULL);
|
|
|
|
|
free(key);
|
|
|
|
|
free(value);
|
|
|
|
|
//free(value_status);
|
|
|
|
|
if (vec_temp->vectorList.total> 0) {
|
|
|
|
|
for (int i = 0; i < vec_temp->pfVectorTotal(vec_temp); i++) {
|
|
|
|
|
config_u_g_p* _config = (config_u_g_p*)vec_temp->pfVectorGet(vec_temp, i);
|
|
|
|
|
char* key = save_format_key(_config, i);
|
|
|
|
|
char* value = save_format_str_value(_config, i);
|
|
|
|
|
if (key!= NULL) {
|
|
|
|
|
cmd = yon_char_unite(cmd, key, "=" , value, " ", NULL);
|
|
|
|
|
free(key);
|
|
|
|
|
free(value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
if (strlen(cmd) > 8 && save_check_save(_all_config)== 0) {
|
|
|
|
|
cmd = yon_char_unite(source_set_cmd, " " ,cmd, NULL);
|
|
|
|
|
return cmd;
|
|
|
|
|
return cmd;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char* wrapper_template_format_save(config_all* _all_config, char* source_set_cmd) {
|
|
|
|
|
char* cmd_user = template_format_save(&_all_config->v_user);
|
|
|
|
|
char* cmd_group = template_format_save(&_all_config->v_group);
|
|
|
|
|
char* cmd_project = template_format_save(&_all_config->v_project);
|
|
|
|
|
if ((strlen(cmd_user) > 3 || strlen(cmd_group) > 3 || strlen(cmd_project) > 3) && !save_check_save(_all_config)) {
|
|
|
|
|
return yon_char_unite(source_set_cmd," ", cmd_user, " ", cmd_group, " ", cmd_project, NULL);
|
|
|
|
|
}
|
|
|
|
|
free(cmd);
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
char* template_format_remove_save(config_all* _all_config, char* source_remove_cmd) {
|
|
|
|
|
char* cmd = yon_char_new(source_remove_cmd);
|
|
|
|
|
if (_all_config->count_remove == 0) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
for (int i = 0; i < _all_config->v_u_g_p.pfVectorTotal(&_all_config->v_u_g_p); i++) {
|
|
|
|
|
config_u_g_p* _config = (config_u_g_p*)_all_config->v_u_g_p.pfVectorGet(&_all_config->v_u_g_p, i);
|
|
|
|
|
if (_config->status_set >= 0) {
|
|
|
|
|
cmd = yon_char_unite(cmd, " " , _config->loaded_keys, " ", NULL);
|
|
|
|
|
if (_all_config->v_remove.vectorList.total > 0) {
|
|
|
|
|
char* cmd = yon_char_new(source_remove_cmd);
|
|
|
|
|
for (int i = 0; i < _all_config->v_remove.vectorList.total; i++) {
|
|
|
|
|
char* str_remove = (char*)_all_config->v_remove.pfVectorGet(&_all_config->v_remove, i);
|
|
|
|
|
cmd = yon_char_unite(cmd, " " , str_remove, " ", NULL);
|
|
|
|
|
}
|
|
|
|
|
if (strlen(cmd) > strlen(source_remove_cmd) && save_check_save(_all_config)== 0) {
|
|
|
|
|
return cmd;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (strlen(cmd) > strlen(source_remove_cmd) && save_check_save(_all_config)== 0) {
|
|
|
|
|
return cmd;
|
|
|
|
|
}
|
|
|
|
|
return cmd;
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int wrapper_template_save(config_all* _all_config, char* source_set_cmd, char* source_remove_cmd) {
|
|
|
|
|
char* str_cmd_remove = template_format_remove_save(_all_config,source_remove_cmd);
|
|
|
|
|
char* str_cmd_set = template_format_save(_all_config,source_set_cmd);
|
|
|
|
|
char* str_cmd_set = wrapper_template_format_save(_all_config,source_set_cmd);
|
|
|
|
|
if (str_cmd_set != NULL && str_cmd_remove != NULL) {
|
|
|
|
|
philos_config_save(yon_char_unite(str_cmd_remove, "; " , str_cmd_set, NULL));
|
|
|
|
|
}
|
|
|
|
@ -70,14 +84,10 @@ int wrapper_template_save(config_all* _all_config, char* source_set_cmd, char* s
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char* save_format_key(config_u_g_p* config, int index) {
|
|
|
|
|
if (config->status_set == 1) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
char* cmd = yon_char_new("");
|
|
|
|
|
char* value = yon_char_new("");
|
|
|
|
|
char* key = yon_char_new("");
|
|
|
|
|
int number = config->id;
|
|
|
|
|
|
|
|
|
|
key = yon_char_unite("CGROUP_QUOTA[", config->type_arr, ":", NULL);
|
|
|
|
|
if (strstr(config->type_arr, "prjquota")) {
|
|
|
|
|
if (number!=-1) {
|
|
|
|
@ -90,63 +100,26 @@ char* save_format_key(config_u_g_p* config, int index) {
|
|
|
|
|
else {
|
|
|
|
|
key = yon_char_unite(config->UNIX_file, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
key = yon_char_unite(key, save_str_users(config, index) , "]", NULL);
|
|
|
|
|
|
|
|
|
|
return cmd;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
char* save_format_str_value(config_u_g_p* config, int index) {
|
|
|
|
|
if (config->status_set == 1) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
char* value = yon_char_new("");
|
|
|
|
|
value = philos_format_cfg_str_size_memory(value, config->soft_restriction_size,config->soft_restriction_size_pow);
|
|
|
|
|
value = yon_char_unite(value, ",");
|
|
|
|
|
philos_format_cfg_str_size_memory(value, config->soft_restriction_file,config->soft_restriction_file_pow);
|
|
|
|
|
value = yon_char_unite(value, ",");
|
|
|
|
|
philos_format_cfg_str_size_memory(value, config->severe_limitation_size,config->severe_limitation_size_pow);
|
|
|
|
|
value = yon_char_unite(value, ",");
|
|
|
|
|
philos_format_cfg_str_size_memory(value, config->severe_limitation_file, config->severe_limitation_file_pow);
|
|
|
|
|
value = yon_char_unite(value, ",");
|
|
|
|
|
//philos_format_cfg_str_size_memory(value, config->deferring_size, config->deferring_size_pow);
|
|
|
|
|
value = yon_char_unite(value, ",");
|
|
|
|
|
//value = philos_format_cfg_str_size_memory(value, config->deferring_file, config->deferring_file_pow);
|
|
|
|
|
value = yon_char_unite(value, ",", NULL);
|
|
|
|
|
value = yon_char_unite(value, yon_char_from_int(config->soft_restriction_file));
|
|
|
|
|
value = yon_char_unite(value, ",", NULL);
|
|
|
|
|
value = philos_format_cfg_str_size_memory(value, config->severe_limitation_size,config->severe_limitation_size_pow);
|
|
|
|
|
value = yon_char_unite(value, ",", NULL);
|
|
|
|
|
value = yon_char_unite(value, yon_char_from_int(config->severe_limitation_file), NULL);
|
|
|
|
|
value = yon_char_unite(value, ",", NULL);
|
|
|
|
|
value = yon_char_unite(value, philos_char_from_size_t(config->deferring_size), ",", NULL);
|
|
|
|
|
value = yon_char_unite(value, philos_char_from_size_t(config->deferring_file), NULL);
|
|
|
|
|
return value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char* save_str_users(config_u_g_p* config, int index) {
|
|
|
|
|
char* cmd = yon_char_new("");
|
|
|
|
|
char split_simvol[2] = {0};
|
|
|
|
|
split_simvol[0] = 0;
|
|
|
|
|
split_simvol[1] = 0;
|
|
|
|
|
if (strstr(config->type_arr, "prjquota")) {
|
|
|
|
|
//for (int i=0; config->actors[i]; i++) {
|
|
|
|
|
// cmd = yon_char_unite(":", split_simvol, config->actors[i], NULL);
|
|
|
|
|
// split_simvol[0] = ',';
|
|
|
|
|
// split_simvol[1] = '\0';
|
|
|
|
|
//}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char* save_format_status_cmd(config_u_g_p* config, int index) {
|
|
|
|
|
if (config->status_set == 1) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
if (config->status) {
|
|
|
|
|
return yon_char_new("enable");
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return yon_char_new("disable");
|
|
|
|
|
}
|
|
|
|
|
return yon_char_new("disable");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int save_check_save(config_all* _all_config) {
|
|
|
|
|
if (_all_config->flag_set_data == 1 || _all_config->flag_save>0) {
|
|
|
|
|
return 0;
|
|
|
|
@ -156,18 +129,15 @@ int save_check_save(config_all* _all_config) {
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void save_remove_array(config_all* _all_config) {
|
|
|
|
|
for (int i = 0; i < _all_config->v_u_g_p.pfVectorTotal(&_all_config->v_u_g_p); i++) {
|
|
|
|
|
config_u_g_p* _config = (config_u_g_p*)_all_config->v_u_g_p.pfVectorGet(&_all_config->v_u_g_p, i);
|
|
|
|
|
if (_config->status_set == 1) {
|
|
|
|
|
_all_config->v_u_g_p.pfVectorDelete(&_all_config->v_u_g_p, i);
|
|
|
|
|
}
|
|
|
|
|
if (_config->status_set == 2) {
|
|
|
|
|
_config->status_set = 0;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
char* save_format_status_cmd(config_u_g_p* config, int index) {
|
|
|
|
|
/*if (config->status) {
|
|
|
|
|
return yon_char_new("enable");
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return yon_char_new("disable");
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
return yon_char_new("disable");
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#endif
|