aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLibravatar smitsohu <smitsohu@gmail.com>2020-03-19 23:56:43 +0100
committerLibravatar GitHub <noreply@github.com>2020-03-19 23:56:43 +0100
commit132d606af0b544cfe728a7dfe660858df69d62bf (patch)
treecfd5f3af8d6eb13f1685a1610552dadaab8fcf3c /src
parentMerge branch 'master' of https://github.com/netblue30/firejail (diff)
parenthandle malloc() failures; use gnu_basename() instead of basenaem() (diff)
downloadfirejail-132d606af0b544cfe728a7dfe660858df69d62bf.tar.gz
firejail-132d606af0b544cfe728a7dfe660858df69d62bf.tar.zst
firejail-132d606af0b544cfe728a7dfe660858df69d62bf.zip
Merge pull request #3275 from dmfreemon/add-name-or-private-dir-to-xpra-window-title
add name or private directory being used to the window title when xpra is being used
Diffstat (limited to 'src')
-rw-r--r--src/firejail/x11.c62
1 files changed, 61 insertions, 1 deletions
diff --git a/src/firejail/x11.c b/src/firejail/x11.c
index 6395903f9..74de24b47 100644
--- a/src/firejail/x11.c
+++ b/src/firejail/x11.c
@@ -625,6 +625,63 @@ void x11_start_xephyr(int argc, char **argv) {
625} 625}
626 626
627 627
628// this function returns the string that will appear in the window title when xpra is being used
629// this string may include one of these items:
630// * the "--name" argument, if specified
631// * the basename portion of the "--private" directory, if specified
632// note: the malloc() is leaking, but this is a small string allocated one time only during startup, so don't care
633static char * get_title_arg_str() {
634
635 char * title_arg_str = NULL;
636
637 const char * title_start = "--title=firejail x11 sandbox";
638 const char * title_sep = " ";
639
640 // use the "--name" argument if it was explicitly specified
641 if ((cfg.name != NULL) && (strlen(cfg.name) > 0)) {
642
643 title_arg_str = malloc(strlen(title_start) + strlen(title_sep) + strlen(cfg.name) + 1);
644 if (title_arg_str == NULL) {
645 fprintf(stderr, "Error: malloc() failed to allocate memory\n");
646 exit(1);
647 }
648
649 strcpy(title_arg_str, title_start);
650 strcat(title_arg_str, title_sep);
651 strcat(title_arg_str, cfg.name);
652 }
653
654 // use the "--private" argument if it was explicitly specified
655 else if ((cfg.home_private != NULL) && (strlen(cfg.home_private) > 0)) {
656
657 const char * base_out = gnu_basename(cfg.home_private);
658
659 title_arg_str = malloc(strlen(title_start) + strlen(title_sep) + strlen(base_out) + 1);
660 if (title_arg_str == NULL) {
661 fprintf(stderr, "Error: malloc() failed to allocate memory\n");
662 exit(1);
663 }
664
665 strcpy(title_arg_str, title_start);
666 strcat(title_arg_str, title_sep);
667 strcat(title_arg_str, base_out);
668 }
669
670 // default
671 else {
672 title_arg_str = malloc(strlen(title_start) + 1);
673 if (title_arg_str == NULL) {
674 fprintf(stderr, "Error: malloc() failed to allocate memory\n");
675 exit(1);
676 }
677
678 strcpy(title_arg_str, title_start);
679 }
680
681 return title_arg_str;
682}
683
684
628void x11_start_xpra_old(int argc, char **argv, int display, char *display_str) { 685void x11_start_xpra_old(int argc, char **argv, int display, char *display_str) {
629 EUID_ASSERT(); 686 EUID_ASSERT();
630 int i; 687 int i;
@@ -752,7 +809,10 @@ void x11_start_xpra_old(int argc, char **argv, int display, char *display_str) {
752 free(fname); 809 free(fname);
753 810
754 // build attach command 811 // build attach command
755 char *attach_argv[] = { "xpra", "--title=\"firejail x11 sandbox\"", "attach", display_str, NULL }; 812
813 char * title_arg_str = get_title_arg_str();
814
815 char *attach_argv[] = { "xpra", title_arg_str, "attach", display_str, NULL };
756 816
757 // run attach command 817 // run attach command
758 client = fork(); 818 client = fork();