static int _set_oom_adj(const char *oom_adj_path, int val) { FILE *fp; if (!(fp = fopen(oom_adj_path, "w"))) { perror("oom_adj: fopen failed"); return 0; } fprintf(fp, "%i", val); if (dm_fclose(fp)) perror("oom_adj: fclose failed"); return 1; }
void fin_log(void) { if (_log_direct) { (void) dev_close(&_log_dev); _log_direct = 0; } if (_log_to_file) { if (dm_fclose(_log_file)) { if (errno) fprintf(stderr, "failed to write log file: %s\n", strerror(errno)); else fprintf(stderr, "failed to write log file\n"); } _log_to_file = 0; } }
int config_write(struct dm_config_tree *cft, const char *file, int argc, char **argv) { const struct dm_config_node *cn; int r = 1; FILE *fp = NULL; if (!file) { fp = stdout; file = "stdout"; } else if (!(fp = fopen(file, "w"))) { log_sys_error("open", file); return 0; } log_verbose("Dumping configuration to %s", file); if (!argc) { if (!dm_config_write_node(cft->root, _putline_fn, fp)) { log_error("Failure while writing to %s", file); r = 0; } } else while (argc--) { if ((cn = dm_config_find_node(cft->root, *argv))) { if (!dm_config_write_node(cn, _putline_fn, fp)) { log_error("Failure while writing to %s", file); r = 0; } } else { log_error("Configuration node %s not found", *argv); r = 0; } argv++; } if (fp && dm_fclose(fp)) { stack; r = 0; } return r; }