summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Markus Ongyerth <ongy@ongy.net>2017-09-11 22:32:00 +0200
committerLibravatar Markus Ongyerth <ongy@ongy.net>2017-09-11 22:32:00 +0200
commit22656ae1e423918eb3bbee78c463e4cd190491de (patch)
tree8d17ab39341f29d36983fe069793139498feeb0c
parentMerge pull request #1342 from DarkReef/master (diff)
downloadsway-22656ae1e423918eb3bbee78c463e4cd190491de.tar.gz
sway-22656ae1e423918eb3bbee78c463e4cd190491de.tar.zst
sway-22656ae1e423918eb3bbee78c463e4cd190491de.zip
fixes a hanging swaygrab
https://github.com/SirCmpwn/sway/issues/1350 is fixed with this. The commit that change swaygrab to use fork instead of Popen tried to write to the read end of the pipe in the child branch and exec in the parent branch. This commit fixes both of those and closes the write fd after writing, so convert actually exits.
-rw-r--r--swaygrab/main.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/swaygrab/main.c b/swaygrab/main.c
index 6e851899..1b699bb9 100644
--- a/swaygrab/main.c
+++ b/swaygrab/main.c
@@ -58,14 +58,19 @@ void grab_and_apply_magick(const char *file, const char *payload,
58 if ((child = fork()) < 0) { 58 if ((child = fork()) < 0) {
59 sway_log(L_ERROR, "Swaygrab failed to fork."); 59 sway_log(L_ERROR, "Swaygrab failed to fork.");
60 exit(EXIT_FAILURE); 60 exit(EXIT_FAILURE);
61 } else if (child == 0) { 61 } else if (child != 0) {
62 close(fd[0]);
63 write(fd[1], pixels, len);
62 close(fd[1]); 64 close(fd[1]);
63 write(fd[0], pixels, len);
64 free(pixels - 9); 65 free(pixels - 9);
65 waitpid(child, NULL, 0); 66 waitpid(child, NULL, 0);
66 } else { 67 } else {
68 close(fd[1]);
69 if (dup2(fd[0], 0) != 0) {
70 sway_log(L_ERROR, "Could not fdup the pipe");
71 }
67 close(fd[0]); 72 close(fd[0]);
68 execlp("convert", "-depth", "8", "-size", size, "rgba:-", "-flip", file, NULL); 73 execlp("convert", "convert", "-depth", "8", "-size", size, "rgba:-", "-flip", file, NULL);
69 sway_log(L_ERROR, "Swaygrab could not run convert."); 74 sway_log(L_ERROR, "Swaygrab could not run convert.");
70 exit(EXIT_FAILURE); 75 exit(EXIT_FAILURE);
71 } 76 }
@@ -104,7 +109,7 @@ void grab_and_apply_movie_magic(const char *file, const char *payload,
104 "-video_size %dx%d -pixel_format argb " 109 "-video_size %dx%d -pixel_format argb "
105 "-i pipe:0 -r %d -vf vflip %s"; 110 "-i pipe:0 -r %d -vf vflip %s";
106 char *cmd = malloc(strlen(fmt) - 8 /*args*/ 111 char *cmd = malloc(strlen(fmt) - 8 /*args*/
107 + strlen(ffmpeg_opts) + numlen(width) + numlen(height) 112 + strlen(ffmpeg_opts) + numlen(width) + numlen(height)
108 + numlen(framerate) * 2 + strlen(file) + 1); 113 + numlen(framerate) * 2 + strlen(file) + 1);
109 sprintf(cmd, fmt, ffmpeg_opts, framerate, width, height, framerate, file); 114 sprintf(cmd, fmt, ffmpeg_opts, framerate, width, height, framerate, file);
110 115