AC_PREREQ([2.65])
AC_INIT([gsimplecal],
- [1.4],
+ [1.5],
[https://github.com/dmedvinsky/gsimplecal/issues],
[gsimplecal],
[https://github.com/dmedvinsky/gsimplecal])
fork \
execl])
+# Checks for host
+AC_CANONICAL_HOST
+case $host_os in
+ *linux* | *Linux*)
+ AC_DEFINE([PROC_SELF_PATH], ["/proc/self/exe"], [Path to symlink in proc that leads to current executable.])
+ ;;
+ *bsd* | *BSD*)
+ AC_DEFINE([PROC_SELF_PATH], ["/proc/curproc/file"], [Path to symlink in proc that leads to current executable.])
+ ;;
+ *)
+ AC_MSG_ERROR([Your platform $host_os is not currently supported.
+ Please, report this to the issue tracker.])
+ ;;
+esac
+
# Flags
AM_CPPFLAGS="-Wall"
AM_LDFLAGS="-Wl,--as-needed"
-.TH GSIMPLECAL 1 "2012-02-18"
+.TH GSIMPLECAL 1 "2012\-03\-26"
.SH NAME
gsimplecal \- lightweight calendar applet
.SH SYNOPSIS
-.B gsimplecal [-h|--help|-v|--version|next_month|prev_month]
+.B gsimplecal [\-h|\-\-help|\-v|\-\-version|next_month|prev_month]
.SH DESCRIPTION
.SH COMMANDS AND OPTIONS
.TP 5
-\fB-v, --version\fP
+\fB\-v, \-\-version\fP
Print the program name and version to stdout, then exit with code 0.
.TP 5
-\fB-h, --help\fP
+\fB\-h, \-\-help\fP
Print the short usage help to stderr, then exit with error code 2.
.TP 5
.br
close_on_unfocus = 0
.br
-external_viewer = sunbird -showdate "%Y-%m-%d"
+external_viewer = sunbird \-showdate "%Y\-%m\-%d"
.br
clock_format = %a %d %b %H:%M
.br
#include <signal.h>
#include "Unique.hpp"
-
-
-union semun
-{
- int val;
-};
+#include "config.h"
Unique::Unique()
{
// Get path to the current binary.
// It's a bit ugly, I guess, to rely on /proc, but it'll do for now.
- char szTmp[32];
- sprintf(szTmp, "/proc/%d/exe", getpid());
-
+ // Also, /proc has different layout on Linux and BSD, so there is ugly
+ // conditional compilation in configure script.
char* filename = new char[PATH_MAX + 1];
- int bytes = readlink(szTmp, filename,
+ int bytes = readlink(PROC_SELF_PATH, filename,
sizeof(*filename) * PATH_MAX);
if (bytes > PATH_MAX - 1) {
bytes = PATH_MAX;
{
if (!isRunning()) {
// Create semaphore; fail if already exists.
- int semid = semget(semaphore_key, 1,
- IPC_CREAT | IPC_EXCL | 0660);
+ int semid = semget(semaphore_key, 1, IPC_CREAT | IPC_EXCL | 0660);
if (semid == -1) {
throw UniqueException("semget failed while creating semaphore");
}
- // Set initial semaphore value to the current pid, so we could use it to
- // kill the process from the second instance.
- union semun semopts;
- semopts.val = getpid();
- if (semctl(semid, 0, SETVAL, semopts) == -1) {
- throw UniqueException("semctl (SETVAL) failed");
+ // Perform an operation on semaphore so that semctl(GETPID) returns
+ // current PID.
+ struct sembuf ops = {0, 1, 0};
+ if (semop(semid, &ops, 1) == -1) {
+ throw UniqueException("semop failed");
}
}
}
}
// Get the pid from semaphore value (stored before) to kill the process.
- int pid = semctl(semid, 0, GETVAL, 0);
+ int pid = semctl(semid, 0, GETPID, 0);
if (pid <= 0) {
- throw UniqueException("semctl (GETVAL) failed");
+ throw UniqueException("semctl(GETPID) failed");
}
if (::kill(pid, signal_id)) {
throw UniqueException("kill failed");
void Unique::stop()
{
+ // Clean up semaphore, if exists.
int semid = semget(semaphore_key, 1, 0660);
if (semid != -1) {
semctl(semid, 0, IPC_RMID, 0);