Skip to content

Commit

Permalink
log: expose ability query/set fd
Browse files Browse the repository at this point in the history
This allows for the logging FD to be queried and set -- which is useful
for modules to be able to know the FD for being able to use fvwm_debug()
  • Loading branch information
ThomasAdam committed Dec 30, 2024
1 parent 2c0c3c5 commit 1c15e5b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
11 changes: 11 additions & 0 deletions fvwm/modconf.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#include "module_interface.h"
#include "colorset.h"
#include "libs/FScreen.h"
#include "libs/log.h"
#include "expand.h"

extern int nColorsets; /* in libs/Colorset.c */
Expand Down Expand Up @@ -365,6 +366,15 @@ void send_ignore_modifiers(fmodule *module)
return;
}

void
send_logging_fd(fmodule *module)
{
char msg[64];

snprintf(msg, sizeof(msg), "LoggingFD %d\n", log_get_fd());
SendName(module, M_CONFIG_INFO, 0, 0, 0, msg);
}

void send_monitor_list(fmodule *module)
{
BroadcastMonitorList(module);
Expand All @@ -387,6 +397,7 @@ void CMD_Send_ConfigInfo(F_CMD_ARGS)
send_click_time(mod);
send_move_threshold(mod);
send_desktop_geometry(mod);
send_logging_fd(mod);
match = PeekToken(action, &action);
if (match)
{
Expand Down
18 changes: 18 additions & 0 deletions libs/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,24 @@ static char *log_file_name;
static FILE *log_file;
int lib_log_level = 0;

int
log_get_fd(void)
{
if (log_file == NULL)
return -1;
return fileno(log_file);
}

void
log_set_fd(int fd)
{
if (fd == -1)
return;

/* This is enough to allow modules to be able to log. */
log_file = fdopen(fd, "a");
}

void
set_log_file(char *name)
{
Expand Down
2 changes: 2 additions & 0 deletions libs/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ void set_log_file(char *name);
void log_open(const char *);
void log_toggle(const char *);
void log_close(void);
int log_get_fd(void);
void log_set_fd(int);
void printflike(2, 3) fvwm_debug(const char *, const char *, ...);

#endif

0 comments on commit 1c15e5b

Please sign in to comment.