Added support for WINEPREFIX environment variable.
diff --git a/files/profile.c b/files/profile.c
index 12eaf74..f578c90 100644
--- a/files/profile.c
+++ b/files/profile.c
@@ -25,7 +25,6 @@
#include "file.h"
#include "heap.h"
#include "debugtools.h"
-#include "xmalloc.h"
#include "options.h"
#include "server.h"
@@ -79,7 +78,6 @@
#define IS_ENTRY_COMMENT(str) ((str)[0] == ';')
#define WINE_INI_GLOBAL ETCDIR "/wine.conf"
-#define WINE_CONFIG_DIR "/.wine" /* config dir inside $HOME */
static const WCHAR wininiW[] = { 'w','i','n','.','i','n','i',0 };
@@ -88,36 +86,6 @@
static const char hex[16] = "0123456789ABCDEF";
/***********************************************************************
- * PROFILE_GetConfigDir
- *
- * Return the name of the configuration directory ($HOME/.wine)
- */
-const char *PROFILE_GetConfigDir(void)
-{
- static char *confdir;
- if (!confdir)
- {
- const char *home = getenv( "HOME" );
- if (!home)
- {
- struct passwd *pwd = getpwuid( getuid() );
- if (!pwd)
- {
- fprintf( stderr, "wine: could not find your home directory\n" );
- exit(1);
- }
- home = pwd->pw_dir;
- }
- confdir = xmalloc( strlen(home) + strlen(WINE_CONFIG_DIR) + 1 );
- strcpy( confdir, home );
- strcat( confdir, WINE_CONFIG_DIR );
- mkdir( confdir, 0755 ); /* create it just in case */
- }
- return confdir;
-}
-
-
-/***********************************************************************
* PROFILE_CopyEntry
*
* Copy the content of an entry into a buffer, removing quotes, and possibly
@@ -501,7 +469,7 @@
{
/* Try to create it in $HOME/.wine */
/* FIXME: this will need a more general solution */
- strcpy( buffer, PROFILE_GetConfigDir() );
+ strcpy( buffer, get_config_dir() );
p = buffer + strlen(buffer);
*p++ = '/';
strcpy( p, strrchr( CurProfile->dos_name, '\\' ) + 1 );
@@ -635,7 +603,7 @@
/* Try to open the profile file, first in $HOME/.wine */
/* FIXME: this will need a more general solution */
- strcpy( buffer, PROFILE_GetConfigDir() );
+ strcpy( buffer, get_config_dir() );
p = buffer + strlen(buffer);
*p++ = '/';
strcpy( p, strrchr( newdos_name, '\\' ) + 1 );
diff --git a/include/options.h b/include/options.h
index d05fde3..51e5308 100644
--- a/include/options.h
+++ b/include/options.h
@@ -75,7 +75,6 @@
/* Profile functions */
-extern const char *PROFILE_GetConfigDir(void);
extern int PROFILE_LoadWineIni(void);
extern void PROFILE_UsageWineIni(void);
extern int PROFILE_GetWineIniString( const char *section, const char *key_name,
diff --git a/include/server.h b/include/server.h
index 15fa780..ad12dae 100644
--- a/include/server.h
+++ b/include/server.h
@@ -1227,6 +1227,7 @@
extern unsigned int server_call_noerr( enum request req );
extern unsigned int server_call_fd( enum request req, int fd_out, int *fd_in );
extern void server_protocol_error( const char *err, ... ) WINE_NORETURN;
+extern const char *get_config_dir(void);
/* get a pointer to the request buffer */
static inline void * WINE_UNUSED get_req_buffer(void)
diff --git a/scheduler/client.c b/scheduler/client.c
index 3a99781..6770a7d 100644
--- a/scheduler/client.c
+++ b/scheduler/client.c
@@ -10,6 +10,7 @@
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
+#include <pwd.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
@@ -36,6 +37,7 @@
#define SCM_RIGHTS 1
#endif
+#define CONFDIR "/.wine" /* directory for Wine config relative to $HOME */
#define SERVERDIR "/wineserver-" /* server socket directory (hostname appended) */
#define SOCKETNAME "socket" /* name of the socket file */
@@ -286,6 +288,43 @@
/***********************************************************************
+ * get_config_dir
+ *
+ * Return the configuration directory ($WINEPREFIX or $HOME/.wine)
+ */
+const char *get_config_dir(void)
+{
+ static char *confdir;
+ if (!confdir)
+ {
+ const char *prefix = getenv( "WINEPREFIX" );
+ if (prefix)
+ {
+ int len = strlen(prefix);
+ if (!(confdir = strdup( prefix ))) fatal_error( "out of memory\n" );
+ if (len > 1 && confdir[len-1] == '/') confdir[len-1] = 0;
+ }
+ else
+ {
+ const char *home = getenv( "HOME" );
+ if (!home)
+ {
+ struct passwd *pwd = getpwuid( getuid() );
+ if (!pwd) fatal_error( "could not find your home directory\n" );
+ home = pwd->pw_dir;
+ }
+ if (!(confdir = malloc( strlen(home) + strlen(CONFDIR) + 1 )))
+ fatal_error( "out of memory\n" );
+ strcpy( confdir, home );
+ strcat( confdir, CONFDIR );
+ }
+ mkdir( confdir, 0755 ); /* just in case */
+ }
+ return confdir;
+}
+
+
+/***********************************************************************
* start_server
*
* Start a new wine server.
@@ -406,7 +445,7 @@
/* get the server directory name */
if (gethostname( hostname, sizeof(hostname) ) == -1) fatal_perror( "gethostname" );
- configdir = PROFILE_GetConfigDir();
+ configdir = get_config_dir();
serverdir = malloc( strlen(configdir) + strlen(SERVERDIR) + strlen(hostname) + 1 );
if (!serverdir) fatal_error( "out of memory\n" );
strcpy( serverdir, configdir );
diff --git a/server/request.c b/server/request.c
index 011124c..d15faac 100644
--- a/server/request.c
+++ b/server/request.c
@@ -302,23 +302,33 @@
socket_cleanup();
}
-/* return the configuration directory ($HOME/.wine) */
+/* return the configuration directory ($WINEPREFIX or $HOME/.wine) */
static const char *get_config_dir(void)
{
static char *confdir;
if (!confdir)
{
- const char *home = getenv( "HOME" );
- if (!home)
+ const char *prefix = getenv( "WINEPREFIX" );
+ if (prefix)
{
- struct passwd *pwd = getpwuid( getuid() );
- if (!pwd) fatal_error( "could not find your home directory\n" );
- home = pwd->pw_dir;
+ int len = strlen(prefix);
+ if (!(confdir = strdup( prefix ))) fatal_error( "out of memory\n" );
+ if (len > 1 && confdir[len-1] == '/') confdir[len-1] = 0;
}
- if (!(confdir = malloc( strlen(home) + strlen(CONFDIR) + 1 )))
- fatal_error( "out of memory\n" );
- strcpy( confdir, home );
- strcat( confdir, CONFDIR );
+ else
+ {
+ const char *home = getenv( "HOME" );
+ if (!home)
+ {
+ struct passwd *pwd = getpwuid( getuid() );
+ if (!pwd) fatal_error( "could not find your home directory\n" );
+ home = pwd->pw_dir;
+ }
+ if (!(confdir = malloc( strlen(home) + strlen(CONFDIR) + 1 )))
+ fatal_error( "out of memory\n" );
+ strcpy( confdir, home );
+ strcat( confdir, CONFDIR );
+ }
mkdir( confdir, 0755 ); /* just in case */
}
return confdir;