Pi66

pino
Python notification daemon.
git clone https://git.pi66.xyz/pino

← back to log

root

author: pixel2175
date: 2024-12-21 14:29
hash: f4fbfb147d97e21b1f824f9554ec76eed0776744

Diffstat:

A

plugs/src/pino_start.c
81 ++++++++++++++++++++++++++++++
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
diff --git a/plugs/src/pino_start.c b/plugs/src/pino_start.c
new file mode 100644
index 0000000..eb4737f
--- /dev/null
+++ b/plugs/src/pino_start.c
@@ -0,0 +1,81 @@
+#include <dirent.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+#define MAX_PATH_LENGTH 1024
+
+int is_executable(const char *path) {
+  struct stat st;
+
+  // Check if file exists and is a regular file
+  if (stat(path, &st) != 0) {
+    return 0;
+  }
+
+  // Check if file is executable
+  return (st.st_mode & S_IXUSR) || (st.st_mode & S_IXGRP) ||
+         (st.st_mode & S_IXOTH);
+}
+
+int main() {
+  const char *home_dir = getenv("HOME");
+  if (home_dir == NULL) {
+    fprintf(stderr, "Could not get HOME directory\n");
+    return 1;
+  }
+
+  char plugs_dir[MAX_PATH_LENGTH];
+  snprintf(plugs_dir, sizeof(plugs_dir), "%s/.config/pino/plugs/", home_dir);
+
+  DIR *dir;
+  struct dirent *entry;
+
+  // Open directory
+  dir = opendir(plugs_dir);
+  if (dir == NULL) {
+    fprintf(stderr, "Unable to open directory %s: %s\n", plugs_dir,
+            strerror(errno));
+    return 1;
+  }
+
+  // Read directory entries
+  while ((entry = readdir(dir)) != NULL) {
+    // Skip current and parent directory entries
+    if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) {
+      continue;
+    }
+
+    // Construct full path
+    char full_path[MAX_PATH_LENGTH];
+    snprintf(full_path, sizeof(full_path), "%s%s", plugs_dir, entry->d_name);
+
+    // Check if file is executable
+    if (is_executable(full_path)) {
+      printf("Starting: %s\n", full_path);
+
+      // Fork and execute
+      pid_t pid = fork();
+
+      if (pid == 0) {
+        // Child process
+        execl(full_path, full_path, NULL);
+
+        // If execl fails
+        fprintf(stderr, "Failed to execute %s\n", strerror(errno));
+        exit(1);
+      }
+      // Parent process continues to next file
+    }
+  }
+
+  // Close directory
+  closedir(dir);
+
+  printf("Finished.\n");
+
+  return 0;
+}