2002-06-21 01:21:27 +02:00
|
|
|
/*
|
|
|
|
* Configuration parameters shared between Wine server and clients
|
|
|
|
*
|
|
|
|
* Copyright 2002 Alexandre Julliard
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2002-06-21 01:21:27 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "wine/port.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2003-10-08 02:36:09 +02:00
|
|
|
#include <errno.h>
|
2002-06-21 01:21:27 +02:00
|
|
|
#include <sys/stat.h>
|
2002-08-29 01:42:34 +02:00
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
# include <unistd.h>
|
|
|
|
#endif
|
2002-06-25 01:00:25 +02:00
|
|
|
#ifdef HAVE_PWD_H
|
|
|
|
#include <pwd.h>
|
|
|
|
#endif
|
2004-05-11 06:29:18 +02:00
|
|
|
#include "wine/library.h"
|
2002-06-25 01:00:25 +02:00
|
|
|
|
2004-05-11 06:29:18 +02:00
|
|
|
static const char server_config_dir[] = "/.wine"; /* config dir relative to $HOME */
|
2013-09-16 12:43:07 +02:00
|
|
|
static const char server_root_prefix[] = "/tmp/.wine"; /* prefix for server root dir */
|
2004-05-11 06:29:18 +02:00
|
|
|
static const char server_dir_prefix[] = "/server-"; /* prefix for server dir */
|
2002-06-21 01:21:27 +02:00
|
|
|
|
2006-02-17 14:08:19 +01:00
|
|
|
static char *bindir;
|
|
|
|
static char *dlldir;
|
2006-03-06 18:50:15 +01:00
|
|
|
static char *datadir;
|
2002-06-21 01:21:27 +02:00
|
|
|
static char *config_dir;
|
|
|
|
static char *server_dir;
|
2006-03-16 17:35:14 +01:00
|
|
|
static char *build_dir;
|
2002-08-27 20:30:53 +02:00
|
|
|
static char *user_name;
|
2003-11-11 23:21:29 +01:00
|
|
|
static char *argv0_name;
|
2002-06-21 01:21:27 +02:00
|
|
|
|
|
|
|
#ifdef __GNUC__
|
|
|
|
static void fatal_error( const char *err, ... ) __attribute__((noreturn,format(printf,1,2)));
|
|
|
|
static void fatal_perror( const char *err, ... ) __attribute__((noreturn,format(printf,1,2)));
|
|
|
|
#endif
|
|
|
|
|
2012-06-04 22:14:14 +02:00
|
|
|
#if defined(__linux__) || defined(__FreeBSD_kernel__ )
|
2012-06-03 12:26:30 +02:00
|
|
|
#define EXE_LINK "/proc/self/exe"
|
2012-06-04 22:14:14 +02:00
|
|
|
#elif defined (__FreeBSD__) || defined(__DragonFly__)
|
2012-06-03 12:26:30 +02:00
|
|
|
#define EXE_LINK "/proc/curproc/file"
|
|
|
|
#endif
|
|
|
|
|
2002-06-21 01:21:27 +02:00
|
|
|
/* die on a fatal error */
|
|
|
|
static void fatal_error( const char *err, ... )
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
va_start( args, err );
|
|
|
|
fprintf( stderr, "wine: " );
|
|
|
|
vfprintf( stderr, err, args );
|
|
|
|
va_end( args );
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* die on a fatal error */
|
|
|
|
static void fatal_perror( const char *err, ... )
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
va_start( args, err );
|
|
|
|
fprintf( stderr, "wine: " );
|
|
|
|
vfprintf( stderr, err, args );
|
|
|
|
perror( " " );
|
|
|
|
va_end( args );
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* malloc wrapper */
|
|
|
|
static void *xmalloc( size_t size )
|
|
|
|
{
|
|
|
|
void *res;
|
|
|
|
|
|
|
|
if (!size) size = 1;
|
|
|
|
if (!(res = malloc( size ))) fatal_error( "virtual memory exhausted\n");
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2002-08-27 20:30:53 +02:00
|
|
|
/* strdup wrapper */
|
|
|
|
static char *xstrdup( const char *str )
|
|
|
|
{
|
|
|
|
size_t len = strlen(str) + 1;
|
|
|
|
char *res = xmalloc( len );
|
|
|
|
memcpy( res, str, len );
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2010-12-16 17:59:30 +01:00
|
|
|
/* check if a string ends in a given substring */
|
|
|
|
static inline int strendswith( const char* str, const char* end )
|
|
|
|
{
|
|
|
|
size_t len = strlen( str );
|
|
|
|
size_t tail = strlen( end );
|
|
|
|
return len >= tail && !strcmp( str + len - tail, end );
|
|
|
|
}
|
|
|
|
|
2002-06-21 01:21:27 +02:00
|
|
|
/* remove all trailing slashes from a path name */
|
2007-03-26 21:26:29 +02:00
|
|
|
static inline void remove_trailing_slashes( char *path )
|
2002-06-21 01:21:27 +02:00
|
|
|
{
|
|
|
|
int len = strlen( path );
|
|
|
|
while (len > 1 && path[len-1] == '/') path[--len] = 0;
|
|
|
|
}
|
|
|
|
|
2006-02-17 14:08:19 +01:00
|
|
|
/* build a path from the specified dir and name */
|
|
|
|
static char *build_path( const char *dir, const char *name )
|
|
|
|
{
|
|
|
|
size_t len = strlen(dir);
|
|
|
|
char *ret = xmalloc( len + strlen(name) + 2 );
|
|
|
|
|
|
|
|
memcpy( ret, dir, len );
|
|
|
|
if (len && ret[len-1] != '/') ret[len++] = '/';
|
|
|
|
strcpy( ret + len, name );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2006-02-11 22:38:44 +01:00
|
|
|
/* return the directory that contains the library at run-time */
|
2006-04-07 07:20:49 +02:00
|
|
|
static char *get_runtime_libdir(void)
|
2006-02-11 22:38:44 +01:00
|
|
|
{
|
|
|
|
#ifdef HAVE_DLADDR
|
|
|
|
Dl_info info;
|
2006-02-17 14:08:19 +01:00
|
|
|
char *libdir;
|
2006-02-11 22:38:44 +01:00
|
|
|
|
2006-02-17 14:08:19 +01:00
|
|
|
if (dladdr( get_runtime_libdir, &info ) && info.dli_fname[0] == '/')
|
2006-02-11 22:38:44 +01:00
|
|
|
{
|
2006-02-16 20:03:06 +01:00
|
|
|
const char *p = strrchr( info.dli_fname, '/' );
|
2006-02-11 22:38:44 +01:00
|
|
|
unsigned int len = p - info.dli_fname;
|
|
|
|
if (!len) len++; /* include initial slash */
|
|
|
|
libdir = xmalloc( len + 1 );
|
|
|
|
memcpy( libdir, info.dli_fname, len );
|
|
|
|
libdir[len] = 0;
|
2006-02-17 14:08:19 +01:00
|
|
|
return libdir;
|
2006-02-11 22:38:44 +01:00
|
|
|
}
|
|
|
|
#endif /* HAVE_DLADDR */
|
2006-02-17 14:08:19 +01:00
|
|
|
return NULL;
|
2006-02-11 22:38:44 +01:00
|
|
|
}
|
|
|
|
|
2009-08-25 12:47:50 +02:00
|
|
|
/* return the directory that contains the main exe at run-time */
|
2013-09-16 12:34:44 +02:00
|
|
|
static char *get_runtime_exedir(void)
|
2009-08-25 12:47:50 +02:00
|
|
|
{
|
2012-06-03 12:26:30 +02:00
|
|
|
#ifdef EXE_LINK
|
2013-09-16 12:34:44 +02:00
|
|
|
char *p, *bindir;
|
|
|
|
int size;
|
|
|
|
|
2009-08-25 12:47:50 +02:00
|
|
|
for (size = 256; ; size *= 2)
|
|
|
|
{
|
|
|
|
int ret;
|
2013-09-16 12:34:44 +02:00
|
|
|
if (!(bindir = malloc( size ))) return NULL;
|
2012-06-03 12:26:30 +02:00
|
|
|
if ((ret = readlink( EXE_LINK, bindir, size )) == -1) break;
|
2009-08-25 12:47:50 +02:00
|
|
|
if (ret != size)
|
|
|
|
{
|
2012-06-06 12:39:33 +02:00
|
|
|
bindir[ret] = 0;
|
|
|
|
if (!(p = strrchr( bindir, '/' ))) break;
|
2009-08-25 12:47:50 +02:00
|
|
|
if (p == bindir) p++;
|
|
|
|
*p = 0;
|
|
|
|
return bindir;
|
|
|
|
}
|
|
|
|
free( bindir );
|
|
|
|
}
|
|
|
|
free( bindir );
|
|
|
|
#endif
|
2013-09-16 12:34:44 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* return the base directory from argv0 */
|
|
|
|
static char *get_runtime_argvdir( const char *argv0 )
|
|
|
|
{
|
|
|
|
char *p, *bindir, *cwd;
|
|
|
|
int len, size;
|
2009-08-25 12:47:50 +02:00
|
|
|
|
|
|
|
if (!(p = strrchr( argv0, '/' ))) return NULL;
|
|
|
|
|
|
|
|
len = p - argv0;
|
|
|
|
if (!len) len++; /* include leading slash */
|
|
|
|
|
|
|
|
if (argv0[0] == '/') /* absolute path */
|
|
|
|
{
|
|
|
|
bindir = xmalloc( len + 1 );
|
|
|
|
memcpy( bindir, argv0, len );
|
|
|
|
bindir[len] = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* relative path, make it absolute */
|
|
|
|
for (size = 256 + len; ; size *= 2)
|
|
|
|
{
|
|
|
|
if (!(cwd = malloc( size ))) return NULL;
|
|
|
|
if (getcwd( cwd, size - len ))
|
|
|
|
{
|
|
|
|
bindir = cwd;
|
|
|
|
cwd += strlen(cwd);
|
|
|
|
*cwd++ = '/';
|
|
|
|
memcpy( cwd, argv0, len );
|
|
|
|
cwd[len] = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
free( cwd );
|
|
|
|
if (errno != ERANGE) return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return bindir;
|
|
|
|
}
|
|
|
|
|
2004-05-11 06:29:18 +02:00
|
|
|
/* initialize the server directory value */
|
|
|
|
static void init_server_dir( dev_t dev, ino_t ino )
|
|
|
|
{
|
2013-09-16 12:43:07 +02:00
|
|
|
char *p, *root;
|
|
|
|
|
2013-09-16 12:44:15 +02:00
|
|
|
#ifdef __ANDROID__ /* there's no /tmp dir on Android */
|
|
|
|
root = build_path( config_dir, ".wineserver" );
|
|
|
|
#elif defined(HAVE_GETUID)
|
2013-09-16 12:43:07 +02:00
|
|
|
root = xmalloc( sizeof(server_root_prefix) + 12 );
|
|
|
|
sprintf( root, "%s-%u", server_root_prefix, getuid() );
|
2004-10-04 22:45:49 +02:00
|
|
|
#else
|
2013-09-16 12:43:07 +02:00
|
|
|
root = xstrdup( server_root_prefix );
|
2004-10-04 22:45:49 +02:00
|
|
|
#endif
|
2004-05-11 06:29:18 +02:00
|
|
|
|
2013-09-16 12:43:07 +02:00
|
|
|
server_dir = xmalloc( strlen(root) + sizeof(server_dir_prefix) + 2*sizeof(dev) + 2*sizeof(ino) + 2 );
|
|
|
|
strcpy( server_dir, root );
|
|
|
|
strcat( server_dir, server_dir_prefix );
|
2004-09-27 22:50:37 +02:00
|
|
|
p = server_dir + strlen(server_dir);
|
2004-05-11 06:29:18 +02:00
|
|
|
|
2012-01-17 15:00:25 +01:00
|
|
|
if (dev != (unsigned long)dev)
|
2006-06-15 14:14:26 +02:00
|
|
|
p += sprintf( p, "%lx%08lx-", (unsigned long)((unsigned long long)dev >> 32), (unsigned long)dev );
|
2004-05-11 06:29:18 +02:00
|
|
|
else
|
2004-12-20 19:55:18 +01:00
|
|
|
p += sprintf( p, "%lx-", (unsigned long)dev );
|
2004-05-11 06:29:18 +02:00
|
|
|
|
2012-01-17 15:00:25 +01:00
|
|
|
if (ino != (unsigned long)ino)
|
2006-06-15 14:14:26 +02:00
|
|
|
sprintf( p, "%lx%08lx", (unsigned long)((unsigned long long)ino >> 32), (unsigned long)ino );
|
2004-05-11 06:29:18 +02:00
|
|
|
else
|
|
|
|
sprintf( p, "%lx", (unsigned long)ino );
|
2013-09-16 12:43:07 +02:00
|
|
|
free( root );
|
2004-05-11 06:29:18 +02:00
|
|
|
}
|
|
|
|
|
2006-02-11 22:38:44 +01:00
|
|
|
/* retrieve the default dll dir */
|
2015-11-09 03:37:51 +01:00
|
|
|
const char *get_dlldir( const char **default_dlldir )
|
2006-02-11 22:38:44 +01:00
|
|
|
{
|
2006-02-17 17:39:44 +01:00
|
|
|
*default_dlldir = DLLDIR;
|
|
|
|
return dlldir;
|
2006-02-11 22:38:44 +01:00
|
|
|
}
|
|
|
|
|
2002-06-21 01:21:27 +02:00
|
|
|
/* initialize all the paths values */
|
|
|
|
static void init_paths(void)
|
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
|
|
|
|
const char *home = getenv( "HOME" );
|
|
|
|
const char *user = NULL;
|
|
|
|
const char *prefix = getenv( "WINEPREFIX" );
|
2002-07-01 20:17:30 +02:00
|
|
|
|
|
|
|
#ifdef HAVE_GETPWUID
|
|
|
|
char uid_str[32];
|
2002-06-21 01:21:27 +02:00
|
|
|
struct passwd *pwd = getpwuid( getuid() );
|
|
|
|
|
|
|
|
if (pwd)
|
|
|
|
{
|
|
|
|
user = pwd->pw_name;
|
|
|
|
if (!home) home = pwd->pw_dir;
|
|
|
|
}
|
|
|
|
if (!user)
|
|
|
|
{
|
2006-09-12 11:01:57 +02:00
|
|
|
sprintf( uid_str, "%lu", (unsigned long)getuid() );
|
2002-06-21 01:21:27 +02:00
|
|
|
user = uid_str;
|
|
|
|
}
|
2002-07-01 20:17:30 +02:00
|
|
|
#else /* HAVE_GETPWUID */
|
|
|
|
if (!(user = getenv( "USER" )))
|
|
|
|
fatal_error( "cannot determine your user name, set the USER environment variable\n" );
|
|
|
|
#endif /* HAVE_GETPWUID */
|
2002-08-27 20:30:53 +02:00
|
|
|
user_name = xstrdup( user );
|
2002-06-21 01:21:27 +02:00
|
|
|
|
|
|
|
/* build config_dir */
|
|
|
|
|
|
|
|
if (prefix)
|
|
|
|
{
|
2007-03-16 14:57:31 +01:00
|
|
|
config_dir = xstrdup( prefix );
|
2002-06-21 01:21:27 +02:00
|
|
|
remove_trailing_slashes( config_dir );
|
|
|
|
if (config_dir[0] != '/')
|
|
|
|
fatal_error( "invalid directory %s in WINEPREFIX: not an absolute path\n", prefix );
|
|
|
|
if (stat( config_dir, &st ) == -1)
|
2004-05-11 06:29:18 +02:00
|
|
|
{
|
2008-04-21 15:48:12 +02:00
|
|
|
if (errno == ENOENT) return; /* will be created later on */
|
|
|
|
fatal_perror( "cannot open %s as specified in WINEPREFIX", config_dir );
|
2004-05-11 06:29:18 +02:00
|
|
|
}
|
2002-06-21 01:21:27 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!home) fatal_error( "could not determine your home directory\n" );
|
|
|
|
if (home[0] != '/') fatal_error( "your home directory %s is not an absolute path\n", home );
|
2004-05-11 06:29:18 +02:00
|
|
|
config_dir = xmalloc( strlen(home) + sizeof(server_config_dir) );
|
2002-06-21 01:21:27 +02:00
|
|
|
strcpy( config_dir, home );
|
|
|
|
remove_trailing_slashes( config_dir );
|
|
|
|
strcat( config_dir, server_config_dir );
|
|
|
|
if (stat( config_dir, &st ) == -1)
|
2004-05-11 06:29:18 +02:00
|
|
|
{
|
|
|
|
if (errno == ENOENT) return; /* will be created later on */
|
2002-06-21 01:21:27 +02:00
|
|
|
fatal_perror( "cannot open %s", config_dir );
|
2004-05-11 06:29:18 +02:00
|
|
|
}
|
2002-06-21 01:21:27 +02:00
|
|
|
}
|
|
|
|
if (!S_ISDIR(st.st_mode)) fatal_error( "%s is not a directory\n", config_dir );
|
2007-11-09 18:07:36 +01:00
|
|
|
#ifdef HAVE_GETUID
|
2007-11-08 12:21:10 +01:00
|
|
|
if (st.st_uid != getuid()) fatal_error( "%s is not owned by you\n", config_dir );
|
2007-11-09 18:07:36 +01:00
|
|
|
#endif
|
2002-06-21 01:21:27 +02:00
|
|
|
|
2004-05-11 06:29:18 +02:00
|
|
|
init_server_dir( st.st_dev, st.st_ino );
|
2002-06-21 01:21:27 +02:00
|
|
|
}
|
|
|
|
|
2009-08-25 12:47:50 +02:00
|
|
|
/* check if bindir is valid by checking for wineserver */
|
|
|
|
static int is_valid_bindir( const char *bindir )
|
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
char *path = build_path( bindir, "wineserver" );
|
|
|
|
int ret = (stat( path, &st ) != -1);
|
|
|
|
free( path );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2006-06-19 22:45:28 +02:00
|
|
|
/* check if basedir is a valid build dir by checking for wineserver and ntdll */
|
|
|
|
/* helper for running_from_build_dir */
|
|
|
|
static inline int is_valid_build_dir( char *basedir, int baselen )
|
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
|
|
|
|
strcpy( basedir + baselen, "/server/wineserver" );
|
|
|
|
if (stat( basedir, &st ) == -1) return 0; /* no wineserver found */
|
|
|
|
/* check for ntdll too to make sure */
|
|
|
|
strcpy( basedir + baselen, "/dlls/ntdll/ntdll.dll.so" );
|
|
|
|
if (stat( basedir, &st ) == -1) return 0; /* no ntdll found */
|
|
|
|
|
|
|
|
basedir[baselen] = 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2006-03-16 17:35:14 +01:00
|
|
|
/* check if we are running from the build directory */
|
2009-08-25 12:47:50 +02:00
|
|
|
static char *running_from_build_dir( const char *basedir )
|
2006-03-16 17:35:14 +01:00
|
|
|
{
|
|
|
|
const char *p;
|
2006-06-19 22:45:28 +02:00
|
|
|
char *path;
|
2006-03-16 17:35:14 +01:00
|
|
|
|
|
|
|
/* remove last component from basedir */
|
|
|
|
p = basedir + strlen(basedir) - 1;
|
|
|
|
while (p > basedir && *p == '/') p--;
|
|
|
|
while (p > basedir && *p != '/') p--;
|
|
|
|
if (p == basedir) return NULL;
|
|
|
|
path = xmalloc( p - basedir + sizeof("/dlls/ntdll/ntdll.dll.so") );
|
|
|
|
memcpy( path, basedir, p - basedir );
|
|
|
|
|
2006-06-19 22:45:28 +02:00
|
|
|
if (!is_valid_build_dir( path, p - basedir ))
|
2006-03-16 17:35:14 +01:00
|
|
|
{
|
2006-06-19 22:45:28 +02:00
|
|
|
/* remove another component */
|
|
|
|
while (p > basedir && *p == '/') p--;
|
|
|
|
while (p > basedir && *p != '/') p--;
|
|
|
|
if (p == basedir || !is_valid_build_dir( path, p - basedir ))
|
|
|
|
{
|
|
|
|
free( path );
|
|
|
|
return NULL;
|
|
|
|
}
|
2006-03-16 17:35:14 +01:00
|
|
|
}
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
2003-10-08 02:36:09 +02:00
|
|
|
/* initialize the argv0 path */
|
2003-11-11 23:21:29 +01:00
|
|
|
void wine_init_argv0_path( const char *argv0 )
|
2003-10-08 02:36:09 +02:00
|
|
|
{
|
2009-08-25 12:47:50 +02:00
|
|
|
const char *basename;
|
|
|
|
char *libdir;
|
2003-10-08 02:36:09 +02:00
|
|
|
|
2009-08-25 12:47:50 +02:00
|
|
|
if (!(basename = strrchr( argv0, '/' ))) basename = argv0;
|
|
|
|
else basename++;
|
2006-03-16 17:35:14 +01:00
|
|
|
|
2013-09-16 12:34:44 +02:00
|
|
|
bindir = get_runtime_exedir();
|
2009-08-25 12:47:50 +02:00
|
|
|
if (bindir && !is_valid_bindir( bindir ))
|
2003-10-08 02:36:09 +02:00
|
|
|
{
|
2009-08-25 12:47:50 +02:00
|
|
|
build_dir = running_from_build_dir( bindir );
|
|
|
|
free( bindir );
|
|
|
|
bindir = NULL;
|
|
|
|
}
|
2013-09-16 12:34:44 +02:00
|
|
|
|
|
|
|
libdir = get_runtime_libdir();
|
2009-08-25 12:47:50 +02:00
|
|
|
if (libdir && !bindir && !build_dir)
|
|
|
|
{
|
|
|
|
build_dir = running_from_build_dir( libdir );
|
|
|
|
if (!build_dir) bindir = build_path( libdir, LIB_TO_BINDIR );
|
2003-10-08 02:36:09 +02:00
|
|
|
}
|
|
|
|
|
2013-09-16 12:34:44 +02:00
|
|
|
if (!libdir && !bindir && !build_dir)
|
|
|
|
{
|
|
|
|
bindir = get_runtime_argvdir( argv0 );
|
|
|
|
if (bindir && !is_valid_bindir( bindir ))
|
|
|
|
{
|
|
|
|
build_dir = running_from_build_dir( bindir );
|
|
|
|
free( bindir );
|
|
|
|
bindir = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-25 12:47:50 +02:00
|
|
|
if (build_dir)
|
2006-02-17 14:08:19 +01:00
|
|
|
{
|
2009-08-25 12:47:50 +02:00
|
|
|
argv0_name = build_path( "loader/", basename );
|
2006-02-17 14:08:19 +01:00
|
|
|
}
|
|
|
|
else
|
2003-10-08 02:36:09 +02:00
|
|
|
{
|
2009-08-25 12:47:50 +02:00
|
|
|
if (libdir) dlldir = build_path( libdir, LIB_TO_DLLDIR );
|
|
|
|
else if (bindir) dlldir = build_path( bindir, BIN_TO_DLLDIR );
|
2006-03-16 17:35:14 +01:00
|
|
|
|
2009-08-25 12:47:50 +02:00
|
|
|
if (bindir) datadir = build_path( bindir, BIN_TO_DATADIR );
|
|
|
|
argv0_name = xstrdup( basename );
|
|
|
|
}
|
|
|
|
free( libdir );
|
2003-10-08 02:36:09 +02:00
|
|
|
}
|
|
|
|
|
2002-06-21 01:21:27 +02:00
|
|
|
/* return the configuration directory ($WINEPREFIX or $HOME/.wine) */
|
|
|
|
const char *wine_get_config_dir(void)
|
|
|
|
{
|
|
|
|
if (!config_dir) init_paths();
|
|
|
|
return config_dir;
|
|
|
|
}
|
|
|
|
|
2006-03-06 18:50:15 +01:00
|
|
|
/* retrieve the wine data dir */
|
|
|
|
const char *wine_get_data_dir(void)
|
|
|
|
{
|
|
|
|
return datadir;
|
|
|
|
}
|
|
|
|
|
2006-03-16 17:36:19 +01:00
|
|
|
/* retrieve the wine build dir (if we are running from there) */
|
|
|
|
const char *wine_get_build_dir(void)
|
|
|
|
{
|
|
|
|
return build_dir;
|
|
|
|
}
|
|
|
|
|
2002-06-21 01:21:27 +02:00
|
|
|
/* return the full name of the server directory (the one containing the socket) */
|
|
|
|
const char *wine_get_server_dir(void)
|
|
|
|
{
|
2004-05-11 06:29:18 +02:00
|
|
|
if (!server_dir)
|
|
|
|
{
|
|
|
|
if (!config_dir) init_paths();
|
|
|
|
else
|
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
|
|
|
|
if (stat( config_dir, &st ) == -1)
|
|
|
|
{
|
|
|
|
if (errno != ENOENT) fatal_error( "cannot stat %s\n", config_dir );
|
|
|
|
return NULL; /* will have to try again once config_dir has been created */
|
|
|
|
}
|
|
|
|
init_server_dir( st.st_dev, st.st_ino );
|
|
|
|
}
|
|
|
|
}
|
2002-06-21 01:21:27 +02:00
|
|
|
return server_dir;
|
|
|
|
}
|
2002-08-27 20:30:53 +02:00
|
|
|
|
|
|
|
/* return the current user name */
|
|
|
|
const char *wine_get_user_name(void)
|
|
|
|
{
|
|
|
|
if (!user_name) init_paths();
|
|
|
|
return user_name;
|
|
|
|
}
|
2003-10-08 02:36:09 +02:00
|
|
|
|
2008-03-26 19:33:06 +01:00
|
|
|
/* return the standard version string */
|
|
|
|
const char *wine_get_version(void)
|
|
|
|
{
|
|
|
|
return PACKAGE_VERSION;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* return the build id string */
|
|
|
|
const char *wine_get_build_id(void)
|
|
|
|
{
|
|
|
|
extern const char wine_build[];
|
|
|
|
return wine_build;
|
|
|
|
}
|
|
|
|
|
2004-05-28 22:59:22 +02:00
|
|
|
/* exec a binary using the preloader if requested; helper for wine_exec_wine_binary */
|
2006-02-16 20:26:55 +01:00
|
|
|
static void preloader_exec( char **argv, int use_preloader )
|
2004-05-28 22:59:22 +02:00
|
|
|
{
|
|
|
|
if (use_preloader)
|
|
|
|
{
|
|
|
|
static const char preloader[] = "wine-preloader";
|
2010-12-16 17:59:30 +01:00
|
|
|
static const char preloader64[] = "wine64-preloader";
|
2004-05-28 22:59:22 +02:00
|
|
|
char *p, *full_name;
|
2004-06-15 22:31:06 +02:00
|
|
|
char **last_arg = argv, **new_argv;
|
2004-05-28 22:59:22 +02:00
|
|
|
|
|
|
|
if (!(p = strrchr( argv[0], '/' ))) p = argv[0];
|
|
|
|
else p++;
|
|
|
|
|
2010-12-16 17:59:30 +01:00
|
|
|
full_name = xmalloc( p - argv[0] + sizeof(preloader64) );
|
2004-05-28 22:59:22 +02:00
|
|
|
memcpy( full_name, argv[0], p - argv[0] );
|
2010-12-16 17:59:30 +01:00
|
|
|
if (strendswith( p, "64" ))
|
|
|
|
memcpy( full_name + (p - argv[0]), preloader64, sizeof(preloader64) );
|
|
|
|
else
|
|
|
|
memcpy( full_name + (p - argv[0]), preloader, sizeof(preloader) );
|
2004-06-15 22:31:06 +02:00
|
|
|
|
|
|
|
/* make a copy of argv */
|
|
|
|
while (*last_arg) last_arg++;
|
|
|
|
new_argv = xmalloc( (last_arg - argv + 2) * sizeof(*argv) );
|
|
|
|
memcpy( new_argv + 1, argv, (last_arg - argv + 1) * sizeof(*argv) );
|
|
|
|
new_argv[0] = full_name;
|
2006-02-16 20:26:55 +01:00
|
|
|
execv( full_name, new_argv );
|
2004-06-15 22:31:06 +02:00
|
|
|
free( new_argv );
|
2004-05-28 22:59:22 +02:00
|
|
|
free( full_name );
|
|
|
|
}
|
2006-02-16 20:26:55 +01:00
|
|
|
execv( argv[0], argv );
|
2004-05-28 22:59:22 +02:00
|
|
|
}
|
|
|
|
|
2003-11-11 23:21:29 +01:00
|
|
|
/* exec a wine internal binary (either the wine loader or the wine server) */
|
2006-02-16 20:26:55 +01:00
|
|
|
void wine_exec_wine_binary( const char *name, char **argv, const char *env_var )
|
2003-10-08 02:36:09 +02:00
|
|
|
{
|
2003-11-11 23:21:29 +01:00
|
|
|
const char *path, *pos, *ptr;
|
2010-12-16 17:59:30 +01:00
|
|
|
int use_preloader;
|
2003-11-11 23:21:29 +01:00
|
|
|
|
2010-12-16 17:59:30 +01:00
|
|
|
if (!name) name = argv0_name; /* no name means default loader */
|
2012-01-15 18:16:23 +01:00
|
|
|
|
|
|
|
#ifdef linux
|
2010-12-16 17:59:30 +01:00
|
|
|
use_preloader = !strendswith( name, "wineserver" );
|
2012-01-15 18:16:23 +01:00
|
|
|
#else
|
|
|
|
use_preloader = 0;
|
|
|
|
#endif
|
2003-11-11 23:21:29 +01:00
|
|
|
|
2006-03-16 17:35:32 +01:00
|
|
|
if ((ptr = strrchr( name, '/' )))
|
|
|
|
{
|
|
|
|
/* if we are in build dir and name contains a path, try that */
|
|
|
|
if (build_dir)
|
|
|
|
{
|
|
|
|
argv[0] = build_path( build_dir, name );
|
|
|
|
preloader_exec( argv, use_preloader );
|
|
|
|
free( argv[0] );
|
|
|
|
}
|
|
|
|
name = ptr + 1; /* get rid of path */
|
|
|
|
}
|
|
|
|
|
2006-02-16 20:06:20 +01:00
|
|
|
/* first, bin directory from the current libdir or argv0 */
|
2006-02-17 14:08:19 +01:00
|
|
|
if (bindir)
|
|
|
|
{
|
|
|
|
argv[0] = build_path( bindir, name );
|
|
|
|
preloader_exec( argv, use_preloader );
|
|
|
|
free( argv[0] );
|
|
|
|
}
|
2003-11-11 23:21:29 +01:00
|
|
|
|
2006-02-16 20:26:55 +01:00
|
|
|
/* then specified environment variable */
|
|
|
|
if (env_var)
|
|
|
|
{
|
|
|
|
argv[0] = (char *)env_var;
|
|
|
|
preloader_exec( argv, use_preloader );
|
|
|
|
}
|
|
|
|
|
2003-11-11 23:21:29 +01:00
|
|
|
/* now search in the Unix path */
|
|
|
|
if ((path = getenv( "PATH" )))
|
|
|
|
{
|
|
|
|
argv[0] = xmalloc( strlen(path) + strlen(name) + 2 );
|
|
|
|
pos = path;
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
while (*pos == ':') pos++;
|
|
|
|
if (!*pos) break;
|
|
|
|
if (!(ptr = strchr( pos, ':' ))) ptr = pos + strlen(pos);
|
|
|
|
memcpy( argv[0], pos, ptr - pos );
|
|
|
|
strcpy( argv[0] + (ptr - pos), "/" );
|
|
|
|
strcat( argv[0] + (ptr - pos), name );
|
2006-02-16 20:26:55 +01:00
|
|
|
preloader_exec( argv, use_preloader );
|
2003-11-11 23:21:29 +01:00
|
|
|
pos = ptr;
|
|
|
|
}
|
|
|
|
free( argv[0] );
|
|
|
|
}
|
2006-02-16 20:06:20 +01:00
|
|
|
|
|
|
|
/* and finally try BINDIR */
|
2006-02-17 14:08:19 +01:00
|
|
|
argv[0] = build_path( BINDIR, name );
|
2006-02-16 20:26:55 +01:00
|
|
|
preloader_exec( argv, use_preloader );
|
2006-02-17 14:08:19 +01:00
|
|
|
free( argv[0] );
|
2003-10-08 02:36:09 +02:00
|
|
|
}
|