summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Moreau <oreaus@gmail.com>2009-10-26 12:15:28 -0600
committerScott Moreau <oreaus@gmail.com>2009-10-26 12:15:28 -0600
commitfadb5a76a1dd8f2ab11d50bb136e66a4b2f2e2f5 (patch)
treef2aadf35260ebeac5045b0e050aecc1a4db32b7f
parentd259053a6003c81ff762139b1909104c59e47193 (diff)
downloadstartup-fadb5a76a1dd8f2ab11d50bb136e66a4b2f2e2f5.tar.gz
startup-fadb5a76a1dd8f2ab11d50bb136e66a4b2f2e2f5.tar.bz2
Error if environment variables are not set
-rw-r--r--src/startup.cpp58
-rw-r--r--src/startup.h16
2 files changed, 39 insertions, 35 deletions
diff --git a/src/startup.cpp b/src/startup.cpp
index f760645..2f6c952 100644
--- a/src/startup.cpp
+++ b/src/startup.cpp
@@ -28,12 +28,19 @@ void
StartupScreen::RunCommands()
{
updateOptions();
-
+
for (int i = 0; i < numCommands; i++)
{
// We're running the commands. FIXME: There may be a neater way to set this bool
if ( i == 0)
ranCommands = true;
+
+ if (error)
+ {
+ compLogMessage ("startup", CompLogLevelError, "An error occurred, doing nothing.");
+ return;
+ }
+ // else
// If first time in this session, run all commands except with option 2
if ( firstSession && commands[i].interval != 2 )
{
@@ -49,39 +56,35 @@ StartupScreen::RunCommands()
// Hopefully, these will be all of the commands with option 2 :-P
if ( !firstSession && !alreadyRunning && commands[i].interval == 2 )
screen->runCommand ( commands[i].command );
-
}
+
+ return;
}
void
StartupScreen::UpdateStatus()
{
-
- char* dbus_env_var = getenv("DBUS_SESSION_BUS_ADDRESS");
- char* dsp = getenv("DISPLAY");
- char* home = getenv("HOME");
-
- if( dbus_env_var == NULL )
- {
- compLogMessage ("startup", CompLogLevelWarn, "Environment variable DBUS_SESSION_BUS_ADDRESS is not set");
- return;
- }
- if( dsp == NULL )
- {
- compLogMessage ("startup", CompLogLevelWarn, "Environment variable DISPLAY is not set");
- return;
- }
- if( home == NULL )
- {
- compLogMessage ("startup", CompLogLevelWarn, "Environment variable HOME is not set");
- return;
+
+#define GET_ENV_VAR(ourvar, envvar, error) \
+ char* ourvar = getenv(#envvar); \
+ if ( ourvar == NULL ) \
+ { \
+ compLogMessage ("startup", CompLogLevelError, "Environment variable " #envvar " is not set");\
+ error = true; \
+ return; \
}
+
+ GET_ENV_VAR (dbus_env_var, DBUS_SESSION_BUS_ADDRESS, error)
+ GET_ENV_VAR (dsp, DISPLAY, error)
+ GET_ENV_VAR (home, HOME, error)
+#undef GET_ENV_VAR
+
// We're only interested in the dbus ID
CompString s(dbus_env_var);
size_t idx = s.find("guid=");
CompString dbus_id = s.substr(idx+5) + "\n";
-
-
+
+
std::fstream lock;
int nCompLock = 0;
int nCompPid = getpid();
@@ -89,7 +92,7 @@ StartupScreen::UpdateStatus()
lockdir.insert (0,home);
CompString compLockFile = lockdir + "complock" + dsp;
CompString xLockFile = lockdir + "xlock" + dsp;
-
+
lock.open(xLockFile.c_str (), std::ios::in);
if (!lock)
{
@@ -168,7 +171,7 @@ StartupScreen::UpdateStatus()
lock.close ();
return;
}
-
+
return;
}
@@ -182,7 +185,7 @@ StartupWindow::damageRect (bool initial,
ss->RunCommands();
else
cWindow->damageRectSetEnabled (this, false);
-
+
return cWindow->damageRect (initial, rect);
}
@@ -213,6 +216,7 @@ StartupScreen::updateOptions ()
}
UpdateStatus ();
+
return;
}
@@ -230,7 +234,7 @@ StartupScreen::StartupScreen (CompScreen *screen) :
optionSetPostStartupCommandNotify (boost::bind (&StartupScreen::
optionChanged, this, _1, _2));
- ranCommands = firstRun = firstSession = alreadyRunning = false;
+ ranCommands = firstRun = firstSession = alreadyRunning = error = false;
updateOptions ();
}
diff --git a/src/startup.h b/src/startup.h
index 33ce887..9582387 100644
--- a/src/startup.h
+++ b/src/startup.h
@@ -10,7 +10,7 @@
class StartupCommand
{
public:
-
+
CompString command;
int interval;
};
@@ -28,18 +28,18 @@ class StartupScreen :
CompositeScreen *cScreen;
- bool ranCommands, firstRun, firstSession, alreadyRunning;
-
+ bool ranCommands, firstRun, firstSession, alreadyRunning, error;
+
StartupCommands commands;
-
+
int numCommands;
-
+
void updateOptions ();
-
+
void UpdateStatus ();
-
+
void RunCommands ();
-
+
void optionChanged (CompOption*, Options);
};