From 21779fd5e79ceeb5de91665552d7f0cec49c5e79 Mon Sep 17 00:00:00 2001 From: Adam Tkac Date: Fri, 29 Oct 2010 12:17:19 +0000 Subject: [PATCH] [Development] Use gethomedir() function in vncpasswd and vncviewer. git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@4177 3789f03b-4d11-0410-bbf8-ca57d06f2519 --- unix/vncpasswd/Makefile.am | 3 ++- unix/vncpasswd/vncpasswd.cxx | 13 ++++++++----- unix/vncviewer/Makefile.am | 1 + unix/vncviewer/vncviewer.cxx | 11 +++++++---- 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/unix/vncpasswd/Makefile.am b/unix/vncpasswd/Makefile.am index 00951be3..7acc89ff 100644 --- a/unix/vncpasswd/Makefile.am +++ b/unix/vncpasswd/Makefile.am @@ -7,6 +7,7 @@ vncpasswd_SOURCES = vncpasswd.cxx vncpasswd_CPPFLAGS = -I$(top_srcdir)/common vncpasswd_LDADD = $(top_builddir)/common/rfb/librfb.la \ - $(top_builddir)/common/rdr/librdr.la + $(top_builddir)/common/rdr/librdr.la \ + $(top_builddir)/common/os/libos.la EXTRA_DIST = vncpasswd.man diff --git a/unix/vncpasswd/vncpasswd.cxx b/unix/vncpasswd/vncpasswd.cxx index d21ea942..4cdff57c 100644 --- a/unix/vncpasswd/vncpasswd.cxx +++ b/unix/vncpasswd/vncpasswd.cxx @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -100,14 +101,16 @@ int main(int argc, char** argv) } if (!fname) { - if (!getenv("HOME")) { - fprintf(stderr,"HOME is not set\n"); + char *homeDir = NULL; + if (gethomedir(&homeDir) == -1) { + fprintf(stderr, "Can't obtain home directory\n"); exit(1); } - fname = new char[strlen(getenv("HOME")) + 20]; - sprintf(fname, "%s/.vnc", getenv("HOME")); + fname = new char[strlen(homeDir) + 20]; + sprintf(fname, "%s/.vnc", homeDir); mkdir(fname, 0777); - sprintf(fname, "%s/.vnc/passwd", getenv("HOME")); + sprintf(fname, "%s/.vnc/passwd", homeDir); + delete [] homeDir; } while (true) { diff --git a/unix/vncviewer/Makefile.am b/unix/vncviewer/Makefile.am index cfbe430f..32d5c6cc 100644 --- a/unix/vncviewer/Makefile.am +++ b/unix/vncviewer/Makefile.am @@ -16,6 +16,7 @@ vncviewer_LDADD = $(top_builddir)/unix/tx/libtx.la \ $(top_builddir)/common/rfb/librfb.la \ $(top_builddir)/common/network/libnetwork.la \ $(top_builddir)/common/rdr/librdr.la \ + $(top_builddir)/common/os/libos.la \ @X_PRE_LIBS@ @X_LIBS@ -lXext -lX11 @X_EXTRA_LIBS@ @GNUTLS_LIBS@ # @LIBINTL@ if INCLUDED_ZLIB diff --git a/unix/vncviewer/vncviewer.cxx b/unix/vncviewer/vncviewer.cxx index 80d65c55..9edb80d3 100644 --- a/unix/vncviewer/vncviewer.cxx +++ b/unix/vncviewer/vncviewer.cxx @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -323,15 +324,17 @@ int main(int argc, char** argv) } // Create .vnc in the user's home directory if it doesn't already exist - char* homeDir = getenv("HOME"); - if (homeDir) { + char* homeDir = NULL; + if (gethomedir(&homeDir) == -1) + vlog.error("Could not create .vnc directory: can't obtain home directory path."); + else { CharArray vncDir(strlen(homeDir)+6); sprintf(vncDir.buf, "%s/.vnc", homeDir); int result = mkdir(vncDir.buf, 0755); if (result == -1 && errno != EEXIST) vlog.error("Could not create .vnc directory: %s.", strerror(errno)); - } else - vlog.error("Could not create .vnc directory: environment variable $HOME not set."); + delete [] homeDir; + } if (!::autoSelect.hasBeenSet()) { // Default to AutoSelect=0 if -PreferredEncoding or -FullColor is used -- 2.39.5