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
|
||||
|
||||
#include <getopt.h>
|
||||
|
||||
#include <signal.h>
|
||||
|
@ -28,6 +30,7 @@
|
|||
#include <dirent.h>
|
||||
#include <pwd.h>
|
||||
#include <sys/types.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <confuse.h>
|
||||
|
||||
|
@ -222,7 +225,7 @@ get_last_word(char *text)
|
|||
static Bool
|
||||
item_list_fill_file(const char *directory)
|
||||
{
|
||||
char cwd[PATH_MAX], *home, *user, *filename;
|
||||
char *cwd, *home, *user, *filename;
|
||||
const char *file;
|
||||
DIR *dir;
|
||||
struct dirent *dirinfo;
|
||||
|
@ -234,14 +237,13 @@ item_list_fill_file(const char *directory)
|
|||
item_list_wipe(&globalconf.items);
|
||||
|
||||
if(!directory)
|
||||
a_strcpy(cwd, sizeof(cwd), "./");
|
||||
cwd = a_strdup("./");
|
||||
else if(a_strlen(directory) > 1 && directory[0] == '~')
|
||||
{
|
||||
if(directory[1] == '/')
|
||||
{
|
||||
if((home = getenv("HOME")))
|
||||
a_strcpy(cwd, sizeof(cwd), home);
|
||||
a_strcat(cwd, sizeof(cwd), directory + 1);
|
||||
home = getenv("HOME");
|
||||
asprintf(&cwd, "%s%s", (home ? home : ""), directory + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -252,8 +254,7 @@ item_list_fill_file(const char *directory)
|
|||
a_strncpy(user, len, directory + 1, (file - directory) - 1);
|
||||
if((passwd = getpwnam(user)))
|
||||
{
|
||||
a_strcpy(cwd, sizeof(cwd), passwd->pw_dir);
|
||||
a_strcat(cwd, sizeof(cwd), file);
|
||||
asprintf(&cwd, "%s%s", passwd->pw_dir, file);
|
||||
p_delete(&user);
|
||||
}
|
||||
else
|
||||
|
@ -264,10 +265,13 @@ item_list_fill_file(const char *directory)
|
|||
}
|
||||
}
|
||||
else
|
||||
a_strcpy(cwd, sizeof(cwd), directory);
|
||||
cwd = a_strdup(directory);
|
||||
|
||||
if(!(dir = opendir(cwd)))
|
||||
{
|
||||
p_delete(&cwd);
|
||||
return False;
|
||||
}
|
||||
|
||||
while((dirinfo = readdir(dir)))
|
||||
{
|
||||
|
@ -296,6 +300,7 @@ item_list_fill_file(const char *directory)
|
|||
}
|
||||
|
||||
closedir(dir);
|
||||
p_delete(&cwd);
|
||||
|
||||
return True;
|
||||
}
|
||||
|
@ -568,25 +573,31 @@ handle_kpress(XKeyEvent *e)
|
|||
static Bool
|
||||
item_list_fill_stdin(void)
|
||||
{
|
||||
char buf[PATH_MAX];
|
||||
char *buf = NULL;
|
||||
size_t len = 0;
|
||||
ssize_t line_len;
|
||||
|
||||
item_t *newitem;
|
||||
Bool has_entry = False;
|
||||
|
||||
item_list_init(&globalconf.items);
|
||||
|
||||
if(fgets(buf, sizeof(buf), stdin))
|
||||
if((line_len = getline(&buf, &len, stdin)) != -1)
|
||||
has_entry = True;
|
||||
|
||||
if(has_entry)
|
||||
do
|
||||
{
|
||||
buf[a_strlen(buf) - 1] = '\0';
|
||||
buf[line_len - 1] = '\0';
|
||||
newitem = p_new(item_t, 1);
|
||||
newitem->data = a_strdup(buf);
|
||||
newitem->match = True;
|
||||
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;
|
||||
}
|
||||
|
|
26
uicb.c
26
uicb.c
|
@ -23,7 +23,11 @@
|
|||
* @defgroup ui_callback User Interface Callbacks
|
||||
*/
|
||||
|
||||
/* strndup() */
|
||||
#define _GNU_SOURCE
|
||||
|
||||
#include <sys/wait.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "awesome.h"
|
||||
#include "tag.h"
|
||||
|
@ -45,10 +49,11 @@ extern AwesomeConf globalconf;
|
|||
* \ingroup ui_callback
|
||||
*/
|
||||
void
|
||||
uicb_exec(int screen __attribute__ ((unused)), char *arg)
|
||||
uicb_exec(int screen __attribute__ ((unused)), char *cmd)
|
||||
{
|
||||
Client *c;
|
||||
char path[PATH_MAX];
|
||||
int args_pos;
|
||||
char *args, *path;
|
||||
|
||||
/* remap all clients since some WM won't handle them otherwise */
|
||||
for(c = globalconf.clients; c; c = c->next)
|
||||
|
@ -59,8 +64,21 @@ uicb_exec(int screen __attribute__ ((unused)), char *arg)
|
|||
if(globalconf.display)
|
||||
close(ConnectionNumber(globalconf.display));
|
||||
|
||||
sscanf(arg, "%s", path);
|
||||
execlp(path, arg, NULL);
|
||||
/* Ignore the leading spaces if any */
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue