netwerk/ipc/RemoteOpenFileParent.cpp

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* vim: set sw=2 ts=8 et tw=80 : */
michael@0 3
michael@0 4 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 5 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 7
michael@0 8 #include "mozilla/net/RemoteOpenFileParent.h"
michael@0 9 #include "mozilla/unused.h"
michael@0 10 #include "nsEscape.h"
michael@0 11
michael@0 12 #if !defined(XP_WIN) && !defined(MOZ_WIDGET_COCOA)
michael@0 13 #include <fcntl.h>
michael@0 14 #include <unistd.h>
michael@0 15 #endif
michael@0 16
michael@0 17 namespace mozilla {
michael@0 18 namespace net {
michael@0 19
michael@0 20 bool
michael@0 21 RemoteOpenFileParent::OpenSendCloseDelete()
michael@0 22 {
michael@0 23 #if defined(XP_WIN) || defined(MOZ_WIDGET_COCOA)
michael@0 24 MOZ_CRASH("OS X and Windows shouldn't be doing IPDL here");
michael@0 25 #else
michael@0 26
michael@0 27 // TODO: make this async!
michael@0 28
michael@0 29 FileDescriptor fileDescriptor;
michael@0 30
michael@0 31 nsAutoCString path;
michael@0 32 nsresult rv = mURI->GetFilePath(path);
michael@0 33 NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "GetFilePath failed!");
michael@0 34
michael@0 35 NS_UnescapeURL(path);
michael@0 36
michael@0 37 if (NS_SUCCEEDED(rv)) {
michael@0 38 int fd = open(path.get(), O_RDONLY);
michael@0 39 if (fd == -1) {
michael@0 40 printf_stderr("RemoteOpenFileParent: file '%s' was not found!\n",
michael@0 41 path.get());
michael@0 42 } else {
michael@0 43 fileDescriptor = FileDescriptor(fd);
michael@0 44 }
michael@0 45 }
michael@0 46
michael@0 47 // Sending a potentially invalid file descriptor is just fine.
michael@0 48 unused << Send__delete__(this, fileDescriptor);
michael@0 49
michael@0 50 if (fileDescriptor.IsValid()) {
michael@0 51 // close file now that other process has it open, else we'll leak fds in the
michael@0 52 // parent process.
michael@0 53 close(fileDescriptor.PlatformHandle());
michael@0 54 }
michael@0 55
michael@0 56 #endif // OS_TYPE
michael@0 57
michael@0 58 return true;
michael@0 59 }
michael@0 60
michael@0 61 } // namespace net
michael@0 62 } // namespace mozilla

mercurial