Commit 4ff99618 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Fix the most common strerror() usages (threads, network, input) - refs #1297

parent 357771f9
......@@ -64,7 +64,7 @@
#include <stdlib.h>
#include <stdarg.h>
#include <string.h> /* strerror() */
#include <string.h>
#include <stdio.h>
#ifdef HAVE_SYS_TYPES_H
......
......@@ -63,7 +63,6 @@ extern const char *net_strerror( int val );
# endif
# include <netdb.h>
# define net_errno errno
# define net_strerror strerror
#endif
# ifdef __cplusplus
......
......@@ -81,7 +81,6 @@ static inline int __vlc_mutex_lock( const char * psz_file, int i_line,
int i_result;
/* In case of error : */
unsigned long int i_thread = 0;
const char * psz_error = "";
#if defined( PTH_INIT_IN_PTH_H )
i_result = ( pth_mutex_acquire( &p_mutex->mutex, FALSE, NULL ) == FALSE );
......@@ -126,7 +125,7 @@ static inline int __vlc_mutex_lock( const char * psz_file, int i_line,
if ( i_result )
{
i_thread = CAST_PTHREAD_TO_INT(pthread_self());
psz_error = strerror(i_result);
errno = i_result;
}
#elif defined( HAVE_CTHREADS_H )
......@@ -138,8 +137,8 @@ static inline int __vlc_mutex_lock( const char * psz_file, int i_line,
if( i_result )
{
msg_Err( p_mutex->p_this,
"thread %li: mutex_lock failed at %s:%d (%d:%s)",
i_thread, psz_file, i_line, i_result, psz_error );
"thread %li: mutex_lock failed at %s:%d (%d:%m)",
i_thread, psz_file, i_line, i_result );
}
return i_result;
}
......@@ -160,7 +159,6 @@ static inline int __vlc_mutex_unlock( const char * psz_file, int i_line,
int i_result;
/* In case of error : */
unsigned long int i_thread = 0;
const char * psz_error = "";
#if defined( PTH_INIT_IN_PTH_H )
i_result = ( pth_mutex_release( &p_mutex->mutex ) == FALSE );
......@@ -203,7 +201,7 @@ static inline int __vlc_mutex_unlock( const char * psz_file, int i_line,
if ( i_result )
{
i_thread = CAST_PTHREAD_TO_INT(pthread_self());
psz_error = strerror(i_result);
errno = i_result;
}
#elif defined( HAVE_CTHREADS_H )
......@@ -215,8 +213,8 @@ static inline int __vlc_mutex_unlock( const char * psz_file, int i_line,
if( i_result )
{
msg_Err( p_mutex->p_this,
"thread %li: mutex_unlock failed at %s:%d (%d:%s)",
i_thread, psz_file, i_line, i_result, psz_error );
"thread %li: mutex_unlock failed at %s:%d (%d:%m)",
i_thread, psz_file, i_line, i_result );
}
return i_result;
......@@ -246,7 +244,6 @@ static inline int __vlc_cond_signal( const char * psz_file, int i_line,
int i_result;
/* In case of error : */
unsigned long int i_thread = 0;
const char * psz_error = "";
#if defined( PTH_INIT_IN_PTH_H )
i_result = ( pth_cond_notify( &p_condvar->cond, FALSE ) == FALSE );
......@@ -341,7 +338,7 @@ static inline int __vlc_cond_signal( const char * psz_file, int i_line,
if ( i_result )
{
i_thread = CAST_PTHREAD_TO_INT(pthread_self());
psz_error = strerror(i_result);
errno = i_result;
}
#elif defined( HAVE_CTHREADS_H )
......@@ -357,8 +354,8 @@ static inline int __vlc_cond_signal( const char * psz_file, int i_line,
if( i_result )
{
msg_Err( p_condvar->p_this,
"thread %li: cond_signal failed at %s:%d (%d:%s)",
i_thread, psz_file, i_line, i_result, psz_error );
"thread %li: cond_signal failed at %s:%d (%d:%m)",
i_thread, psz_file, i_line, i_result );
}
return i_result;
......@@ -376,7 +373,6 @@ static inline int __vlc_cond_wait( const char * psz_file, int i_line,
int i_result;
/* In case of error : */
unsigned long int i_thread = 0;
const char * psz_error = "";
#if defined( PTH_INIT_IN_PTH_H )
i_result = ( pth_cond_await( &p_condvar->cond, &p_mutex->mutex, NULL )
......@@ -513,10 +509,11 @@ static inline int __vlc_cond_wait( const char * psz_file, int i_line,
if( i_result == ETIMEDOUT )
{
errno = ETIMEDOUT;
msg_Dbg( p_condvar->p_this,
"thread %li: possible condition deadlock "
"at %s:%d (%s)", CAST_PTHREAD_TO_INT(pthread_self()),
psz_file, i_line, strerror(i_result) );
"at %s:%d (%m)", CAST_PTHREAD_TO_INT(pthread_self()),
psz_file, i_line );
i_result = pthread_cond_wait( &p_condvar->cond, &p_mutex->mutex );
}
......@@ -528,7 +525,7 @@ static inline int __vlc_cond_wait( const char * psz_file, int i_line,
if ( i_result )
{
i_thread = CAST_PTHREAD_TO_INT(pthread_self());
psz_error = strerror(i_result);
errno = i_result;
}
#elif defined( HAVE_CTHREADS_H )
......@@ -540,8 +537,8 @@ static inline int __vlc_cond_wait( const char * psz_file, int i_line,
if( i_result )
{
msg_Err( p_condvar->p_this,
"thread %li: cond_wait failed at %s:%d (%d:%s)",
i_thread, psz_file, i_line, i_result, psz_error );
"thread %li: cond_wait failed at %s:%d (%d:%m)",
i_thread, psz_file, i_line, i_result );
}
return i_result;
......@@ -563,7 +560,6 @@ static inline int __vlc_cond_timedwait( const char * psz_file, int i_line,
{
int i_res;
unsigned long int i_thread = 0;
const char * psz_error = "";
#if defined( PTH_INIT_IN_PTH_H )
# error Unimplemented
......@@ -588,7 +584,7 @@ static inline int __vlc_cond_timedwait( const char * psz_file, int i_line,
if ( i_res ) /* other errors = bug */
{
i_thread = CAST_PTHREAD_TO_INT(pthread_self());
psz_error = strerror(i_res);
errno = i_res;
}
#elif defined( HAVE_CTHREADS_H )
......@@ -598,8 +594,8 @@ static inline int __vlc_cond_timedwait( const char * psz_file, int i_line,
if( i_res )
{
msg_Err( p_condvar->p_this,
"thread %li: cond_wait failed at %s:%d (%d:%s)",
i_thread, psz_file, i_line, i_res, psz_error );
"thread %li: cond_wait failed at %s:%d (%d:%m)",
i_thread, psz_file, i_line, i_res );
}
return i_res;
......
......@@ -458,7 +458,10 @@ int input_DownloadAndCacheArt( playlist_t *p_playlist, input_item_t *p_item )
stream_Delete( p_stream );
if( err )
msg_Err( p_playlist, "%s: %s", psz_filename, strerror( err ) );
{
errno = err;
msg_Err( p_playlist, "%s: %m", psz_filename );
}
else
msg_Dbg( p_playlist, "album art saved to %s\n", psz_filename );
......@@ -545,7 +548,7 @@ void input_ExtractAttachmentAndCacheArt( input_thread_t *p_input )
if( f )
{
if( fwrite( p_attachment->p_data, p_attachment->i_data, 1, f ) != 1 )
msg_Err( p_input, "%s: %s", psz_filename, strerror( errno ) );
msg_Err( p_input, "%s: %m", psz_filename );
else
msg_Dbg( p_input, "album art saved to %s\n", psz_filename );
fclose( f );
......
......@@ -330,7 +330,6 @@ int __vlc_mutex_destroy( const char * psz_file, int i_line, vlc_mutex_t *p_mutex
int i_result;
/* In case of error : */
int i_thread = -1;
const char * psz_error = "";
#if defined( PTH_INIT_IN_PTH_H )
return 0;
......@@ -367,7 +366,7 @@ int __vlc_mutex_destroy( const char * psz_file, int i_line, vlc_mutex_t *p_mutex
if( i_result )
{
i_thread = CAST_PTHREAD_TO_INT(pthread_self());
psz_error = strerror(i_result);
errno = i_result;
}
#elif defined( HAVE_CTHREADS_H )
......@@ -378,8 +377,8 @@ int __vlc_mutex_destroy( const char * psz_file, int i_line, vlc_mutex_t *p_mutex
if( i_result )
{
msg_Err( p_mutex->p_this,
"thread %d: mutex_destroy failed at %s:%d (%d:%s)",
i_thread, psz_file, i_line, i_result, psz_error );
"thread %d: mutex_destroy failed at %s:%d (%d:%m)",
i_thread, psz_file, i_line, i_result );
}
return i_result;
}
......@@ -500,7 +499,6 @@ int __vlc_cond_destroy( const char * psz_file, int i_line, vlc_cond_t *p_condvar
int i_result;
/* In case of error : */
int i_thread = -1;
const char * psz_error = "";
#if defined( PTH_INIT_IN_PTH_H )
return 0;
......@@ -530,7 +528,7 @@ int __vlc_cond_destroy( const char * psz_file, int i_line, vlc_cond_t *p_condvar
if( i_result )
{
i_thread = CAST_PTHREAD_TO_INT(pthread_self());
psz_error = strerror(i_result);
errno = i_result;
}
#elif defined( HAVE_CTHREADS_H )
......@@ -541,8 +539,8 @@ int __vlc_cond_destroy( const char * psz_file, int i_line, vlc_cond_t *p_condvar
if( i_result )
{
msg_Err( p_condvar->p_this,
"thread %d: cond_destroy failed at %s:%d (%d:%s)",
i_thread, psz_file, i_line, i_result, psz_error );
"thread %d: cond_destroy failed at %s:%d (%d:%m)",
i_thread, psz_file, i_line, i_result );
}
return i_result;
}
......@@ -665,8 +663,9 @@ int __vlc_thread_create( vlc_object_t *p_this, const char * psz_file, int i_line
if( (i_error = pthread_setschedparam( p_priv->thread_id,
i_policy, &param )) )
{
msg_Warn( p_this, "couldn't set thread priority (%s:%d): %s",
psz_file, i_line, strerror(i_error) );
errno = i_error;
msg_Warn( p_this, "couldn't set thread priority (%s:%d): %m",
psz_file, i_line );
i_priority = 0;
}
}
......@@ -708,8 +707,9 @@ int __vlc_thread_create( vlc_object_t *p_this, const char * psz_file, int i_line
}
else
{
msg_Err( p_this, "%s thread could not be created at %s:%d (%s)",
psz_name, psz_file, i_line, strerror(i_ret) );
errno = i_ret;
msg_Err( p_this, "%s thread could not be created at %s:%d (%m)",
psz_name, psz_file, i_line );
vlc_mutex_unlock( &p_this->object_lock );
}
......@@ -762,8 +762,9 @@ int __vlc_thread_set_priority( vlc_object_t *p_this, const char * psz_file,
if( (i_error = pthread_setschedparam( p_priv->thread_id,
i_policy, &param )) )
{
msg_Warn( p_this, "couldn't set thread priority (%s:%d): %s",
psz_file, i_line, strerror(i_error) );
errno = i_error;
msg_Warn( p_this, "couldn't set thread priority (%s:%d): %m",
psz_file, i_line );
i_priority = 0;
}
}
......@@ -881,9 +882,9 @@ void __vlc_thread_join( vlc_object_t *p_this, const char * psz_file, int i_line
if( i_ret )
{
msg_Err( p_this, "thread_join(%u) failed at %s:%d (%s)",
(unsigned int)p_priv->thread_id, psz_file, i_line,
strerror(i_ret) );
errno = i_ret;
msg_Err( p_this, "thread_join(%u) failed at %s:%d (%m)",
(unsigned int)p_priv->thread_id, psz_file, i_line );
}
else
{
......
......@@ -317,8 +317,7 @@ int ACL_LoadFile( vlc_acl_t *p_acl, const char *psz_path )
{
if( ferror( file ) )
{
msg_Err( p_acl->p_owner, "error reading %s : %s\n", psz_path,
strerror( errno ) );
msg_Err( p_acl->p_owner, "error reading %s : %m", psz_path );
goto error;
}
continue;
......@@ -337,7 +336,7 @@ int ACL_LoadFile( vlc_acl_t *p_acl, const char *psz_path )
ptr = strchr( psz_ip, '\n' );
if( ptr == NULL )
{
msg_Warn( p_acl->p_owner, "skipping overly long line in %s\n",
msg_Warn( p_acl->p_owner, "skipping overly long line in %s",
psz_path);
do
{
......@@ -345,8 +344,8 @@ int ACL_LoadFile( vlc_acl_t *p_acl, const char *psz_path )
{
if( ferror( file ) )
{
msg_Err( p_acl->p_owner, "error reading %s : %s\n",
psz_path, strerror( errno ) );
msg_Err( p_acl->p_owner, "error reading %s : %m",
psz_path );
}
goto error;
}
......
......@@ -2362,7 +2362,7 @@ static void httpd_HostThread( httpd_host_t *host )
if (errno != EINTR)
{
/* This is most likely a bug */
msg_Err( host, "polling error: %s", strerror (errno));
msg_Err( host, "polling error: %m" );
msleep( 1000 );
}
case 0:
......
......@@ -88,8 +88,7 @@ int net_Socket (vlc_object_t *p_this, int family, int socktype,
if (fd == -1)
{
if (net_errno != EAFNOSUPPORT)
msg_Err (p_this, "cannot create socket: %s",
net_strerror (net_errno));
msg_Err (p_this, "cannot create socket: %m");
return -1;
}
......@@ -148,7 +147,7 @@ int *net_Listen (vlc_object_t *p_this, const char *psz_host,
protocol ?: ptr->ai_protocol);
if (fd == -1)
{
msg_Dbg (p_this, "socket error: %s", net_strerror (net_errno));
msg_Dbg (p_this, "socket error: %m");
continue;
}
......@@ -176,8 +175,6 @@ int *net_Listen (vlc_object_t *p_this, const char *psz_host,
#endif
if (bind (fd, ptr->ai_addr, ptr->ai_addrlen))
{
int saved_errno = net_errno;
net_Close (fd);
#if !defined(WIN32) && !defined(UNDER_CE)
fd = rootwrap_bind (ptr->ai_family, ptr->ai_socktype,
......@@ -190,8 +187,7 @@ int *net_Listen (vlc_object_t *p_this, const char *psz_host,
else
#endif
{
msg_Err (p_this, "socket bind error (%s)",
net_strerror( saved_errno ) );
msg_Err (p_this, "socket bind error (%m)");
continue;
}
}
......@@ -216,8 +212,7 @@ int *net_Listen (vlc_object_t *p_this, const char *psz_host,
#endif
if (listen (fd, INT_MAX))
{
msg_Err (p_this, "socket listen error (%s)",
net_strerror (net_errno));
msg_Err (p_this, "socket listen error (%m)");
net_Close (fd);
continue;
}
......@@ -362,7 +357,7 @@ net_ReadInner (vlc_object_t *restrict p_this, unsigned fdc, const int *fdv,
return i_total;
error:
msg_Err (p_this, "Read error: %s", net_strerror (net_errno));
msg_Err (p_this, "Read error: %m");
return i_total ? (ssize_t)i_total : -1;
}
......@@ -421,7 +416,7 @@ ssize_t __net_Write( vlc_object_t *p_this, int fd, const v_socket_t *p_vs,
switch (val)
{
case -1:
msg_Err (p_this, "Write error: %s", net_strerror (net_errno));
msg_Err (p_this, "Write error: %m");
goto out;
case 0:
......@@ -442,7 +437,7 @@ ssize_t __net_Write( vlc_object_t *p_this, int fd, const v_socket_t *p_vs,
if (val == -1)
{
msg_Err (p_this, "Write error: %s", net_strerror (net_errno));
msg_Err (p_this, "Write error: %m");
break;
}
......
......@@ -147,7 +147,7 @@ int __net_Connect( vlc_object_t *p_this, const char *psz_host, int i_port,
proto ?: ptr->ai_protocol );
if( fd == -1 )
{
msg_Dbg( p_this, "socket error: %s", strerror( net_errno ) );
msg_Dbg( p_this, "socket error: %m" );
continue;
}
......@@ -159,8 +159,7 @@ int __net_Connect( vlc_object_t *p_this, const char *psz_host, int i_port,
if( net_errno != EINPROGRESS )
{
msg_Err( p_this, "connection failed: %s",
strerror( net_errno ) );
msg_Err( p_this, "connection failed: %m" );
goto next_ai;
}
......@@ -199,8 +198,7 @@ int __net_Connect( vlc_object_t *p_this, const char *psz_host, int i_port,
if( ( i_ret == -1 ) && ( net_errno != EINTR ) )
{
msg_Err( p_this, "connection polling error: %s",
strerror( net_errno ) );
msg_Err( p_this, "connection polling error: %m" );
goto next_ai;
}
......@@ -217,8 +215,7 @@ int __net_Connect( vlc_object_t *p_this, const char *psz_host, int i_port,
if( getsockopt( fd, SOL_SOCKET, SO_ERROR, (void*)&i_val,
&i_val_size ) == -1 || i_val != 0 )
{
msg_Err( p_this, "connection failed: %s",
net_strerror( i_val ) );
msg_Err( p_this, "connection failed: %m" );
goto next_ai;
}
#endif
......@@ -288,8 +285,7 @@ int __net_Accept( vlc_object_t *p_this, int pi_fd[], mtime_t i_wait )
case -1:
if (net_errno != EINTR)
{
msg_Err (p_this, "poll error: %s",
net_strerror (net_errno));
msg_Err (p_this, "poll error: %m");
}
return -1;
......@@ -308,8 +304,7 @@ int __net_Accept( vlc_object_t *p_this, int pi_fd[], mtime_t i_wait )
int fd = accept (sfd, NULL, NULL);
if (fd == -1)
{
msg_Err (p_this, "accept failed (%s)",
net_strerror (net_errno));
msg_Err (p_this, "accept failed (%m)");
continue;
}
net_SetupSocket (fd);
......
......@@ -124,7 +124,7 @@ static int net_ListenSingle (vlc_object_t *obj, const char *host, int port,
protocol ?: ptr->ai_protocol);
if (fd == -1)
{
msg_Dbg (obj, "socket error: %s", net_strerror (net_errno));
msg_Dbg (obj, "socket error: %m");
continue;
}
......@@ -157,7 +157,7 @@ static int net_ListenSingle (vlc_object_t *obj, const char *host, int port,
#endif
if (bind (fd, ptr->ai_addr, ptr->ai_addrlen))
{
msg_Err (obj, "socket bind error (%s)", net_strerror (net_errno));
msg_Err (obj, "socket bind error (%m)");
net_Close (fd);
continue;
}
......@@ -204,7 +204,8 @@ static int net_SetMcastHopLimit( vlc_object_t *p_this,
#endif
default:
msg_Warn( p_this, "%s", strerror( EAFNOSUPPORT ) );
errno = EAFNOSUPPORT;
msg_Warn( p_this, "%m" );
return VLC_EGENERIC;
}
......@@ -274,7 +275,7 @@ static int net_SetMcastOut (vlc_object_t *p_this, int fd, int family,
if (net_SetMcastOutIface (fd, family, scope) == 0)
return 0;
msg_Err (p_this, "%s: %s", iface, net_strerror (net_errno));
msg_Err (p_this, "%s: %m", iface);
}
if (addr != NULL)
......@@ -292,7 +293,7 @@ static int net_SetMcastOut (vlc_object_t *p_this, int fd, int family,
if (net_SetMcastOutIPv4 (fd, ipv4) == 0)
return 0;
msg_Err (p_this, "%s: %s", addr, net_strerror (net_errno));
msg_Err (p_this, "%s: %m", addr);
}
}
......@@ -362,8 +363,7 @@ net_IPv4Join (vlc_object_t *obj, int fd,
error:
#endif
msg_Err (obj, "cannot join IPv4 multicast group (%s)",
net_strerror (net_errno));
msg_Err (obj, "cannot join IPv4 multicast group (%m)");
return -1;
}
......@@ -385,8 +385,7 @@ net_IPv6Join (vlc_object_t *obj, int fd, const struct sockaddr_in6 *src)
errno = ENOSYS;
#endif
msg_Err (obj, "cannot join IPv6 any-source multicast group (%s)",
net_strerror (net_errno));
msg_Err (obj, "cannot join IPv6 any-source multicast group (%m)");
return -1;
}
......@@ -549,8 +548,7 @@ net_SourceSubscribe (vlc_object_t *obj, int fd,
#endif
}
msg_Err (obj, "Multicast group join error (%s)",
net_strerror (net_errno));
msg_Err (obj, "Multicast group join error (%m)");
if (src != NULL)
{
......@@ -687,8 +685,7 @@ int __net_ConnectDgram( vlc_object_t *p_this, const char *psz_host, int i_port,
b_unreach = VLC_TRUE;
else
{
msg_Warn( p_this, "%s port %d : %s", psz_host, i_port,
strerror( errno ) );
msg_Warn( p_this, "%s port %d : %m", psz_host, i_port);
net_Close( fd );
continue;
}
......@@ -803,8 +800,8 @@ int __net_OpenDgram( vlc_object_t *obj, const char *psz_bind, int i_bind,
ptr->ai_addr, ptr->ai_addrlen)
: connect (fd, ptr2->ai_addr, ptr2->ai_addrlen))
{
msg_Err (obj, "cannot connect to %s port %d: %s",
psz_server, i_server, net_strerror (net_errno));
msg_Err (obj, "cannot connect to %s port %d: %m",
psz_server, i_server);
continue;
}
val = fd;
......
......@@ -30,7 +30,7 @@
#include <stdlib.h> /* free() */
#include <stdio.h> /* sprintf() */
#include <string.h> /* strerror() */
#include <string.h>
#include <ctype.h> /* tolower(), isxdigit() */
#include <vlc_sout.h>
......
......@@ -31,7 +31,7 @@
#include <stdlib.h> /* free() */
#include <stdio.h> /* sprintf() */
#include <string.h> /* strerror() */
#include <string.h>
#include <vlc_sout.h>
#include <vlc_playlist.h>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment