33 #include <config-kleopatra.h>
39 #include <KLocalizedString>
45 #include <sys/types.h>
46 #include <sys/socket.h>
53 using namespace boost;
56 QString UiServer::Private::systemErrorString() {
60 void UiServer::Private::doMakeListeningSocket(
const QByteArray & encodedFileName ) {
62 #if defined(HAVE_ASSUAN2) || HAVE_ASSUAN_SOCK_GET_NONCE
63 const assuan_fd_t sock = assuan_sock_new( AF_UNIX, SOCK_STREAM, 0 );
65 const assuan_fd_t sock = ::socket( AF_UNIX, SOCK_STREAM, 0 );
68 throw_<std::runtime_error>( i18n(
"Could not create socket: %1", systemErrorString() ) );
72 struct sockaddr_un sa;
73 std::memset( &sa, 0,
sizeof(sa) );
74 sa.sun_family = AF_UNIX;
75 std::strncpy( sa.sun_path, encodedFileName.
constData(),
sizeof( sa.sun_path ) - 1 );
76 #if defined(HAVE_ASSUAN2) || defined(HAVE_ASSUAN_SOCK_GET_NONCE)
77 if ( assuan_sock_bind( sock, (
struct sockaddr*)&sa,
sizeof( sa ) ) )
79 if ( ::bind( sock, (
struct sockaddr*)&sa,
sizeof( sa ) ) )
81 throw_<std::runtime_error>( i18n(
"Could not bind to socket: %1", systemErrorString() ) );
85 #if defined(HAVE_ASSUAN2) || defined(HAVE_ASSUAN_SOCK_GET_NONCE)
86 if ( assuan_sock_get_nonce( (
struct sockaddr*)&sa,
sizeof( sa ), &nonce ) )
87 throw_<std::runtime_error>( i18n(
"Could not get socket nonce: %1", systemErrorString() ) );
91 if ( ::listen( sock, SOMAXCONN ) )
92 throw_<std::runtime_error>( i18n(
"Could not listen to socket: %1", systemErrorString() ) );
94 if ( !setSocketDescriptor( sock ) )
95 throw_<std::runtime_error>( i18n(
"Could not pass socket to Qt: %1. This should not happen, please report this bug.", errorString() ) );
QString fromLocal8Bit(const char *str, int size)
#define ASSUAN_INVALID_FD
const char * constData() const