From 6340351c3bb161bf9e9f98e6239465fb9c788e3c Mon Sep 17 00:00:00 2001 From: Jerry Date: Fri, 11 Aug 2023 09:57:17 +0800 Subject: [PATCH] allow usage of --screen-blank --capture-raw-fb=/dev/null --- drm_master.c | 7 +++---- kmsvnc.c | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/drm_master.c b/drm_master.c index b924068..8d762ce 100644 --- a/drm_master.c +++ b/drm_master.c @@ -27,7 +27,6 @@ static inline int clone_fd(pid_t pid, int target_fd) { } static inline int cmp_fds(pid_t pid, const char *drm_pth) { - if (pid == 1) return -1; char path[PATH_MAX+1]; snprintf(path, PATH_MAX+1, "/proc/%d/fd", pid); @@ -48,9 +47,9 @@ static inline int cmp_fds(pid_t pid, const char *drm_pth) { int cloned = clone_fd(pid, fd); if (cloned > 0 && drmIsMaster(cloned)) { ret = cloned; - //if (kmsvnc->debug_enabled) { + if (kmsvnc->debug_enabled) { fprintf(stderr, "found drm master pid=%d, fd=%d, cloned=%d\n", pid, fd, cloned); - //} + } } else { if (cloned > 0) close(cloned); @@ -76,7 +75,7 @@ int drm_get_master_fd() { int count = scandir("/proc", &proclist, NULL, versionsort); int ret = -1; if (count >= 0) { - for (int n = count - 1; n > 0; n--) { + for (int n = 0; n < count; n++) { if (ret == -1 && proclist[n]->d_type == DT_DIR) { pid_t pid = (pid_t)atoi(proclist[n]->d_name); if (pid > 0) { diff --git a/kmsvnc.c b/kmsvnc.c index 541e327..2e4eb32 100644 --- a/kmsvnc.c +++ b/kmsvnc.c @@ -208,6 +208,7 @@ static void cleanup() { } } +void signal_handler_noop(int signum){} void signal_handler(int signum){ if (kmsvnc->shutdown) { return; @@ -437,6 +438,20 @@ int main(int argc, char **argv) else { fprintf(stderr, "open file %s failed, %s\n", kmsvnc->debug_capture_fb, strerror(errno)); } + if (kmsvnc->screen_blank) { + sigset_t signal_set; + int sig; + sigemptyset(&signal_set); + signal(SIGHUP, &signal_handler_noop); + signal(SIGINT, &signal_handler_noop); + signal(SIGTERM, &signal_handler_noop); + sigaddset(&signal_set, SIGHUP); + sigaddset(&signal_set, SIGINT); + sigaddset(&signal_set, SIGTERM); + fprintf(stderr, "blanking screen...\n"); + sigwait(&signal_set, &sig); + fprintf(stderr, "got sig %d\n", sig); + } cleanup(); return 0; }