From 794dffcfe2204a6b7d92072e7af54e6e058dcbe9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AB=8F=E8=A8=AA=E5=AD=90?= Date: Tue, 18 Jun 2024 14:06:43 +0900 Subject: =?UTF-8?q?=E3=83=9E=E3=82=A4=E3=82=AF=E3=81=A8=E3=82=AB=E3=83=A1?= =?UTF-8?q?=E3=83=A9=EF=BC=88OpenBSD=E3=81=AE=E3=81=BF=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.c | 15 +++++++++++++-- src/cpu.c | 2 +- src/recording.c | 32 ++++++++++++++++++++++++++++++++ src/recording.h | 9 +++++++++ src/uptime.c | 2 +- 5 files changed, 56 insertions(+), 4 deletions(-) create mode 100644 src/recording.c create mode 100644 src/recording.h diff --git a/main.c b/main.c index 3cb7faf..63a6a0a 100644 --- a/main.c +++ b/main.c @@ -4,11 +4,14 @@ #include "src/user.h" #include "src/os.h" -#include "src/host.h" -#include "src/uptime.h" #if defined(__linux__) #include "src/distro.h" #endif +#include "src/host.h" +#include "src/uptime.h" +#if defined(__OpenBSD__) +#include "src/recording.h" +#endif #include "src/cpu.h" #include "src/memory.h" @@ -45,6 +48,14 @@ int main() { display_time(); printf("\n"); +#if defined(__OpenBSD__) + printf("Recording: audio = "); + display_recording_audio(); + printf(", video = "); + display_recording_video(); + printf("\n"); +#endif + printf("CPU: "); display_cpu(); printf("\n"); diff --git a/src/cpu.c b/src/cpu.c index 9b79eca..5cd9d3d 100644 --- a/src/cpu.c +++ b/src/cpu.c @@ -1,4 +1,4 @@ -#include "memory.h" +#include "cpu.h" #include #include diff --git a/src/recording.c b/src/recording.c new file mode 100644 index 0000000..8ed3d98 --- /dev/null +++ b/src/recording.c @@ -0,0 +1,32 @@ +#if defined(__OpenBSD__) +#include "recording.h" + +#include +#include +#include + +void run_rec_command(const char *command) { + char buf[128]; + + FILE *p = popen(command, "r"); + if (!p) { + fprintf(stderr, "録画コマンドを実効に失敗: %s", command); + return; + } + + while (fgets(buf, sizeof(buf), p) != NULL) { + buf[strcspn(buf, "\n")] = '\0'; + printf("%s", strncmp(buf, "0", strlen(buf)) ? "off" : "on"); + } + + pclose(p); +} + +void display_recording_audio() { + run_rec_command("sysctl -n kern.audio.record"); +} + +void display_recording_video() { + run_rec_command("sysctl -n kern.video.record"); +} +#endif diff --git a/src/recording.h b/src/recording.h new file mode 100644 index 0000000..bf68106 --- /dev/null +++ b/src/recording.h @@ -0,0 +1,9 @@ +#if defined(__OpenBSD__) +#ifndef RECORDING_H +#define RECORDING_H + +void display_recording_audio(); +void display_recording_video(); + +#endif +#endif diff --git a/src/uptime.c b/src/uptime.c index da19270..8198669 100644 --- a/src/uptime.c +++ b/src/uptime.c @@ -1,4 +1,4 @@ -#include "memory.h" +#include "uptime.h" #include #include -- cgit v1.2.3