コード例 #1
0
bool GZCompressAction::execute(log4cxx::helpers::Pool& p) const {
    if (source.exists(p)) {
        apr_pool_t* pool = p.getAPRPool();
        apr_procattr_t* attr;
        apr_status_t stat = apr_procattr_create(&attr, pool);
        if (stat != APR_SUCCESS) throw IOException(stat);
    
        stat = apr_procattr_io_set(attr, APR_NO_PIPE, APR_FULL_BLOCK, APR_FULL_BLOCK);
        if (stat != APR_SUCCESS) throw IOException(stat);
    
        stat = apr_procattr_cmdtype_set(attr, APR_PROGRAM_PATH);
        if (stat != APR_SUCCESS) throw IOException(stat);

        //
        //   set child process output to destination file
        //
        apr_file_t* child_out;
        apr_int32_t flags = APR_FOPEN_READ | APR_FOPEN_WRITE |
            APR_FOPEN_CREATE | APR_FOPEN_TRUNCATE;
        stat = destination.open(&child_out, flags, APR_OS_DEFAULT, p);
        if (stat != APR_SUCCESS) throw IOException(stat);

        stat =  apr_procattr_child_out_set(attr, child_out, NULL);
        if (stat != APR_SUCCESS) throw IOException(stat);

        //
        //   redirect the child's error stream to this processes' error stream
        //
        apr_file_t* child_err;
        stat = apr_file_open_stderr(&child_err, pool);
        if (stat == APR_SUCCESS) {
         stat =  apr_procattr_child_err_set(attr, child_err, NULL);
         if (stat != APR_SUCCESS) throw IOException(stat);
        }

        const char** args = (const char**) 
            apr_palloc(pool, 4 *sizeof(*args));
        int i = 0;
        args[i++] = "gzip";
        args[i++] = "-c";
        args[i++] = Transcoder::encode(source.getPath(), p);
        args[i++] = NULL;
    

        apr_proc_t pid;
        stat = apr_proc_create(&pid, "gzip", args, NULL, attr, pool);
        if (stat != APR_SUCCESS) throw IOException(stat);

        apr_proc_wait(&pid, NULL, NULL, APR_WAIT);
        stat = apr_file_close(child_out);
        if (stat != APR_SUCCESS) throw IOException(stat);
    
        if (deleteSource) {
            source.deleteFile(p);
        }
        return true;
    }
    return false;
}
コード例 #2
0
bool TimeBasedRollingPolicy::isMapFileEmpty(log4cxx::helpers::Pool& pool){
    apr_finfo_t finfo;
    apr_status_t st = apr_stat(&finfo, _mapFileName.c_str(), APR_FINFO_SIZE, pool.getAPRPool());
    if (st != APR_SUCCESS){
        LogLog::warn(LOG4CXX_STR("apr_stat failed."));
    }
    if (st == APR_SUCCESS && !finfo.size)
        return true;
    return false;
}
コード例 #3
0
bool ZipCompressAction::execute(log4cxx::helpers::Pool& p) const {
    if (source.exists(p)) {
        apr_pool_t* pool = p.getAPRPool();
        apr_procattr_t* attr;
        apr_status_t stat = apr_procattr_create(&attr, pool);
        if (stat != APR_SUCCESS) throw IOException(stat);
    
        stat = apr_procattr_io_set(attr, APR_NO_PIPE, APR_NO_PIPE, APR_FULL_BLOCK);
        if (stat != APR_SUCCESS) throw IOException(stat);
    
        stat = apr_procattr_cmdtype_set(attr, APR_PROGRAM_PATH);
        if (stat != APR_SUCCESS) throw IOException(stat);


        //
        //   redirect the child's error stream to this processes' error stream
        //
        apr_file_t* child_err;
        stat = apr_file_open_stderr(&child_err, pool);
        if (stat == APR_SUCCESS) {
         stat =  apr_procattr_child_err_set(attr, child_err, NULL);
         if (stat != APR_SUCCESS) throw IOException(stat);
        }

        const char** args = (const char**) 
            apr_palloc(pool, 5 *sizeof(*args));
        int i = 0;
        args[i++] = "zip";
      args[i++] = "-q";
        args[i++] = Transcoder::encode(destination.getPath(), p);
        args[i++] = Transcoder::encode(source.getPath(), p);
        args[i++] = NULL;
    
        if (destination.exists(p)) {
            destination.deleteFile(p);
        }

        apr_proc_t pid;
        stat = apr_proc_create(&pid, "zip", args, NULL, attr, pool);
        if (stat != APR_SUCCESS) throw IOException(stat);

        apr_proc_wait(&pid, NULL, NULL, APR_WAIT);
    
        if (deleteSource) {
            source.deleteFile(p);
        }
        return true;
    }
    return false;
}
コード例 #4
0
const std::string TimeBasedRollingPolicy::createFile(const std::string& fileName, const std::string& suffix, log4cxx::helpers::Pool& pool) {
   char szUid[MAX_FILE_LEN] = {'\0'};
   char szBaseName[MAX_FILE_LEN] = {'\0'};
   char szDirName[MAX_FILE_LEN] = {'\0'};
   memcpy(szDirName, fileName.c_str(), fileName.size() > MAX_FILE_LEN ? MAX_FILE_LEN : fileName.size());
   memcpy(szBaseName, fileName.c_str(), fileName.size() > MAX_FILE_LEN ? MAX_FILE_LEN : fileName.size());

   apr_uid_t uid; 
   apr_gid_t groupid;
   apr_status_t stat = apr_uid_current(&uid, &groupid, pool.getAPRPool());
   if (stat == APR_SUCCESS){
       snprintf(szUid, MAX_FILE_LEN, "%u", uid);
   }
   return std::string(::dirname(szDirName)) + "/." + ::basename(szBaseName) + szUid + suffix;
}