get rid of PATH_MAX
I replaced stack memory allocations with PATH_MAX by heap memory allocations on post-2.2 branch because PATH_MAX isn't necessary defined according to POSIX specification. For instance GNU/Hurd doesn't have PATH size restriction, thus doesn't defined PATH_MAX and compilation will fail. Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
6b4c9fed83
commit
fc9e31ff62
|
@ -19,7 +19,9 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/* getline(), asprintf() */
|
||||||
#define _GNU_SOURCE
|
#define _GNU_SOURCE
|
||||||
|
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
|
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
@ -28,6 +30,7 @@
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include <confuse.h>
|
#include <confuse.h>
|
||||||
|
|
||||||
|
@ -222,7 +225,7 @@ get_last_word(char *text)
|
||||||
static Bool
|
static Bool
|
||||||
item_list_fill_file(const char *directory)
|
item_list_fill_file(const char *directory)
|
||||||
{
|
{
|
||||||
char cwd[PATH_MAX], *home, *user, *filename;
|
char *cwd, *home, *user, *filename;
|
||||||
const char *file;
|
const char *file;
|
||||||
DIR *dir;
|
DIR *dir;
|
||||||
struct dirent *dirinfo;
|
struct dirent *dirinfo;
|
||||||
|
@ -234,14 +237,13 @@ item_list_fill_file(const char *directory)
|
||||||
item_list_wipe(&globalconf.items);
|
item_list_wipe(&globalconf.items);
|
||||||
|
|
||||||
if(!directory)
|
if(!directory)
|
||||||
a_strcpy(cwd, sizeof(cwd), "./");
|
cwd = a_strdup("./");
|
||||||
else if(a_strlen(directory) > 1 && directory[0] == '~')
|
else if(a_strlen(directory) > 1 && directory[0] == '~')
|
||||||
{
|
{
|
||||||
if(directory[1] == '/')
|
if(directory[1] == '/')
|
||||||
{
|
{
|
||||||
if((home = getenv("HOME")))
|
home = getenv("HOME");
|
||||||
a_strcpy(cwd, sizeof(cwd), home);
|
asprintf(&cwd, "%s%s", (home ? home : ""), directory + 1);
|
||||||
a_strcat(cwd, sizeof(cwd), directory + 1);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -252,8 +254,7 @@ item_list_fill_file(const char *directory)
|
||||||
a_strncpy(user, len, directory + 1, (file - directory) - 1);
|
a_strncpy(user, len, directory + 1, (file - directory) - 1);
|
||||||
if((passwd = getpwnam(user)))
|
if((passwd = getpwnam(user)))
|
||||||
{
|
{
|
||||||
a_strcpy(cwd, sizeof(cwd), passwd->pw_dir);
|
asprintf(&cwd, "%s%s", passwd->pw_dir, file);
|
||||||
a_strcat(cwd, sizeof(cwd), file);
|
|
||||||
p_delete(&user);
|
p_delete(&user);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -264,10 +265,13 @@ item_list_fill_file(const char *directory)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
a_strcpy(cwd, sizeof(cwd), directory);
|
cwd = a_strdup(directory);
|
||||||
|
|
||||||
if(!(dir = opendir(cwd)))
|
if(!(dir = opendir(cwd)))
|
||||||
|
{
|
||||||
|
p_delete(&cwd);
|
||||||
return False;
|
return False;
|
||||||
|
}
|
||||||
|
|
||||||
while((dirinfo = readdir(dir)))
|
while((dirinfo = readdir(dir)))
|
||||||
{
|
{
|
||||||
|
@ -296,6 +300,7 @@ item_list_fill_file(const char *directory)
|
||||||
}
|
}
|
||||||
|
|
||||||
closedir(dir);
|
closedir(dir);
|
||||||
|
p_delete(&cwd);
|
||||||
|
|
||||||
return True;
|
return True;
|
||||||
}
|
}
|
||||||
|
@ -568,25 +573,31 @@ handle_kpress(XKeyEvent *e)
|
||||||
static Bool
|
static Bool
|
||||||
item_list_fill_stdin(void)
|
item_list_fill_stdin(void)
|
||||||
{
|
{
|
||||||
char buf[PATH_MAX];
|
char *buf = NULL;
|
||||||
|
size_t len = 0;
|
||||||
|
ssize_t line_len;
|
||||||
|
|
||||||
item_t *newitem;
|
item_t *newitem;
|
||||||
Bool has_entry = False;
|
Bool has_entry = False;
|
||||||
|
|
||||||
item_list_init(&globalconf.items);
|
item_list_init(&globalconf.items);
|
||||||
|
|
||||||
if(fgets(buf, sizeof(buf), stdin))
|
if((line_len = getline(&buf, &len, stdin)) != -1)
|
||||||
has_entry = True;
|
has_entry = True;
|
||||||
|
|
||||||
if(has_entry)
|
if(has_entry)
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
buf[a_strlen(buf) - 1] = '\0';
|
buf[line_len - 1] = '\0';
|
||||||
newitem = p_new(item_t, 1);
|
newitem = p_new(item_t, 1);
|
||||||
newitem->data = a_strdup(buf);
|
newitem->data = a_strdup(buf);
|
||||||
newitem->match = True;
|
newitem->match = True;
|
||||||
item_list_append(&globalconf.items, newitem);
|
item_list_append(&globalconf.items, newitem);
|
||||||
}
|
}
|
||||||
while(fgets(buf, sizeof(buf), stdin));
|
while((line_len = getline(&buf, &len, stdin)) != -1);
|
||||||
|
|
||||||
|
if(buf)
|
||||||
|
p_delete(&buf);
|
||||||
|
|
||||||
return has_entry;
|
return has_entry;
|
||||||
}
|
}
|
||||||
|
|
26
uicb.c
26
uicb.c
|
@ -23,7 +23,11 @@
|
||||||
* @defgroup ui_callback User Interface Callbacks
|
* @defgroup ui_callback User Interface Callbacks
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/* strndup() */
|
||||||
|
#define _GNU_SOURCE
|
||||||
|
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include "awesome.h"
|
#include "awesome.h"
|
||||||
#include "tag.h"
|
#include "tag.h"
|
||||||
|
@ -45,10 +49,11 @@ extern AwesomeConf globalconf;
|
||||||
* \ingroup ui_callback
|
* \ingroup ui_callback
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
uicb_exec(int screen __attribute__ ((unused)), char *arg)
|
uicb_exec(int screen __attribute__ ((unused)), char *cmd)
|
||||||
{
|
{
|
||||||
Client *c;
|
Client *c;
|
||||||
char path[PATH_MAX];
|
int args_pos;
|
||||||
|
char *args, *path;
|
||||||
|
|
||||||
/* remap all clients since some WM won't handle them otherwise */
|
/* remap all clients since some WM won't handle them otherwise */
|
||||||
for(c = globalconf.clients; c; c = c->next)
|
for(c = globalconf.clients; c; c = c->next)
|
||||||
|
@ -59,8 +64,21 @@ uicb_exec(int screen __attribute__ ((unused)), char *arg)
|
||||||
if(globalconf.display)
|
if(globalconf.display)
|
||||||
close(ConnectionNumber(globalconf.display));
|
close(ConnectionNumber(globalconf.display));
|
||||||
|
|
||||||
sscanf(arg, "%s", path);
|
/* Ignore the leading spaces if any */
|
||||||
execlp(path, arg, NULL);
|
for(args_pos = 0;
|
||||||
|
args_pos < strlen(cmd) && cmd[args_pos] == ' ';
|
||||||
|
++args_pos);
|
||||||
|
|
||||||
|
/* Get the beginning of the arguments */
|
||||||
|
if((args = strchr(cmd + args_pos, ' ')) == NULL)
|
||||||
|
{
|
||||||
|
warn("Invalid command %s\n", cmd);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
path = strndup(cmd + args_pos, args - (cmd + args_pos));
|
||||||
|
execlp(path, cmd, NULL);
|
||||||
|
p_delete(&path);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Spawn another process
|
/** Spawn another process
|
||||||
|
|
Loading…
Reference in New Issue