Skip to content

Commit

Permalink
Fix race condition on shutdown
Browse files Browse the repository at this point in the history
This commit fixes primarily a race condition that occurs when xinit(1) shuts
down: by not acting properly fluxbox gets caught in an infinite loop. It
caused bug #1100.

xinit(1) sends a SIGHUP signal to all processes. fluxbox tries to shutdown
itself properly by shutting down workspaces and screens. While doing that, the
Xserver might be gone already. Additionally, fluxbox used to restart() itself
on SIGHUP, which is clearly not the right thing to do when xinit(1) is about
to end the session.

So, fluxbox does this:

* handling SIGHUP now shuts down fluxbox without clearing workspaces and
  screens.

* A 2 second alarm() is triggered in Fluxbox::shutdown() as a last resort

* XSetIOErrorHandler() is used to recognize the disconnect from the xserver.

* SIGUSR1 is for restarting fluxbox, SIGUSR2 for reloading the config

* FbTk/SignalHandler.cc/hh is gone; this unused abstraction served currently
  no real purpose. Signal handling is now done in main.cc

* Unrelated to the issue itself src/main.cc was trimmed down quite a bit and
  the code (responsible for handling the command line interface) was moved to
  src/cli*
  • Loading branch information
Mathias Gumz committed Feb 18, 2014
1 parent 3696562 commit 43bdf49
Show file tree
Hide file tree
Showing 17 changed files with 701 additions and 874 deletions.
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ AC_FUNC_SELECT_ARGTYPES
AC_FUNC_STAT

AC_CHECK_FUNCS(basename, , AC_CHECK_LIB(gen, basename, LIBS="-lgen $LIBS"))
AC_CHECK_FUNCS(catclose catgets catopen getpid memset mkdir \
AC_CHECK_FUNCS(alarm catclose catgets catopen getpid memset mkdir \
nl_langinfo putenv regcomp select setenv setlocale sigaction snprintf \
sqrt strcasecmp strcasestr strchr strstr strtol strtoul sync vsnprintf)

Expand Down
5 changes: 2 additions & 3 deletions doc/asciidoc/fluxbox.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1256,9 +1256,8 @@ SIGNALS
-------
fluxbox responds to the following signals:

- SIGHUP fluxbox loads the configuration.
- SIGUSR1 Forces reloading of configuration.
- SIGUSR2 Forces reloading of menu file.
- SIGUSR1 restarts fluxbox.
- SIGUSR2 Forces reloading of configuration.

AUTHORS
-------
Expand Down
4 changes: 3 additions & 1 deletion src/Debug.hh
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#ifndef DEBUG_HH
#define DEBUG_HH

#ifdef HAVE_CONFIG_H
#include "config.h"
#include <iostream>
#endif // HAVE_CONFIG_H

#ifdef DEBUG
#include <iostream>
#define fbdbg std::cerr<<__FILE__<<"("<<__LINE__<< "): "
#else
#define fbdbg if (false) std::cerr
Expand Down
2 changes: 1 addition & 1 deletion src/FbTk/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ libFbTk_a_SOURCES = App.hh App.cc \
MultiButtonMenuItem.hh MultiButtonMenuItem.cc \
MenuTheme.hh MenuTheme.cc NotCopyable.hh \
BorderTheme.hh BorderTheme.cc TextTheme.hh TextTheme.cc \
RefCount.hh SimpleCommand.hh SignalHandler.cc SignalHandler.hh \
RefCount.hh SimpleCommand.hh \
TextUtils.hh TextUtils.cc Orientation.hh \
Texture.cc Texture.hh TextureRender.hh TextureRender.cc \
Shape.hh Shape.cc \
Expand Down
79 changes: 0 additions & 79 deletions src/FbTk/SignalHandler.cc

This file was deleted.

66 changes: 0 additions & 66 deletions src/FbTk/SignalHandler.hh

This file was deleted.

5 changes: 4 additions & 1 deletion src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ defaults.hh: Makefile
echo '#else'; \
echo '#define PATHPREFIX'; \
echo '#endif'; \
echo '#define CONFIG_VERSION 13'; \
echo '#define DEFAULTMENU PATHPREFIX "$(DEFAULT_MENU)"'; \
echo '#define DEFAULTSTYLE PATHPREFIX "$(DEFAULT_STYLE)"'; \
echo '#define DEFAULTKEYSFILE PATHPREFIX "$(DEFAULT_KEYSFILE)"'; \
Expand Down Expand Up @@ -123,7 +124,9 @@ fluxbox_SOURCES = AtomHandler.hh ArrowButton.hh ArrowButton.cc \
FbAtoms.hh FbAtoms.cc FbWinFrame.hh FbWinFrame.cc \
FbWinFrameTheme.hh FbWinFrameTheme.cc \
fluxbox.cc fluxbox.hh \
Keys.cc Keys.hh main.cc \
Keys.cc Keys.hh \
main.cc \
cli.hh cli_cfiles.cc cli_options.cc cli_info.cc \
RootTheme.hh RootTheme.cc \
FbRootWindow.hh FbRootWindow.cc \
OSDWindow.hh OSDWindow.cc \
Expand Down
50 changes: 50 additions & 0 deletions src/cli.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#ifndef CLI_HH
#define CLI_HH

// cli.hh for Fluxbox Window Manager
// Copyright (c) 2014 - Mathias Gumz <akira at fluxbox.org>
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.

#include <fstream>
#include <string>

namespace FluxboxCli {

struct Options {
Options();
int parse(int argc, char** argv);

std::string session_display;
std::string rc_path;
std::string rc_file;
std::string log_filename;
bool xsync;
};


void showInfo(std::ostream&);

void setupConfigFiles(const std::string& dirname, const std::string& rc);
void updateConfigFilesIfNeeded(const std::string& rc_file);

}

#endif /* end of include guard: CLI_HH */

0 comments on commit 43bdf49

Please sign in to comment.