|
@@ -16,25 +16,16 @@
|
|
|
|
|
|
#include "util.h"
|
|
|
|
|
|
+extern "C" bool rs_add_mcookie(const char*, const char*, const char*, const char*);
|
|
|
+
|
|
|
/*
|
|
|
* Adds the given cookie to the specified Xauthority file.
|
|
|
* Returns true on success, false on fault.
|
|
|
*/
|
|
|
bool Util::add_mcookie(const std::string &mcookie, const char *display,
|
|
|
- const std::string &xauth_cmd, const std::string &authfile)
|
|
|
+ const std::string &xauth_cmd, const std::string &authfile)
|
|
|
{
|
|
|
- FILE *fp;
|
|
|
- std::string cmd = xauth_cmd + " -f " + authfile + " -q";
|
|
|
-
|
|
|
- fp = popen(cmd.c_str(), "w");
|
|
|
- if (!fp)
|
|
|
- return false;
|
|
|
- fprintf(fp, "remove %s\n", display);
|
|
|
- fprintf(fp, "add %s %s %s\n", display, ".", mcookie.c_str());
|
|
|
- fprintf(fp, "exit\n");
|
|
|
-
|
|
|
- pclose(fp);
|
|
|
- return true;
|
|
|
+ return rs_add_mcookie(mcookie.c_str(), display, xauth_cmd.c_str(), authfile.c_str());
|
|
|
}
|
|
|
|
|
|
/*
|
|
@@ -43,12 +34,12 @@ bool Util::add_mcookie(const std::string &mcookie, const char *display,
|
|
|
*/
|
|
|
void Util::srandom(unsigned long seed)
|
|
|
{
|
|
|
- ::srandom(seed);
|
|
|
+ ::srandom(seed);
|
|
|
}
|
|
|
|
|
|
long Util::random(void)
|
|
|
{
|
|
|
- return ::random();
|
|
|
+ return ::random();
|
|
|
}
|
|
|
|
|
|
/*
|
|
@@ -57,13 +48,13 @@ long Util::random(void)
|
|
|
*/
|
|
|
long Util::makeseed(void)
|
|
|
{
|
|
|
- struct timespec ts;
|
|
|
- long pid = getpid();
|
|
|
- long tm = time(NULL);
|
|
|
+ struct timespec ts;
|
|
|
+ long pid = getpid();
|
|
|
+ long tm = time(NULL);
|
|
|
|
|
|
- if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) {
|
|
|
- ts.tv_sec = ts.tv_nsec = 0;
|
|
|
- }
|
|
|
+ if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) {
|
|
|
+ ts.tv_sec = ts.tv_nsec = 0;
|
|
|
+ }
|
|
|
|
|
|
- return pid + tm + (ts.tv_sec ^ ts.tv_nsec);
|
|
|
+ return pid + tm + (ts.tv_sec ^ ts.tv_nsec);
|
|
|
}
|