Permalink
Browse files

* 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
  • Loading branch information...
1 parent 2d76804 commit 47f45af58e531308cb45531dcace19fcc08028ad @nickgravgaard committed Nov 14, 2009
Showing with 63 additions and 28 deletions.
  1. +8 −0 CHANGELOG
  2. +13 −4 Makefile
  3. +7 −0 events.c
  4. +27 −18 menufile.c
  5. +3 −3 misc.c
  6. +5 −3 windowlab.h
View
@@ -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!):
View
@@ -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
@@ -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
View
@@ -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:
View
@@ -20,6 +20,9 @@
#include "windowlab.h"
+/* a semaphor activated by SIGHUP */
+int do_menuitems;
+
static int parseline(char *, char *, char *);
MenuItem *menuitems = NULL;
@@ -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';
@@ -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
@@ -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);
@@ -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;
@@ -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)
@@ -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;
}
View
@@ -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");
@@ -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)
View
@@ -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>
@@ -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"
@@ -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);

0 comments on commit 47f45af

Please sign in to comment.