all repos — tint2 @ f4ec61340fbbcc2640a1014a7d5cdb2065c137b0

fork of the tint2 desktop panel for my custom setup - only minimized windows across all desktops for the taskbar

Fix fd leak to children
o9000 mrovi9000@gmail.com
commit

f4ec61340fbbcc2640a1014a7d5cdb2065c137b0

parent

a46d22b31f3185d6c346f745d2ade3f3a07dcd0c

3 files changed, 14 insertions(+), 1 deletions(-)

jump to
M src/execplugin/execplugin.csrc/execplugin/execplugin.c

@@ -644,6 +644,7 @@ close(pipe_fd_stdout[1]);

close(pipe_fd_stderr[0]); dup2(pipe_fd_stderr[1], 2); // 2 is stderr close(pipe_fd_stderr[1]); + close_all_fds(); setpgid(0, 0); execl("/bin/sh", "/bin/sh", "-c", execp->backend->command, NULL); // This should never happen!
M src/util/common.csrc/util/common.c

@@ -230,6 +230,7 @@ setsid();

// Run the command if (dir) chdir(dir); + close_all_fds(); execl("/bin/sh", "/bin/sh", "-c", command, NULL); fprintf(stderr, "Failed to execlp %s\n", command); #if HAVE_SN

@@ -754,7 +755,8 @@ available_width = MAX(0, available_width);

available_height = MAX(0, available_height); Pixmap pmap = XCreatePixmap(server.display, server.root_win, available_height, available_width, server.depth); - cairo_surface_t *cs = cairo_xlib_surface_create(server.display, pmap, server.visual, available_height, available_width); + cairo_surface_t *cs = + cairo_xlib_surface_create(server.display, pmap, server.visual, available_height, available_width); cairo_t *c = cairo_create(cs); PangoLayout *layout = pango_cairo_create_layout(c);

@@ -848,3 +850,11 @@ return 0;

else return 1; } + +void close_all_fds() +{ + long maxfd = sysconf(_SC_OPEN_MAX); + for (int fd = 3; fd < maxfd; fd++) { + close(fd); + } +}
M src/util/common.hsrc/util/common.h

@@ -116,6 +116,8 @@

// Clears the pixmap (with transparent color) void clear_pixmap(Pixmap p, int x, int y, int w, int h); +void close_all_fds(); + // Appends to the list locations all the directories contained in the environment variable var (split by ":"). // Optional suffixes are added to each directory. The suffix arguments MUST end with NULL. // Returns the new value of the list.