aboutsummaryrefslogtreecommitdiff
path: root/src/FbCommands.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/FbCommands.cc')
-rw-r--r--src/FbCommands.cc39
1 files changed, 5 insertions, 34 deletions
diff --git a/src/FbCommands.cc b/src/FbCommands.cc
index 8683711..7ff689e 100644
--- a/src/FbCommands.cc
+++ b/src/FbCommands.cc
@@ -142,8 +142,7 @@ int ExecuteCmd::run() {
142 if (pid) 142 if (pid)
143 return pid; 143 return pid;
144 144
145 string displaystring("DISPLAY="); 145 string display = DisplayString(FbTk::App::instance()->display());
146 displaystring += DisplayString(FbTk::App::instance()->display());
147 int screen_num = m_screen_num; 146 int screen_num = m_screen_num;
148 if (screen_num < 0) { 147 if (screen_num < 0) {
149 if (Fluxbox::instance()->mouseScreen() == 0) 148 if (Fluxbox::instance()->mouseScreen() == 0)
@@ -158,12 +157,11 @@ int ExecuteCmd::run() {
158 if (!shell) 157 if (!shell)
159 shell = "/bin/sh"; 158 shell = "/bin/sh";
160 159
161 // remove last number of display and add screen num 160 display.erase(display.size()-1);
162 displaystring.erase(displaystring.size()-1); 161 display += FbTk::StringUtil::number2String(screen_num);
163 displaystring += FbTk::StringUtil::number2String(screen_num);
164 162
165 setsid(); 163 setsid();
166 putenv(const_cast<char *>(displaystring.c_str())); 164 FbTk::App::setenv("DISPLAY", display.c_str());
167 execl(shell, shell, "-c", m_cmd.c_str(), static_cast<void*>(NULL)); 165 execl(shell, shell, "-c", m_cmd.c_str(), static_cast<void*>(NULL));
168 exit(EXIT_SUCCESS); 166 exit(EXIT_SUCCESS);
169 167
@@ -197,34 +195,7 @@ ExportCmd::ExportCmd(const string& name, const string& value) :
197 195
198void ExportCmd::execute() { 196void ExportCmd::execute() {
199 197
200 // the setenv()-routine is not everywhere available and 198 FbTk::App::instance()->setenv(m_name.c_str(), m_value.c_str());
201 // putenv() doesnt manage the strings in the environment
202 // and hence we have to do that on our own to avoid memleaking
203 static set<char*> stored;
204 char* newenv = new char[m_name.size() + m_value.size() + 2];
205 if (newenv) {
206
207 char* oldenv = getenv(m_name.c_str());
208
209 // oldenv points to the value .. we have to go back a bit
210 if (oldenv && stored.find(oldenv - (m_name.size() + 1)) != stored.end())
211 oldenv -= (m_name.size() + 1);
212 else
213 oldenv = NULL;
214
215 memset(newenv, 0, m_name.size() + m_value.size() + 2);
216 strcat(newenv, m_name.c_str());
217 strcat(newenv, "=");
218 strcat(newenv, m_value.c_str());
219
220 if (putenv(newenv) == 0) {
221 if (oldenv) {
222 stored.erase(oldenv);
223 delete[] oldenv;
224 }
225 stored.insert(newenv);
226 }
227 }
228} 199}
229 200
230REGISTER_COMMAND(exit, FbCommands::ExitFluxboxCmd, void); 201REGISTER_COMMAND(exit, FbCommands::ExitFluxboxCmd, void);