Commit ea919d9d authored by Alexandre Julliard's avatar Alexandre Julliard

server: Use strerror instead of perror.

parent 7f5a3a4d
......@@ -1737,7 +1737,7 @@ void init_registry(void)
/* switch to the config dir */
if (fchdir( config_dir_fd ) == -1) fatal_perror( "chdir to config dir" );
if (fchdir( config_dir_fd ) == -1) fatal_error( "chdir to config dir: %s\n", strerror( errno ));
/* create the root key */
root_key = alloc_key( &root_name, current_time );
......@@ -1790,7 +1790,7 @@ void init_registry(void)
set_periodic_save_timer();
/* go back to the server dir */
if (fchdir( server_dir_fd ) == -1) fatal_perror( "chdir to server dir" );
if (fchdir( server_dir_fd ) == -1) fatal_error( "chdir to server dir: %s\n", strerror( errno ));
}
/* save a registry branch to a file */
......@@ -1922,7 +1922,7 @@ static void periodic_save( void *arg )
save_timeout_user = NULL;
for (i = 0; i < save_branch_count; i++)
save_branch( save_branch_info[i].key, save_branch_info[i].path );
if (fchdir( server_dir_fd ) == -1) fatal_perror( "chdir to server dir" );
if (fchdir( server_dir_fd ) == -1) fatal_error( "chdir to server dir: %s\n", strerror( errno ));
set_periodic_save_timer();
}
......@@ -1948,7 +1948,7 @@ void flush_registry(void)
perror( " " );
}
}
if (fchdir( server_dir_fd ) == -1) fatal_perror( "chdir to server dir" );
if (fchdir( server_dir_fd ) == -1) fatal_error( "chdir to server dir: %s\n", strerror( errno ));
}
/* determine if the thread is wow64 (32-bit client running on 64-bit prefix) */
......
......@@ -142,20 +142,6 @@ void fatal_protocol_error( struct thread *thread, const char *err, ... )
kill_thread( thread, 1 );
}
/* complain about a protocol error and terminate the client connection */
void fatal_protocol_perror( struct thread *thread, const char *err, ... )
{
va_list args;
va_start( args, err );
fprintf( stderr, "Protocol error:%04x: ", thread->id );
vfprintf( stderr, err, args );
perror( " " );
va_end( args );
thread->exit_code = 1;
kill_thread( thread, 1 );
}
/* die on a fatal error */
void fatal_error( const char *err, ... )
{
......@@ -168,19 +154,6 @@ void fatal_error( const char *err, ... )
exit(1);
}
/* die on a fatal error */
void fatal_perror( const char *err, ... )
{
va_list args;
va_start( args, err );
fprintf( stderr, "wineserver: " );
vfprintf( stderr, err, args );
perror( " " );
va_end( args );
exit(1);
}
/* allocate the reply data */
void *set_reply_data_size( data_size_t size )
{
......@@ -212,7 +185,7 @@ void write_reply( struct thread *thread )
if (errno == EPIPE)
kill_thread( thread, 0 ); /* normal death */
else if (errno != EWOULDBLOCK && errno != EAGAIN)
fatal_protocol_perror( thread, "reply write" );
fatal_protocol_error( thread, "reply write: %s\n", strerror( errno ));
}
/* send a reply to the current thread */
......@@ -254,7 +227,7 @@ static void send_reply( union generic_reply *reply )
else if (errno == EPIPE)
kill_thread( current, 0 ); /* normal death */
else
fatal_protocol_perror( current, "reply write" );
fatal_protocol_error( current, "reply write: %s\n", strerror( errno ));
}
/* call a request handler */
......@@ -339,7 +312,7 @@ error:
else if (ret > 0)
fatal_protocol_error( thread, "partial read %d\n", ret );
else if (errno != EWOULDBLOCK && errno != EAGAIN)
fatal_protocol_perror( thread, "read" );
fatal_protocol_error( thread, "read: %s\n", strerror( errno ));
}
/* receive a file descriptor on the process socket */
......@@ -557,9 +530,12 @@ static void create_dir( const char *name, struct stat *st )
{
if (lstat( name, st ) == -1)
{
if (errno != ENOENT) fatal_perror( "lstat %s", name );
if (mkdir( name, 0700 ) == -1 && errno != EEXIST) fatal_perror( "mkdir %s", name );
if (lstat( name, st ) == -1) fatal_perror( "lstat %s", name );
if (errno != ENOENT)
fatal_error( "lstat %s: %s", name, strerror( errno ));
if (mkdir( name, 0700 ) == -1 && errno != EEXIST)
fatal_error( "mkdir %s: %s\n", name, strerror( errno ));
if (lstat( name, st ) == -1)
fatal_error( "lstat %s: %s\n", name, strerror( errno ));
}
if (!S_ISDIR(st->st_mode)) fatal_error( "%s is not a directory\n", name );
if (st->st_uid != getuid()) fatal_error( "%s is not owned by you\n", name );
......@@ -585,9 +561,12 @@ static void create_server_dir( const char *dir )
*p = '/';
create_dir( server_dir, &st );
if (chdir( server_dir ) == -1) fatal_perror( "chdir %s", server_dir );
if ((server_dir_fd = open( ".", O_RDONLY )) == -1) fatal_perror( "open %s", server_dir );
if (fstat( server_dir_fd, &st2 ) == -1) fatal_perror( "stat %s", server_dir );
if (chdir( server_dir ) == -1)
fatal_error( "chdir %s: %s\n", server_dir, strerror( errno ));
if ((server_dir_fd = open( ".", O_RDONLY )) == -1)
fatal_error( "open %s: %s\n", server_dir, strerror( errno ));
if (fstat( server_dir_fd, &st2 ) == -1)
fatal_error( "stat %s: %s\n", server_dir, strerror( errno ));
if (st.st_dev != st2.st_dev || st.st_ino != st2.st_ino)
fatal_error( "chdir did not end up in %s\n", server_dir );
......@@ -603,7 +582,7 @@ static int create_server_lock(void)
if (lstat( server_lock_name, &st ) == -1)
{
if (errno != ENOENT)
fatal_perror( "lstat %s/%s", wine_get_server_dir(), server_lock_name );
fatal_error( "lstat %s/%s: %s", wine_get_server_dir(), server_lock_name, strerror( errno ));
}
else
{
......@@ -612,7 +591,7 @@ static int create_server_lock(void)
}
if ((fd = open( server_lock_name, O_CREAT|O_TRUNC|O_WRONLY, 0600 )) == -1)
fatal_perror( "error creating %s/%s", wine_get_server_dir(), server_lock_name );
fatal_error( "error creating %s/%s: %s", wine_get_server_dir(), server_lock_name, strerror( errno ));
return fd;
}
......@@ -729,13 +708,13 @@ static void acquire_lock(void)
case EAGAIN:
exit(2); /* we didn't get the lock, exit with special status */
default:
fatal_perror( "fcntl %s/%s", wine_get_server_dir(), server_lock_name );
fatal_error( "fcntl %s/%s: %s", wine_get_server_dir(), server_lock_name, strerror( errno ));
}
/* it seems we can't use locks on this fs, so we will use the socket existence as lock */
close( fd );
}
if ((fd = socket( AF_UNIX, SOCK_STREAM, 0 )) == -1) fatal_perror( "socket" );
if ((fd = socket( AF_UNIX, SOCK_STREAM, 0 )) == -1) fatal_error( "socket: %s\n", strerror( errno ));
addr.sun_family = AF_UNIX;
strcpy( addr.sun_path, server_socket_name );
slen = sizeof(addr) - sizeof(addr.sun_path) + strlen(addr.sun_path) + 1;
......@@ -750,11 +729,11 @@ static void acquire_lock(void)
fatal_error( "couldn't bind to the socket even though we hold the lock\n" );
exit(2); /* we didn't get the lock, exit with special status */
}
fatal_perror( "bind" );
fatal_error( "bind: %s\n", strerror( errno ));
}
atexit( socket_cleanup );
chmod( server_socket_name, 0600 ); /* make sure no other user can connect */
if (listen( fd, 5 ) == -1) fatal_perror( "listen" );
if (listen( fd, 5 ) == -1) fatal_error( "listen: %s\n", strerror( errno ));
if (!(master_socket = alloc_object( &master_socket_ops )) ||
!(master_socket->fd = create_anonymous_fd( &master_socket_fd_ops, fd, &master_socket->obj, 0 )))
......@@ -779,15 +758,18 @@ void open_master_socket(void)
fd = open( "/dev/null", O_RDWR );
while (fd >= 0 && fd <= 2) fd = dup( fd );
if (!server_dir) fatal_error( "directory %s cannot be accessed\n", config_dir );
if (chdir( config_dir ) == -1) fatal_perror( "chdir to %s", config_dir );
if ((config_dir_fd = open( ".", O_RDONLY )) == -1) fatal_perror( "open %s", config_dir );
if (!server_dir)
fatal_error( "directory %s cannot be accessed\n", config_dir );
if (chdir( config_dir ) == -1)
fatal_error( "chdir to %s: %s\n", config_dir, strerror( errno ));
if ((config_dir_fd = open( ".", O_RDONLY )) == -1)
fatal_error( "open %s: %s\n", config_dir, strerror( errno ));
create_server_dir( server_dir );
if (!foreground)
{
if (pipe( sync_pipe ) == -1) fatal_perror( "pipe" );
if (pipe( sync_pipe ) == -1) fatal_error( "pipe: %s\n", strerror( errno ));
pid = fork();
switch( pid )
{
......@@ -808,7 +790,7 @@ void open_master_socket(void)
break;
case -1:
fatal_perror( "fork" );
fatal_error( "fork: %s\n", strerror( errno ));
break;
default: /* parent */
......
......@@ -38,15 +38,10 @@
#ifdef __GNUC__
extern void fatal_protocol_error( struct thread *thread,
const char *err, ... ) __attribute__((format (printf,2,3)));
extern void fatal_protocol_perror( struct thread *thread,
const char *err, ... ) __attribute__((format (printf,2,3)));
extern void fatal_error( const char *err, ... ) __attribute__((noreturn,format(printf,1,2)));
extern void fatal_perror( const char *err, ... ) __attribute__((noreturn,format(printf,1,2)));
#else
extern void fatal_protocol_error( struct thread *thread, const char *err, ... );
extern void fatal_protocol_perror( struct thread *thread, const char *err, ... );
extern void fatal_error( const char *err, ... );
extern void fatal_perror( const char *err, ... );
#endif
extern const char *get_config_dir(void);
......
......@@ -652,7 +652,7 @@ static int send_thread_wakeup( struct thread *thread, client_ptr_t cookie, int s
else if (errno == EPIPE)
kill_thread( thread, 0 ); /* normal death */
else
fatal_protocol_perror( thread, "write" );
fatal_protocol_error( thread, "write: %s\n", strerror( errno ));
return -1;
}
......
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