/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
/* Only give access to all if no security handle was specified, otherwise security
depends on umask */
if (!Security)
(void)chmod(name.getStr(),S_IRWXU | S_IRWXG |S_IRWXO);
strcpy(pPipe->m_Name, name.getStr()); // safe, see check above
if (listen(pPipe->m_Socket, 5) < 0)
{
SAL_WARN("sal.osl.pipe", "listen() failed: " << UnixErrnoString(errno)); // cid#1255391 warns about unlink(name) after stat(name, &status) // above, but the intervening call to bind makes those two clearly // unrelated, as it would fail if name existed at that point in // time: // coverity[toctou] - this is bogus
unlink(name.getStr()); /* remove filesystem entry */
close(pPipe->m_Socket);
destroyPipeImpl(pPipe); return nullptr;
}
return pPipe;
}
/* osl_pipe_OPEN */ if (access(name.getStr(), F_OK) != -1)
{ if (connect(pPipe->m_Socket, reinterpret_cast< sockaddr* >(&addr), len) >= 0) return pPipe;
void SAL_CALL osl_releasePipe(oslPipe pPipe)
{ if (!pPipe) return;
if (osl_atomic_decrement(&(pPipe->m_nRefCount)) == 0)
{
osl_closePipe(pPipe);
destroyPipeImpl(pPipe);
}
}
void SAL_CALL osl_closePipe(oslPipe pPipe)
{ int nRet; int ConnFD;
if (!pPipe) return;
std::unique_lock aGuard(pPipe->m_Mutex);
if (pPipe->m_bClosed) return;
ConnFD = pPipe->m_Socket;
/* Thread does not return from accept on linux, so connect to the accepting pipe
*/ #ifdefined(CLOSESOCKET_DOESNT_WAKE_UP_ACCEPT) struct sockaddr_un addr;
if (pPipe->m_bIsAccepting)
{
pPipe->m_bIsInShutdown = true;
pPipe->m_Socket = -1;
int fd = socket(AF_UNIX, SOCK_STREAM, 0); if (fd < 0)
{
SAL_WARN("sal.osl.pipe", "socket() failed: " << UnixErrnoString(errno)); return;
}
memset(&addr, 0, sizeof(addr));
SAL_INFO("sal.osl.pipe", "osl_destroyPipe : Pipe Name '" << pPipe->m_Name << "'");
addr.sun_family = AF_UNIX;
strcpy(addr.sun_path, pPipe->m_Name); // safe, as both are same size
/* remove filesystem entry */ if (pPipe->m_Name[0] != '\0')
unlink(pPipe->m_Name);
pPipe->m_bClosed = true;
}
oslPipe SAL_CALL osl_acceptPipe(oslPipe pPipe)
{ int s;
oslPipe pAcceptedPipe;
SAL_WARN_IF(!pPipe, "sal.osl.pipe", "invalid pipe"); if (!pPipe) return nullptr;
int socket;
{ // don't hold lock while accepting, so it is possible to close a socket blocked in accept
std::unique_lock aGuard(pPipe->m_Mutex);
assert(pPipe->m_Name[0] != '\0'); // you cannot have an empty pipe name #ifdefined(CLOSESOCKET_DOESNT_WAKE_UP_ACCEPT)
pPipe->m_bIsAccepting = true; #endif
int socket;
{ // don't hold lock while receiving, so it is possible to close a socket blocked in recv
std::unique_lock aGuard(pPipe->m_Mutex);
socket = pPipe->m_Socket;
}
int socket;
{ // don't hold lock while sending, so it is possible to close a socket blocked in send
std::unique_lock aGuard(pPipe->m_Mutex);
socket = pPipe->m_Socket;
}
nRet = send(socket, pBuffer, BytesToSend, 0);
if (nRet <= 0)
SAL_WARN("sal.osl.pipe", "send() failed: " << UnixErrnoString(errno));
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.