Skip to content

Commit e36f55c

Browse files
committed
Merge branch 'fifo-logger'
2 parents f0c546f + 92a6248 commit e36f55c

File tree

10 files changed

+479
-35
lines changed

10 files changed

+479
-35
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ endif
4444

4545
DEPEND=Makefile.dep
4646

47-
OBJECTS=$(OBJ)/config.o $(OBJ)/devilspie2.o $(OBJ)/xutils.o $(OBJ)/script.o $(OBJ)/script_functions.o $(OBJ)/error_strings.o
47+
OBJECTS=$(OBJ)/config.o $(OBJ)/devilspie2.o $(OBJ)/xutils.o $(OBJ)/script.o $(OBJ)/script_functions.o $(OBJ)/error_strings.o $(OBJ)/logger.o
4848

4949
ifndef PREFIX
5050
ifdef INSTALL_PREFIX

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,26 @@ Unfortunately the rules of the original Devil's Pie are not supported.
2020
|:--|:--|
2121
| `-h`, `--help` | Show help options |
2222
| `-d`, `--debug` | Print debug information to stdout |
23+
| `-D`, `--debug-fifo` | Print debug info & copy stdout to a FIFO |
24+
| `-P`, `--print-fifo` | Print the debug FIFO's file name then quit |
2325
| `-e`, `--emulate` | Don't apply any rules, only emulate execution |
2426
| `-f`, `--folder` | Search for scripts in this folder |
2527
| `-v`, `--version` | Print program version then quit |
2628
| `-w`, `--wnck-version` | Show libwnck version then quit |
2729
| `-l`, `--lua-version` | Show Lua version then quit |
2830

31+
If you run `devilspie2 --debug-fifo`, you can connect to its FIFO at any
32+
time and see the same text as for `devilspie --debug`. The reason for this
33+
is to allow `devilspie2` to be dæmonised while still having access to
34+
debugging output etc. at need.
35+
36+
A useful way of doing this is to run, in a terminal, this command:
37+
```sh
38+
cat "$(devilspie2 -P)"
39+
```
40+
(No text backlog will be shown; if there's nothing reading the FIFO, nothing
41+
is written to it.)
42+
2943
## Configuration
3044

3145
Scripts are read from the scripts folder, which is customisable by using the

devilspie2.1

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,24 @@ Displays the version of Devilspie2.
2323
Sets the folder where the Lua scripts are loaded from.
2424
.TP
2525
\fB\-d\fR, \fB\-\-debug
26-
Shows debug information from the Lua scripts. If debug_print is used in the Lua
27-
scripts, that output will only be printed to stdout if this option is used.
26+
Shows debug information from the Lua scripts. If \fIdebug_print\fR is used
27+
in the Lua scripts, it will output to stdout.
28+
.TP
29+
\fB\-D\fR, \fB\-\-debug\-fifo
30+
Copy stdout & send debug info to a FIFO. If \fIdebug_print\fR is used in
31+
the Lua scripts, it will output to the FIFO. This is intended for running
32+
dæmonised while allowing access to debug text etc. at need.
33+
34+
Nothing is output to the FIFO if nothing is reading it.
35+
You can read it using a program such as \fBcat\fR.
36+
37+
\fB\-\-debug\fR and \fB\-\-debug\-fifo\fR may be used together.
38+
.TP
39+
\fB\-P\fR, \fB\-\-print\-fifo
40+
Print the FIFO's file name then exit. This may be used as follows:
41+
.EX
42+
cat "$(devilspie2 \-\-print\-fifo)"
43+
.EE
2844
.TP
2945
\fB\-e\fR, \fB\-\-emulate
3046
Emulation mode. This prevents windows from being affected by the scripts,
@@ -41,6 +57,17 @@ See
4157
.I /usr/share/doc/devilspie2/README.md
4258
for a detailed description of the commands recognised in Lua scripts.
4359

60+
.SH Files
61+
.TP
62+
.B $XDG_RUNTIME_DIR/devilspie2\-$DISPLAY
63+
.TP
64+
.B $TMPDIR/devilspie2\-$DISPLAY
65+
.TP
66+
.B /tmp/devilspie2\-$DISPLAY
67+
These are the possible locations of the FIFO which is created if
68+
\fB\-\-debug\-fifo\fR is used. The first one for which the referenced
69+
environment variables are set is used.
70+
4471
.SH Author
4572
.P
4673
.B Devilspie2

src/compat.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@
2222

2323
#if defined(__GNUC__) || defined(__clang__)
2424
# define ATTR_MALLOC __attribute__((malloc))
25+
# define ATTR_FORMAT_PRINTF(fmt, args) __attribute__((format(printf, fmt, args)))
2526
#else
2627
# define ATTR_MALLOC
28+
# define ATTR_FORMAT_PRINTF(fmt, args)
2729
#endif
2830

2931
#endif /* __HEADER_COMPAT_ */

src/config.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
#include "script.h"
3535
#include "script_functions.h"
36+
#include "logger.h"
3637

3738
#include "config.h"
3839

@@ -221,7 +222,7 @@ int load_config(gchar *filename)
221222
if (g_file_test(filename, G_FILE_TEST_EXISTS)) {
222223

223224
if (run_script(config_lua_state, filename) != 0) {
224-
printf(_("Error: %s\n"), filename);
225+
logger_err_printf(_("Error: %s\n"), filename);
225226
result = -1;
226227
goto EXITPOINT;
227228
}

src/devilspie2.c

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838
#include "script.h"
3939
#include "script_functions.h"
40+
#include "logger.h"
4041

4142
#include "error_strings.h"
4243

@@ -53,7 +54,11 @@
5354
GMainLoop *loop = NULL;
5455

5556
static gboolean debug = FALSE;
57+
static gboolean logtofifo = FALSE;
5658
static gboolean emulate = FALSE;
59+
60+
static gboolean show_fifo = FALSE;
61+
5762
static gboolean show_version = FALSE;
5863

5964
// libwnck Version Information is only availible if you have
@@ -215,7 +220,7 @@ static void signal_handler(int sig)
215220
/**
216221
*
217222
*/
218-
void print_list(GSList *list)
223+
static void print_list(GSList *list)
219224
{
220225
GSList *temp_list;
221226
if (list != NULL) {
@@ -226,7 +231,7 @@ void print_list(GSList *list)
226231

227232
if (file_name) {
228233
if (g_str_has_suffix((gchar*)file_name, ".lua")) {
229-
printf("%s\n", (gchar*)file_name);
234+
logger_printf("%s\n", (gchar*)file_name);
230235
}
231236
}
232237
temp_list = temp_list->next;
@@ -238,30 +243,26 @@ void print_list(GSList *list)
238243
/**
239244
*
240245
*/
241-
void print_script_lists()
246+
static void print_script_lists()
242247
{
243248
gboolean have_any_files = FALSE;
244249
win_event_type i;
245250

246-
if (debug)
247-
printf("------------\n");
251+
logger_print("------------\n");
248252

249253
for (i = 0; i < W_NUM_EVENTS; i++) {
250254
if (event_lists[i])
251255
have_any_files = TRUE;
252256
// If we are running debug mode - print the list of files:
253-
if (debug) {
254-
printf(_("List of Lua files handling \"%s\" events in folder:"),
255-
event_names[i]);
256-
printf("\n");
257-
if (event_lists[i]) {
258-
print_list(event_lists[i]);
259-
}
257+
logger_printf(_("List of Lua files handling \"%s\" events in folder:\n"),
258+
event_names[i]);
259+
if (event_lists[i]) {
260+
print_list(event_lists[i]);
260261
}
261262
}
262263

263264
if (!have_any_files) {
264-
printf("%s\n\n", _("No script files found in the script folder - exiting."));
265+
logger_err_printf("%s\n\n", _("No script files found in the script folder - exiting."));
265266
exit(EXIT_SUCCESS);
266267
}
267268
}
@@ -275,19 +276,17 @@ void refresh_config_and_script()
275276
set_current_window(NULL);
276277

277278
if (load_config(config_filename) != 0) {
278-
printf("Configuration file cannot be re-loaded. Processing will not continue until the error is corrected");
279+
logger_print_always("Configuration file cannot be re-loaded. Processing will not continue until the error is corrected.\n");
279280
return;
280281
}
281282

282283
global_lua_state = reinit_script(global_lua_state, script_folder);
283284

284-
if (debug)
285-
printf("Files in folder updated!\n - new lists:\n\n");
285+
logger_print("Files in folder updated!\n - new lists:\n\n");
286286

287287
print_script_lists();
288288

289-
if (debug)
290-
printf("-----------\n");
289+
logger_print("-----------\n");
291290
}
292291

293292
/**
@@ -332,7 +331,6 @@ void folder_changed_callback(GFileMonitor *mon G_GNUC_UNUSED,
332331
}
333332
}
334333

335-
336334
/**
337335
* Program main entry
338336
*/
@@ -342,6 +340,12 @@ int main(int argc, char *argv[])
342340
{ "debug", 'd', 0, G_OPTION_ARG_NONE, &debug,
343341
N_("Print debug info to stdout"), NULL
344342
},
343+
{ "debug-fifo", 'D', 0, G_OPTION_ARG_NONE, &logtofifo,
344+
N_("Print debug info & copy stdout to a FIFO"), NULL
345+
},
346+
{ "print-fifo", 'P', 0, G_OPTION_ARG_NONE, &show_fifo,
347+
N_("Print the debug FIFO's file name then quit"), NULL
348+
},
345349
{ "emulate", 'e', 0, G_OPTION_ARG_NONE, &emulate,
346350
N_("Don't apply any rules, only emulate execution"), NULL
347351
},
@@ -383,6 +387,12 @@ int main(int argc, char *argv[])
383387
printf("\n");
384388
exit(EXIT_FAILURE);
385389
}
390+
391+
if (show_fifo) {
392+
puts(logger_get_fifo_name());
393+
exit(EXIT_SUCCESS);
394+
}
395+
386396
gboolean shown = FALSE;
387397
if (show_version) {
388398
printf("Devilspie2 v%s\n", DEVILSPIE2_VERSION);
@@ -503,9 +513,11 @@ int main(int argc, char *argv[])
503513
(gpointer)(config_filename));
504514

505515
global_lua_state = init_script(script_folder);
516+
if (logtofifo)
517+
logger_create(global_lua_state);
506518
print_script_lists();
507519

508-
if (debug) printf("------------\n");
520+
logger_print("------------\n");
509521

510522
// remove stuff cleanly
511523
atexit(devilspie_exit);

0 commit comments

Comments
 (0)