int32_t filesystem_copy(asl_out_dst_data_t *asldst, const char *src, const char *dst, uint32_t flags) { char *dot; if ((src == NULL) || (dst == NULL)) return 0; dot = strrchr(src, '.'); if ((dot != NULL) && (!strcmp(dot, ".gz"))) flags &= ~MODULE_FLAG_COMPRESS; if (((flags & MODULE_FLAG_COMPRESS) == 0) && (!strcmp(src, dst))) return 0; if (flags & MODULE_FLAG_TYPE_ASL) debug_log(ASL_LEVEL_NOTICE, " copy asl %s ---> %s\n", src, dst); else if (flags & MODULE_FLAG_COMPRESS) debug_log(ASL_LEVEL_NOTICE, " copy compress %s ---> %s.gz\n", src, dst); else debug_log(ASL_LEVEL_NOTICE, " copy %s ---> %s\n", src, dst); if (dryrun == 1) return 0; if (flags & MODULE_FLAG_TYPE_ASL) { uint32_t status = copy_asl_file(src, dst, asldst->mode); if (status != 0) { debug_log(ASL_LEVEL_ERR, " FAILED status %u [%s] asl copy %s ---> %s\n", status, asl_core_error(status), src, dst); return 0; } } else if (flags & MODULE_FLAG_COMPRESS) { char gzdst[MAXPATHLEN]; snprintf(gzdst, sizeof(gzdst), "%s.gz", dst); int status = copy_compress_file(asldst, src, gzdst); if (status != 0) { debug_log(ASL_LEVEL_ERR, " FAILED status %d errno %d [%s] copy & compress %s ---> %s\n", status, errno, strerror(errno), src, dst); return 0; } } else { int status = 0; //copyfile(src, dst, NULL, COPYFILE_ALL | COPYFILE_RECURSIVE); if (status != 0) { debug_log(ASL_LEVEL_ERR, " FAILED status %d errno %d [%s] copy %s ---> %s\n", status, errno, strerror(errno), src, dst); return 0; } } return 1; }
static void db_asl_open(uint32_t dbtype) { uint32_t status; struct stat sb; if ((dbtype & DB_TYPE_FILE) && (global.file_db == NULL)) { memset(&sb, 0, sizeof(struct stat)); if (stat(PATH_ASL_STORE, &sb) == 0) { /* must be a directory */ if (!S_ISDIR(sb.st_mode)) { asldebug("error: %s is not a directory", PATH_ASL_STORE); return; } } else { if (errno == ENOENT) { /* /var/log/asl doesn't exist - create it */ if (mkdir(PATH_ASL_STORE, 0755) != 0) { asldebug("error: can't create data store %s: %s\n", PATH_ASL_STORE, strerror(errno)); return; } } else { /* stat failed for some other reason */ asldebug("error: can't stat data store %s: %s\n", PATH_ASL_STORE, strerror(errno)); return; } } /* * One-time store conversion from the old "LongTTL" style to the new "Best Before" style. * bb_convert returns quickly if the store has already been converted. */ status = bb_convert(PATH_ASL_STORE); if (status != ASL_STATUS_OK) { asldebug("ASL data store conversion failed!: %s\n", asl_core_error(status)); } status = asl_store_open_write(NULL, &(global.file_db)); if (status != ASL_STATUS_OK) { asldebug("asl_store_open_write: %s\n", asl_core_error(status)); } else { if (global.db_file_max != 0) asl_store_max_file_size(global.file_db, global.db_file_max); asl_trigger_aslmanager(); } } if ((dbtype & DB_TYPE_MEMORY) && (global.memory_db == NULL)) { status = asl_memory_open(global.db_memory_max, &(global.memory_db)); if (status != ASL_STATUS_OK) { asldebug("asl_memory_open: %s\n", asl_core_error(status)); } } if ((dbtype & DB_TYPE_MINI) && (global.mini_db == NULL)) { status = asl_mini_memory_open(global.db_mini_max, &(global.mini_db)); if (status != ASL_STATUS_OK) { asldebug("asl_mini_memory_open: %s\n", asl_core_error(status)); } } }