From 040e80d1539a0e19b2ae535ac5a44bc2f485345b Mon Sep 17 00:00:00 2001 From: Julien Valroff Date: Fri, 6 Apr 2012 15:57:21 +0200 Subject: [PATCH] Imported Upstream version 1.5 --- .gitignore | 2 ++ AUTHORS | 1 + ChangeLog | 5 +++++ configure.ac | 17 ++++++++++++++++- doc/gsimplecal.1 | 10 +++++----- src/Unique.cpp | 33 +++++++++++++-------------------- 6 files changed, 42 insertions(+), 26 deletions(-) diff --git a/.gitignore b/.gitignore index 91d8dea..894dcf3 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,8 @@ aclocal.m4 autom4te.cache/ config.log config.status +config.guess +config.sub configure depcomp install-sh diff --git a/AUTHORS b/AUTHORS index d603bc6..7d2bf78 100644 --- a/AUTHORS +++ b/AUTHORS @@ -9,6 +9,7 @@ Bugs and ideas: * Julien Valroff * Iffan Arzanul Haq * Thomas Koch + * Rick Nekus Packages: - Arch Linux: diff --git a/ChangeLog b/ChangeLog index 00f61c7..2ad05c5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2012-03-26: v1.5: +- Fix compilation on BSD +- Fix current executable path on BSD +- Fix exception when gsimplecal gets a PID > SEMVMX + 2012-02-18: v1.4: + Add option to close gsimplecal when it loses focus diff --git a/configure.ac b/configure.ac index d5491ad..a5d6b27 100644 --- a/configure.ac +++ b/configure.ac @@ -1,6 +1,6 @@ AC_PREREQ([2.65]) AC_INIT([gsimplecal], - [1.4], + [1.5], [https://github.com/dmedvinsky/gsimplecal/issues], [gsimplecal], [https://github.com/dmedvinsky/gsimplecal]) @@ -51,6 +51,21 @@ AC_CHECK_FUNCS([atexit \ 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" diff --git a/doc/gsimplecal.1 b/doc/gsimplecal.1 index 84b39fe..a28e91e 100644 --- a/doc/gsimplecal.1 +++ b/doc/gsimplecal.1 @@ -1,10 +1,10 @@ -.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 @@ -27,11 +27,11 @@ See the \fICONFIGURATION\fP section to get to know how to. .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 @@ -65,7 +65,7 @@ show_week_numbers = 0 .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 diff --git a/src/Unique.cpp b/src/Unique.cpp index 7df248b..c2c7f51 100644 --- a/src/Unique.cpp +++ b/src/Unique.cpp @@ -8,23 +8,17 @@ #include #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; @@ -56,18 +50,16 @@ void Unique::start() { 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"); } } } @@ -90,9 +82,9 @@ void Unique::kill(int signal_id) } // 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"); @@ -102,6 +94,7 @@ void Unique::kill(int signal_id) void Unique::stop() { + // Clean up semaphore, if exists. int semid = semget(semaphore_key, 1, 0660); if (semid != -1) { semctl(semid, 0, IPC_RMID, 0); -- 2.20.1