/*
* Copyright (c) [2004-2011] Novell, Inc.
+ * Copyright (c) 2018 SUSE LLC
*
* All Rights Reserved.
*
#include <string>
#include <boost/algorithm/string.hpp>
+extern char **environ;
+
#include "snapper/Log.h"
#include "snapper/AppUtil.h"
#include "snapper/SystemCmd.h"
}
}
y2deb("sout:" << pfds[0].fd << " serr:" << (Combine_b?-1:pfds[1].fd));
+
+ const vector<const char*> env = make_env();
+
switch( (Pid_i=fork()) )
{
case 0:
- setenv( "LC_ALL", "C", 1 );
- setenv( "LANGUAGE", "C", 1 );
if( dup2( sout[1], STDOUT_FILENO )<0 )
{
y2err("dup2 stdout child failed errno:" << errno << " (" << stringerror(errno) << ")");
y2err("close child failed errno:" << errno << " (" << stringerror(errno) << ")");
}
closeOpenFds();
- Ret_i = execl( Shell_Ci.c_str(), Shell_Ci.c_str(), "-c",
- Cmd.c_str(), NULL );
+ Ret_i = execle(Shell_Ci.c_str(), Shell_Ci.c_str(), "-c", Cmd.c_str(), nullptr, &env[0]);
y2err("SHOULD NOT HAPPEN \"" << Shell_Ci << "\" Ret:" << Ret_i);
break;
case -1:
}
+ vector<const char*>
+ SystemCmd::make_env() const
+ {
+ vector<const char*> env;
+
+ for (char** v = environ; *v != NULL; ++v)
+ {
+ if (strncmp(*v, "LC_ALL=", strlen("LC_ALL=")) != 0 &&
+ strncmp(*v, "LANGUAGE=", strlen("LANGUAGE=")) != 0)
+ env.push_back(*v);
+ }
+
+ env.push_back("LC_ALL=C");
+ env.push_back("LANGUAGE=C");
+
+ env.push_back(nullptr);
+
+ return env;
+ }
+
+
string
SystemCmd::quote(const string& str)
{
/*
* Copyright (c) [2004-2014] Novell, Inc.
+ * Copyright (c) 2018 SUSE LLC
*
* All Rights Reserved.
*
void logOutput() const;
+ /**
+ * Constructs the environment for the child process.
+ *
+ * Must not be called after exec since allocating the memory
+ * for the vector is not allowed then (in a multithreaded
+ * program), see fork(2) and signal-safety(7). So simply call
+ * it right before fork.
+ */
+ vector<const char*> make_env() const;
+
FILE* File_aC[2];
std::vector<string> Lines_aC[2];
std::vector<string*> SelLines_aC[2];