aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/firejail/fs_hostname.c11
1 files changed, 5 insertions, 6 deletions
diff --git a/src/firejail/fs_hostname.c b/src/firejail/fs_hostname.c
index 32b314a8b..cddf3c903 100644
--- a/src/firejail/fs_hostname.c
+++ b/src/firejail/fs_hostname.c
@@ -53,7 +53,8 @@ static char *random_hostname(void) {
53} 53}
54 54
55void fs_hostname(void) { 55void fs_hostname(void) {
56 const char *hostname = (cfg.hostname)? cfg.hostname: random_hostname(); 56 if (!cfg.hostname)
57 cfg.hostname = random_hostname();
57 struct stat s; 58 struct stat s;
58 59
59 // create a new /etc/hostname 60 // create a new /etc/hostname
@@ -63,11 +64,9 @@ void fs_hostname(void) {
63 64
64 create_empty_file_as_root(RUN_HOSTNAME_FILE, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); 65 create_empty_file_as_root(RUN_HOSTNAME_FILE, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
65 FILE *fp = fopen(RUN_HOSTNAME_FILE, "we"); 66 FILE *fp = fopen(RUN_HOSTNAME_FILE, "we");
66 if (!fp) { 67 if (!fp)
67 fclose(fp);
68 goto errexit; 68 goto errexit;
69 } 69 fprintf(fp, "%s\n", cfg.hostname);
70 fprintf(fp, "%s\n", hostname);
71 SET_PERMS_STREAM(fp, 0, 0, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); 70 SET_PERMS_STREAM(fp, 0, 0, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
72 fclose(fp); 71 fclose(fp);
73 72
@@ -104,7 +103,7 @@ void fs_hostname(void) {
104 // copy line 103 // copy line
105 if (strstr(buf, "127.0.0.1") && done == 0) { 104 if (strstr(buf, "127.0.0.1") && done == 0) {
106 done = 1; 105 done = 1;
107 fprintf(fp2, "127.0.0.1 %s\n", hostname); 106 fprintf(fp2, "127.0.0.1 %s\n", cfg.hostname);
108 } 107 }
109 else 108 else
110 fprintf(fp2, "%s\n", buf); 109 fprintf(fp2, "%s\n", buf);