Skip to content

Commit

Permalink
Check for DISPLAY variable.
Browse files Browse the repository at this point in the history
  • Loading branch information
Giovanni [dacav] Simoni committed Jun 14, 2010
1 parent e910969 commit 6136a5b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/gnup/pipe.hpp
Expand Up @@ -21,12 +21,14 @@ namespace gnup {
void command (const char *fmt, ...);

protected:
Comm (const char *prog) throw (CommError);
Comm (const char *prog, bool req_X) throw (CommError);

private:
pid_t child;
FILE *output;

void checkX() throw (CommError);

};

}
Expand Down
2 changes: 1 addition & 1 deletion src/gp_base.cpp
Expand Up @@ -62,7 +62,7 @@ namespace gnup {
}

GnuPlot::GnuPlot (size_t dims, const char *prog) throw (CommError)
: Comm(prog)
: Comm(prog, true)
{
dimensions = dims;
}
Expand Down
14 changes: 13 additions & 1 deletion src/pipe.cpp
Expand Up @@ -10,10 +10,14 @@

namespace gnup {

Comm::Comm (const char *prog) throw (CommError)
Comm::Comm (const char *prog, bool req_X) throw (CommError)
{
int pipefd[2];

if (req_X) {
checkX();
}

if (pipe(pipefd) == -1) {
CommError err("Unable to pipe");
throw err;
Expand Down Expand Up @@ -42,6 +46,14 @@ namespace gnup {
output = fdopen(pipefd[1], "a");
}

void Comm::checkX () throw (CommError)
{
if (getenv("DISPLAY") == NULL) {
CommError err("Cannot find DISPLAY variable");
throw err;
}
}

Comm::~Comm ()
{
fclose(output);
Expand Down

0 comments on commit 6136a5b

Please sign in to comment.