Author: mlandres
Date: Thu Mar 13 12:36:22 2008
New Revision: 9112
URL: http://svn.opensuse.org/viewcvs/zypp?rev=9112&view=rev
Log:
Add ExternalProgram::execError and ExternalProgram::command to improve error reporting.
Modified:
trunk/libzypp/zypp/ExternalProgram.cc
trunk/libzypp/zypp/ExternalProgram.h
Modified: trunk/libzypp/zypp/ExternalProgram.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/ExternalProgram.cc?rev=9112&r1=9111&r2=9112&view=diff
==============================================================================
--- trunk/libzypp/zypp/ExternalProgram.cc (original)
+++ trunk/libzypp/zypp/ExternalProgram.cc Thu Mar 13 12:36:22 2008
@@ -24,6 +24,8 @@
#include <sstream>
#include "zypp/base/Logger.h"
+#include "zypp/base/String.h"
+#include "zypp/base/Gettext.h"
#include "zypp/ExternalProgram.h"
using namespace std;
@@ -136,14 +138,32 @@
int to_external[2], from_external[2]; // fds for pair of pipes
int master_tty, slave_tty; // fds for pair of ttys
+ // do not remove the single quotes around every argument, copy&paste of
+ // command to shell will not work otherwise!
+ {
+ stringstream cmdstr;
+ for (int i = 0; argv[i]; i++)
+ {
+ if (i>0) cmdstr << ' ';
+ cmdstr << '\'';
+ cmdstr << argv[i];
+ cmdstr << '\'';
+ }
+ _command = cmdstr.str();
+ }
+ DBG << "Executing " << _command << endl;
+
+
if (use_pty)
{
// Create pair of ttys
- DBG << "Using ttys for communication with " << argv[0] << endl;
+ DBG << "Using ttys for communication with " << argv[0] << endl;
if (openpty (&master_tty, &slave_tty, 0, 0, 0) != 0)
{
- ERR << "openpty failed" << endl;
- return;
+ _execError = str::form( _("Can't open pty (%s)."), strerror(errno) );
+ _exitStatus = 126;
+ ERR << _execError << endl;
+ return;
}
}
else
@@ -151,26 +171,13 @@
// Create pair of pipes
if (pipe (to_external) != 0 || pipe (from_external) != 0)
{
- ERR << "pipe failed" << endl;
- return;
+ _execError = str::form( _("Can't open pipe (%s)."), strerror(errno) );
+ _exitStatus = 126;
+ ERR << _execError << endl;
+ return;
}
}
- // do not remove the single quotes around every argument, copy&paste of
- // command to shell will not work otherwise!
-
- stringstream cmdstr;
-
- cmdstr << "Executing ";
- for (int i = 0; argv[i]; i++)
- {
- if (i>0) cmdstr << ' ';
- cmdstr << '\'';
- cmdstr << argv[i];
- cmdstr << '\'';
- }
- DBG << cmdstr.str() << endl;
-
// Create module process
if ((pid = fork()) == 0)
{
@@ -228,13 +235,17 @@
{
if(chroot(root) == -1)
{
- ERR << "chroot to " << root << " failed: " << strerror(errno) << endl;
- _exit (3); // No sense in returning! I am forked away!!
+ _execError = str::form( _("Can't chroot to '%s' (%s)."), root, strerror(errno) );
+ ERR << _execError << endl;
+ std::cerr << _execError << endl;// After fork log on stderr too
+ _exit (128); // No sense in returning! I am forked away!!
}
if(chdir("/") == -1)
{
- ERR << "chdir to / inside chroot failed: " << strerror(errno) << endl;
- _exit (4); // No sense in returning! I am forked away!!
+ _execError = str::form( _("Can't chdir to '/' inside chroot (%s)."), strerror(errno) );
+ ERR << _execError << endl;
+ std::cerr << _execError << endl;// After fork log on stderr too
+ _exit (128); // No sense in returning! I am forked away!!
}
}
@@ -244,14 +255,20 @@
}
execvp(argv[0], const_cast