From ead29c2a366eb2c5006d7da64963ce5f60deb684 Mon Sep 17 00:00:00 2001 From: Roman Perepelitsa Date: Fri, 23 Oct 2020 11:42:30 +0200 Subject: Fix a race condition in zf_mkdir -p If ~/foo does not exist and `zf_mkdir -p zf_mkdir -p` is executed concurrently in multiple shells, it was possible prior to this patch for the command to fail with EEXIST. --- Src/Modules/files.c | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) (limited to 'Src/Modules/files.c') diff --git a/Src/Modules/files.c b/Src/Modules/files.c index 6d20e38a8..7ebacba6c 100644 --- a/Src/Modules/files.c +++ b/Src/Modules/files.c @@ -122,19 +122,29 @@ domkdir(char *nam, char *path, mode_t mode, int p) { int err; mode_t oumask; + struct stat st; + int n = 8; char const *rpath = unmeta(path); - if(p) { - struct stat st; - - if(!stat(rpath, &st) && S_ISDIR(st.st_mode)) + while(n-- > 0) { + oumask = umask(0); + err = mkdir(rpath, mode) ? errno : 0; + umask(oumask); + if (!err) + return 0; + if(!p || err != EEXIST) + break; + if(stat(rpath, &st)) { + if(errno == ENOENT) + continue; + err = errno; + break; + } + if(S_ISDIR(st.st_mode)) return 0; + break; } - oumask = umask(0); - err = mkdir(rpath, mode) ? errno : 0; - umask(oumask); - if(!err) - return 0; + zwarnnam(nam, "cannot make directory `%s': %e", path, err); return 1; } -- cgit v1.2.3 From df48cc8404f3fc2976c9d70c9aeefda171432cf9 Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Wed, 30 Dec 2020 23:41:30 -0600 Subject: 47785: remove deprecated autoconf functions STDC_HEADERS and TIME_WITH_SYS_TIME are deprecated. --- ChangeLog | 5 +++++ Src/Modules/files.c | 6 ------ Src/mem.c | 16 ++++------------ Src/zsh_system.h | 21 ++------------------- configure.ac | 4 +--- 5 files changed, 12 insertions(+), 40 deletions(-) (limited to 'Src/Modules/files.c') diff --git a/ChangeLog b/ChangeLog index 18c576b5c..b3cd5b8de 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2021-04-09 Oliver Kiddle + + * Felipe Contreras: 47785: Src/Modules/files.c, Src/zsh_system.h, + Src/mem.c, configure.ac: remove deprecated autoconf functions + 2021-04-08 Jun-ichi Takimoto * 48416: Completion/Unix/Command/_gcore: support macOS, with diff --git a/Src/Modules/files.c b/Src/Modules/files.c index 7ebacba6c..a1d6f6bf2 100644 --- a/Src/Modules/files.c +++ b/Src/Modules/files.c @@ -32,12 +32,6 @@ typedef int (*MoveFunc) _((char const *, char const *)); typedef int (*RecurseFunc) _((char *, char *, struct stat const *, void *)); -#ifndef STDC_HEADERS -extern int link _((const char *, const char *)); -extern int symlink _((const char *, const char *)); -extern int rename _((const char *, const char *)); -#endif - struct recursivecmd; #include "files.pro" diff --git a/Src/mem.c b/Src/mem.c index 5951e57ed..25b2bbce7 100644 --- a/Src/mem.c +++ b/Src/mem.c @@ -1072,18 +1072,10 @@ zrealloc(void *ptr, size_t size) # endif #endif -#if defined(_BSD) && !defined(STDC_HEADERS) -# define FREE_RET_T int -# define FREE_ARG_T char * -# define FREE_DO_RET -# define MALLOC_RET_T char * -# define MALLOC_ARG_T size_t -#else -# define FREE_RET_T void -# define FREE_ARG_T void * -# define MALLOC_RET_T void * -# define MALLOC_ARG_T size_t -#endif +#define FREE_RET_T void +#define FREE_ARG_T void * +#define MALLOC_RET_T void * +#define MALLOC_ARG_T size_t /* structure for building free list in blocks holding small blocks */ diff --git a/Src/zsh_system.h b/Src/zsh_system.h index 161b073b4..6f4efce96 100644 --- a/Src/zsh_system.h +++ b/Src/zsh_system.h @@ -235,16 +235,8 @@ char *alloca _((size_t)); # include #endif -#ifdef TIME_WITH_SYS_TIME -# include -# include -#else -# ifdef HAVE_SYS_TIME_H -# include -# else -# include -# endif -#endif +#include +#include /* This is needed by some old SCO unices */ #if !defined(HAVE_STRUCT_TIMEZONE) && !defined(ZSH_OOT_MODULE) @@ -279,16 +271,7 @@ struct timespec { # include #endif -#if STDC_HEADERS || HAVE_STRING_H # include -/* An ANSI string.h and pre-ANSI memory.h might conflict. */ -# if !STDC_HEADERS && HAVE_MEMORY_H -# include -# endif /* not STDC_HEADERS and HAVE_MEMORY_H */ -#else /* not STDC_HEADERS and not HAVE_STRING_H */ -# include -/* memory.h and strings.h conflict on some systems. */ -#endif /* not STDC_HEADERS and not HAVE_STRING_H */ #ifdef HAVE_LOCALE_H # include diff --git a/configure.ac b/configure.ac index 16dafac05..e2ddf0e55 100644 --- a/configure.ac +++ b/configure.ac @@ -28,7 +28,7 @@ dnl AC_INIT AC_CONFIG_SRCDIR([Src/zsh.h]) AC_PREREQ([2.69]) -AC_CONFIG_HEADER(config.h) +AC_CONFIG_HEADERS([config.h]) dnl What version of zsh are we building ? . ${srcdir}/Config/version.mk @@ -657,8 +657,6 @@ dnl ------------------ dnl CHECK HEADER FILES dnl ------------------ AC_HEADER_DIRENT -AC_HEADER_STDC -AC_HEADER_TIME AC_HEADER_STAT AC_HEADER_SYS_WAIT -- cgit v1.2.3 From 4a9437317fd374e983934d5b18c7d1d6ee041645 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Tue, 24 Aug 2021 19:21:53 +0100 Subject: 49297 (quoting amended): error message in files module. If ENONENT it could be the other argument that doesn't exist, so check. --- ChangeLog | 5 +++++ Src/Modules/files.c | 8 +++++++- 2 files changed, 12 insertions(+), 1 deletion(-) (limited to 'Src/Modules/files.c') diff --git a/ChangeLog b/ChangeLog index 3d1a97e41..428998717 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2021-08-24 Peter Stephenson + + * 49297 with quoting updated: Src/Modules/files.c: check + which files is in error when ENOENT on link etc. + 2021-08-24 dana * github #78: DCsunset: Completion/Unix/Command/_pandoc: Fix diff --git a/Src/Modules/files.c b/Src/Modules/files.c index a1d6f6bf2..d991f69d7 100644 --- a/Src/Modules/files.c +++ b/Src/Modules/files.c @@ -346,7 +346,13 @@ domove(char *nam, MoveFunc movefn, char *p, char *q, int flags) unlink(qbuf); } if(movefn(pbuf, qbuf)) { - zwarnnam(nam, "%s: %e", p, errno); + int ferrno = errno; + char *errfile = p; + if (ferrno == ENOENT && !lstat(pbuf, &st)) { + /* p *does* exist, so error is in q */ + errfile = q; + } + zwarnnam(nam, "`%s': %e", errfile, ferrno); zsfree(pbuf); return 1; } -- cgit v1.2.3 From 2b81d4be3232fced220be1cf9c80c087d91d88d6 Mon Sep 17 00:00:00 2001 From: Jun-ichi Takimoto Date: Wed, 8 Sep 2021 11:58:29 +0900 Subject: unposted: add/remove UNUSED() for some function parameters --- ChangeLog | 4 ++++ Src/Modules/db_gdbm.c | 2 +- Src/Modules/files.c | 2 +- Src/Modules/nearcolor.c | 2 +- Src/Zle/complete.c | 2 +- Src/builtin.c | 2 +- 6 files changed, 9 insertions(+), 5 deletions(-) (limited to 'Src/Modules/files.c') diff --git a/ChangeLog b/ChangeLog index fe9a3b4ee..6f4646287 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2021-09-08 Jun-ichi Takimoto + * unposted: Src/Modules/db_gdbm.c, Src/Modules/files.c, + Src/Modules/nearcolor.c, Src/Zle/complete.c, Src/builtin.c: + add/remove UNUSED() for some funtion parameters + * unposted: Src/input.c: add 'static' to shinsavestack * 49377: Src/Zle/zle_keymap.c, Test/X03zlebindkey.ztst: fix diff --git a/Src/Modules/db_gdbm.c b/Src/Modules/db_gdbm.c index 84fdfa905..7e11ec939 100644 --- a/Src/Modules/db_gdbm.c +++ b/Src/Modules/db_gdbm.c @@ -233,7 +233,7 @@ bin_zuntie(char *nam, char **args, Options ops, UNUSED(int func)) /**/ static int -bin_zgdbmpath(char *nam, char **args, Options ops, UNUSED(int func)) +bin_zgdbmpath(char *nam, char **args, UNUSED(Options ops), UNUSED(int func)) { Param pm; char *pmname; diff --git a/Src/Modules/files.c b/Src/Modules/files.c index d991f69d7..bf0e8f8a8 100644 --- a/Src/Modules/files.c +++ b/Src/Modules/files.c @@ -652,7 +652,7 @@ chmod_dochmod(char *arg, char *rp, UNUSED(struct stat const *sp), void *magic) /**/ static int -bin_chmod(char *nam, char **args, Options ops, int func) +bin_chmod(char *nam, char **args, Options ops, UNUSED(int func)) { struct chmodmagic chm; char *str = args[0], *ptr; diff --git a/Src/Modules/nearcolor.c b/Src/Modules/nearcolor.c index b49ee9afb..d50a6bb44 100644 --- a/Src/Modules/nearcolor.c +++ b/Src/Modules/nearcolor.c @@ -188,7 +188,7 @@ enables_(Module m, int **enables) /**/ int -boot_(Module m) +boot_(UNUSED(Module m)) { addhookfunc("get_color_attr", (Hookfn) getnearestcolor); return 0; diff --git a/Src/Zle/complete.c b/Src/Zle/complete.c index 7beb6d847..71d114de9 100644 --- a/Src/Zle/complete.c +++ b/Src/Zle/complete.c @@ -1343,7 +1343,7 @@ get_compstate(Param pm) /**/ static void -set_compstate(UNUSED(Param pm), HashTable ht) +set_compstate(Param pm, HashTable ht) { struct compparam *cp; Param *pp; diff --git a/Src/builtin.c b/Src/builtin.c index d7d2ea297..89bcd98db 100644 --- a/Src/builtin.c +++ b/Src/builtin.c @@ -2024,7 +2024,7 @@ typeset_setwidth(const char * name, Param pm, Options ops, int on, int always) /**/ static Param -typeset_single(char *cname, char *pname, Param pm, UNUSED(int func), +typeset_single(char *cname, char *pname, Param pm, int func, int on, int off, int roff, Asgment asg, Param altpm, Options ops, int joinchar) { -- cgit v1.2.3