X-Git-Url: https://git.decadent.org.uk/gitweb/?p=videolink.git;a=blobdiff_plain;f=framebuffer.cpp;h=c9dc31f7159b0fd20c7d5e1a634f18fc48792a96;hp=eab879a34eeb3d940bf9f717cddb091087c507c5;hb=fed762f0b70eeb556c4b1bd660beb129099e8068;hpb=90012acc26c4a8210c4bce3dac69a09309cce9f8 diff --git a/framebuffer.cpp b/framebuffer.cpp index eab879a..c9dc31f 100644 --- a/framebuffer.cpp +++ b/framebuffer.cpp @@ -1,6 +1,8 @@ // Copyright 2005 Ben Hutchings . // See the file "COPYING" for licence details. +#include "framebuffer.hpp" + #include #include #include @@ -15,8 +17,8 @@ #include #include -#include "framebuffer.hpp" #include "auto_fd.hpp" +#include "temp_file.hpp" namespace { @@ -56,18 +58,9 @@ namespace throw std::runtime_error(std::strerror(errno)); } - auto_temp_file create_temp_auth_file(int display_num) + std::auto_ptr create_temp_auth_file(int display_num) { - char auth_file_name[] = "/tmp/Xvfb-auth-XXXXXX"; - auto_fd auth_file_fd(mkstemp(auth_file_name)); - if (auth_file_fd.get() == -1) - throw std::runtime_error(std::strerror(errno)); - auto_temp_file auth_file(auth_file_name); - - // mkstemp may use lax permissions, so fix that before writing - // the auth data to it. - fchmod(auth_file_fd.get(), S_IREAD|S_IWRITE); - ftruncate(auth_file_fd.get(), 0); + std::auto_ptr auth_file(new temp_file("Xvfb-auth-")); // An xauth entry consists of the following fields. All u16 fields // are big-endian and unaligned. Character arrays are not null- @@ -82,27 +75,27 @@ namespace // u16 length of auth data (= 16) // char[] auth data (= random bytes) uint16_t family = htons(0x100); - write(auth_file_fd.get(), &family, sizeof(family)); + write(auth_file->get_fd(), &family, sizeof(family)); utsname my_uname; uname(&my_uname); uint16_t len = htons(strlen(my_uname.nodename)); - write(auth_file_fd.get(), &len, sizeof(len)); - write(auth_file_fd.get(), + write(auth_file->get_fd(), &len, sizeof(len)); + write(auth_file->get_fd(), my_uname.nodename, strlen(my_uname.nodename)); char display[15]; std::sprintf(display, "%d", display_num); len = htons(strlen(display)); - write(auth_file_fd.get(), &len, sizeof(len)); - write(auth_file_fd.get(), display, strlen(display)); + write(auth_file->get_fd(), &len, sizeof(len)); + write(auth_file->get_fd(), display, strlen(display)); static const char auth_type[] = "MIT-MAGIC-COOKIE-1"; len = htons(sizeof(auth_type) - 1); - write(auth_file_fd.get(), &len, sizeof(len)); - write(auth_file_fd.get(), auth_type, sizeof(auth_type) - 1); + write(auth_file->get_fd(), &len, sizeof(len)); + write(auth_file->get_fd(), auth_type, sizeof(auth_type) - 1); unsigned char auth_key[16]; get_random_bytes(auth_key, sizeof(auth_key)); len = htons(sizeof(auth_key)); - write(auth_file_fd.get(), &len, sizeof(len)); - write(auth_file_fd.get(), auth_key, sizeof(auth_key)); + write(auth_file->get_fd(), &len, sizeof(len)); + write(auth_file->get_fd(), auth_key, sizeof(auth_key)); return auth_file; } @@ -167,7 +160,7 @@ FrameBuffer::FrameBuffer(int width, int height, int depth) std::string FrameBuffer::get_x_authority() const { - return auth_file_.get(); + return auth_file_->get_name(); } std::string FrameBuffer::get_x_display() const