mirror of
				https://github.com/labwc/labwc.git
				synced 2025-11-03 09:01:51 -05:00 
			
		
		
		
	session: resolve variables in environment file
When parsing <key>=<value> pairs to set enrivonment variables,
resolve variables in <value>.
For example, resolve $bar in
    foo=$bar
Fix issue #70
			
			
This commit is contained in:
		
							parent
							
								
									d4e1791c88
								
							
						
					
					
						commit
						71c8aa1361
					
				
					 1 changed files with 12 additions and 5 deletions
				
			
		| 
						 | 
					@ -7,6 +7,7 @@
 | 
				
			||||||
#include <string.h>
 | 
					#include <string.h>
 | 
				
			||||||
#include <sys/stat.h>
 | 
					#include <sys/stat.h>
 | 
				
			||||||
#include <wlr/util/log.h>
 | 
					#include <wlr/util/log.h>
 | 
				
			||||||
 | 
					#include "common/buf.h"
 | 
				
			||||||
#include "common/dir.h"
 | 
					#include "common/dir.h"
 | 
				
			||||||
#include "common/spawn.h"
 | 
					#include "common/spawn.h"
 | 
				
			||||||
#include "common/string-helpers.h"
 | 
					#include "common/string-helpers.h"
 | 
				
			||||||
| 
						 | 
					@ -30,18 +31,24 @@ process_line(char *line)
 | 
				
			||||||
	if (string_empty(line) || line[0] == '#') {
 | 
						if (string_empty(line) || line[0] == '#') {
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	char *key = NULL, *value = NULL;
 | 
						char *key = NULL;
 | 
				
			||||||
	char *p = strchr(line, '=');
 | 
						char *p = strchr(line, '=');
 | 
				
			||||||
	if (!p) {
 | 
						if (!p) {
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	*p = '\0';
 | 
						*p = '\0';
 | 
				
			||||||
	key = string_strip(line);
 | 
						key = string_strip(line);
 | 
				
			||||||
	value = string_strip(++p);
 | 
					
 | 
				
			||||||
	if (string_empty(key) || string_empty(value)) {
 | 
						struct buf value;
 | 
				
			||||||
		return;
 | 
						buf_init(&value);
 | 
				
			||||||
 | 
						buf_add(&value, string_strip(++p));
 | 
				
			||||||
 | 
						buf_expand_shell_variables(&value);
 | 
				
			||||||
 | 
						if (string_empty(key) || !value.len) {
 | 
				
			||||||
 | 
							goto error;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	setenv(key, value, 1);
 | 
						setenv(key, value.buf, 1);
 | 
				
			||||||
 | 
					error:
 | 
				
			||||||
 | 
						free(value.buf);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void
 | 
					void
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue