Skip to content

Commit 0cd609c

Browse files
committed
Adding logging for labwc / wayvnc
Add a way to create debug logs for labwc and wayvnc
1 parent 8a80033 commit 0cd609c

File tree

4 files changed

+161
-15
lines changed

4 files changed

+161
-15
lines changed

sesman/libsesman/sesman_config.c

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -429,8 +429,11 @@ config_read_labwc(int file, struct config_labwc *sc,
429429
list_clear(param_n);
430430

431431
/* setting defaults */
432-
sc->labwc_exe_path = g_strdup("");
433-
sc->wayvnc_exe_path = g_strdup("");
432+
sc->labwc_exe = g_strdup("");
433+
sc->wayvnc_exe = g_strdup("");
434+
sc->enable_labwc_log = 0;
435+
sc->enable_wayvnc_log = 0;
436+
sc->log_file_path = g_strdup("");
434437

435438
file_read_section(file, "Labwc", param_n, param_v);
436439

@@ -441,18 +444,32 @@ config_read_labwc(int file, struct config_labwc *sc,
441444

442445
if (0 == g_strcasecmp(buf, "LabwcExe"))
443446
{
444-
g_free(sc->labwc_exe_path);
445-
sc->labwc_exe_path = g_strdup(value);
447+
g_free(sc->labwc_exe);
448+
sc->labwc_exe = g_strdup(value);
449+
}
450+
else if (0 == g_strcasecmp(buf, "EnableLabwcLog"))
451+
{
452+
sc->enable_labwc_log = g_text2bool(value);
446453
}
447454
else if (0 == g_strcasecmp(buf, "WayvncExe"))
448455
{
449-
g_free(sc->labwc_exe_path);
450-
sc->wayvnc_exe_path = g_strdup(value);
456+
g_free(sc->wayvnc_exe);
457+
sc->wayvnc_exe = g_strdup(value);
458+
}
459+
else if (0 == g_strcasecmp(buf, "EnableWayvncLog"))
460+
{
461+
sc->enable_wayvnc_log = g_text2bool(value);
462+
}
463+
else if (0 == g_strcasecmp(buf, "LogFilePath"))
464+
{
465+
g_free(sc->log_file_path);
466+
sc->log_file_path = g_strdup(value);
451467
}
452468
}
453469

454470
/* Check all memory allocations worked */
455-
if (sc->labwc_exe_path == NULL || sc->wayvnc_exe_path == NULL)
471+
if (sc->labwc_exe == NULL || sc->wayvnc_exe == NULL ||
472+
sc->log_file_path == NULL)
456473
{
457474
LOG(LOG_LEVEL_ERROR, "Memory allocation failure reading config");
458475
return 1;
@@ -805,9 +822,15 @@ config_dump(struct config_sesman *config)
805822
/* labwc */
806823
g_writeln("labwc parameters:");
807824
g_writeln(" LabwcExe: %s",
808-
config->labwc.labwc_exe_path);
825+
config->labwc.labwc_exe);
809826
g_writeln(" WayvncExe: %s",
810-
config->labwc.wayvnc_exe_path);
827+
config->labwc.wayvnc_exe);
828+
g_writeln(" EnableLabwcLog: %d",
829+
config->labwc.enable_labwc_log);
830+
g_writeln(" EnableWayvncLog: %d",
831+
config->labwc.enable_wayvnc_log);
832+
g_writeln(" LogFilePath: %s",
833+
config->labwc.log_file_path);
811834

812835
/* SessionVariables */
813836
if (config->env_names->count)
@@ -841,8 +864,9 @@ config_free(struct config_sesman *cs)
841864
g_free(cs->sec.ts_users);
842865
g_free(cs->sec.ts_admins);
843866
g_free(cs->sec.session_sockdir_group);
844-
g_free(cs->labwc.labwc_exe_path);
845-
g_free(cs->labwc.wayvnc_exe_path);
867+
g_free(cs->labwc.labwc_exe);
868+
g_free(cs->labwc.wayvnc_exe);
869+
g_free(cs->labwc.log_file_path);
846870
g_free(cs);
847871
}
848872
}

sesman/libsesman/sesman_config.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,11 @@ struct config_sessions
175175

176176
struct config_labwc
177177
{
178-
char *labwc_exe_path;
179-
char *wayvnc_exe_path;
178+
char *labwc_exe;
179+
char *wayvnc_exe;
180+
int enable_labwc_log;
181+
int enable_wayvnc_log;
182+
char *log_file_path;
180183
};
181184

182185
/**

sesman/sesexec/session_labwc.c

Lines changed: 112 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,97 @@ start_window_manager(struct session_data *baseobj,
192192
s->x11_display);
193193
}
194194

195+
/*****************************************************************************/
196+
/*
197+
* Opens a log file on stdout and stderr
198+
* @param name Unqualified name
199+
* @return != 0 for error
200+
*
201+
* @pre Current directory is $HOME
202+
*
203+
* The file is either opened or not. If not, an error is logged on the
204+
* standard mechanisms
205+
*/
206+
static int
207+
redirect_stdout_stderr(const char *name)
208+
{
209+
char path[256];
210+
char *log_path;
211+
int rv;
212+
213+
rv = 1;
214+
// Use the log path if it exists
215+
if ((log_path = g_cfg->labwc.log_file_path) != NULL && log_path[0] != '\0')
216+
{
217+
char uidstr[64];
218+
char username[64];
219+
const struct info_string_tag map[] =
220+
{
221+
{'u', uidstr},
222+
{'U', username},
223+
INFO_STRING_END_OF_LIST
224+
};
225+
226+
int uid = g_getuid();
227+
g_snprintf(uidstr, sizeof(uidstr), "%d", uid);
228+
if (g_getlogin(username, sizeof(username)) != 0)
229+
{
230+
/* Fall back to UID */
231+
g_strncpy(username, uidstr, sizeof(username) - 1);
232+
}
233+
234+
(void)g_format_info_string(path, sizeof(path), log_path, map);
235+
if (g_create_path(path))
236+
{
237+
rv = 0;
238+
}
239+
}
240+
else if ((log_path = g_getenv("XDG_DATA_HOME")) != NULL &&
241+
log_path[0] != '\0')
242+
{
243+
g_snprintf(path, sizeof(path), "%s/xrdp", log_path);
244+
if (g_create_path(path))
245+
{
246+
rv = 0;
247+
}
248+
}
249+
250+
// Always fall back to the home directory
251+
if (rv != 0)
252+
{
253+
strlcpy(path, ".local/share/xrdp", sizeof(path));
254+
if (g_create_path(path))
255+
{
256+
rv = 0;
257+
}
258+
}
259+
260+
if (rv == 0)
261+
{
262+
/* Add the name to the end */
263+
unsigned int len = strlen(path);
264+
if (len < sizeof(path))
265+
{
266+
g_snprintf(path + len, sizeof(path) - len, "/%s", name);
267+
}
268+
269+
int fd = g_file_open_rw(path);
270+
if (fd >= 0)
271+
{
272+
g_file_duplicate_on(fd, 1);
273+
g_file_duplicate_on(fd, 2);
274+
g_file_close(fd);
275+
}
276+
else
277+
{
278+
LOG(LOG_LEVEL_ERROR, "Can't open %s for writing [%s]",
279+
path, g_get_strerror());
280+
rv = 1;
281+
}
282+
}
283+
return rv;
284+
}
285+
195286
/******************************************************************************/
196287
/* Either execs wayvnc, or returns */
197288
static void
@@ -211,7 +302,7 @@ start_wayvnc(struct session_data *baseobj,
211302
auth_set_env(login_info->auth_info);
212303

213304
/* get path of wayvnc from config */
214-
const char *wayvnc = g_cfg->labwc.wayvnc_exe_path;
305+
const char *wayvnc = g_cfg->labwc.wayvnc_exe;
215306
if (wayvnc == NULL || wayvnc[0] == '\0')
216307
{
217308
wayvnc = "wayvnc";
@@ -242,6 +333,17 @@ start_wayvnc(struct session_data *baseobj,
242333
LOG(LOG_LEVEL_INFO, "Starting wayvnc: %s",
243334
dumpItemsToString(params, execvpparams, 2048));
244335
LOG_DEVEL_LEAKING_FDS("wayvnc", 3, -1);
336+
337+
/* Logging? */
338+
if (g_cfg->labwc.enable_wayvnc_log)
339+
{
340+
char name[64];
341+
g_snprintf(name, sizeof(name),
342+
"wayvnc.%s.log", baseobj->display);
343+
redirect_stdout_stderr(name);
344+
(void)list_add_strdup_multi(params, "-L", "debug", NULL);
345+
}
346+
245347
g_execvp_list((const char *)params->items[0],
246348
params);
247349

@@ -292,7 +394,7 @@ start_labwc(struct session_data *baseobj,
292394
g_setenv("LABWC_UPDATE_ACTIVATION_ENV", "1", 1);
293395

294396
/* get path of labwc from config */
295-
const char *labwc = g_cfg->labwc.labwc_exe_path;
397+
const char *labwc = g_cfg->labwc.labwc_exe;
296398
if (labwc == NULL || labwc[0] == '\0')
297399
{
298400
labwc = "labwc";
@@ -314,6 +416,14 @@ start_labwc(struct session_data *baseobj,
314416
LOG(LOG_LEVEL_INFO, "Starting labwc: %s",
315417
dumpItemsToString(params, execvpparams, 2048));
316418
LOG_DEVEL_LEAKING_FDS("labwc", 3, -1);
419+
420+
/* Logging? */
421+
if (g_cfg->labwc.enable_labwc_log)
422+
{
423+
redirect_stdout_stderr("labwc.log");
424+
(void)list_add_strdup_multi(params, "-d", NULL);
425+
}
426+
317427
g_execvp_list((const char *)params->items[0],
318428
params);
319429

sesman/sesman.ini.in

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,15 @@ param=96
183183
[Labwc]
184184
#LabwcExe=labwc
185185
#WayvncExe=wayvnc
186+
; Enable debug logs
187+
;
188+
; The labwc log cannot be qualified with a WAYLAND_DISPLAY. If a user
189+
; has two or more labwc sessions running at once, the labwc logs for
190+
; the sessions will collide.
191+
#EnableLabwcLog=0
192+
#EnableWayvncLog=0
193+
; Log file path (the default is in $XDG_DATA_HOME/xrdp)
194+
#LogFilePath=/run/user/%u/xrdp
186195

187196
[Chansrv]
188197
; drive redirection

0 commit comments

Comments
 (0)