Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

swaygrab no longer exits #1350

Closed
helaan opened this issue Sep 11, 2017 · 4 comments
Closed

swaygrab no longer exits #1350

helaan opened this issue Sep 11, 2017 · 4 comments

Comments

@helaan
Copy link

helaan commented Sep 11, 2017

When running the git version of Sway, swaygrab no longer works: it just waits there, doing nothing. I suspect fab5720 is to blame as it is the only commit since 0.14.0, but I have not formally bisected this.

@helaan
Copy link
Author

helaan commented Sep 11, 2017

I've tried to fix it myself, but it doesn't quite work yet: convert now exits with the following:

convert: unable to open image `8': No such file or directory @ error/blob.c/OpenBlob/2701.
convert: no decode delegate for this image format `' @ error/constitute.c/ReadImage/504.
convert: unexpected end-of-file `-': No such file or directory @ error/rgb.c/ReadRGBImage/239.

Here is my non-functional patch:

diff --git a/swaygrab/main.c b/swaygrab/main.c
index 6e85189..c5f4922 100644
--- a/swaygrab/main.c
+++ b/swaygrab/main.c
@@ -58,13 +58,15 @@ void grab_and_apply_magick(const char *file, const char *payload,
 	if ((child = fork()) < 0) {
 		sway_log(L_ERROR, "Swaygrab failed to fork.");
 		exit(EXIT_FAILURE);
-	} else if (child == 0) {
+	} else if (child != 0) {
+		close(fd[0]);
+		write(fd[1], pixels, len);
 		close(fd[1]);
-		write(fd[0], pixels, len);
 		free(pixels - 9);
 		waitpid(child, NULL, 0);
 	} else {
-		close(fd[0]);
+		close(fd[1]);
+		dup2(fd[0], 0);
 		execlp("convert", "-depth", "8", "-size", size, "rgba:-", "-flip", file, NULL);
 		sway_log(L_ERROR, "Swaygrab could not run convert.");
 		exit(EXIT_FAILURE);
-- 
2.13.5

Ongy pushed a commit to Ongy/sway that referenced this issue Sep 11, 2017
swaywm#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.
@ddevault
Copy link
Contributor

Can you test #1351 please?

@helaan
Copy link
Author

helaan commented Sep 12, 2017

#1351 works, swaygrab seems to work fine now.

@ddevault
Copy link
Contributor

Cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants