summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlastair Poole <mail@alastairpoole.com>2021-10-24 11:10:23 +0100
committerAlastair Poole <mail@alastairpoole.com>2021-10-24 11:10:23 +0100
commit873cb02bf871b311eb9301f19adffe021e1386b9 (patch)
treebbb7cbe81c6883739c8dc5ab68eced6e364975de
parenta6ac72bff5fbb7636f510dc986d0726906037c0a (diff)
launch: first run/no log launch.
Try to ensure we have flushed to disk.
-rw-r--r--src/bin/Enigmatic.h21
-rw-r--r--src/bin/client/enigmatic_client.c1
-rw-r--r--src/bin/client/enigmatic_test.c4
-rw-r--r--src/bin/enigmatic_log.c25
-rw-r--r--src/bin/enigmatic_log.h6
-rw-r--r--src/bin/enigmatic_start.c20
-rw-r--r--src/bin/enigmatic_util.c (renamed from src/bin/enigmatic.c)30
-rw-r--r--src/bin/enigmatic_util.h33
-rw-r--r--src/bin/examples/blindmin.c4
-rw-r--r--src/bin/examples/cpu.c2
-rw-r--r--src/bin/meson.build6
11 files changed, 93 insertions, 59 deletions
diff --git a/src/bin/Enigmatic.h b/src/bin/Enigmatic.h
index 3938072..a1aaa5e 100644
--- a/src/bin/Enigmatic.h
+++ b/src/bin/Enigmatic.h
@@ -103,25 +103,6 @@ struct _Enigmatic
103 } log; 103 } log;
104}; 104};
105 105
106Eina_Bool 106#include "enigmatic_util.h"
107enigmatic_pidfile_create(Enigmatic *enigmatic);
108
109void
110enigmatic_pidfile_delete(Enigmatic *enigmatic);
111
112uint32_t
113enigmatic_pidfile_pid_get(const char *path);
114
115void
116enigmatic_launch(void);
117
118void
119enigmatic_terminate(void);
120
121Eina_Bool
122enigmatic_running(void);
123
124const char *
125enigmatic_cache_dir_get(void);
126 107
127#endif 108#endif
diff --git a/src/bin/client/enigmatic_client.c b/src/bin/client/enigmatic_client.c
index 1c6e927..97d720c 100644
--- a/src/bin/client/enigmatic_client.c
+++ b/src/bin/client/enigmatic_client.c
@@ -1,5 +1,6 @@
1#include "Events.h" 1#include "Events.h"
2#include "enigmatic_log.h" 2#include "enigmatic_log.h"
3#include "enigmatic_util.h"
3#include "Enigmatic_Client.h" 4#include "Enigmatic_Client.h"
4#include <Eina.h> 5#include <Eina.h>
5#include <Ecore.h> 6#include <Ecore.h>
diff --git a/src/bin/client/enigmatic_test.c b/src/bin/client/enigmatic_test.c
index 8d1247e..b646444 100644
--- a/src/bin/client/enigmatic_test.c
+++ b/src/bin/client/enigmatic_test.c
@@ -185,11 +185,11 @@ cb_event_change_init(Enigmatic_Client *client, Snapshot *s, void *data)
185static void 185static void
186follow(void) 186follow(void)
187{ 187{
188 if (!enigmatic_launch()) return;
189
188 Enigmatic_Client *client = client_open(); 190 Enigmatic_Client *client = client_open();
189 EINA_SAFETY_ON_NULL_RETURN(client); 191 EINA_SAFETY_ON_NULL_RETURN(client);
190 192
191 enigmatic_launch();
192
193 client_monitor_add(client, cb_event_change_init, cb_event_change, NULL); 193 client_monitor_add(client, cb_event_change_init, cb_event_change, NULL);
194 194
195 ecore_main_loop_begin(); 195 ecore_main_loop_begin();
diff --git a/src/bin/enigmatic_log.c b/src/bin/enigmatic_log.c
index c1a67f0..3c90666 100644
--- a/src/bin/enigmatic_log.c
+++ b/src/bin/enigmatic_log.c
@@ -2,6 +2,7 @@
2#include "Enigmatic.h" 2#include "Enigmatic.h"
3#include "Events.h" 3#include "Events.h"
4#include "enigmatic_log.h" 4#include "enigmatic_log.h"
5#include "enigmatic_util.h"
5#include "lz4.h" 6#include "lz4.h"
6#include "lz4frame.h" 7#include "lz4frame.h"
7 8
@@ -467,30 +468,6 @@ enigmatic_log_rotate(Enigmatic *enigmatic)
467 return 1; 468 return 1;
468} 469}
469 470
470char *
471enigmatic_log_path(void)
472{
473 char path[PATH_MAX];
474
475 snprintf(path, sizeof(path), "%s/%s", enigmatic_cache_dir_get(), PACKAGE);
476 if (!ecore_file_exists(path))
477 ecore_file_mkdir(path);
478
479 snprintf(path, sizeof(path), "%s/%s/%s", enigmatic_cache_dir_get(), PACKAGE, LOG_FILE_NAME);
480
481 return strdup(path);
482}
483
484char *
485enigmatic_log_directory(void)
486{
487 char path[PATH_MAX];
488
489 snprintf(path, sizeof(path), "%s/%s", enigmatic_cache_dir_get(), PACKAGE);
490
491 return strdup(path);
492}
493
494void 471void
495enigmatic_log_diff(Enigmatic *enigmatic, Message msg, int64_t value) 472enigmatic_log_diff(Enigmatic *enigmatic, Message msg, int64_t value)
496{ 473{
diff --git a/src/bin/enigmatic_log.h b/src/bin/enigmatic_log.h
index 47269b0..d2b30e7 100644
--- a/src/bin/enigmatic_log.h
+++ b/src/bin/enigmatic_log.h
@@ -43,12 +43,6 @@ enigmatic_log_crush(Enigmatic *enigmatic);
43Eina_Bool 43Eina_Bool
44enigmatic_log_rotate(Enigmatic *enigmatic); 44enigmatic_log_rotate(Enigmatic *enigmatic);
45 45
46char *
47enigmatic_log_path(void);
48
49char *
50enigmatic_log_directory(void);
51
52void 46void
53enigmatic_log_lock(Enigmatic *enigmatic); 47enigmatic_log_lock(Enigmatic *enigmatic);
54 48
diff --git a/src/bin/enigmatic_start.c b/src/bin/enigmatic_start.c
index 7e0ffc6..d40cb36 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 "enigmatic_util.h"
8 9
9static void 10static void
10launch(void) 11launch(void)
@@ -41,6 +42,7 @@ int
41main(int argc, char **argv) 42main(int argc, char **argv)
42{ 43{
43 pid_t pid; 44 pid_t pid;
45 int ret = 1;
44 46
45 pid = fork(); 47 pid = fork();
46 if (pid == -1) 48 if (pid == -1)
@@ -55,5 +57,21 @@ main(int argc, char **argv)
55 close(fileno(stderr)); 57 close(fileno(stderr));
56 launch(); 58 launch();
57 } 59 }
58 return 0; 60 else
61 {
62 struct stat st;
63 char *path = enigmatic_log_path();
64 // We have a log?
65 for (int i = 0; i < 20; i++)
66 {
67 if (stat(path, &st) != -1)
68 {
69 ret = 0;
70 break;
71 }
72 usleep(1000000 / 20);
73 }
74 free(path);
75 }
76 return ret;
59} 77}
diff --git a/src/bin/enigmatic.c b/src/bin/enigmatic_util.c
index ae7bb87..f440d3f 100644
--- a/src/bin/enigmatic.c
+++ b/src/bin/enigmatic_util.c
@@ -1,4 +1,5 @@
1#include "Enigmatic.h" 1#include "Enigmatic.h"
2#include "enigmatic_util.h"
2#include <Ecore_File.h> 3#include <Ecore_File.h>
3#include <sys/types.h> 4#include <sys/types.h>
4#include <signal.h> 5#include <signal.h>
@@ -96,10 +97,10 @@ enigmatic_terminate(void)
96 free(path); 97 free(path);
97} 98}
98 99
99void 100Eina_Bool
100enigmatic_launch(void) 101enigmatic_launch(void)
101{ 102{
102 ecore_exe_run(PACKAGE"_start", NULL); 103 return !system(PACKAGE"_start");
103} 104}
104 105
105Eina_Bool 106Eina_Bool
@@ -125,3 +126,28 @@ enigmatic_running(void)
125 126
126 return running; 127 return running;
127} 128}
129
130char *
131enigmatic_log_path(void)
132{
133 char path[PATH_MAX];
134
135 snprintf(path, sizeof(path), "%s/%s", enigmatic_cache_dir_get(), PACKAGE);
136 if (!ecore_file_exists(path))
137 ecore_file_mkdir(path);
138
139 snprintf(path, sizeof(path), "%s/%s/%s", enigmatic_cache_dir_get(), PACKAGE, LOG_FILE_NAME);
140
141 return strdup(path);
142}
143
144char *
145enigmatic_log_directory(void)
146{
147 char path[PATH_MAX];
148
149 snprintf(path, sizeof(path), "%s/%s", enigmatic_cache_dir_get(), PACKAGE);
150
151 return strdup(path);
152}
153
diff --git a/src/bin/enigmatic_util.h b/src/bin/enigmatic_util.h
new file mode 100644
index 0000000..ee211df
--- /dev/null
+++ b/src/bin/enigmatic_util.h
@@ -0,0 +1,33 @@
1#ifndef ENIGMATIC_UTIL_H
2#define ENIGMATIC_UTIL_H
3
4#include "Enigmatic.h"
5
6Eina_Bool
7enigmatic_pidfile_create(Enigmatic *enigmatic);
8
9const char *
10enigmatic_cache_dir_get(void);
11
12void
13enigmatic_pidfile_delete(Enigmatic *enigmatic);
14
15uint32_t
16enigmatic_pidfile_pid_get(const char *path);
17
18void
19enigmatic_terminate(void);
20
21Eina_Bool
22enigmatic_launch(void);
23
24Eina_Bool
25enigmatic_running(void);
26
27char *
28enigmatic_log_path(void);
29
30char *
31enigmatic_log_directory(void);
32
33#endif
diff --git a/src/bin/examples/blindmin.c b/src/bin/examples/blindmin.c
index 90c63d2..e74f784 100644
--- a/src/bin/examples/blindmin.c
+++ b/src/bin/examples/blindmin.c
@@ -186,11 +186,11 @@ cb_event_change_init(Enigmatic_Client *client, Snapshot *s, void *data)
186static void 186static void
187monitor(void) 187monitor(void)
188{ 188{
189 if (!enigmatic_launch()) return;
190
189 Enigmatic_Client *client = client_open(); 191 Enigmatic_Client *client = client_open();
190 EINA_SAFETY_ON_NULL_RETURN(client); 192 EINA_SAFETY_ON_NULL_RETURN(client);
191 193
192 enigmatic_launch();
193
194 client_monitor_add(client, cb_event_change_init, cb_event_change, NULL); 194 client_monitor_add(client, cb_event_change_init, cb_event_change, NULL);
195 195
196 ecore_main_loop_begin(); 196 ecore_main_loop_begin();
diff --git a/src/bin/examples/cpu.c b/src/bin/examples/cpu.c
index 6b3643c..ac39a3d 100644
--- a/src/bin/examples/cpu.c
+++ b/src/bin/examples/cpu.c
@@ -91,7 +91,7 @@ elm_main(int argc, char **argv)
91 91
92 if (!enigmatic_running()) 92 if (!enigmatic_running())
93 { 93 {
94 enigmatic_launch(); 94 if (!enigmatic_launch()) return 1;
95 keep_around = 0; 95 keep_around = 0;
96 } 96 }
97 97
diff --git a/src/bin/meson.build b/src/bin/meson.build
index f36b5ee..54d1c6e 100644
--- a/src/bin/meson.build
+++ b/src/bin/meson.build
@@ -16,7 +16,7 @@ src_log = files([
16src += src_log 16src += src_log
17 17
18src_generic = files([ 18src_generic = files([
19 'enigmatic.c', 19 'enigmatic_util.c',
20]) 20])
21 21
22src += src_generic 22src += src_generic
@@ -38,8 +38,12 @@ src_start = files([
38 'enigmatic_start.c', 38 'enigmatic_start.c',
39]) 39])
40 40
41src_start += src_generic
42src_start += src_system
43
41executable('enigmatic_start', src_start, 44executable('enigmatic_start', src_start,
42 include_directories : [ config_dir ], 45 include_directories : [ config_dir ],
46 dependencies : [ dep_eina, dep_ecore, dep_ecore_file ],
43 gui_app : false, 47 gui_app : false,
44 install : true) 48 install : true)
45 49