[FFmpeg-devel] avformat/internal: log errno with ff_rename failure

Submitted by Aman Gupta on Dec. 22, 2017, 11:17 p.m.

Details

Message ID 20171222231733.1849-1-ffmpeg@tmm1.net
State New
Headers show

Commit Message

Aman Gupta Dec. 22, 2017, 11:17 p.m.
From: Aman Gupta <aman@tmm1.net>

---
 libavformat/internal.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

wm4 Dec. 22, 2017, 11:37 p.m.
On Fri, 22 Dec 2017 15:17:33 -0800
Aman Gupta <ffmpeg@tmm1.net> wrote:

> From: Aman Gupta <aman@tmm1.net>
> 
> ---
>  libavformat/internal.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/libavformat/internal.h b/libavformat/internal.h
> index 36a57214ce..aac566aace 100644
> --- a/libavformat/internal.h
> +++ b/libavformat/internal.h
> @@ -542,7 +542,7 @@ static inline int ff_rename(const char *oldpath, const char *newpath, void *logc
>      if (rename(oldpath, newpath) == -1) {
>          ret = AVERROR(errno);
>          if (logctx)
> -            av_log(logctx, AV_LOG_ERROR, "failed to rename file %s to %s\n", oldpath, newpath);
> +            av_log(logctx, AV_LOG_ERROR, "failed to rename file %s to %s: %s\n", oldpath, newpath, strerror(errno));
>      }
>      return ret;
>  }

strerror() is not thread-safe. you could use av_err2str() after
wrapping the errno value as AVERROR. This would return the same as
strerror(), but using a thread-safe alternative function if possible.
Aman Gupta Dec. 23, 2017, 2:01 a.m.
On Fri, Dec 22, 2017 at 3:37 PM, wm4 <nfxjfg@googlemail.com> wrote:

> On Fri, 22 Dec 2017 15:17:33 -0800
> Aman Gupta <ffmpeg@tmm1.net> wrote:
>
> > From: Aman Gupta <aman@tmm1.net>
> >
> > ---
> >  libavformat/internal.h | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/libavformat/internal.h b/libavformat/internal.h
> > index 36a57214ce..aac566aace 100644
> > --- a/libavformat/internal.h
> > +++ b/libavformat/internal.h
> > @@ -542,7 +542,7 @@ static inline int ff_rename(const char *oldpath,
> const char *newpath, void *logc
> >      if (rename(oldpath, newpath) == -1) {
> >          ret = AVERROR(errno);
> >          if (logctx)
> > -            av_log(logctx, AV_LOG_ERROR, "failed to rename file %s to
> %s\n", oldpath, newpath);
> > +            av_log(logctx, AV_LOG_ERROR, "failed to rename file %s to
> %s: %s\n", oldpath, newpath, strerror(errno));
> >      }
> >      return ret;
> >  }
>
> strerror() is not thread-safe. you could use av_err2str() after
> wrapping the errno value as AVERROR. This would return the same as
> strerror(), but using a thread-safe alternative function if possible.
>

Thanks. Fixed and applied to master.

Aman


> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>

Patch hide | download patch | download mbox

diff --git a/libavformat/internal.h b/libavformat/internal.h
index 36a57214ce..aac566aace 100644
--- a/libavformat/internal.h
+++ b/libavformat/internal.h
@@ -542,7 +542,7 @@  static inline int ff_rename(const char *oldpath, const char *newpath, void *logc
     if (rename(oldpath, newpath) == -1) {
         ret = AVERROR(errno);
         if (logctx)
-            av_log(logctx, AV_LOG_ERROR, "failed to rename file %s to %s\n", oldpath, newpath);
+            av_log(logctx, AV_LOG_ERROR, "failed to rename file %s to %s: %s\n", oldpath, newpath, strerror(errno));
     }
     return ret;
 }