119 Commits

Author SHA1 Message Date
Lukas Fleischer
01ad848628 Update copyright ranges for 2022
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2022-03-11 11:33:19 -05:00
Lukas Fleischer
5398f3a24e Call setsid() for hook/notification commands
We do not want hook or notification commands to interact with the
terminal in any way. Create a new session for them.

Addresses GitHub issue #326.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2021-04-04 12:15:31 -04:00
Lukas Fleischer
193ad3415a Redirect standard descriptors for hook/notify commands
Disconnect stdin, stdout and stderr when running an external hook or
notification command. The previous solution of appending "<&- >&- 2>&-"
to the shell command line does not work if the command includes pipes.

Use shell_exec() in notify_launch_cmd() instead of a custom (and
incomplete) reimplementation of that command.

Partially addresses GitHub issue #326.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2021-04-04 12:15:31 -04:00
Lars Henriksen
f743eab5ac Remove SIGCHLD signal handler
The purpose is to make child_wait() reliable. The handler is meant for
the notify main thread, but signal handlers are shared by all threads.
In the calcurse main thread and the periodic save thread (hooks) the
handler and child_wait() will compete (if the signal handler kicks in
first, the waitpid() call in child_wait() will fail with errno ECHILD).

All child processes in the main thread, the notify thread, the periodic
save thread and the notify demon are explicitly waited for.

Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk>
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2020-07-26 10:31:28 -04:00
Lars Henriksen
3f7bd331c8 Use "struct rpt" to shorten argument lists
Also, prepare for extension of the structure, shorten names and
rearrange comments.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2020-04-28 07:32:44 -04:00
Lukas Fleischer
5ad76df5fe Update copyright ranges
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2020-01-30 19:22:23 +01:00
Lars Henriksen
a0129d6751 Fix next recurrent appointment deleted
If the notify bar displays a recurrent appointment after midnight as next
upcoming appointment, the bar is not updated when the appointment/occurrence is
deleted.  The problem is not seen in 4.3.0 because of the bug described in
commit 8cbd456, Fix next recurring appointment.  The problem and the solution is
the same, this time in the function notify_same_recur_item().

Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk>
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2019-12-23 13:16:39 -05:00
Lars Henriksen
371c7eb00f Fix display of time left before next appointment
In the notify bar, the clock is shown in hours, minutes and seconds,
whereas the time left to the next appointment is shown in hours and
minutes only. When you read the clock in hours and minutes (discarding
the seconds), you are mentally rounding down to the nearest minute. To
agree with that reading, the time left (in seconds) should be
(programmatically) rounded up to the nearest minute for display.

In that way the time left is counted down whenever the minute "hand" of
the clock "ticks", and reaches zero when the clock reaches the time of
the next appointment, not one minute before. Also, the clock (in hours
and minutes) and the time left always add up to the time of the next
appointment.

Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk>
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2019-04-13 11:58:04 +02:00
Lars Henriksen
a5d8ca5cbf Fix one-second warning period for notifications
Adresses GitHub issue #204, the interactive part.

Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk>
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2019-04-13 11:57:58 +02:00
Lukas Fleischer
03340db72e Use time_t for system time values
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2019-01-14 06:21:34 +01:00
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
Lukas Fleischer
30f411257a Do not stop already cancelled notification thread
Add a static state variable to indicate whether the notification thread
is already running or not. Only start the thread if the notification
thread is paused. Only stop the thread if the notification thread is
actually running.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-06-03 10:28:28 +02:00
Lukas Fleischer
65c2b6d9b8 notify.c: fix several buffer overflows
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-05-26 11:51:38 +02:00
Lars Henriksen
bb7381765c Scrollbar and right window border (corrected)
When a scrollbar is on display in APP or TOD windows, the right
vertical border (outside the scrollbar) is not highlighted
when the window is selected.

The scrollbar is always highlighted:
- when APP or TOD is deselected
- in configuration windows where borders otherwise are not

The patch moves the scrollbar parameters (except highlight)
from arguments of draw_scrollbar() to the function itself.
The highlight argument was 1; instead it is set higher in
the call hierarchy (wins_update_panels()) and passed on down.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-05-26 11:31:43 +02:00
Lukas Fleischer
8544e4a570 Rename keys_getch() to keys_get()
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-08-30 16:26:10 +02:00
Lukas Fleischer
9f6678bc49 Update copyright ranges
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-01-12 08:40:30 +01:00
Lukas Fleischer
e6f8a2932a Avoid starting the notification thread twice
Starting the notification thread more than once can result in strange
behavior. For example, when launching external commands, only the most
recently started thread is stopped which results in the external
command's screen output being overwritten by the notification bar.

Currently, there are a couple of situations where the thread is started
twice. As a first countermeasure, explicitly check whether the thread is
already running (and terminate it) before starting a new one.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-08-24 21:49:53 +02:00
Lukas Fleischer
e1b6d22669 Add proper UTF-8 support to the notification area
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-02-26 21:52:14 +01:00
Lukas Fleischer
978d24a9d2 Update copyright ranges
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-01-30 11:21:53 +01:00
Lukas Fleischer
ebe483c058 Support sending notifications for all appointments
In 45417bc (Add configuration option to notify all appointments,
2011-07-31), we added an option that allows for choosing whether the
user receives notifications only for flagged or only for unflagged
appointments. Convert this setting into a three-state option and allow
the user to additionally enable notifications for *all* appointments.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-01-27 08:29:33 +01:00
Lukas Fleischer
0145ba12ec Use time_t instead of long in several places
Start converting some variables and return values to store times from
long to time_t.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2015-02-24 13:57:47 +01:00
Lukas Fleischer
9ef427693b Update copyright ranges
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2015-02-07 11:42:20 +01:00
Lukas Fleischer
d0916ced78 Initialize prompt buffers in the configuration menus
malloc() does not make sure that the buffer is initialized to contain
all zeros. Initialize the buffer with the empty string.

Reported-by: Håkan Jerning <jerning@home.se>
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2014-07-18 08:38:15 +02:00
Lukas Fleischer
76563c9b90 Rework key binding context switching
Store key binding contexts using another data structure to optimize
space usage and execution time.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2014-07-17 21:08:55 +02:00
Lukas Fleischer
7920e761c9 Reintroduce key bindings in configuration menus
The key bindings display in the status bar was removed from the general
options menu in bd182fb (Use generic list box for general options,
2014-05-13) and from the notification options menu in 5eea05a (Use
generic list box for notification options, 2014-05-13). Display the new
key bindings to use for navigation.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2014-07-17 09:08:46 +02:00
Lukas Fleischer
e93030befb Add a cleanup handler for the notify main thread
Make sure we do not leave behind unusable mutexes when calling
pthread_cancel().

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2014-07-16 23:19:10 +02:00
Lukas Fleischer
2a15531bb9 Add support for caption rows in list boxes
This adds support for rows that cannot be selected. Such rows can be
used for section headings and the like.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2014-05-18 11:07:27 +02:00
Lukas Fleischer
4210fdd38a Add support for drawing highlighted decoration
This allows for drawing selected scroll windows and list boxes with a
highlighted border.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2014-05-18 11:03:03 +02:00
Lukas Fleischer
7cf42c1083 Remove numbers and whitespace from option menus
These are no longer needed since items are no longer accessed via
numeric keys.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2014-05-18 11:02:59 +02:00
Lukas Fleischer
05ba450c3b Reduce flicker when resizing in option menus
Do not update the main windows when resizing the terminal in the general
options menu or in the notification options menu.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2014-05-18 11:02:56 +02:00
Lukas Fleischer
5eea05a203 Use generic list box for notification options
This changes the notification options menu to use the new generic list
box implementation. The only user-visible change is that items are now
accessed via the arrow and edit key bindings instead of digits.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2014-05-18 11:02:52 +02:00
Lukas Fleischer
7184da0fa3 Rework scroll window implementation
This complete rewrite of the scroll window implementation decouples
scroll windows from every other window abstraction layer we use. Note
that this leads to some code duplication. The long-term purpose of this
rewrite, however, is to eventually make every panel use scroll windows.
This makes for a huge cleanup of the UI code.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2014-05-18 11:02:32 +02:00
Lukas Fleischer
694d28eb78 Use tabs instead of spaces for indentation
This completes our switch to the Linux kernel coding style. Note that we
still use deeply nested constructs at some places which need to be fixed
up later.

Converted using the `Lindent` script from the Linux kernel code base,
along with some manual fixes.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2013-04-14 00:19:01 +02:00
Lukas Fleischer
a363cb9b91 Fix braces in if-else statements
From the Linux kernel coding guidelines:

    Do not unnecessarily use braces where a single statement will do.
    [...] This does not apply if one branch of a conditional statement
    is a single statement. Use braces in both branches.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2013-02-17 09:19:04 +01:00
Lukas Fleischer
a7944d335e Update copyright ranges
Add 2013 to the copyright range for all source and documentation files.

Reported-by: Frederic Culot <frederic@culot.org>
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2013-02-04 20:10:14 +01:00
Lukas Fleischer
e492ac6f95 Add hidden key handler window
After BUG#6 had apparently been closed with the screen locks introduced
in commit a80f8dcf2c6eb3b54658218bc081ee9694204dd5, some people still
had problems with random characters appearing in the notification bar.
This was obviously caused by wgetch() refreshing the screen if the
status panel was changed. From wgetch(3):

    If the window is not a pad, and it has been moved or modified since
    the last call to wrefresh, wrefresh will be called before another
    character is read.

Since the wgetch(3) isn't thread-safe, there were race conditions
between the notification bar thread drawing to the notification bar and
wgetch() updating the screen. Introduce a (hidden) window that handles
all key presses and never gets changed in order to avoid this.

Also, call wins_wrefresh() explicitly in status_mesg(), since we can no
longer rely on wgetch() updating windows automatically.

Fixes reopened BUG#6. Note that this is a hotfix -- FR#26 has been
opened to ensure we fix this properly in the next major release.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-12-16 02:27:36 +01:00
Lukas Fleischer
0ea23c24bf Release screen mutex if thread dies
We did not setup a thread cleanup procedure which resulted in calcurse
freezing if a thread tried to draw on the screen after another thread
was canceled while locking the screen.

Note that this kind of cleanup handlers should be added to other mutexes
as well. This patch just removes the most common case of triggering a
deadlock.

Also note that we cannot move pthread_cleanup_push() and
pthread_cleanup_pop() into the locking/unlocking functions since both
pthread_cleanup_push() and pthread_cleanup_pop() may be implemented as
macros that must be used in pairs within the same lexical scope.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-11-23 11:12:08 +01:00
Lukas Fleischer
a80f8dcf2c Lock screen when drawing on the calendar/notification panel
Lock the screen if either the calendar panel or the notification bar is
updated to avoid race conditions.

Addresses BUG#6.

Note that we currently always use a screen-level lock, even if only one
window is affected. This is to be changed in the future.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-11-23 11:12:08 +01:00
Lukas Fleischer
e269f09438 Replace localtime() with localtime_r()
Since the result of localtime() is stored in a statically allocated
structure, data was overwritten when a context switch occurred during
(or shortly after) the execution of localtime(), potentially resulting
in critical data corruption. BUG#7 and BUG#8 are likely related.

This patch converts all usages of localtime() with localtime_r(), which
is thread-safe.

Reported-by: Baptiste Jonglez <baptiste@jonglez.org>
Reported-by: Erik Saule <esaule@bmi.osu.edu>
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-11-22 22:58:04 +01:00
Baptiste Jonglez
4c4d4d3eb3 Use mvwaddstr() instead of mvwprintw()
When we only want to display a string at a specific place of the
screen, there's no need to use the more complex mvwprintw(), use
mvwaddstr() instead.

This should be slightly more efficient, and, above all, it prevents
weird things to happen if our string contains a '%', being interpreted
as an unwanted format string.

Signed-off-by: Baptiste Jonglez <baptiste--git@jonglez.org>
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-05-31 20:27:43 +02:00
Lukas Fleischer
6898a9dcf1 Do not localize configuration options
The configuration options shown in the configuration menu are meant to
reflect the keys used in the configuration file. The descriptions
displayed alongside each option should be sufficient for non-English
speakers.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-05-23 23:09:55 +02:00
Lukas Fleischer
f5efea85a6 Merge branch 'maint'
Conflicts:
	src/io.c
	src/notify.c
	src/utils.c
2012-05-23 22:26:05 +02:00
Lukas Fleischer
cfd8ede2b3 Switch to Linux kernel coding style
Convert our code base to adhere to Linux kernel coding style using
Lindent, with the following exceptions:

* Use spaces, instead of tabs, for indentation.
* Use 2-character indentations (instead of 8 characters).

Rationale: We currently have too much levels of indentation. Using
8-character tabs would make huge code parts unreadable. These need to be
cleaned up before we can switch to 8 characters.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-05-21 10:13:05 +02:00
Lukas Fleischer
162b871682 src/notify.c: Fix printf() misuse
Make sure we actually copy the notification warning interval to the
correct buffer instead of printing it to stdout (using an arbitrary
format string). This makes sure the current warning interval is shown
when editing the field and also eliminates a potential format string
vulnerability.

Spotted with "-Wformat-nonliteral".

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-05-19 14:32:43 +02:00
Lukas Fleischer
7f68083027 Update configuration dialogs
Rename the configuration options shown in the configuration dialogs to
match the new naming scheme used in the configuration file.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-05-17 22:07:44 +02:00
Lukas Fleischer
6da787a5cc Declare several parameters/variables constant
Add the "const" keyword to parameters and variables that are never
modified. Most of these were spotted by "-Wwrite-strings".

We cast the second parameter to execvp() explicitly as it expects a
"char *const[]" where it should expect a "const char *const[]"
(according to the documentation, this is due to compatibility reasons).
This should be changed once we come up with a better solution.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-05-08 21:50:05 +02:00
Lukas Fleischer
80f7e8ead5 Mark localized string literals constant
Translated strings returned by gettext() are statically allocated and
shouldn't be modified.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-04-05 22:18:46 +02:00
Lukas Fleischer
c9aff6d213 Update copyright ranges
Add 2012 to the copyright range for all source and documentation files.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-03-26 14:38:16 +02:00
Lukas Fleischer
481cb5524f Do not strncpy() strings returned by gettext()
Translated strings returned by gettext() are statically allocated.
There's no need to copy them to a buffer, we can use the pointers
returned by gettext() instead.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-03-12 20:36:22 +01:00
Lukas Fleischer
14b6ae79a2 Merge branch 'maint'
Conflicts:
	src/calcurse.h
	src/io.c
2011-11-11 12:29:48 +01:00