mirror of
				https://github.com/gnif/LookingGlass.git
				synced 2025-11-02 21:52:01 +00:00 
			
		
		
		
	[common] open: detach xdg-open instead of waiting for it
Sometimes, e.g. when xdg-open has to start the browser, the xdg-open process can stay around until the browser exits, which freezes the client. Instead, we should not wait for xdg-open to exit. However, we can't simply not call wait, as that would leave the xdg-open process around as a zombie. We could turn off the SIGCHLD handler, but that's a global solution to a local problem. Instead, we call setsid and fork again to detach the xdg-open process as if it's a daemon, and let init take care of the reaping process. Co-Authored-By: Tudor Brindus <me@tbrindus.ca>
This commit is contained in:
		@@ -31,8 +31,15 @@ static bool xdgOpen(const char * path)
 | 
			
		||||
  pid_t pid = fork();
 | 
			
		||||
  if (pid == 0)
 | 
			
		||||
  {
 | 
			
		||||
    execlp("xdg-open", "xdg-open", path, NULL);
 | 
			
		||||
    _exit(127);
 | 
			
		||||
    // setsid and fork again to detach the xdg-open process.
 | 
			
		||||
    setsid();
 | 
			
		||||
    pid_t pid = fork();
 | 
			
		||||
    if (pid == 0)
 | 
			
		||||
    {
 | 
			
		||||
      execlp("xdg-open", "xdg-open", path, NULL);
 | 
			
		||||
      _exit(127);
 | 
			
		||||
    }
 | 
			
		||||
    _exit(pid < 0);
 | 
			
		||||
  }
 | 
			
		||||
  else if (pid < 0)
 | 
			
		||||
  {
 | 
			
		||||
@@ -52,9 +59,9 @@ static bool xdgOpen(const char * path)
 | 
			
		||||
      return true;
 | 
			
		||||
 | 
			
		||||
    if (WIFEXITED(status))
 | 
			
		||||
      DEBUG_ERROR("xdg-open exited with code %d", WEXITSTATUS(status));
 | 
			
		||||
      DEBUG_ERROR("helper process exited with code %d", WEXITSTATUS(status));
 | 
			
		||||
    else
 | 
			
		||||
      DEBUG_ERROR("xdg-open exited with signal: %s", strsignal(WTERMSIG(status)));
 | 
			
		||||
      DEBUG_ERROR("helper process exited with signal: %s", strsignal(WTERMSIG(status)));
 | 
			
		||||
    return false;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user