aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTatsuya Kinoshita <tats@debian.org>2018-01-20 16:29:10 +0000
committerTatsuya Kinoshita <tats@debian.org>2018-01-21 01:34:11 +0000
commit18dcbadf2771cdb0c18509b14e4e73505b242753 (patch)
tree1ea6237b8f2c596d86d14f92d72716b579dfed07
parentSuppress error messages when ~/.w3m is unwritable (diff)
downloadw3m-18dcbadf2771cdb0c18509b14e4e73505b242753.tar.gz
w3m-18dcbadf2771cdb0c18509b14e4e73505b242753.zip
Make temporary directory safely when ~/.w3m is unwritable
-rw-r--r--config.h.dist1
-rw-r--r--config.h.in1
-rwxr-xr-xconfigure2
-rw-r--r--configure.ac2
-rw-r--r--main.c7
-rw-r--r--rc.c5
6 files changed, 16 insertions, 2 deletions
diff --git a/config.h.dist b/config.h.dist
index 0440927..4d9c119 100644
--- a/config.h.dist
+++ b/config.h.dist
@@ -210,6 +210,7 @@ typedef long clen_t;
#define HAVE_SRANDOM
#undef HAVE_GETPASSPHRASE
#define HAVE_CHDIR
+#define HAVE_MKDTEMP
#define SETJMP(env) sigsetjmp(env,1)
diff --git a/config.h.in b/config.h.in
index 3b575e4..6ab3008 100644
--- a/config.h.in
+++ b/config.h.in
@@ -143,6 +143,7 @@ typedef long clen_t;
#undef HAVE_SRANDOM
#undef HAVE_GETPASSPHRASE
#undef HAVE_CHDIR
+#undef HAVE_MKDTEMP
#undef HAVE_SETPGRP
#undef HAVE_SETLOCALE
#undef HAVE_LANGINFO_CODESET
diff --git a/configure b/configure
index 140f050..8699b43 100755
--- a/configure
+++ b/configure
@@ -8767,7 +8767,7 @@ _ACEOF
-for ac_func in strcasecmp strcasestr strchr memcpy strerror bcopy setpgrp chdir getcwd getwd readlink setenv putenv strtoll stroq atoll atoq symlink readlink lstat srand48 srandom getpassphrase waitpid setlocale
+for ac_func in strcasecmp strcasestr strchr memcpy strerror bcopy setpgrp chdir mkdtemp getcwd getwd readlink setenv putenv strtoll stroq atoll atoq symlink readlink lstat srand48 srandom getpassphrase waitpid setlocale
do :
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
diff --git a/configure.ac b/configure.ac
index 320a6e2..ebb3282 100644
--- a/configure.ac
+++ b/configure.ac
@@ -150,7 +150,7 @@ dnl AC_FUNC_MEMCMP
dnl AC_FUNC_MMAP
dnl AC_FUNC_SETVBUF_REVERSED
dnl AC_FUNC_VPRINTF
-AC_CHECK_FUNCS(strcasecmp strcasestr strchr memcpy strerror bcopy setpgrp chdir getcwd getwd readlink setenv putenv strtoll stroq atoll atoq symlink readlink lstat srand48 srandom getpassphrase waitpid setlocale)
+AC_CHECK_FUNCS(strcasecmp strcasestr strchr memcpy strerror bcopy setpgrp chdir mkdtemp getcwd getwd readlink setenv putenv strtoll stroq atoll atoq symlink readlink lstat srand48 srandom getpassphrase waitpid setlocale)
AC_FUNC_STRFTIME
AC_FUNC_WAIT3
AC_FUNC_SETPGRP
diff --git a/main.c b/main.c
index a20b4a1..43e181c 100644
--- a/main.c
+++ b/main.c
@@ -5972,6 +5972,13 @@ w3m_exit(int i)
#ifdef __MINGW32_VERSION
WSACleanup();
#endif
+#ifdef HAVE_MKDTEMP
+ if (no_rc_dir && tmp_dir != rc_dir)
+ if (rmdir(tmp_dir) != 0) {
+ fprintf(stderr, "Can't remove temporary directory (%s)!\n", tmp_dir);
+ exit(1);
+ }
+#endif
exit(i);
}
diff --git a/rc.c b/rc.c
index eb562c9..3fd84ef 100644
--- a/rc.c
+++ b/rc.c
@@ -1330,6 +1330,11 @@ init_rc(void)
((tmp_dir = getenv("TMP")) == NULL || *tmp_dir == '\0') &&
((tmp_dir = getenv("TEMP")) == NULL || *tmp_dir == '\0'))
tmp_dir = "/tmp";
+#ifdef HAVE_MKDTEMP
+ tmp_dir = mkdtemp(Strnew_m_charp(tmp_dir, "/w3m-XXXXXX", NULL)->ptr);
+ if (tmp_dir == NULL)
+ tmp_dir = rc_dir;
+#endif
create_option_search_table();
goto open_rc;
}