implemented pipe_spawn
This commit is contained in:
		
							
								
								
									
										2
									
								
								config.h
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								config.h
									
									
									
									
									
								
							@@ -7,3 +7,5 @@
 | 
				
			|||||||
#define BGCOLOR		"#000000"
 | 
					#define BGCOLOR		"#000000"
 | 
				
			||||||
#define FGCOLOR		"#ffaa00"
 | 
					#define FGCOLOR		"#ffaa00"
 | 
				
			||||||
#define BORDERCOLOR	"#000000"
 | 
					#define BORDERCOLOR	"#000000"
 | 
				
			||||||
 | 
					#define STATUSCMD	"echo -n `date` `uptime | sed 's/.*://; s/,//g'`" \
 | 
				
			||||||
 | 
										" `acpi | awk '{print $4}' | sed 's/,//'`"
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										6
									
								
								event.c
									
									
									
									
									
								
							
							
						
						
									
										6
									
								
								event.c
									
									
									
									
									
								
							@@ -218,7 +218,6 @@ keymapnotify(XEvent *e)
 | 
				
			|||||||
static void
 | 
					static void
 | 
				
			||||||
maprequest(XEvent *e)
 | 
					maprequest(XEvent *e)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
#if 0
 | 
					 | 
				
			||||||
	XMapRequestEvent *ev = &e->xmaprequest;
 | 
						XMapRequestEvent *ev = &e->xmaprequest;
 | 
				
			||||||
	static XWindowAttributes wa;
 | 
						static XWindowAttributes wa;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -231,9 +230,8 @@ maprequest(XEvent *e)
 | 
				
			|||||||
		return;
 | 
							return;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if(!client_of_win(ev->window))
 | 
						/*if(!client_of_win(ev->window))*/
 | 
				
			||||||
		manage_client(create_client(ev->window, &wa));
 | 
							manage(create_client(ev->window, &wa));
 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void
 | 
					static void
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										9
									
								
								menu.c
									
									
									
									
									
								
							
							
						
						
									
										9
									
								
								menu.c
									
									
									
									
									
								
							@@ -356,6 +356,15 @@ main(int argc, char *argv[])
 | 
				
			|||||||
	char *maxname;
 | 
						char *maxname;
 | 
				
			||||||
	XEvent ev;
 | 
						XEvent ev;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						char buf[256];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						fputs(STATUSCMD, stdout);
 | 
				
			||||||
 | 
						fputs("\n", stdout);
 | 
				
			||||||
 | 
						pipe_spawn(buf, sizeof(buf), NULL, STATUSCMD);
 | 
				
			||||||
 | 
						fputs(buf, stderr);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* command line args */
 | 
						/* command line args */
 | 
				
			||||||
	for(i = 1; i < argc; i++) {
 | 
						for(i = 1; i < argc; i++) {
 | 
				
			||||||
		if (argv[i][0] == '-')
 | 
							if (argv[i][0] == '-')
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										56
									
								
								util.c
									
									
									
									
									
								
							
							
						
						
									
										56
									
								
								util.c
									
									
									
									
									
								
							@@ -13,6 +13,8 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#include "util.h"
 | 
					#include "util.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static char *shell = NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void
 | 
					void
 | 
				
			||||||
error(char *errstr, ...) {
 | 
					error(char *errstr, ...) {
 | 
				
			||||||
	va_list ap;
 | 
						va_list ap;
 | 
				
			||||||
@@ -82,19 +84,65 @@ swap(void **p1, void **p2)
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void
 | 
					void
 | 
				
			||||||
spawn(Display *dpy, const char *shell, const char *cmd)
 | 
					spawn(Display *dpy, const char *cmd)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	if(!cmd || !shell)
 | 
						if(!shell && !(shell = getenv("SHELL")))
 | 
				
			||||||
 | 
							shell = "/bin/sh";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if(!cmd)
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
	if(fork() == 0) {
 | 
						if(fork() == 0) {
 | 
				
			||||||
		if(fork() == 0) {
 | 
							if(fork() == 0) {
 | 
				
			||||||
 | 
								setsid();
 | 
				
			||||||
			if(dpy)
 | 
								if(dpy)
 | 
				
			||||||
				close(ConnectionNumber(dpy));
 | 
									close(ConnectionNumber(dpy));
 | 
				
			||||||
			execl(shell, shell, "-c", cmd, (const char *)0);
 | 
								execlp(shell, "shell", "-c", cmd, NULL);
 | 
				
			||||||
			fprintf(stderr, "gridwm: execl %s", shell);
 | 
								fprintf(stderr, "gridwm: execvp %s", cmd);
 | 
				
			||||||
			perror(" failed");
 | 
								perror(" failed");
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		exit (0);
 | 
							exit (0);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	wait(0);
 | 
						wait(0);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void
 | 
				
			||||||
 | 
					pipe_spawn(char *buf, unsigned int len, Display *dpy, const char *cmd)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						unsigned int l, n;
 | 
				
			||||||
 | 
						int pfd[2];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if(!shell && !(shell = getenv("SHELL")))
 | 
				
			||||||
 | 
							shell = "/bin/sh";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if(!cmd)
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if(pipe(pfd) == -1) {
 | 
				
			||||||
 | 
							perror("pipe");
 | 
				
			||||||
 | 
							exit(1);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if(fork() == 0) {
 | 
				
			||||||
 | 
							setsid();
 | 
				
			||||||
 | 
							if(dpy)
 | 
				
			||||||
 | 
								close(ConnectionNumber(dpy));
 | 
				
			||||||
 | 
							dup2(pfd[1], STDOUT_FILENO);
 | 
				
			||||||
 | 
							close(pfd[0]);
 | 
				
			||||||
 | 
							close(pfd[1]);
 | 
				
			||||||
 | 
							execlp(shell, "shell", "-c", cmd, NULL);
 | 
				
			||||||
 | 
							fprintf(stderr, "gridwm: execvp %s", cmd);
 | 
				
			||||||
 | 
							perror(" failed");
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						else {
 | 
				
			||||||
 | 
							n = 0;
 | 
				
			||||||
 | 
							close(pfd[1]);
 | 
				
			||||||
 | 
							while(l > n) {
 | 
				
			||||||
 | 
								if((l = read(pfd[0], buf + n, len - n)) < 1)
 | 
				
			||||||
 | 
									break;
 | 
				
			||||||
 | 
								n += l;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							close(pfd[0]);
 | 
				
			||||||
 | 
							buf[n - 1] = 0;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						wait(0);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										3
									
								
								util.h
									
									
									
									
									
								
							
							
						
						
									
										3
									
								
								util.h
									
									
									
									
									
								
							@@ -14,5 +14,6 @@ extern char *estrdup(const char *str);
 | 
				
			|||||||
			failed_assert(#a, __FILE__, __LINE__); \
 | 
								failed_assert(#a, __FILE__, __LINE__); \
 | 
				
			||||||
	} while (0)
 | 
						} while (0)
 | 
				
			||||||
extern void failed_assert(char *a, char *file, int line);
 | 
					extern void failed_assert(char *a, char *file, int line);
 | 
				
			||||||
 | 
					void pipe_spawn(char *buf, unsigned int len, Display *dpy, const char *cmd);
 | 
				
			||||||
 | 
					extern void spawn(Display *dpy, const char *cmd);
 | 
				
			||||||
extern void swap(void **p1, void **p2);
 | 
					extern void swap(void **p1, void **p2);
 | 
				
			||||||
extern void spawn(Display *dpy, const char *shell, const char *cmd);
 | 
					 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										7
									
								
								wm.c
									
									
									
									
									
								
							
							
						
						
									
										7
									
								
								wm.c
									
									
									
									
									
								
							@@ -21,7 +21,7 @@ Cursor cursor[CurLast];
 | 
				
			|||||||
XRectangle rect, barrect;
 | 
					XRectangle rect, barrect;
 | 
				
			||||||
Bool running = True;
 | 
					Bool running = True;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
char *bartext, *shell;
 | 
					char *bartext;
 | 
				
			||||||
int screen, sel_screen;
 | 
					int screen, sel_screen;
 | 
				
			||||||
unsigned int lock_mask, numlock_mask;
 | 
					unsigned int lock_mask, numlock_mask;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -56,7 +56,7 @@ scan_wins()
 | 
				
			|||||||
			if(wa.override_redirect || XGetTransientForHint(dpy, wins[i], &d1))
 | 
								if(wa.override_redirect || XGetTransientForHint(dpy, wins[i], &d1))
 | 
				
			||||||
				continue;
 | 
									continue;
 | 
				
			||||||
			if(wa.map_state == IsViewable)
 | 
								if(wa.map_state == IsViewable)
 | 
				
			||||||
				/*manage*/;
 | 
									manage(create_client(wins[i], &wa));
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if(wins)
 | 
						if(wins)
 | 
				
			||||||
@@ -219,9 +219,6 @@ main(int argc, char *argv[])
 | 
				
			|||||||
	if(other_wm_running)
 | 
						if(other_wm_running)
 | 
				
			||||||
		error("gridwm: another window manager is already running\n");
 | 
							error("gridwm: another window manager is already running\n");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if(!(shell = getenv("SHELL")))
 | 
					 | 
				
			||||||
		shell = "/bin/sh";
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	rect.x = rect.y = 0;
 | 
						rect.x = rect.y = 0;
 | 
				
			||||||
	rect.width = DisplayWidth(dpy, screen);
 | 
						rect.width = DisplayWidth(dpy, screen);
 | 
				
			||||||
	rect.height = DisplayHeight(dpy, screen);
 | 
						rect.height = DisplayHeight(dpy, screen);
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										2
									
								
								wm.h
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								wm.h
									
									
									
									
									
								
							@@ -55,7 +55,7 @@ extern void (*handler[LASTEvent]) (XEvent *);
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
extern int screen, sel_screen;
 | 
					extern int screen, sel_screen;
 | 
				
			||||||
extern unsigned int lock_mask, numlock_mask;
 | 
					extern unsigned int lock_mask, numlock_mask;
 | 
				
			||||||
extern char *bartext, *shell;
 | 
					extern char *bartext;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern Brush brush;
 | 
					extern Brush brush;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user