const int kMaxPendingConnection = 128;
const uid_t kRegularUidMin = 5000;
+void CreatePreviousSocketFile() {
+ auto path = std::format("{}/{}/.launchpad-process-pool-sock",
+ kRunAulDaemonsPath, getuid());
+ int fd = open(path.c_str(), O_RDWR | O_CREAT,
+ S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
+ if (fd != 0) {
+ _E("open() is failed. errno=%d", errno);
+ return;
+ }
+
+ close(fd);
+}
+
int GetLaunchpadFdFromSystemd() {
auto path = std::format("{}-{}", kLaunchpadProcessPoolSock, getuid());
path[0] = '\0';
}
ServerSocket* GetLaunchpadSocket() {
- int marker;
- char path[PATH_MAX] = {0,};
-
- //TODO(Abstract Socket Issue): file-based socket check
int fd = GetLaunchpadFdFromSystemd();
if (fd < 0) fd = GetLaunchpadFdFromEnvironment();
if (fd > -1) {
- snprintf(path, PATH_MAX, "%s%d/%s",
- kRunAulDaemonsPath, getuid(), kLaunchpadProcessPoolSock);
- marker = open(path, O_RDWR | O_CREAT,
- S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
- close(marker);
-
+ CreatePreviousSocketFile();
return new ServerSocket(fd);
- } else {
- auto* socket = new ServerSocket();
- const std::string endpoint = std::string(kLaunchpadProcessPoolSock) + "-" +
- std::to_string(getuid());
- socket->Bind(endpoint);
- socket->SetReceiveBufferSize(kReceivedBufferSize);
- socket->Listen(kMaxPendingConnection);
+ }
- snprintf(path, PATH_MAX, "%s%d/%s",
- kRunAulDaemonsPath, getuid(), kLaunchpadProcessPoolSock);
- marker = open(path, O_RDWR | O_CREAT,
- S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
- close(marker);
+ auto* socket = new ServerSocket();
+ auto endpoint = std::format("{}-{}", kLaunchpadProcessPoolSock, getuid());
+ socket->Bind(endpoint);
+ socket->SetReceiveBufferSize(kReceivedBufferSize);
+ socket->Listen(kMaxPendingConnection);
- return socket;
- }
+ CreatePreviousSocketFile();
+ return socket;
}
void PrintAppInfo(const AppInfo* app_info) {