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;
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;
}
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;
}
}
+ 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, ...)
{
string realpath(const string& path);
+ string stringerror(int errnum);
+
template<class StreamType>
void classic(StreamType& stream)
{
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();
}
}
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();
}
}
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();
}
FILE* file = mkstemp(tmp_name);
if (!file)
{
- y2err("mkstemp failed errno:" << errno << " (" << strerror(errno) << ")");
+ y2err("mkstemp failed errno:" << errno << " (" << stringerror(errno) << ")");
throw IOErrorException();
}
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;
}
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;
}
}
else if (errno != EEXIST)
{
- y2err("mkdir failed errno:" << errno << " (" << strerror(errno) << ")");
+ y2err("mkdir failed errno:" << errno << " (" << stringerror(errno) << ")");
throw CreateConfigFailedException("mkdir failed");
}
}
else if (errno != EEXIST)
{
- y2err("mkdir failed errno:" << errno << " (" << strerror(errno) << ")");
+ y2err("mkdir failed errno:" << errno << " (" << stringerror(errno) << ")");
throw CreateConfigFailedException("mkdir failed");
}
}
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");
}
}
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();
}
if (errno == EEXIST)
continue;
- y2err("mkdir failed errno:" << errno << " (" << strerror(errno) << ")");
+ y2err("mkdir failed errno:" << errno << " (" << stringerror(errno) << ")");
throw IOErrorException();
}
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();
}
}
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 )
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));
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",
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 )
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 )
#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];
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);