-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
apply_scgi: try to avoid removing socket opened by another instance
This change prevents a rTorrent instance that may be erroneously launched from removing the socket of the existing rTorrent instance.
- Loading branch information
Showing
1 changed file
with
19 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,8 @@ | |
// Copyright (C) 2005-2011, Jari Sundell <[email protected]> | ||
|
||
#include <cstdio> | ||
#include <filesystem> | ||
#include <fstream> | ||
#include <functional> | ||
#include <limits> | ||
#include <torrent/common.h> | ||
|
@@ -194,8 +196,25 @@ apply_scgi(const std::string& arg, int type) { | |
default: | ||
path = torrent::utils::path_expand(arg); | ||
|
||
// Try to avoid removing socket opened by another instance | ||
if (std::filesystem::is_socket(path) && | ||
std::filesystem::exists("/proc/net/unix")) { | ||
try { | ||
auto list = std::ifstream("/proc/net/unix"); | ||
std::string entry; | ||
while (std::getline(list, entry)) { | ||
if (entry.find(path) != std::string::npos) { | ||
throw torrent::input_error("Socket already in use."); | ||
} | ||
} | ||
} catch (std::ios_base::failure&) { | ||
// do nothing. | ||
} | ||
} | ||
|
||
unlink(path.c_str()); | ||
scgi->open_named(path); | ||
|
||
break; | ||
} | ||
|
||
|