Lars Henriksen 5e53708648 Solve deadlock in notification bar
calcurse deadlocks when

1) an upcoming appointment is on display in the notification bar,
2) an external command (like help) is started,
3) the time for the upcoming appointment arrives, and
4) the external command is exited.

The notification bar thread is stopped while the external command is
running. Upon exit from the external command, the n-bar thread is
restarted and calcurse locks.

The cause is the way in which the main notification bar thread is
stopped:

static pthread_t notify_t_main;
void notify_stop_main_thread(void)
{
	if (notify_t_main) {
		pthread_cancel(notify_t_main);
		pthread_join(notify_t_main, NULL);
	}
}

Objects of type pthread_t are opaque and should not be accessed
directly.  Initially notify_t_main is an uninitialised static variable
(0), but later it has a value, which may or may not be the thread id of
the notification main thread.

Note that the thread id after exit of a thread may become the thread id
of a new thread. Thus the variable set when the thread is created, is
invalid after exit of the thread.

Specifically, the first time notify_stop_main_thread() is called (by
notify_start_main_thread() before the thread is created) is harmless
(because notify_t_main is 0). Calling notify_stop_main_thread() later
may be either

OK
    because the main thread is running, or
harmless
    because no thread with id notify_t_main is running: the two
    functions will fail with return value ESRCH (no such process), or
fatal
    because an unrelated thread with this thread id is running: it will
    be cancelled, and the join may or may not succeed depending on
    whether the thread is joinable or detached.

The "unrelated thread" could be the next-appointment thread,
notify_thread_app, launched by notify_check_next_app().

Always calling notify_stop_main_thread() before starting the main thread
becomes fatal when notify_check_next_app() is called shortly before
notify_start_main_thread(). This is the case in the scenario described.
The next-app-thread is then running when notify_stop_main_thread() is
called, and apparently it has the thread id of the old main thread
(confirmed by logging the return values from pthread_cancel() and
pthread_join(); the first succeeds while the second fails with EINVALID
which means that the thread is not joinable). The next-app-thread will
therefore exit without unlocking mutexes.

Ensure that notify_t_main, in case the notify main thread is not
running, has a value that it will never have when it is running. A
possibility is the thread id of the main() calcurse process (returned by
pthread_self()).

Check for this condition in notify_stop_main_thread() and set
notify_t_main when the thread is stopped.

Similar changes have been introduced for the periodic save thread and
the calendar date thread.

Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk>
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-07-28 14:06:15 +02:00
2014-07-28 13:12:42 +02:00
2017-11-02 08:42:52 +01:00
2017-11-02 08:42:52 +01:00
2017-01-12 08:40:30 +01:00
2018-07-28 14:06:15 +02:00
2012-11-26 01:46:56 +01:00
2015-04-12 17:32:44 +02:00
2015-04-12 19:14:15 +02:00
2017-01-12 08:40:30 +01:00
2017-11-02 08:42:52 +01:00
2017-01-12 08:40:30 +01:00
2011-03-03 12:21:16 +01:00
2016-02-09 22:22:12 +01:00
2017-11-10 16:01:18 +01:00

calcurse

Building

Install the following build dependencies. If your distro segments development files from core packages (i.e., *-devel or *-dev packages), you may need to install those as well:

  • gcc
  • automake
  • asciidoc
  • gettext with development files
  • ncurses with development files

If you are using a release tarball, the following commands can be used to build and install calcurse:

$ ./configure
$ make
$ make install

Note that make install needs to be run as root. When working on a Git checkout, you need to run ./autogen.sh before ./configure.

Package Overview

  • src: contains calcurse sources
  • test: contains a test suite and test cases for calcurse
  • scripts: contains additional scripts, such as calcurse-upgrade
  • doc: contains detailed documentation in plain text and HTML

Authors

  • Lukas Fleischer (Maintainer)
  • Frederic Culot (Original Author)

Contributors

  • RegEx support: Erik Saule
  • Dutch translation: Jeremy Roon, 2007-2010
  • French translation: Frédéric Culot, 2006-2010
  • French translation: Toucouch, 2007
  • French translation: Erik Saule, 2011-2012
  • French translation: Stéphane Aulery, 2012
  • French translation: Baptiste Jonglez, 2012
  • German translation: Michael Schulz, 2006-2010
  • German translation: Chris M., 2006
  • German translation: Benjamin Moeller, 2010
  • German translation: Lukas Fleischer, 2011-2012
  • Portuguese (Brazil) translation: Rafael Ferreira, 2012
  • Russian translation: Aleksey Mechonoshin, 2011-2012
  • Spanish translation: Jose Lopez, 2006-2010

Also check the Thanks section in the manual for a list of people who have contributed by reporting bugs, sending fixes, or suggesting improvements.

Description
No description provided
Readme 5.2 MiB
Languages
C 65.7%
Shell 29.6%
Python 3.4%
M4 0.8%
Makefile 0.5%