cmddatas_t * remove_working_in_cmdfile( cmddatas_t *cmddatas, pid_t pid) { cmddatas_t *new_cmddatas; // take the lock and read new_cmddatas = read_cmdfile(cmddatas->lock->filename); // remove if same pid g_hash_table_foreach(new_cmddatas->cmdfile, &cmdfile_remove_working, &pid); // write write_cmdfile(new_cmddatas); close_cmdfile(cmddatas); return new_cmddatas; }
cmddatas_t * remove_cmd_in_cmdfile( cmddatas_t *cmddatas, int id) { cmddatas_t *new_cmddatas; // take the lock and read new_cmddatas = read_cmdfile(cmddatas->lock->filename); // remove the cmd id g_hash_table_remove(new_cmddatas->cmdfile, GINT_TO_POINTER(id)); // write write_cmdfile(new_cmddatas); close_cmdfile(cmddatas); return new_cmddatas; }
gboolean holding_in_cmdfile( cmddatas_t *cmddatas, char *holding_file) { cmd_holding_t cmd_holding = { holding_file, FALSE }; cmddatas_t *new_cmddatas; g_hash_table_foreach(cmddatas->cmdfile, &cmdfile_holding_file, &cmd_holding); new_cmddatas = read_cmdfile(cmddatas->lock->filename); unlock_cmdfile(new_cmddatas); g_hash_table_foreach(new_cmddatas->cmdfile, &cmdfile_holding_file, &cmd_holding); close_cmdfile(new_cmddatas); return cmd_holding.found; }
cmddatas_t * add_cmd_in_cmdfile( cmddatas_t *cmddatas, cmddata_t *cmddata) { cmddatas_t *new_cmddatas; // take the lock and read new_cmddatas = read_cmdfile(cmddatas->lock->filename); // add the cmd new_cmddatas->max_id++; cmddata->id = new_cmddatas->max_id; g_hash_table_insert(new_cmddatas->cmdfile, GINT_TO_POINTER(new_cmddatas->max_id), cmddata); // write write_cmdfile(new_cmddatas); close_cmdfile(cmddatas); return new_cmddatas; }
cmddatas_t * change_cmd_in_cmdfile( cmddatas_t *cmddatas, int id, cmdstatus_t status, off_t size) { cmddatas_t *new_cmddatas; cmddata_t *cmddata; // take the lock and read new_cmddatas = read_cmdfile(cmddatas->lock->filename); // update status for cmd id in cmddatas and new_cmddatas cmddata = g_hash_table_lookup(new_cmddatas->cmdfile, GINT_TO_POINTER(id)); cmddata->status = status; cmddata->size = size; // write write_cmdfile(new_cmddatas); close_cmdfile(cmddatas); return new_cmddatas; }
cmddatas_t * add_cmd_in_cmdfile( cmddatas_t *cmddatas, cmddata_t *cmddata) { cmddatas_t *new_cmddatas; // take the lock and read new_cmddatas = read_cmdfile(cmddatas->lock->filename); // add the cmd new_cmddatas->max_id++; cmddata->id = new_cmddatas->max_id; if (cmddata->operation == CMD_RESTORE && cmddata->working_pid == 0) cmddata->expire = time(NULL) + EXPIRE_DELAY; g_hash_table_insert(new_cmddatas->cmdfile, GINT_TO_POINTER(new_cmddatas->max_id), cmddata); // write write_cmdfile(new_cmddatas); close_cmdfile(cmddatas); return new_cmddatas; }