Commit 171df6aa authored by jan.koester's avatar jan.koester
Browse files

test

parent 6306e451
Loading
Loading
Loading
Loading
+24 −6
Changes for src/blogi.cpp: 24 added lines, 6 removed lines.
Original line number Diff line number Diff line
@@ -2991,11 +2991,11 @@ public:

#ifndef Windows
void logFiles(const char *path, int fd) {
    int pfd=open(path,O_APPEND|O_CREAT|O_WRONLY,0x760);
    int pfd = open(path, O_APPEND | O_CREAT | O_WRONLY, 0660);

    if (pfd < 0) {
        libhttppp::HTTPException exp;
        exp[libhttppp::HTTPException::Critical] << "can't open or create logfile !";
        exp[libhttppp::HTTPException::Error] << "can't open or create logfile: " << path;
        throw exp;
    }

@@ -3005,15 +3005,33 @@ void logFiles(const char *path,int fd){
    const char *username = "blogi";

    if (getpwnam_r(username, &pwd_storage, buffer, sizeof(buffer), &result) != 0 || result == nullptr) {
        close(pfd);
        libhttppp::HTTPException exp;
        exp[libhttppp::HTTPException::Error] << "can't locate user runtime info for: " << username;
        throw exp;
    }

    if (fchown(pfd, result->pw_uid, result->pw_gid) != 0) {
        if (errno != EPERM) {
            close(pfd);
            libhttppp::HTTPException exp;
        exp[libhttppp::HTTPException::Critical] << "can't change user !";
            exp[libhttppp::HTTPException::Error] << "fchown failed on log file!";
            throw exp;
        }
    }

    // Flush the existing stream interface before clobbering the underlying file descriptor
    if (fd == 1) std::cout << std::flush;
    if (fd == 2) std::cerr << std::flush;

    if(result!=nullptr)
        fchown(pfd,result->pw_uid,result->pw_gid);
    // 3. Duplicate and clean up
    if (dup2(pfd, fd) < 0) {
        close(pfd);
        libhttppp::HTTPException exp;
        exp[libhttppp::HTTPException::Error] << "dup2 system call failed!";
        throw exp;
    }
    
    dup2(pfd, fd);
    close(pfd);
}