Skip to content

Commit

Permalink
* integrated more changes from Mats Erik Andersson:
Browse files Browse the repository at this point in the history
	* makefile made more flexible
	* signal handler for SIGHUP now just sets a semaphore, and reloading of menu resources happens in the event loop
	* fixed problems found by auditing the code with Flawfinder
  • Loading branch information
nickgravgaard committed Nov 14, 2009
1 parent 2d76804 commit 47f45af
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 28 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
1.38 (2009-11-14)

* integrated more changes from Mats Erik Andersson:
* makefile made more flexible
* signal handler for SIGHUP now just sets a semaphore, and reloading of menu resources happens in the event loop
* fixed problems found by auditing the code with Flawfinder


1.37 (2009-10-04)

* integrated a change from Campbell Barton (thanks!):
Expand Down
17 changes: 13 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,22 @@ DEFINES += -DSHAPE
EXTRA_LIBS += -lXext

# Set this to the hardcoded location of all files if it's not /
PREFIX =
PREFIX = /usr/local

# Set this to the directory, below PREFIX, where man pages
# are expected. Below this directory, the target "install"
# will put "windowlab.1x" in section "man1".
MANBASE = /man

# Set this to the location of the X installation you want to compile against
XROOT = /usr/X11R6

# Some flexibility for configuration location
CONFPREFIX = $(PREFIX)
CONFDIR = /etc/X11/windowlab

# Set this to the location of the global configuration files
SYSCONFDIR = $(PREFIX)/etc/X11/windowlab
SYSCONFDIR = $(CONFPREFIX)$(CONFDIR)

# Information about the location of the menurc file
ifndef MENURC
Expand Down Expand Up @@ -39,8 +48,8 @@ ifndef CFLAGS
CFLAGS = -g -O2 -Wall -W
endif

BINDIR = $(DESTDIR)$(PREFIX)$(XROOT)/bin
MANDIR = $(DESTDIR)$(PREFIX)$(XROOT)/man/man1
BINDIR = $(DESTDIR)$(PREFIX)/bin
MANDIR = $(DESTDIR)$(PREFIX)$(MANBASE)/man1
CFGDIR = $(DESTDIR)$(SYSCONFDIR)
INCLUDES = -I$(XROOT)/include $(EXTRA_INC)
LDPATH = -L$(XROOT)/lib
Expand Down
7 changes: 7 additions & 0 deletions events.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ void do_event_loop(void)
#ifdef DEBUG
show_event(ev);
#endif
/* check to see if menu rebuild has been requested */
if (do_menuitems)
{
free_menuitems();
get_menuitems();
}

switch (ev.type)
{
case KeyPress:
Expand Down
45 changes: 27 additions & 18 deletions menufile.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@

#include "windowlab.h"

/* a semaphor activated by SIGHUP */
int do_menuitems;

static int parseline(char *, char *, char *);

MenuItem *menuitems = NULL;
Expand All @@ -36,21 +39,32 @@ void get_menuitems(void)
extern int errno;

menuitems = (MenuItem *)malloc(MAX_MENUITEMS_SIZE);
memset(menuitems, '\0', MAX_MENUITEMS_SIZE);
if (menuitems == NULL)
{
err("Unable to allocate menu items array.");
return;
}
memset(menuitems, 0, MAX_MENUITEMS_SIZE);

snprintf(menurcpath, sizeof menurcpath, "%s/.windowlab/windowlab.menurc", getenv("HOME"));
snprintf(menurcpath, sizeof(menurcpath), "%s/.windowlab/windowlab.menurc", getenv("HOME"));
#ifdef DEBUG
printf("trying to open: %s\n", menurcpath);
#endif
if ((menufile = fopen(menurcpath, "r")) == NULL)
{
ssize_t len;
// get location of the executable
if (readlink("/proc/self/exe", menurcpath, PATH_MAX) == -1)
if ((len = readlink("/proc/self/exe", menurcpath, PATH_MAX - 1)) == -1)
{
err("readlink() /proc/self/exe failed: %s\n", strerror(errno));
menurcpath[0] = '.';
menurcpath[1] = '\0';
}
else
{
/* insert a null byte to end the file path correctly */
menurcpath[len] = '\0';
}
if ((c = strrchr(menurcpath, '/')) != NULL)
{
*c = '\0';
Expand All @@ -59,7 +73,7 @@ void get_menuitems(void)
{
*c = '\0';
}
strncat(menurcpath, "/etc/windowlab.menurc", PATH_MAX);
strncat(menurcpath, "/etc/windowlab.menurc", PATH_MAX - strlen(menurcpath) - 1);
#ifdef DEBUG
printf("trying to open: %s\n", menurcpath);
#endif
Expand All @@ -74,15 +88,16 @@ void get_menuitems(void)
if (menufile != NULL)
{
num_menuitems = 0;
while ((!feof(menufile)) && (!ferror(menufile)))
while ((!feof(menufile)) && (!ferror(menufile)) && (num_menuitems < MAX_MENUITEMS))
{
char menustr[STR_SIZE] = "";
fgets(menustr, STR_SIZE, menufile);
if (strlen(menustr) != 0)
{
/* TODO: allow for leading whitespace? */
if (menustr[0] != '#')
{
char labelstr[STR_SIZE], commandstr[STR_SIZE];
char labelstr[STR_SIZE] = "", commandstr[STR_SIZE] = "";
if (parseline(menustr, labelstr, commandstr))
{
menuitems[num_menuitems].label = (char *)malloc(strlen(labelstr) + 1);
Expand All @@ -107,8 +122,6 @@ void get_menuitems(void)
num_menuitems = 1;
}

menuitems = (MenuItem *)realloc((void *)menuitems, MAX_MENUITEMS_SIZE);

for (i = 0; i < num_menuitems; i++)
{
menuitems[i].x = button_startx;
Expand All @@ -120,6 +133,8 @@ void get_menuitems(void)
#endif
button_startx += menuitems[i].width + 1;
}
/* menu items have been built */
do_menuitems = 0;
}

int parseline(char *menustr, char *labelstr, char *commandstr)
Expand All @@ -134,19 +149,13 @@ int parseline(char *menustr, char *labelstr, char *commandstr)
if (ptemp != NULL)
{
strcpy(labelstr, ptemp);
ptemp = strtok(NULL, "\n");
if (ptemp != NULL)
{
ptemp = strtok(NULL, ":");
if (ptemp != NULL)
{
strcpy(commandstr, ptemp);
}
else
{
success = 0;
}
/* TODO: if ptemp only contains whitespace this item should set success to 0 */
strcpy(commandstr, ptemp);
}
else
else /* applies if RHS of ':' is an empty string */
{
success = 0;
}
Expand Down
6 changes: 3 additions & 3 deletions misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ void fork_exec(char *cmd)
}
else
{
*envshellname++;
/* move to the character after the slash */
envshellname++;
}
execlp(envshell, envshellname, "-c", cmd, NULL);
err("exec failed, cleaning up child");
Expand All @@ -83,8 +84,7 @@ void sig_handler(int signal)
quit_nicely();
break;
case SIGHUP:
free_menuitems();
get_menuitems();
do_menuitems = 1;
break;
case SIGCHLD:
while ((pid = waitpid(-1, &status, WNOHANG)) != 0)
Expand Down
8 changes: 5 additions & 3 deletions windowlab.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
#ifndef WINDOWLAB_H
#define WINDOWLAB_H

#define VERSION "1.37"
#define RELEASEDATE "2009-10-04"
#define VERSION "1.38"
#define RELEASEDATE "2009-11-14"

#include <errno.h>
#include <limits.h>
Expand Down Expand Up @@ -172,7 +172,8 @@ typedef struct PropMwmHints
#define REMAP 1

// stuff for the menu file
#define MAX_MENUITEMS_SIZE (sizeof(MenuItem) * 64)
#define MAX_MENUITEMS 24
#define MAX_MENUITEMS_SIZE (sizeof(MenuItem) * MAX_MENUITEMS)
#define STR_SIZE 128
#define NO_MENU_LABEL "xterm"
#define NO_MENU_COMMAND "xterm"
Expand Down Expand Up @@ -322,6 +323,7 @@ extern void redraw_taskbar(void);
extern float get_button_width(void);

// menufile.c
extern int do_menuitems;
extern MenuItem* menuitems;
extern unsigned int num_menuitems;
extern void get_menuitems(void);
Expand Down

0 comments on commit 47f45af

Please sign in to comment.