Fix bugs.

This commit is contained in:
Panagiotis Dimopoulos 2018-04-05 12:46:04 +03:00 committed by Carlos R. Mafra
parent aba739e980
commit d56480c377
3 changed files with 69 additions and 7 deletions

View file

@ -1,3 +1,9 @@
2018-04-04 Panagiotis A. Dimopoulos <panosdim@gmail.com>
- Release 1.2
- Fix a bug when left click is not working in some cases
- Fix a bug leaving zombie process when checking for new updates
2018-04-02 Panagiotis A. Dimopoulos <panosdim@gmail.com> 2018-04-02 Panagiotis A. Dimopoulos <panosdim@gmail.com>
- Release 1.1 - Release 1.1

View file

@ -1,7 +1,7 @@
CC=gcc CC=gcc
INSTALL=install INSTALL=install
PREFIX=/usr/local PREFIX=/usr/local
CFLAGS+=-Wall -O3 `pkg-config --cflags dockapp` CFLAGS+=-Wall -Wextra -O3 `pkg-config --cflags dockapp`
LIBS=`pkg-config --libs dockapp` LIBS=`pkg-config --libs dockapp`
wmarchup: wmarchup.o wmarchup: wmarchup.o

View file

@ -1,6 +1,10 @@
/* Also includes Xlib, Xresources, XPM, stdlib and stdio */ /* Also includes Xlib, Xresources, XPM, stdlib and stdio */
#include <dockapp.h> #include <dockapp.h>
#include <stdio.h> #include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/wait.h>
/* Include the pixmap to use */ /* Include the pixmap to use */
#include "archlinux.xpm" #include "archlinux.xpm"
@ -10,8 +14,9 @@
#define TRUE 1 #define TRUE 1
#define FALSE 0 #define FALSE 0
#define MAX 256 #define MAX 256
#define MAXPATHLEN 4096
#define CHK_INTERVAL 600 #define CHK_INTERVAL 600
#define WMARCHUP_VER "1.1" #define WMARCHUP_VER "1.2"
#define VERSION "wmArchUp version " WMARCHUP_VER #define VERSION "wmArchUp version " WMARCHUP_VER
/* /*
@ -21,6 +26,7 @@ void destroy(void);
void check_for_updates(); void check_for_updates();
void buttonrelease(int button, int state, int x, int y); void buttonrelease(int button, int state, int x, int y);
void update(); void update();
char *get_update_script();
/* /*
* Global variables * Global variables
@ -29,6 +35,7 @@ Pixmap arch, arch_mask, arch_bw, arch_bw_mask, checking, checking_mask;
unsigned short height, width; unsigned short height, width;
unsigned int check_interval = CHK_INTERVAL; unsigned int check_interval = CHK_INTERVAL;
int updates_available = FALSE; int updates_available = FALSE;
char *script;
/* /*
* M A I N * M A I N
@ -37,6 +44,9 @@ int updates_available = FALSE;
int int
main(int argc, char **argv) main(int argc, char **argv)
{ {
/* Find bash update script */
script = get_update_script();
/* Set callbacks for events */ /* Set callbacks for events */
DACallbacks eventCallbacks = { DACallbacks eventCallbacks = {
destroy, /* destroy */ destroy, /* destroy */
@ -126,8 +136,7 @@ update()
if (updates_available == TRUE) { if (updates_available == TRUE) {
XSelectInput(DAGetDisplay(NULL), DAGetWindow(), NoEventMask); XSelectInput(DAGetDisplay(NULL), DAGetWindow(), NoEventMask);
char *update_script = "./arch_update.sh"; int ret = system(script);
int ret = system(update_script);
if (WEXITSTATUS(ret) == 0) { if (WEXITSTATUS(ret) == 0) {
updates_available = FALSE; updates_available = FALSE;
@ -144,7 +153,6 @@ void
check_for_updates() check_for_updates()
{ {
XSelectInput(DAGetDisplay(NULL), DAGetWindow(), NoEventMask); XSelectInput(DAGetDisplay(NULL), DAGetWindow(), NoEventMask);
FILE *fp;
char res[MAX]; char res[MAX];
@ -152,9 +160,8 @@ check_for_updates()
DASetPixmap(checking); DASetPixmap(checking);
/* Read output from command */ /* Read output from command */
fp = popen("checkupdates", "r"); FILE *fp = popen("checkupdates", "r");
if (fgets(res, MAX, fp) != NULL) { if (fgets(res, MAX, fp) != NULL) {
fclose(fp);
updates_available = TRUE; updates_available = TRUE;
DASetShape(arch_mask); DASetShape(arch_mask);
DASetPixmap(arch); DASetPixmap(arch);
@ -164,6 +171,10 @@ check_for_updates()
DASetPixmap(arch_bw); DASetPixmap(arch_bw);
} }
if (pclose(fp) != 0) {
fprintf(stderr, " Error: Failed to close command stream \n");
}
XSelectInput(DAGetDisplay(NULL), DAGetWindow(), XSelectInput(DAGetDisplay(NULL), DAGetWindow(),
ButtonPressMask | ButtonReleaseMask); ButtonPressMask | ButtonReleaseMask);
} }
@ -185,3 +196,48 @@ buttonrelease(int button, int state, int x, int y)
check_for_updates(); check_for_updates();
} }
} }
char *
get_update_script()
{
int length;
char *p;
char *script_name = "arch_update.sh";
char *fullpath = malloc(MAXPATHLEN + strlen(script_name));
if (fullpath == NULL) {
perror("Can't allocate memory.");
exit(1);
}
/*
* /proc/self is a symbolic link to the process-ID subdir of /proc, e.g.
* /proc/4323 when the pid of the process of this program is 4323.
* Inside /proc/<pid> there is a symbolic link to the executable that is
* running as this <pid>. This symbolic link is called "exe". So if we
* read the path where the symlink /proc/self/exe points to we have the
* full path of the executable.
*/
length = readlink("/proc/self/exe", fullpath, MAXPATHLEN);
/*
* Catch some errors:
*/
if (length < 0) {
perror("resolving symlink /proc/self/exe.");
exit(1);
}
if (length >= MAXPATHLEN) {
fprintf(stderr, "Path too long.\n");
exit(1);
}
fullpath[length] = '\0';
if ((p = strrchr(fullpath, '/'))) {
*(p + 1) = '\0';
}
strcat(fullpath, script_name);
return fullpath;
}