aboutsummaryrefslogtreecommitdiffstats
path: root/src/firejail/env.c
diff options
context:
space:
mode:
authorLibravatar netblue30 <netblue30@yahoo.com>2015-11-04 07:47:45 -0500
committerLibravatar netblue30 <netblue30@yahoo.com>2015-11-04 07:47:45 -0500
commitcc29de3777a4e44cf09b10e5efcc7572400c8e09 (patch)
treea36655b50a7ae10a393ea2dc889559a08e8ac910 /src/firejail/env.c
parent--private.print option (diff)
downloadfirejail-cc29de3777a4e44cf09b10e5efcc7572400c8e09.tar.gz
firejail-cc29de3777a4e44cf09b10e5efcc7572400c8e09.tar.zst
firejail-cc29de3777a4e44cf09b10e5efcc7572400c8e09.zip
IBus support
Diffstat (limited to 'src/firejail/env.c')
-rw-r--r--src/firejail/env.c83
1 files changed, 83 insertions, 0 deletions
diff --git a/src/firejail/env.c b/src/firejail/env.c
index b4f56a9f0..2bbd2d226 100644
--- a/src/firejail/env.c
+++ b/src/firejail/env.c
@@ -18,6 +18,10 @@
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */ 19 */
20#include "firejail.h" 20#include "firejail.h"
21#include <sys/types.h>
22#include <sys/stat.h>
23#include <unistd.h>
24#include <dirent.h>
21 25
22typedef struct env_t { 26typedef struct env_t {
23 struct env_t *next; 27 struct env_t *next;
@@ -31,6 +35,85 @@ static void env_add(Env *env) {
31 envlist = env; 35 envlist = env;
32} 36}
33 37
38// load IBUS env variables
39void env_ibus_load(void) {
40 // check ~/.config/ibus/bus directory
41 char *dirname;
42 if (asprintf(&dirname, "%s/.config/ibus/bus", cfg.homedir) == -1)
43 errExit("asprintf");
44
45 struct stat s;
46 if (stat(dirname, &s) == -1)
47 return;
48
49 // find the file
50 DIR *dir = opendir(dirname);
51 if (!dir) {
52 free(dirname);
53 return;
54 }
55
56 struct dirent *entry;
57 while ((entry = readdir(dir)) != NULL) {
58 // check the file name ends in "unix-0"
59 char *ptr = strstr(entry->d_name, "unix-0");
60 if (!ptr)
61 continue;
62 if (strlen(ptr) != 6)
63 continue;
64
65 // open the file
66 char *fname;
67 if (asprintf(&fname, "%s/%s", dirname, entry->d_name) == -1)
68 errExit("asprintf");
69 FILE *fp = fopen(fname, "r");
70 free(fname);
71 if (!fp)
72 continue;
73
74 // read the file
75 const int maxline = 4096;
76 char buf[maxline];
77 while (fgets(buf, maxline, fp)) {
78 if (strncmp(buf, "IBUS_", 5) != 0)
79 continue;
80 char *ptr = strchr(buf, '=');
81 if (!ptr)
82 continue;
83 ptr = strchr(buf, '\n');
84 if (ptr)
85 *ptr = '\0';
86 if (arg_debug)
87 printf("%s\n", buf);
88 env_store(buf);
89 }
90
91 fclose(fp);
92 }
93
94 free(dirname);
95}
96
97
98// default sandbox env variables
99void env_defaults(void) {
100 // fix qt 4.8
101 if (setenv("QT_X11_NO_MITSHM", "1", 1) < 0)
102 errExit("setenv");
103 if (setenv("container", "firejail", 1) < 0) // LXC sets container=lxc,
104 errExit("setenv");
105 if (arg_zsh && setenv("SHELL", "/usr/bin/zsh", 1) < 0)
106 errExit("setenv");
107 if (arg_csh && setenv("SHELL", "/bin/csh", 1) < 0)
108 errExit("setenv");
109 if (cfg.shell && setenv("SHELL", cfg.shell, 1) < 0)
110 errExit("setenv");
111 // set prompt color to green
112 //export PS1='\[\e[1;32m\][\u@\h \W]\$\[\e[0m\] '
113 if (setenv("PROMPT_COMMAND", "export PS1=\"\\[\\e[1;32m\\][\\u@\\h \\W]\\$\\[\\e[0m\\] \"", 1) < 0)
114 errExit("setenv");
115}
116
34// parse and store the environment setting 117// parse and store the environment setting
35void env_store(const char *str) { 118void env_store(const char *str) {
36 assert(str); 119 assert(str);