]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
- thread safety
authorArvin Schnell <aschnell@suse.de>
Fri, 17 Aug 2012 10:04:49 +0000 (12:04 +0200)
committerArvin Schnell <aschnell@suse.de>
Fri, 17 Aug 2012 10:04:49 +0000 (12:04 +0200)
snapper/AppUtil.cc
snapper/AppUtil.h
snapper/Compare.cc
snapper/Comparison.cc
snapper/File.cc
snapper/Filesystem.cc
snapper/Snapshot.cc
snapper/SystemCmd.cc
snapper/SystemCmd.h

index bad252540c86e8ce96e0b625a8a1c565df691fe0..5c1d276ff9cc7dc93881168f2da1f1db55ffc13b 100644 (file)
@@ -117,7 +117,7 @@ namespace snapper
        int r1 = ioctl(dest_fd, BTRFS_IOC_CLONE, src_fd);
        if (r1 != 0)
        {
-           y2err("ioctl failed errno:" << errno << " (" << strerror(errno) << ")");
+           y2err("ioctl failed errno:" << errno << " (" << stringerror(errno) << ")");
        }
 
        return r1 == 0;
@@ -131,7 +131,7 @@ namespace snapper
        int r1 = fstat(src_fd, &src_stat);
        if (r1 != 0)
        {
-           y2err("fstat failed errno:" << errno << " (" << strerror(errno) << ")");
+           y2err("fstat failed errno:" << errno << " (" << stringerror(errno) << ")");
            return false;
        }
 
@@ -151,14 +151,14 @@ namespace snapper
            int r2 = read(src_fd, block, t);
            if (r2 != t)
            {
-               y2err("read failed errno:" << errno << " (" << strerror(errno) << ")");
+               y2err("read failed errno:" << errno << " (" << stringerror(errno) << ")");
                return false;
            }
 
            int r3 = write(dest_fd, block, t);
            if (r3 != t)
            {
-               y2err("write failed errno:" << errno << " (" << strerror(errno) << ")");
+               y2err("write failed errno:" << errno << " (" << stringerror(errno) << ")");
                return false;
            }
 
@@ -199,6 +199,22 @@ namespace snapper
     }
 
 
+    string
+    stringerror(int errnum)
+    {
+#if (_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && ! _GNU_SOURCE
+       char buf1[100];
+       if (strerror_r(errno, buf1, sizeof(buf1)-1) == 0)
+           return string(buf1);
+       return string("strerror failed");
+#else
+       char buf1[100];
+       const char* buf2 = strerror_r(errno, buf1, sizeof(buf1)-1);
+       return string(buf2);
+#endif
+    }
+
+
     string
     sformat(const string& format, ...)
     {
index 7e4755eda497c9599a33c6d41b4e211baaeab92d..4bca1e7cba662293e1c734121438077103949803 100644 (file)
@@ -55,6 +55,8 @@ namespace snapper
 
     string realpath(const string& path);
 
+    string stringerror(int errnum);
+
     template<class StreamType>
     void classic(StreamType& stream)
     {
index 937eb07af9e4fb97fda17c14ace05594d4bd77ce..d049b64f99a24e4c353c129821a18d25633b8806 100644 (file)
@@ -49,7 +49,7 @@ namespace snapper
        dirfd = ::open(base_path.c_str(), O_RDONLY | O_NOATIME);
        if (dirfd < 0)
        {
-           y2err("open failed path:" << base_path << " error:" << strerror(errno));
+           y2err("open failed path:" << base_path << " error:" << stringerror(errno));
            throw IOErrorException();
        }
     }
@@ -61,7 +61,7 @@ namespace snapper
        dirfd = ::openat(dir.dirfd, name.c_str(), O_RDONLY | O_NOFOLLOW | O_NOATIME);
        if (dirfd < 0)
        {
-           y2err("open failed path:" << dir.fullname(name) << " (" << strerror(errno) << ")");
+           y2err("open failed path:" << dir.fullname(name) << " (" << stringerror(errno) << ")");
            throw IOErrorException();
        }
     }
@@ -93,14 +93,14 @@ namespace snapper
        int fd = dup(dirfd);
        if (fd == -1)
        {
-           y2err("dup failed" << " error:" << strerror(errno));
+           y2err("dup failed" << " error:" << stringerror(errno));
            throw IOErrorException();
        }
 
        DIR* dp = fdopendir(fd);
        if (dp == NULL)
        {
-           y2err("fdopendir failed path:" << fullname() << " error:" << strerror(errno));
+           y2err("fdopendir failed path:" << fullname() << " error:" << stringerror(errno));
            ::close(fd);
            throw IOErrorException();
        }
index 938605b439833fc3c64300e1b97756e304d211cf..8c76dd64594aebc2a9d078c464d5c40720353701 100644 (file)
@@ -190,7 +190,7 @@ namespace snapper
        FILE* file = mkstemp(tmp_name);
        if (!file)
        {
-           y2err("mkstemp failed errno:" << errno << " (" << strerror(errno) << ")");
+           y2err("mkstemp failed errno:" << errno << " (" << stringerror(errno) << ")");
            throw IOErrorException();
        }
 
index b0f3097c9e71984ff316e4588b18566b441d7d64..8af4027d553e45b16415952f01e44b95f0c14a77 100644 (file)
@@ -326,7 +326,7 @@ namespace snapper
        int src_fd = open(getAbsolutePath(LOC_PRE).c_str(), O_RDONLY | O_LARGEFILE);
        if (src_fd < 0)
        {
-           y2err("open failed errno:" << errno << " (" << strerror(errno) << ")");
+           y2err("open failed errno:" << errno << " (" << stringerror(errno) << ")");
            return false;
        }
 
@@ -334,21 +334,21 @@ namespace snapper
                           O_CREAT | O_TRUNC, mode);
        if (dest_fd < 0)
        {
-           y2err("open failed errno:" << errno << " (" << strerror(errno) << ")");
+           y2err("open failed errno:" << errno << " (" << stringerror(errno) << ")");
            return false;
        }
 
        int r1 = fchmod(dest_fd, mode);
        if (r1 != 0)
        {
-           y2err("fchmod failed errno:" << errno << " (" << strerror(errno) << ")");
+           y2err("fchmod failed errno:" << errno << " (" << stringerror(errno) << ")");
            return false;
        }
 
        int r2 = fchown(dest_fd, owner, group);
        if (r2 != 0)
        {
-           y2err("fchown failed errno:" << errno << " (" << strerror(errno) << ")");
+           y2err("fchown failed errno:" << errno << " (" << stringerror(errno) << ")");
            return false;
        }
 
index abd10a3a55c90f9ce7535d081d90484480b06f1d..944b7e182f7cf3021f26bb9295d0d55a15d9d8af 100644 (file)
@@ -166,7 +166,7 @@ namespace snapper
        }
        else if (errno != EEXIST)
        {
-           y2err("mkdir failed errno:" << errno << " (" << strerror(errno) << ")");
+           y2err("mkdir failed errno:" << errno << " (" << stringerror(errno) << ")");
            throw CreateConfigFailedException("mkdir failed");
        }
 
@@ -179,7 +179,7 @@ namespace snapper
        }
        else if (errno != EEXIST)
        {
-           y2err("mkdir failed errno:" << errno << " (" << strerror(errno) << ")");
+           y2err("mkdir failed errno:" << errno << " (" << stringerror(errno) << ")");
            throw CreateConfigFailedException("mkdir failed");
        }
     }
@@ -191,14 +191,14 @@ namespace snapper
        int r1 = rmdir((subvolume + "/.snapshots/.info").c_str());
        if (r1 != 0)
        {
-           y2err("rmdir failed errno:" << errno << " (" << strerror(errno) << ")");
+           y2err("rmdir failed errno:" << errno << " (" << stringerror(errno) << ")");
            throw DeleteConfigFailedException("rmdir failed");
        }
 
        int r2 = rmdir((subvolume + "/.snapshots").c_str());
        if (r2 != 0)
        {
-           y2err("rmdir failed errno:" << errno << " (" << strerror(errno) << ")");
+           y2err("rmdir failed errno:" << errno << " (" << stringerror(errno) << ")");
            throw DeleteConfigFailedException("rmdir failed");
        }
     }
@@ -291,7 +291,7 @@ namespace snapper
        int r1 = mkdir(snapshotDir(num).c_str(), 0755);
        if (r1 != 0 && errno != EEXIST)
        {
-           y2err("mkdir failed errno:" << errno << " (" << strerror(errno) << ")");
+           y2err("mkdir failed errno:" << errno << " (" << stringerror(errno) << ")");
            throw MountSnapshotFailedException();
        }
 
index 00857efd66fa275d754a5e3b1d833f6b6925237e..8066541f3ede54fd819b434a49981dc0022bab5a 100644 (file)
@@ -359,7 +359,7 @@ namespace snapper
            if (errno == EEXIST)
                continue;
 
-           y2err("mkdir failed errno:" << errno << " (" << strerror(errno) << ")");
+           y2err("mkdir failed errno:" << errno << " (" << stringerror(errno) << ")");
            throw IOErrorException();
        }
 
@@ -416,14 +416,14 @@ namespace snapper
        catch (const IOErrorException& e)
        {
            y2err("saving info.xml failed infoDir: " << infoDir() << " errno: << " << errno <<
-                 " (" << strerror(errno) << ")");
+                 " (" << stringerror(errno) << ")");
            throw;
        }
 
        if (rename(string(infoDir() + "/info.xml.tmp").c_str(), string(infoDir() + "/info.xml").c_str()) != 0)
        {
            y2err("rename info.xml failed infoDir: " << infoDir() << " errno: << " << errno <<
-                 " (" << strerror(errno) << ")");
+                 " (" << stringerror(errno) << ")");
            throw IOErrorException();
        }
     }
index 7ad99e8340b4bdba020d85b350ab3733049aafee..ff9d51188e3865be4c854c98b2d921b31ecb5bd6 100644 (file)
@@ -189,12 +189,12 @@ SystemCmd::doExecute( const string& Cmd )
     bool ok_bi = true;
     if( !testmode && pipe(sout)<0 )
        {
-       y2err("pipe stdout creation failed errno:" << errno << " (" << strerror(errno) << ")");
+       y2err("pipe stdout creation failed errno:" << errno << " (" << stringerror(errno) << ")");
        ok_bi = false;
        }
     if( !testmode && !Combine_b && pipe(serr)<0 )
        {
-       y2err("pipe stderr creation failed errno:" << errno << " (" << strerror(errno) << ")");
+       y2err("pipe stderr creation failed errno:" << errno << " (" << stringerror(errno) << ")");
        ok_bi = false;
        }
     if( !testmode && ok_bi )
@@ -202,14 +202,14 @@ SystemCmd::doExecute( const string& Cmd )
        pfds[0].fd = sout[0];
        if( fcntl( pfds[0].fd, F_SETFL, O_NONBLOCK )<0 )
            {
-           y2err("fcntl O_NONBLOCK failed errno:" << errno << " (" << strerror(errno) << ")");
+           y2err("fcntl O_NONBLOCK failed errno:" << errno << " (" << stringerror(errno) << ")");
            }
        if( !Combine_b )
            {
            pfds[1].fd = serr[0];
            if( fcntl( pfds[1].fd, F_SETFL, O_NONBLOCK )<0 )
                {
-               y2err("fcntl O_NONBLOCK failed errno:" << errno << " (" << strerror(errno) << ")");
+               y2err("fcntl O_NONBLOCK failed errno:" << errno << " (" << stringerror(errno) << ")");
                }
            }
        y2deb("sout:" << pfds[0].fd << " serr:" << (Combine_b?-1:pfds[1].fd));
@@ -220,23 +220,23 @@ SystemCmd::doExecute( const string& Cmd )
                setenv( "LANGUAGE", "C", 1 );
                if( dup2( sout[1], STDOUT_FILENO )<0 )
                    {
-                   y2err("dup2 stdout child failed errno:" << errno << " (" << strerror(errno) << ")");
+                   y2err("dup2 stdout child failed errno:" << errno << " (" << stringerror(errno) << ")");
                    }
                if( !Combine_b && dup2( serr[1], STDERR_FILENO )<0 )
                    {
-                   y2err("dup2 stderr child failed errno:" << errno << " (" << strerror(errno) << ")");
+                   y2err("dup2 stderr child failed errno:" << errno << " (" << stringerror(errno) << ")");
                    }
                if( Combine_b && dup2( STDOUT_FILENO, STDERR_FILENO )<0 )
                    {
-                   y2err("dup2 stderr child failed errno:" << errno << " (" << strerror(errno) << ")");
+                   y2err("dup2 stderr child failed errno:" << errno << " (" << stringerror(errno) << ")");
                    }
                if( close( sout[0] )<0 )
                    {
-                   y2err("close child failed errno:" << errno << " (" << strerror(errno) << ")");
+                   y2err("close child failed errno:" << errno << " (" << stringerror(errno) << ")");
                    }
                if( !Combine_b && close( serr[0] )<0 )
                    {
-                   y2err("close child failed errno:" << errno << " (" << strerror(errno) << ")");
+                   y2err("close child failed errno:" << errno << " (" << stringerror(errno) << ")");
                    }
                closeOpenFds();
                Ret_i = execl( Shell_Ci.c_str(), Shell_Ci.c_str(), "-c",
@@ -249,24 +249,24 @@ SystemCmd::doExecute( const string& Cmd )
            default:
                if( close( sout[1] )<0 )
                    {
-                   y2err("close parent failed errno:" << errno << " (" << strerror(errno) << ")");
+                   y2err("close parent failed errno:" << errno << " (" << stringerror(errno) << ")");
                    }
                if( !Combine_b && close( serr[1] )<0 )
                    {
-                   y2err("close parent failed errno:" << errno << " (" << strerror(errno) << ")");
+                   y2err("close parent failed errno:" << errno << " (" << stringerror(errno) << ")");
                    }
                Ret_i = 0;
                File_aC[IDX_STDOUT] = fdopen( sout[0], "r" );
                if( File_aC[IDX_STDOUT] == NULL )
                    {
-                   y2err("fdopen stdout failed errno:" << errno << " (" << strerror(errno) << ")");
+                   y2err("fdopen stdout failed errno:" << errno << " (" << stringerror(errno) << ")");
                    }
                if( !Combine_b )
                    {
                    File_aC[IDX_STDERR] = fdopen( serr[0], "r" );
                    if( File_aC[IDX_STDERR] == NULL )
                        {
-                       y2err("fdopen stderr failed errno:" << errno << " (" << strerror(errno) << ")");
+                       y2err("fdopen stderr failed errno:" << errno << " (" << stringerror(errno) << ")");
                        }
                    }
                if( !Background_b )
@@ -312,7 +312,7 @@ SystemCmd::doWait( bool Hang_bv, int& Ret_ir )
        int sel = poll( pfds, Combine_b?1:2, 1000 );
        if (sel < 0)
            {
-           y2err("poll failed errno:" << errno << " (" << strerror(errno) << ")");
+           y2err("poll failed errno:" << errno << " (" << stringerror(errno) << ")");
            }
        y2deb("poll ret:" << sel);
        if( sel>0 )
@@ -482,8 +482,8 @@ SystemCmd::checkOutput()
 #define BUF_LEN 256
 
 void
-SystemCmd::getUntilEOF( FILE* File_Cr, vector<string>& Lines_Cr,
-                        bool& NewLine_br, bool Stderr_bv )
+SystemCmd::getUntilEOF(FILE* File_Cr, vector<string>& Lines_Cr, bool& NewLine_br,
+                      bool Stderr_bv)
     {
     size_t old_size = Lines_Cr.size();
     char Buf_ti[BUF_LEN];
index 863ee01e41d4447418dca3c1c0d0e3b0d7209755..93e6854e5c8dafc93273177c2d956748c903b160 100644 (file)
@@ -85,9 +85,9 @@ namespace snapper
        void closeOpenFds() const;
        int doExecute(const string& Cmd_Cv);
        bool doWait(bool Hang_bv, int& Ret_ir);
-        void checkOutput();
-       void getUntilEOF(FILE* File_Cr, std::vector<string>& Lines_Cr,
-                        bool& NewLineSeen_br, bool Stderr_bv);
+       void checkOutput();
+       void getUntilEOF(FILE* File_Cr, std::vector<string>& Lines_Cr, bool& NewLineSeen_br,
+                        bool Stderr_bv);
        void extractNewline(const string& Buf_ti, int Cnt_ii, bool& NewLineSeen_br,
                            string& Text_Cr, std::vector<string>& Lines_Cr);
        void addLine(const string& Text_Cv, std::vector<string>& Lines_Cr);