New upstream version 26.1.0+dfsg1
This commit is contained in:
parent
040dcc3fc2
commit
013818c4af
594 changed files with 19576 additions and 4478 deletions
|
|
@ -27,8 +27,151 @@
|
|||
#include <locale.h>
|
||||
|
||||
#include "platform.hpp"
|
||||
|
||||
#ifdef __linux__
|
||||
#include <sys/socket.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/un.h>
|
||||
#endif
|
||||
#if defined(__FreeBSD__) || defined(__DragonFly__)
|
||||
#include <sys/param.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <sys/user.h>
|
||||
#include <libprocstat.h>
|
||||
#include <pthread_np.h>
|
||||
|
||||
#include <condition_variable>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
#endif
|
||||
|
||||
using namespace std;
|
||||
|
||||
#ifdef __linux__
|
||||
void RunningInstanceCheck(bool &already_running)
|
||||
{
|
||||
int uniq = socket(AF_LOCAL, SOCK_DGRAM | SOCK_CLOEXEC, 0);
|
||||
|
||||
if (uniq == -1) {
|
||||
blog(LOG_ERROR,
|
||||
"Failed to check for running instance, socket: %d", errno);
|
||||
already_running = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
struct sockaddr_un bindInfo;
|
||||
memset(&bindInfo, 0, sizeof(sockaddr_un));
|
||||
bindInfo.sun_family = AF_LOCAL;
|
||||
char *abstactSockName = NULL;
|
||||
asprintf(&abstactSockName, "%s %d %s", "/com/obsproject", getpid(),
|
||||
App()->GetVersionString().c_str());
|
||||
memmove(bindInfo.sun_path + 1, abstactSockName,
|
||||
strlen(abstactSockName));
|
||||
free(abstactSockName);
|
||||
|
||||
int bindErr = bind(uniq, (struct sockaddr *)&bindInfo,
|
||||
sizeof(struct sockaddr_un));
|
||||
already_running = bindErr == 0 ? 0 : 1;
|
||||
|
||||
if (already_running) {
|
||||
return;
|
||||
}
|
||||
|
||||
FILE *fp = fopen("/proc/net/unix", "re");
|
||||
|
||||
if (fp == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
char *line = NULL;
|
||||
size_t n = 0;
|
||||
int obsCnt = 0;
|
||||
while (getdelim(&line, &n, ' ', fp) != EOF) {
|
||||
line[strcspn(line, "\n")] = '\0';
|
||||
if (*line == '@') {
|
||||
if (strstr(line, "@/com/obsproject") != NULL) {
|
||||
++obsCnt;
|
||||
}
|
||||
}
|
||||
}
|
||||
already_running = obsCnt == 1 ? 0 : 1;
|
||||
free(line);
|
||||
fclose(fp);
|
||||
}
|
||||
#endif
|
||||
#if defined(__FreeBSD__) || defined(__DragonFly__)
|
||||
struct RunOnce {
|
||||
std::thread thr;
|
||||
static const char *thr_name;
|
||||
std::condition_variable cv;
|
||||
std::condition_variable wait_cv;
|
||||
std::mutex mtx;
|
||||
bool exiting = false;
|
||||
bool name_changed = false;
|
||||
|
||||
void thr_proc()
|
||||
{
|
||||
std::unique_lock<std::mutex> lk(mtx);
|
||||
pthread_set_name_np(pthread_self(), thr_name);
|
||||
name_changed = true;
|
||||
wait_cv.notify_all();
|
||||
cv.wait(lk, [this]() { return exiting; });
|
||||
}
|
||||
|
||||
~RunOnce()
|
||||
{
|
||||
if (thr.joinable()) {
|
||||
std::unique_lock<std::mutex> lk(mtx);
|
||||
exiting = true;
|
||||
cv.notify_one();
|
||||
lk.unlock();
|
||||
thr.join();
|
||||
}
|
||||
}
|
||||
} RO;
|
||||
const char *RunOnce::thr_name = "OBS runonce";
|
||||
|
||||
void PIDFileCheck(bool &already_running)
|
||||
{
|
||||
std::string tmpfile_name =
|
||||
"/tmp/obs-studio.lock." + to_string(geteuid());
|
||||
int fd = open(tmpfile_name.c_str(), O_RDWR | O_CREAT | O_EXLOCK, 0600);
|
||||
if (fd == -1) {
|
||||
already_running = true;
|
||||
return;
|
||||
}
|
||||
|
||||
already_running = false;
|
||||
|
||||
procstat *ps = procstat_open_sysctl();
|
||||
unsigned int count;
|
||||
auto procs = procstat_getprocs(ps, KERN_PROC_UID | KERN_PROC_INC_THREAD,
|
||||
geteuid(), &count);
|
||||
for (unsigned int i = 0; i < count; i++) {
|
||||
if (!strncmp(procs[i].ki_tdname, RunOnce::thr_name,
|
||||
sizeof(procs[i].ki_tdname))) {
|
||||
already_running = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
procstat_freeprocs(ps, procs);
|
||||
procstat_close(ps);
|
||||
|
||||
RO.thr = std::thread(std::mem_fn(&RunOnce::thr_proc), &RO);
|
||||
|
||||
{
|
||||
std::unique_lock<std::mutex> lk(RO.mtx);
|
||||
RO.wait_cv.wait(lk, []() { return RO.name_changed; });
|
||||
}
|
||||
|
||||
unlink(tmpfile_name.c_str());
|
||||
close(fd);
|
||||
}
|
||||
#endif
|
||||
|
||||
static inline bool check_path(const char *data, const char *path,
|
||||
string &output)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue