diff options
author | smitsohu <smitsohu@gmail.com> | 2020-12-21 02:04:07 +0100 |
---|---|---|
committer | smitsohu <smitsohu@gmail.com> | 2020-12-21 02:04:07 +0100 |
commit | a2256c9bebb0ef6a22f111a615530df7e09259de (patch) | |
tree | 6873f6c7b5b3a91db55e21e5f9483d30bddeb008 /src | |
parent | noroot option: don't drop firejail supplementary group (diff) | |
download | firejail-a2256c9bebb0ef6a22f111a615530df7e09259de.tar.gz firejail-a2256c9bebb0ef6a22f111a615530df7e09259de.tar.zst firejail-a2256c9bebb0ef6a22f111a615530df7e09259de.zip |
increase verbosity if masking ~/.config/pulse fails
plus very minor cosmetic improvements
Diffstat (limited to 'src')
-rw-r--r-- | src/firejail/pulseaudio.c | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/src/firejail/pulseaudio.c b/src/firejail/pulseaudio.c index 84cbb1977..a5c924a70 100644 --- a/src/firejail/pulseaudio.c +++ b/src/firejail/pulseaudio.c | |||
@@ -31,6 +31,8 @@ | |||
31 | #define O_PATH 010000000 | 31 | #define O_PATH 010000000 |
32 | #endif | 32 | #endif |
33 | 33 | ||
34 | #define PULSE_CLIENT_SYSCONF "/etc/pulse/client.conf" | ||
35 | |||
34 | // disable pulseaudio socket | 36 | // disable pulseaudio socket |
35 | void pulseaudio_disable(void) { | 37 | void pulseaudio_disable(void) { |
36 | if (arg_debug) | 38 | if (arg_debug) |
@@ -73,8 +75,8 @@ void pulseaudio_disable(void) { | |||
73 | closedir(dir); | 75 | closedir(dir); |
74 | } | 76 | } |
75 | 77 | ||
76 | static void pulseaudio_set_environment(const char *path) { | 78 | static void pulseaudio_fallback(const char *path) { |
77 | assert(path); | 79 | fmessage("Cannot mount tmpfs on %s/.config/pulse\n", cfg.homedir); |
78 | if (setenv("PULSE_CLIENTCONFIG", path, 1) < 0) | 80 | if (setenv("PULSE_CLIENTCONFIG", path, 1) < 0) |
79 | errExit("setenv"); | 81 | errExit("setenv"); |
80 | } | 82 | } |
@@ -84,9 +86,9 @@ void pulseaudio_init(void) { | |||
84 | struct stat s; | 86 | struct stat s; |
85 | 87 | ||
86 | // do we have pulseaudio in the system? | 88 | // do we have pulseaudio in the system? |
87 | if (stat("/etc/pulse/client.conf", &s) == -1) { | 89 | if (stat(PULSE_CLIENT_SYSCONF, &s) == -1) { |
88 | if (arg_debug) | 90 | if (arg_debug) |
89 | printf("/etc/pulse/client.conf not found\n"); | 91 | printf("%s not found\n", PULSE_CLIENT_SYSCONF); |
90 | return; | 92 | return; |
91 | } | 93 | } |
92 | 94 | ||
@@ -101,7 +103,7 @@ void pulseaudio_init(void) { | |||
101 | char *pulsecfg = NULL; | 103 | char *pulsecfg = NULL; |
102 | if (asprintf(&pulsecfg, "%s/client.conf", RUN_PULSE_DIR) == -1) | 104 | if (asprintf(&pulsecfg, "%s/client.conf", RUN_PULSE_DIR) == -1) |
103 | errExit("asprintf"); | 105 | errExit("asprintf"); |
104 | if (copy_file("/etc/pulse/client.conf", pulsecfg, -1, -1, 0644)) // root needed | 106 | if (copy_file(PULSE_CLIENT_SYSCONF, pulsecfg, -1, -1, 0644)) // root needed |
105 | errExit("copy_file"); | 107 | errExit("copy_file"); |
106 | FILE *fp = fopen(pulsecfg, "a"); | 108 | FILE *fp = fopen(pulsecfg, "a"); |
107 | if (!fp) | 109 | if (!fp) |
@@ -126,11 +128,11 @@ void pulseaudio_init(void) { | |||
126 | if (create_empty_dir_as_user(homeusercfg, 0700)) | 128 | if (create_empty_dir_as_user(homeusercfg, 0700)) |
127 | fs_logger2("create", homeusercfg); | 129 | fs_logger2("create", homeusercfg); |
128 | 130 | ||
129 | // if ~/.config/pulse now exists and there are no symbolic links, mount the new directory | 131 | // if ~/.config/pulse exists and there are no symbolic links, mount the new directory |
130 | // else set environment variable | 132 | // else set environment variable |
131 | int fd = safe_fd(homeusercfg, O_PATH|O_DIRECTORY|O_NOFOLLOW|O_CLOEXEC); | 133 | int fd = safe_fd(homeusercfg, O_PATH|O_DIRECTORY|O_NOFOLLOW|O_CLOEXEC); |
132 | if (fd == -1) { | 134 | if (fd == -1) { |
133 | pulseaudio_set_environment(pulsecfg); | 135 | pulseaudio_fallback(pulsecfg); |
134 | goto out; | 136 | goto out; |
135 | } | 137 | } |
136 | // confirm the actual mount destination is owned by the user | 138 | // confirm the actual mount destination is owned by the user |
@@ -138,12 +140,12 @@ void pulseaudio_init(void) { | |||
138 | if (errno != EACCES) | 140 | if (errno != EACCES) |
139 | errExit("fstat"); | 141 | errExit("fstat"); |
140 | close(fd); | 142 | close(fd); |
141 | pulseaudio_set_environment(pulsecfg); | 143 | pulseaudio_fallback(pulsecfg); |
142 | goto out; | 144 | goto out; |
143 | } | 145 | } |
144 | if (s.st_uid != getuid()) { | 146 | if (s.st_uid != getuid()) { |
145 | close(fd); | 147 | close(fd); |
146 | pulseaudio_set_environment(pulsecfg); | 148 | pulseaudio_fallback(pulsecfg); |
147 | goto out; | 149 | goto out; |
148 | } | 150 | } |
149 | // preserve a read-only mount | 151 | // preserve a read-only mount |
@@ -171,8 +173,9 @@ void pulseaudio_init(void) { | |||
171 | char *p; | 173 | char *p; |
172 | if (asprintf(&p, "%s/client.conf", homeusercfg) == -1) | 174 | if (asprintf(&p, "%s/client.conf", homeusercfg) == -1) |
173 | errExit("asprintf"); | 175 | errExit("asprintf"); |
176 | if (setenv("PULSE_CLIENTCONFIG", p, 1) < 0) | ||
177 | errExit("setenv"); | ||
174 | fs_logger2("create", p); | 178 | fs_logger2("create", p); |
175 | pulseaudio_set_environment(p); | ||
176 | free(p); | 179 | free(p); |
177 | 180 | ||
178 | // RUN_PULSE_DIR not needed anymore, mask it | 181 | // RUN_PULSE_DIR not needed anymore, mask it |