Skip to content

Commit 412c991

Browse files
committed
Set umask for files in XDG_RUNTIME_DIR
1 parent 3b7b63b commit 412c991

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

brightnessctl.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,12 +265,16 @@ int process_device(struct device *dev) {
265265
}
266266
free(file_path);
267267
}
268+
mode_t old = umask(0);
268269
char *sys_run_dir = getenv("XDG_RUNTIME_DIR");
269-
if (sys_run_dir)
270+
if (sys_run_dir) {
271+
umask(0077);
270272
run_dir = dir_child(sys_run_dir, "brightnessctl");
273+
}
271274
if (p.save)
272275
if (!save_device_data(dev))
273276
fprintf(stderr, "Could not save data for device '%s'.\n", dev->id);
277+
umask(old);
274278
if (p.restore) {
275279
if (restore_device_data(dev))
276280
p.operation = RESTORE;
@@ -563,9 +567,7 @@ bool save_device_data(struct device *dev) {
563567
char *d_path = dir_child(c_path, dev->id);
564568
bool ret = true;
565569
if (mkdir_parent(c_path)) {
566-
mode_t old = umask(0);
567570
FILE *fp = fopen(d_path, "wb");
568-
umask(old);
569571
if (fp) {
570572
fwrite(&dev->curr_brightness, sizeof(dev->curr_brightness), 1, fp);
571573
if (ferror(fp)) {

0 commit comments

Comments
 (0)