aports

Custom Alpine Linux aports

git clone git://git.lin.moe/aports.git

 1From 7101460edc84b4fe636b5c11d2f597b20c89e397 Mon Sep 17 00:00:00 2001
 2From: capezotte <carana2099@gmail.com>
 3Date: Mon, 15 Apr 2024 14:26:58 -0300
 4Subject: [PATCH] add SOUND_INITIALIZED property and pipewire fix
 5
 6---
 7 udev_device.c    | 34 ++++++++++++++++++++++++++++++++++
 8 udev_enumerate.c |  4 +++-
 9 2 files changed, 37 insertions(+), 1 deletion(-)
10
11diff --git a/udev_device.c b/udev_device.c
12index b0577964..b3027a14 100644
13--- a/udev_device.c
14+++ b/udev_device.c
15@@ -16,6 +16,7 @@
16  */
17 
18 #include <stdio.h>
19+#include <dirent.h>
20 #include <unistd.h>
21 #include <string.h>
22 #include <stdlib.h>
23@@ -379,6 +380,38 @@ static int set_properties_from_uevent(struct udev_device *udev_device, const cha
24     return 0;
25 }
26 
27+static void is_sound_initialized(struct udev_device *udev_device, const char* path) {
28+    const char *subsystem;
29+    DIR *device_folder;
30+    struct dirent *dp;
31+    char control[PATH_MAX];
32+
33+    subsystem = udev_device_get_subsystem(udev_device);
34+    if (!subsystem || strcmp(subsystem, "sound") != 0) {
35+        return;
36+    }
37+
38+    if (strncmp(strrchr(path, '/'), "/card", 5)) {
39+        snprintf(control, PATH_MAX, "%s/..", path);
40+        device_folder = opendir(control);
41+    } else {
42+        device_folder = opendir(path);
43+    }
44+
45+    if (!device_folder) {
46+        return;
47+    }
48+
49+    while ((dp = readdir(device_folder)) != NULL) {
50+        if (strncmp(dp->d_name, "controlC", 8) == 0) {
51+            udev_list_entry_add(&udev_device->properties, "SOUND_INITIALIZED", "1", 0);
52+            break;
53+        }
54+    }
55+
56+    closedir(device_folder);
57+}
58+
59 static void make_bit(unsigned long *arr, int cnt, const char *str)
60 {
61     size_t len;
62@@ -593,6 +626,7 @@ struct udev_device *udev_device_new_from_syspath(struct udev *udev, const char *
63 
64     set_properties_from_evdev(udev_device);
65     set_properties_from_props(udev_device);
66+    is_sound_initialized(udev_device, path);
67 
68     free(driver);
69     free(subsystem);
70diff --git a/udev_enumerate.c b/udev_enumerate.c
71index 6fd49c09..d556ceb3 100644
72--- a/udev_enumerate.c
73+++ b/udev_enumerate.c
74@@ -225,7 +225,7 @@ static int filter_sysattr(struct udev_enumerate *udev_enumerate, struct udev_dev
75 
76 static void add_device(struct udev_enumerate *udev_enumerate, const char *path)
77 {
78-    struct udev_device *udev_device;
79+    struct udev_device *udev_device, *parent;
80 
81     udev_device = udev_device_new_from_syspath(udev_enumerate->udev, path);
82 
83@@ -241,6 +241,8 @@ static void add_device(struct udev_enumerate *udev_enumerate, const char *path)
84         return;
85     }
86 
87+    if ((parent = udev_device_get_parent(udev_device)))
88+        udev_list_entry_add(&udev_enumerate->devices, udev_device_get_syspath(parent), NULL, 0);
89     udev_list_entry_add(&udev_enumerate->devices, udev_device_get_syspath(udev_device), NULL, 0);
90 
91     udev_device_unref(udev_device);