implemented pipe_spawn
3a69c517
7 file(s) · +70 −15
| 7 | 7 | #define BGCOLOR "#000000" |
|
| 8 | 8 | #define FGCOLOR "#ffaa00" |
|
| 9 | 9 | #define BORDERCOLOR "#000000" |
|
| 10 | + | #define STATUSCMD "echo -n `date` `uptime | sed 's/.*://; s/,//g'`" \ |
|
| 11 | + | " `acpi | awk '{print $4}' | sed 's/,//'`" |
| 218 | 218 | static void |
|
| 219 | 219 | maprequest(XEvent *e) |
|
| 220 | 220 | { |
|
| 221 | - | #if 0 |
|
| 222 | 221 | XMapRequestEvent *ev = &e->xmaprequest; |
|
| 223 | 222 | static XWindowAttributes wa; |
|
| 224 | 223 | ||
| 231 | 230 | return; |
|
| 232 | 231 | } |
|
| 233 | 232 | ||
| 234 | - | if(!client_of_win(ev->window)) |
|
| 235 | - | manage_client(create_client(ev->window, &wa)); |
|
| 236 | - | #endif |
|
| 233 | + | /*if(!client_of_win(ev->window))*/ |
|
| 234 | + | manage(create_client(ev->window, &wa)); |
|
| 237 | 235 | } |
|
| 238 | 236 | ||
| 239 | 237 | static void |
|
| 356 | 356 | char *maxname; |
|
| 357 | 357 | XEvent ev; |
|
| 358 | 358 | ||
| 359 | + | char buf[256]; |
|
| 360 | + | ||
| 361 | + | fputs(STATUSCMD, stdout); |
|
| 362 | + | fputs("\n", stdout); |
|
| 363 | + | pipe_spawn(buf, sizeof(buf), NULL, STATUSCMD); |
|
| 364 | + | fputs(buf, stderr); |
|
| 365 | + | ||
| 366 | + | return 0; |
|
| 367 | + | ||
| 359 | 368 | /* command line args */ |
|
| 360 | 369 | for(i = 1; i < argc; i++) { |
|
| 361 | 370 | if (argv[i][0] == '-') |
| 13 | 13 | ||
| 14 | 14 | #include "util.h" |
|
| 15 | 15 | ||
| 16 | + | static char *shell = NULL; |
|
| 17 | + | ||
| 16 | 18 | void |
|
| 17 | 19 | error(char *errstr, ...) { |
|
| 18 | 20 | va_list ap; |
|
| 82 | 84 | } |
|
| 83 | 85 | ||
| 84 | 86 | void |
|
| 85 | - | spawn(Display *dpy, const char *shell, const char *cmd) |
|
| 87 | + | spawn(Display *dpy, const char *cmd) |
|
| 86 | 88 | { |
|
| 87 | - | if(!cmd || !shell) |
|
| 89 | + | if(!shell && !(shell = getenv("SHELL"))) |
|
| 90 | + | shell = "/bin/sh"; |
|
| 91 | + | ||
| 92 | + | if(!cmd) |
|
| 88 | 93 | return; |
|
| 89 | 94 | if(fork() == 0) { |
|
| 90 | 95 | if(fork() == 0) { |
|
| 96 | + | setsid(); |
|
| 91 | 97 | if(dpy) |
|
| 92 | 98 | close(ConnectionNumber(dpy)); |
|
| 93 | - | execl(shell, shell, "-c", cmd, (const char *)0); |
|
| 94 | - | fprintf(stderr, "gridwm: execl %s", shell); |
|
| 99 | + | execlp(shell, "shell", "-c", cmd, NULL); |
|
| 100 | + | fprintf(stderr, "gridwm: execvp %s", cmd); |
|
| 95 | 101 | perror(" failed"); |
|
| 96 | 102 | } |
|
| 97 | 103 | exit (0); |
|
| 98 | 104 | } |
|
| 99 | 105 | wait(0); |
|
| 100 | 106 | } |
|
| 107 | + | ||
| 108 | + | void |
|
| 109 | + | pipe_spawn(char *buf, unsigned int len, Display *dpy, const char *cmd) |
|
| 110 | + | { |
|
| 111 | + | unsigned int l, n; |
|
| 112 | + | int pfd[2]; |
|
| 113 | + | ||
| 114 | + | if(!shell && !(shell = getenv("SHELL"))) |
|
| 115 | + | shell = "/bin/sh"; |
|
| 116 | + | ||
| 117 | + | if(!cmd) |
|
| 118 | + | return; |
|
| 119 | + | ||
| 120 | + | if(pipe(pfd) == -1) { |
|
| 121 | + | perror("pipe"); |
|
| 122 | + | exit(1); |
|
| 123 | + | } |
|
| 124 | + | ||
| 125 | + | if(fork() == 0) { |
|
| 126 | + | setsid(); |
|
| 127 | + | if(dpy) |
|
| 128 | + | close(ConnectionNumber(dpy)); |
|
| 129 | + | dup2(pfd[1], STDOUT_FILENO); |
|
| 130 | + | close(pfd[0]); |
|
| 131 | + | close(pfd[1]); |
|
| 132 | + | execlp(shell, "shell", "-c", cmd, NULL); |
|
| 133 | + | fprintf(stderr, "gridwm: execvp %s", cmd); |
|
| 134 | + | perror(" failed"); |
|
| 135 | + | } |
|
| 136 | + | else { |
|
| 137 | + | n = 0; |
|
| 138 | + | close(pfd[1]); |
|
| 139 | + | while(l > n) { |
|
| 140 | + | if((l = read(pfd[0], buf + n, len - n)) < 1) |
|
| 141 | + | break; |
|
| 142 | + | n += l; |
|
| 143 | + | } |
|
| 144 | + | close(pfd[0]); |
|
| 145 | + | buf[n - 1] = 0; |
|
| 146 | + | } |
|
| 147 | + | wait(0); |
|
| 148 | + | } |
|
| 14 | 14 | failed_assert(#a, __FILE__, __LINE__); \ |
|
| 15 | 15 | } while (0) |
|
| 16 | 16 | extern void failed_assert(char *a, char *file, int line); |
|
| 17 | + | void pipe_spawn(char *buf, unsigned int len, Display *dpy, const char *cmd); |
|
| 18 | + | extern void spawn(Display *dpy, const char *cmd); |
|
| 17 | 19 | extern void swap(void **p1, void **p2); |
|
| 18 | - | extern void spawn(Display *dpy, const char *shell, const char *cmd); |
| 21 | 21 | XRectangle rect, barrect; |
|
| 22 | 22 | Bool running = True; |
|
| 23 | 23 | ||
| 24 | - | char *bartext, *shell; |
|
| 24 | + | char *bartext; |
|
| 25 | 25 | int screen, sel_screen; |
|
| 26 | 26 | unsigned int lock_mask, numlock_mask; |
|
| 27 | 27 | ||
| 56 | 56 | if(wa.override_redirect || XGetTransientForHint(dpy, wins[i], &d1)) |
|
| 57 | 57 | continue; |
|
| 58 | 58 | if(wa.map_state == IsViewable) |
|
| 59 | - | /*manage*/; |
|
| 59 | + | manage(create_client(wins[i], &wa)); |
|
| 60 | 60 | } |
|
| 61 | 61 | } |
|
| 62 | 62 | if(wins) |
|
| 218 | 218 | ||
| 219 | 219 | if(other_wm_running) |
|
| 220 | 220 | error("gridwm: another window manager is already running\n"); |
|
| 221 | - | ||
| 222 | - | if(!(shell = getenv("SHELL"))) |
|
| 223 | - | shell = "/bin/sh"; |
|
| 224 | 221 | ||
| 225 | 222 | rect.x = rect.y = 0; |
|
| 226 | 223 | rect.width = DisplayWidth(dpy, screen); |
|
| 55 | 55 | ||
| 56 | 56 | extern int screen, sel_screen; |
|
| 57 | 57 | extern unsigned int lock_mask, numlock_mask; |
|
| 58 | - | extern char *bartext, *shell; |
|
| 58 | + | extern char *bartext; |
|
| 59 | 59 | ||
| 60 | 60 | extern Brush brush; |
|
| 61 | 61 |