Xinqi Bao's Git
projects
/
dwm.git
/ blobdiff
summary
|
log
|
commit
|
diff
|
tree
raw
|
inline
| side by side
new stuff, fixed several issues
[dwm.git]
/
util.c
diff --git
a/util.c
b/util.c
index
c0f2489
..
3f41b3c
100644
(file)
--- a/
util.c
+++ b/
util.c
@@
-13,8
+13,6
@@
#include "util.h"
#include "util.h"
-static char *shell = NULL;
-
void
error(char *errstr, ...) {
va_list ap;
void
error(char *errstr, ...) {
va_list ap;
@@
-84,21
+82,17
@@
swap(void **p1, void **p2)
}
void
}
void
-spawn(Display *dpy, c
onst char *cmd
)
+spawn(Display *dpy, c
har *argv[]
)
{
{
- if(!shell && !(shell = getenv("SHELL")))
- shell = "/bin/sh";
-
- if(!cmd)
+ if(!argv || !argv[0])
return;
if(fork() == 0) {
if(fork() == 0) {
if(dpy)
close(ConnectionNumber(dpy));
setsid();
return;
if(fork() == 0) {
if(fork() == 0) {
if(dpy)
close(ConnectionNumber(dpy));
setsid();
- fprintf(stderr, "gridwm: execlp %s %s -c %s", shell, shell, cmd);
- execlp(shell, shell, "-c", cmd, NULL);
- fprintf(stderr, "gridwm: execlp %s", cmd);
+ execvp(argv[0], argv);
+ fprintf(stderr, "gridwm: execvp %s", argv[0]);
perror(" failed");
}
exit (0);
perror(" failed");
}
exit (0);
@@
-107,15
+101,12
@@
spawn(Display *dpy, const char *cmd)
}
void
}
void
-pipe_spawn(char *buf, unsigned int len, Display *dpy, c
onst char *cmd
)
+pipe_spawn(char *buf, unsigned int len, Display *dpy, c
har *argv[]
)
{
unsigned int l, n;
int pfd[2];
{
unsigned int l, n;
int pfd[2];
- if(!shell && !(shell = getenv("SHELL")))
- shell = "/bin/sh";
-
- if(!cmd)
+ if(!argv || !argv[0])
return;
if(pipe(pfd) == -1) {
return;
if(pipe(pfd) == -1) {
@@
-130,20
+121,21
@@
pipe_spawn(char *buf, unsigned int len, Display *dpy, const char *cmd)
dup2(pfd[1], STDOUT_FILENO);
close(pfd[0]);
close(pfd[1]);
dup2(pfd[1], STDOUT_FILENO);
close(pfd[0]);
close(pfd[1]);
- exec
lp(shell, shell, "-c", cmd, NULL
);
- fprintf(stderr, "gridwm: exec
lp %s", cmd
);
+ exec
vp(argv[0], argv
);
+ fprintf(stderr, "gridwm: exec
vp %s", argv[0]
);
perror(" failed");
}
else {
perror(" failed");
}
else {
- n = 0;
+
l =
n = 0;
close(pfd[1]);
close(pfd[1]);
- while(
l >
n) {
+ while(
n < le
n) {
if((l = read(pfd[0], buf + n, len - n)) < 1)
break;
n += l;
}
if((l = read(pfd[0], buf + n, len - n)) < 1)
break;
n += l;
}
+ while(l > n);
close(pfd[0]);
close(pfd[0]);
- buf[n - 1] = 0;
+ buf[n
< len ? n : len
- 1] = 0;
}
wait(0);
}
}
wait(0);
}