OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/process_singleton.h" | 5 #include "chrome/browser/process_singleton.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <sys/types.h> | 8 #include <sys/types.h> |
9 #include <sys/socket.h> | 9 #include <sys/socket.h> |
10 #include <sys/un.h> | 10 #include <sys/un.h> |
11 | 11 |
| 12 #include "base/eintr_wrappers.h" |
12 #include "base/logging.h" | 13 #include "base/logging.h" |
13 #include "base/string_util.h" | 14 #include "base/string_util.h" |
14 #include "chrome/common/chrome_constants.h" | 15 #include "chrome/common/chrome_constants.h" |
15 | 16 |
16 ProcessSingleton::ProcessSingleton(const FilePath& user_data_dir) { | 17 ProcessSingleton::ProcessSingleton(const FilePath& user_data_dir) { |
17 socket_path_ = user_data_dir.Append(chrome::kSingletonSocketFilename); | 18 socket_path_ = user_data_dir.Append(chrome::kSingletonSocketFilename); |
18 } | 19 } |
19 | 20 |
20 ProcessSingleton::~ProcessSingleton() { | 21 ProcessSingleton::~ProcessSingleton() { |
21 } | 22 } |
22 | 23 |
23 bool ProcessSingleton::NotifyOtherProcess() { | 24 bool ProcessSingleton::NotifyOtherProcess() { |
24 int sock; | 25 int sock; |
25 sockaddr_un addr; | 26 sockaddr_un addr; |
26 SetupSocket(&sock, &addr); | 27 SetupSocket(&sock, &addr); |
27 | 28 |
28 if (connect(sock, reinterpret_cast<sockaddr*>(&addr), sizeof(addr)) < 0 && | 29 if (HANDLE_EINTR(connect(sock, reinterpret_cast<sockaddr*>(&addr), |
| 30 sizeof(addr))) < 0 && |
29 (errno == ENOENT || errno == ECONNREFUSED)) { | 31 (errno == ENOENT || errno == ECONNREFUSED)) { |
30 return false; // Tell the caller there's nobody to notify. | 32 return false; // Tell the caller there's nobody to notify. |
31 } | 33 } |
32 | 34 |
33 // TODO(port): pass in info to the other process. | 35 // TODO(port): pass in info to the other process. |
34 // http://code.google.com/p/chromium/issues/detail?id=8073 | 36 // http://code.google.com/p/chromium/issues/detail?id=8073 |
35 NOTIMPLEMENTED() << " don't know how to notify other process about us."; | 37 NOTIMPLEMENTED() << " don't know how to notify other process about us."; |
36 | 38 |
37 return true; // We did our best, so we die here. | 39 return true; // We did our best, so we die here. |
38 } | 40 } |
(...skipping 19 matching lines...) Expand all Loading... |
58 | 60 |
59 void ProcessSingleton::SetupSocket(int* sock, struct sockaddr_un* addr) { | 61 void ProcessSingleton::SetupSocket(int* sock, struct sockaddr_un* addr) { |
60 *sock = socket(PF_UNIX, SOCK_STREAM, 0); | 62 *sock = socket(PF_UNIX, SOCK_STREAM, 0); |
61 if (*sock < 0) | 63 if (*sock < 0) |
62 LOG(FATAL) << "socket() failed: " << strerror(errno); | 64 LOG(FATAL) << "socket() failed: " << strerror(errno); |
63 | 65 |
64 addr->sun_family = AF_UNIX; | 66 addr->sun_family = AF_UNIX; |
65 base::strlcpy(addr->sun_path, socket_path_.value().c_str(), | 67 base::strlcpy(addr->sun_path, socket_path_.value().c_str(), |
66 sizeof(addr->sun_path)); | 68 sizeof(addr->sun_path)); |
67 } | 69 } |
OLD | NEW |