faubackup2/src/common system_calls.cpp,1.6,1.7
Martin Waitz <[email protected]> Thu, 16 Jun 2005 14:37:11 +0000
| Newsgroups | gmane.comp.sysutils.backup.faubackup.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/faubackup/faubackup2/src/common
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16040/src/common
Modified Files:
system_calls.cpp
Log Message:
use common output functions and format strings
Index: system_calls.cpp
===================================================================
RCS file: /cvsroot/faubackup/faubackup2/src/common/system_calls.cpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** system_calls.cpp 14 Jun 2005 22:10:18 -0000 1.6
--- system_calls.cpp 16 Jun 2005 14:37:08 -0000 1.7
***************
*** 1,5 ****
#include "support.h"
! #include <common/system_calls.hpp>
#include <sys/stat.h>
--- 1,5 ----
#include "support.h"
! #include "common/system_calls.hpp"
#include <sys/stat.h>
***************
*** 8,11 ****
--- 8,12 ----
#include <sys/socket.h>
#include <netinet/in.h>
+ #include <boost/format.hpp>
#include <dirent.h>
#include <errno.h>
***************
*** 41,44 ****
--- 42,55 ----
extern struct TimeStamp actualbackup;
+
+ static void create_error(boost::format fmter)
+ {
+ if (errno == ENOSPC) {
+ output.critical(fmter, errno);
+ } else {
+ output.non_critical(fmter, errno);
+ }
+ }
+
void getRegFileLink(string name, string link_dest, struct stat st)
{
***************
*** 63,71 ****
if( ret < 0 )
{
! output.non_critical("hardlink: "+ link_dest+ " " + name,
! errno);
! if( errno==ENOSPC )
! exit(1);
! // error++;
return;
}
--- 74,78 ----
if( ret < 0 )
{
! create_error(F_("link %s to %s") % link_dest % name);
return;
}
***************
*** 95,105 ****
*/
ret = mkdir( name.c_str(), 0000 );
! if( ret < 0 && errno!=EEXIST )
! {
! output.non_critical("mkdir(" + name +
! ", 0000)", errno);
! if( errno==ENOSPC )
! exit(1);
! // error++;
return;
}
--- 102,107 ----
*/
ret = mkdir( name.c_str(), 0000 );
! if( ret < 0 && errno!=EEXIST ) {
! create_error(F_("mkdir %s") % name);
return;
}
***************
*** 122,132 ****
*/
ret = mknod( name.c_str(), S_IFCHR, st.st_rdev );
! if( ret < 0 )
! {
! output.non_critical("mknod(" + string(name) +
! ", S_IFCHR, 0x"
! + int2string((int) st.st_rdev),errno);
! if( errno==ENOSPC )
! exit(1);
return;
}
--- 124,129 ----
*/
ret = mknod( name.c_str(), S_IFCHR, st.st_rdev );
! if( ret < 0 ) {
! create_error(F_("mknod %s, S_IFCHR, 0x%x") % name % st.st_rdev);
return;
}
***************
*** 148,159 ****
*/
ret = mknod( name.c_str(), S_IFBLK, st.st_rdev );
! if( ret < 0 )
! {
! fprintf( stderr, "mknod(%s, S_IFBLK, 0x%x): %s\n",
! name.c_str(),
! (int) st.st_rdev, strerror(errno) );
! if( errno==ENOSPC )
! exit(1);
! //error++;
return;
}
--- 145,150 ----
*/
ret = mknod( name.c_str(), S_IFBLK, st.st_rdev );
! if( ret < 0 ) {
! create_error(F_("mknod %s, S_IFBLK, 0x%x") % name % st.st_rdev);
return;
}
***************
*** 171,176 ****
{
! output.information(string("getting symlink: ") + name, DEBUG_OUTPUT);
! output.information("symlink dest: " + link_dest, DEBUG_OUTPUT);
int ret;
--- 162,167 ----
{
! output.information(F_("getting symlink: %s") % name, DEBUG_OUTPUT);
! output.information(F_("symlink dest: %s") % link_dest, DEBUG_OUTPUT);
int ret;
***************
*** 181,191 ****
*/
ret = symlink( link_dest.c_str(), name.c_str() );
! if( ret < 0 )
! {
! fprintf( stderr, "error: symlink %s, %s: %s\n",
! link_dest.c_str(), name.c_str(), strerror(errno) );
! if( errno==ENOSPC )
! exit(1);
! // error++;
return;
}
--- 172,177 ----
*/
ret = symlink( link_dest.c_str(), name.c_str() );
! if( ret < 0 ) {
! create_error(F_("symlink %s to %s") % link_dest % name);
return;
}
***************
*** 204,208 ****
void setPermissions(string path, struct stat st, int flags)
{
! output.information("setPermissions : " + path, DEBUG_OUTPUT);
static bool own_error = false;
mode_t mode;
--- 190,194 ----
void setPermissions(string path, struct stat st, int flags)
{
! output.information(F_("setPermissions: %s") % path, DEBUG_OUTPUT);
static bool own_error = false;
mode_t mode;
***************
*** 218,223 ****
ret = utime( path.c_str(), &u );
if( ret < 0 ) {
! fprintf( stderr, "error: utime(%s, [...]): %s\n",
! path.c_str(), strerror(errno) );
}
}
--- 204,209 ----
ret = utime( path.c_str(), &u );
if( ret < 0 ) {
! output.warning(F_("cannot update timestamp for %s")
! % path, errno);
}
}
***************
*** 239,257 ****
if( ret < 0 && errno == EPERM ) {
if (!own_error) {
! output.warning("cannot set owner: " + string(path.c_str()), errno);
! output.warning("suppressing all further chown warnings!",0);
}
own_error = true;
//cannot_set_owner();
mode &= ~06000;
}
- else
- if( ret < 0 ) {
- fprintf( stderr, "error: lchown(%s, %d, %d): %s\n",
- path.c_str(), (int) st.st_uid,
- (int) st.st_gid, strerror(errno) );
- //error++;
- mode &= ~06000;
- }
}
--- 225,241 ----
if( ret < 0 && errno == EPERM ) {
if (!own_error) {
! output.warning(F_("cannot set owner: %s")
! % path, errno);
! output.warning(_("suppressing all further "
! "chown warnings"), 0);
}
own_error = true;
//cannot_set_owner();
mode &= ~06000;
+ } else if( ret < 0 ) {
+ output.warning(F_("lchown %s, %d:%d")
+ % path % st.st_uid % st.st_gid, errno);
+ mode &= ~06000;
}
}
***************
*** 260,267 ****
ret = chmod(path.c_str(), mode);
if( ret < 0 ) {
! fprintf( stderr, "error: chmod(%s, %03o): %s\n",
! path.c_str(), (int) mode,
! strerror(errno) );
! //error++;
}
}
--- 244,249 ----
ret = chmod(path.c_str(), mode);
if( ret < 0 ) {
! output.warning(F_("chmod %s, %03o")
! % path % mode, errno);
}
}
***************
*** 271,275 ****
void make_path(string path)
{
! output.information("makedir: " + path, DEBUG_OUTPUT);
char *dir;
char *d,*p, *temp;
--- 253,257 ----
void make_path(string path)
{
! output.information(F_("make_path %s") % path, DEBUG_OUTPUT);
char *dir;
char *d,*p, *temp;
***************
*** 296,301 ****
ret = mkdir(dir, 0700);
if( ret<0 && errno!=EEXIST ) {
! fprintf( stderr, "mkdir(\"%s\", 0x700): %s\n",
! dir, strerror(errno) );
return;
}
--- 278,282 ----
ret = mkdir(dir, 0700);
if( ret<0 && errno!=EEXIST ) {
! output.warning(F_("mkdir %s") % dir, errno);
return;
}
***************
*** 314,323 ****
if((len = readlink(name.c_str(), buffer, BUFFSIZE))== -1) {
! output.critical(string("Could not read Symlink: ") + name
! ,errno);
return NULL;
}
buffer[len]= '\0';
! output.information(string("sending symlink dest: ") + buffer, DEBUG_OUTPUT);
return string(buffer);
}
--- 295,304 ----
if((len = readlink(name.c_str(), buffer, BUFFSIZE))== -1) {
! output.critical(F_("Could not read symlink: %s") % name, errno);
return NULL;
}
buffer[len]= '\0';
! output.information(F_("sending symlink dest: %s") % buffer,
! DEBUG_OUTPUT);
return string(buffer);
}
***************
*** 337,341 ****
else
if (pid > 0) { /*------------ Elternprozess -------------*/
! output.information("child created - pid: " + int2string(pid), DEBUG_OUTPUT);
close(pipe1[0]);
close(pipe2[1]);
--- 318,323 ----
else
if (pid > 0) { /*------------ Elternprozess -------------*/
! output.information(F_("child created - pid: %d")
! % int2string(pid), DEBUG_OUTPUT);
close(pipe1[0]);
close(pipe2[1]);
***************
*** 412,416 ****
f_out = to_child_pipe[1];
! output.information("child created - pid: " + int2string(pid), DEBUG_OUTPUT);
return pid;
}
--- 394,398 ----
f_out = to_child_pipe[1];
! output.information(F_("child created - pid %d") % pid, DEBUG_OUTPUT);
return pid;
}
***************
*** 473,478 ****
execlp(ssh_command.c_str(), ssh_command.c_str(),
(username + destination_host).c_str(),cmd.c_str(), NULL);
! output.critical("Could not execute \n\"" + ssh_command + username
! + destination_host + cmd, errno);
}
--- 455,461 ----
execlp(ssh_command.c_str(), ssh_command.c_str(),
(username + destination_host).c_str(),cmd.c_str(), NULL);
! output.critical(F_("Could not execute '%s %s%s %s'")
! % ssh_command % username % destination_host
! % cmd, errno);
}
***************
*** 492,498 ****
d = opendir(directory.c_str());
! if( d == (DIR *) 0 )
! {
! output.critical("opendir(\"" + directory + "\"): " , errno);
}
lastt = 0;
--- 475,480 ----
d = opendir(directory.c_str());
! if( d == (DIR *) 0 ) {
! output.critical(F_("opendir %s") % directory, errno);
}
lastt = 0;
***************
*** 535,541 ****
temp = directory + de->d_name;
ret = lstat( temp.c_str(), &st );
! if( ret < 0 )
! {
! output.critical(string("lstat(") + temp + "): " , errno);
}
--- 517,522 ----
temp = directory + de->d_name;
ret = lstat( temp.c_str(), &st );
! if( ret < 0 ) {
! output.critical(F_("lstat %s") % temp, errno);
}
***************
*** 599,603 ****
d = opendir(directory.c_str());
if( d == (DIR *) 0 ) {
! output.critical("opendir(\"" + directory + "\"): " , errno);
}
--- 580,584 ----
d = opendir(directory.c_str());
if( d == (DIR *) 0 ) {
! output.critical(F_("opendir %s") % directory, errno);
}
***************
*** 614,618 ****
if(lstat( (directory + entry).c_str(), &st ) < 0 )
{
! output.warning(string("lstat(") + directory + entry + "): " , errno);
continue;
}
--- 595,599 ----
if(lstat( (directory + entry).c_str(), &st ) < 0 )
{
! output.warning(F_("lstat %s%s") % directory % entry, errno);
continue;
}
***************
*** 690,694 ****
ret = rename( dir.c_str(), temp.c_str() );
if( ret<0 ) {
! output.non_critical(string("rename(\"") + dir + " , " + temp + "\"): " , errno );
return( ret );
}
--- 671,675 ----
ret = rename( dir.c_str(), temp.c_str() );
if( ret<0 ) {
! output.non_critical(F_("rename %s to %s") % dir, errno );
return( ret );
}
***************
*** 714,718 ****
ret = rename( dir.c_str(), temp.c_str() );
if( ret<0 ) {
! output.non_critical(string("rename(\"") + dir + " , " + temp + "\"): " , errno );
return( ret );
}
--- 695,699 ----
ret = rename( dir.c_str(), temp.c_str() );
if( ret<0 ) {
! output.non_critical(F_("rename %s to %s") % dir % temp, errno );
return( ret );
}
***************
*** 727,734 ****
{
int state = 0;
! output.information("delete File: " + fileName, NORMAL_OUTPUT);
state = remove(fileName.c_str());
if (state != 0)
! output.warning("Could not remove file " + fileName , errno);
}
--- 708,716 ----
{
int state = 0;
! output.information(F_("delete File: %s") % fileName, NORMAL_OUTPUT);
state = remove(fileName.c_str());
if (state != 0)
! output.warning(F_("Could not remove file %s")
! % fileName , errno);
}
***************
*** 742,752 ****
if ( (fd_source = open(source.c_str(), O_RDONLY)) ==- 1)
! output.critical("cannot open file for reading " + source, errno);
if ( (fd_dest = open(destination.c_str(), O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IRGRP)) == -1)
! output.critical("cannot open file for writing " + destination, errno);
if (fstat(fd_source, &st) < 0)
! output.critical("fstat error " + source, errno);
if(st.st_size == 0) {
--- 724,736 ----
if ( (fd_source = open(source.c_str(), O_RDONLY)) ==- 1)
! output.critical(F_("cannot open file %s for reading")
! % source, errno);
if ( (fd_dest = open(destination.c_str(), O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IRGRP)) == -1)
! output.critical(F_("cannot open file %s for writing")
! % destination, errno);
if (fstat(fd_source, &st) < 0)
! output.critical(F_("fstat %s") % source, errno);
if(st.st_size == 0) {
***************
*** 756,769 ****
else {
if (lseek(fd_dest, st.st_size-1, SEEK_SET) == -1)
! output.critical("lseek error " + destination, errno);
if (write(fd_dest, "", 1) != 1)
! output.critical("write error " + destination, errno);
if ( (source_mem = mmap(0, st.st_size, PROT_READ, MAP_SHARED, fd_source, 0)) == NULL)
! output.critical("mmap error " + source, errno);
if ( (dest_mem = mmap(0, st.st_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd_dest, 0)) == NULL)
! output.critical("mmap error " + destination, errno);
memcpy(dest_mem, source_mem, st.st_size);
--- 740,753 ----
else {
if (lseek(fd_dest, st.st_size-1, SEEK_SET) == -1)
! output.critical(F_("lseek %s") % destination, errno);
if (write(fd_dest, "", 1) != 1)
! output.critical(F_("write %s") % destination, errno);
if ( (source_mem = mmap(0, st.st_size, PROT_READ, MAP_SHARED, fd_source, 0)) == NULL)
! output.critical(F_("mmap %s") % source, errno);
if ( (dest_mem = mmap(0, st.st_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd_dest, 0)) == NULL)
! output.critical(F_("mmap %s") % destination, errno);
memcpy(dest_mem, source_mem, st.st_size);
***************
*** 771,775 ****
if (munmap(source_mem, st.st_size) == -1 ||
munmap(dest_mem, st.st_size) == -1)
! output.critical("munmap error", errno);
close(fd_source);
--- 755,759 ----
if (munmap(source_mem, st.st_size) == -1 ||
munmap(dest_mem, st.st_size) == -1)
! output.critical(_("munmap error"), errno);
close(fd_source);
***************
*** 787,804 ****
if ( (fd_source = open(source.c_str(), O_RDONLY)) ==- 1) {
! perror("kann Quelldatei nicht ?ffnen\n");
! exit(EXIT_FAILURE);
}
if ( (fd_dest = open(destination.c_str(), O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IRGRP)) == -1) {
! perror("kann Zieldatei nicht schreiben\n");
! exit(EXIT_FAILURE);
}
while ( (n = read(fd_source, puffer, BUFFER_SIZE)) > 0) {
if (write(fd_dest, puffer, n) != n)
! perror("Fehler beim Schreiben");
}
if (n < 0)
! perror("Fehler beim Lesen");
close(fd_source);
--- 771,790 ----
if ( (fd_source = open(source.c_str(), O_RDONLY)) ==- 1) {
! output.critical(F_("cannot open %s for reading")
! % source, errno);
}
if ( (fd_dest = open(destination.c_str(), O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IRGRP)) == -1) {
! output.critical(F_("cannot open %s for writing")
! % destination, errno);
}
while ( (n = read(fd_source, puffer, BUFFER_SIZE)) > 0) {
if (write(fd_dest, puffer, n) != n)
! output.critical(F_("cannot write %s")
! % destination, errno);
}
if (n < 0)
! output.critical(F_("cannot read %s")
! % source, errno);
close(fd_source);
***************
*** 826,830 ****
DIR *directory = opendir(dirName.c_str());
if (directory == NULL) {
! output.warning("could not open dir for delete: " + dirName, errno);
return;
}
--- 812,816 ----
DIR *directory = opendir(dirName.c_str());
if (directory == NULL) {
! output.warning(F_("cannot open dir %s") % dirName, errno);
return;
}
***************
*** 841,849 ****
else
if(remove(filename.c_str()) != 0)
! output.warning("could not delete: " + filename, errno);
}
if(closedir(directory)!= 0)
! output.warning("error closing directory " + dirName, errno);
remove(dirName.c_str());
}
--- 827,837 ----
else
if(remove(filename.c_str()) != 0)
! output.warning(F_("could not delete: %s")
! % filename, errno);
}
if(closedir(directory)!= 0)
! output.warning(F_("error closing directory %s")
! % dirName, errno);
remove(dirName.c_str());
}
-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click