summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlastair Poole <netstar@gmail.com>2021-09-09 19:39:11 +0100
committerAlastair Poole <netstar@gmail.com>2021-09-09 19:45:58 +0100
commit75fa4b7a84281f698a7a5a8ebc8504f85b2d1b7f (patch)
tree951b9b508b28a3956af0ddf9206701fd71ec99c2
parent63301be2775aed0e50ca7e32457492c342351984 (diff)
BSD: Fix build.HEADmaster
Need a portable pidfile_create for a reliable way to check program is running... Need to think about it. Fix linking against -lkvm...client shouldn't do this, so ellaborate process walking is out of the question... BSD now will ignore SIG_CHLD (launch).
-rw-r--r--NOTES14
-rw-r--r--src/bin/enigmatic_main.c22
-rw-r--r--src/bin/enigmatic_start.c3
-rw-r--r--src/bin/enigmatic_util.c63
-rw-r--r--src/bin/examples/cpu.c10
-rw-r--r--src/bin/meson.build1
-rw-r--r--src/bin/system/meson.build7
7 files changed, 30 insertions, 90 deletions
diff --git a/NOTES b/NOTES
index 97e1fbd..4f0ac84 100644
--- a/NOTES
+++ b/NOTES
@@ -1,5 +1,13 @@
1sleep: 1sleep:
2 what to do after we sleep to save power while the 2 what to do after we sleep to save power while the
3 world mines crypto and no GPU to play ark??? :( 3 world mines crypto and no GPU to play ark??? :(
4playback: 4playback:
5 when we rotate...what to do? 5 when we rotate...what to do?
6
7portability:
8 Really need to avoid proc_info* function calls outside
9 of the logger otherwise linking is unacceptable and
10 also kvm requires setgid on OpenBSD...acceptable in
11 the main program...
12
13
diff --git a/src/bin/enigmatic_main.c b/src/bin/enigmatic_main.c
index dfaa37f..7bf09af 100644
--- a/src/bin/enigmatic_main.c
+++ b/src/bin/enigmatic_main.c
@@ -108,6 +108,7 @@ enigmatic_init(Enigmatic *enigmatic)
108 enigmatic_log_lock(enigmatic); 108 enigmatic_log_lock(enigmatic);
109 109
110 enigmatic->pid = getpid(); 110 enigmatic->pid = getpid();
111 // LOCK before...ok FIX pidfile create
111 enigmatic_pidfile_create(enigmatic); 112 enigmatic_pidfile_create(enigmatic);
112 enigmatic->device_refresh_interval = 900 * 10; 113 enigmatic->device_refresh_interval = 900 * 10;
113 enigmatic->log.hour = -1; 114 enigmatic->log.hour = -1;
@@ -136,6 +137,8 @@ enigmatic_shutdown(Enigmatic *enigmatic)
136 enigmatic_pidfile_delete(enigmatic); 137 enigmatic_pidfile_delete(enigmatic);
137} 138}
138 139
140/*
141 *
139void 142void
140usage(void) 143usage(void)
141{ 144{
@@ -147,29 +150,12 @@ usage(void)
147 PACKAGE); 150 PACKAGE);
148 exit(0); 151 exit(0);
149} 152}
153*/
150 154
151int main(int argc, char **argv) 155int main(int argc, char **argv)
152{ 156{
153 Eina_Bool count_instances = 0;
154 Eina_Bool really_nuke_all_instances = 0;
155
156 for (int i = 1; i < argc; i++)
157 {
158 if ((!strcasecmp(argv[i], "-h")) || (!strcasecmp(argv[i], "--help")))
159 usage();
160 else if (!strcmp(argv[i], "-c"))
161 count_instances = 1;
162 else if (!strcmp(argv[i], "--yes-really-nuke"))
163 really_nuke_all_instances = 1;
164 }
165
166 ecore_init(); 157 ecore_init();
167 158
168 if (count_instances)
169 printf("%i instances\n", enigmatic_count());
170 else if (really_nuke_all_instances)
171 enigmatic_nuke();
172 else
173 { 159 {
174 Enigmatic *enigmatic = calloc(1, sizeof(Enigmatic)); 160 Enigmatic *enigmatic = calloc(1, sizeof(Enigmatic));
175 EINA_SAFETY_ON_NULL_RETURN_VAL(enigmatic, 1); 161 EINA_SAFETY_ON_NULL_RETURN_VAL(enigmatic, 1);
diff --git a/src/bin/enigmatic_start.c b/src/bin/enigmatic_start.c
index d40cb36..d67f26d 100644
--- a/src/bin/enigmatic_start.c
+++ b/src/bin/enigmatic_start.c
@@ -5,6 +5,7 @@
5#include <sys/stat.h> 5#include <sys/stat.h>
6#include <limits.h> 6#include <limits.h>
7#include <unistd.h> 7#include <unistd.h>
8#include <signal.h>
8#include "enigmatic_util.h" 9#include "enigmatic_util.h"
9 10
10static void 11static void
@@ -44,6 +45,8 @@ main(int argc, char **argv)
44 pid_t pid; 45 pid_t pid;
45 int ret = 1; 46 int ret = 1;
46 47
48 signal(SIGCHLD, SIG_IGN);
49
47 pid = fork(); 50 pid = fork();
48 if (pid == -1) 51 if (pid == -1)
49 { 52 {
diff --git a/src/bin/enigmatic_util.c b/src/bin/enigmatic_util.c
index e58b6fa..fde908d 100644
--- a/src/bin/enigmatic_util.c
+++ b/src/bin/enigmatic_util.c
@@ -18,8 +18,8 @@ enigmatic_pidfile_create(Enigmatic *enigmatic)
18 char path[PATH_MAX], *tmp; 18 char path[PATH_MAX], *tmp;
19 FILE *f; 19 FILE *f;
20 20
21 if (enigmatic_running()) 21 // XXX: FIXME
22 ERROR("Program already running"); 22 // ERROR("Program already running");
23 23
24 snprintf(path, sizeof(path), "%s/%s", enigmatic_cache_dir_get(), PACKAGE); 24 snprintf(path, sizeof(path), "%s/%s", enigmatic_cache_dir_get(), PACKAGE);
25 if (!ecore_file_exists(path)) 25 if (!ecore_file_exists(path))
@@ -97,44 +97,6 @@ enigmatic_terminate(void)
97 free(path); 97 free(path);
98} 98}
99 99
100uint8_t
101enigmatic_count(void)
102{
103 Eina_List *procs;
104 Proc_Info *proc;
105 uint8_t n = 0;
106
107 procs = proc_info_all_get();
108 EINA_LIST_FREE(procs, proc)
109 {
110 if ((getpid() != proc->pid) && (!strcmp(proc->command, PACKAGE)))
111 n++;
112 proc_info_free(proc);
113 }
114 return n;
115}
116
117void
118enigmatic_nuke(void)
119{
120 Eina_List *procs;
121 Proc_Info *proc;
122 int n = 0;
123
124 procs = proc_info_all_get();
125 EINA_LIST_FREE(procs, proc)
126 {
127 if ((getpid() != proc->pid) && (!strcmp(proc->command, PACKAGE)))
128 {
129 fprintf(stderr, "nuking %i\n", proc->pid);
130 kill(proc->pid, SIGINT);
131 n++;
132 }
133 proc_info_free(proc);
134 }
135 if (n > 1) fprintf(stderr, "nuked %i!!!\n", n);
136}
137
138Eina_Bool 100Eina_Bool
139enigmatic_launch(void) 101enigmatic_launch(void)
140{ 102{
@@ -144,25 +106,10 @@ enigmatic_launch(void)
144Eina_Bool 106Eina_Bool
145enigmatic_running(void) 107enigmatic_running(void)
146{ 108{
147 char *path; 109 puts("FIXME");
148 Proc_Info *proc; 110 exit(1);
149 Eina_Bool running = 0;
150
151 path = _pidfile_path();
152 if (ecore_file_exists(path))
153 {
154 pid_t pid = enigmatic_pidfile_pid_get(path);
155 proc = proc_info_by_pid(pid);
156 if (proc)
157 {
158 if (!strcmp(proc->command, PACKAGE))
159 running = 1;
160 proc_info_free(proc);
161 }
162 }
163 free(path);
164 111
165 return running; 112 return 0;
166} 113}
167 114
168char * 115char *
diff --git a/src/bin/examples/cpu.c b/src/bin/examples/cpu.c
index ac39a3d..92da24b 100644
--- a/src/bin/examples/cpu.c
+++ b/src/bin/examples/cpu.c
@@ -87,13 +87,8 @@ elm_main(int argc, char **argv)
87{ 87{
88 Evas_Object *win, *scr, *bx; 88 Evas_Object *win, *scr, *bx;
89 Enigmatic_Client *client; 89 Enigmatic_Client *client;
90 Eina_Bool keep_around = 1;
91 90
92 if (!enigmatic_running()) 91 if (!enigmatic_launch()) return 1;
93 {
94 if (!enigmatic_launch()) return 1;
95 keep_around = 0;
96 }
97 92
98 client = client_open(); 93 client = client_open();
99 EINA_SAFETY_ON_NULL_RETURN_VAL(client, 1); 94 EINA_SAFETY_ON_NULL_RETURN_VAL(client, 1);
@@ -124,9 +119,6 @@ elm_main(int argc, char **argv)
124 119
125 ecore_main_loop_begin(); 120 ecore_main_loop_begin();
126 121
127 if (!keep_around)
128 enigmatic_terminate();
129
130 client_del(client); 122 client_del(client);
131 123
132 return 0; 124 return 0;
diff --git a/src/bin/meson.build b/src/bin/meson.build
index 54d1c6e..cfac2dd 100644
--- a/src/bin/meson.build
+++ b/src/bin/meson.build
@@ -7,6 +7,7 @@ subdir('monitor')
7 7
8src += src_system 8src += src_system
9src += src_monitor 9src += src_monitor
10src += src_process
10 11
11src_log = files([ 12src_log = files([
12 'enigmatic_log.c', 13 'enigmatic_log.c',
diff --git a/src/bin/system/meson.build b/src/bin/system/meson.build
index 872075c..6594496 100644
--- a/src/bin/system/meson.build
+++ b/src/bin/system/meson.build
@@ -1,12 +1,15 @@
1src_system = files([ 1src_system = files([
2 'machine.c', 2 'machine.c',
3 'machine.h', 3 'machine.h',
4 'process.c',
5 'process.h',
6 'file_systems.c', 4 'file_systems.c',
7 'file_systems.h', 5 'file_systems.h',
8]) 6])
9 7
8src_process = files([
9 'process.c',
10 'process.h',
11])
12
10src_stubby = files([ 13src_stubby = files([
11 'process_stubby.c', 14 'process_stubby.c',
12 'process_stubby.h', 15 'process_stubby.h',