diff cinst/nssstore_linux.c @ 841:216a65d7fc4b

(issue66) Implement is_system_install and use it This has completly different implementations for linux and Windows. The commit also moves some code into util.c for better reuse.
author Andre Heinecke <andre.heinecke@intevation.de>
date Tue, 29 Jul 2014 18:12:57 +0200
parents e41a2537b84d
children 698b6a9bd75e
line wrap: on
line diff
--- a/cinst/nssstore_linux.c	Tue Jul 29 13:15:32 2014 +0200
+++ b/cinst/nssstore_linux.c	Tue Jul 29 18:12:57 2014 +0200
@@ -25,52 +25,10 @@
 #include "nssstore.h"
 #include "logging.h"
 #include "strhelp.h"
+#include "util.h"
 
 #define NSS_PROCESS_NAME "mozilla"
 
-/**@brief get the current path of the executable
- *
- * Looks up the current executables directory. The caller
- * has to free the return value.
- *
- * The returned value includes the last /
- *
- * @returns the absolute directory of the currently executed executable or NULL
- */
-char *
-get_exe_dir()
-{
-  char *retval = NULL,
-       *p = NULL,
-       buf[PATH_MAX];
-  ssize_t ret;
-  size_t path_len = 0;
-
-  ret = readlink ("/proc/self/exe", buf, PATH_MAX);
-  if (ret <= 0)
-    {
-      ERRORPRINTF ("readlink failed\n");
-      return NULL;
-    }
-
-  buf[ret] = '\0';
-
-  /* cut off the filename */
-  p = strrchr (buf, '/');
-  if (p == NULL)
-    {
-      ERRORPRINTF ("No filename found.\n");
-      return NULL;
-    }
-  *(p + 1) = '\0';
-
-  path_len = strlen (buf);
-  retval = xmalloc (path_len + 1);
-  strncpy (retval, buf, path_len);
-  retval[path_len] = '\0';
-
-  return retval;
-}
 
 /**@brief Start the process to install / remove
  *
@@ -123,7 +81,7 @@
     }
 
   /* Set up the file name of the installer process */
-  inst_dir = get_exe_dir();
+  inst_dir = get_install_dir();
   if (inst_dir == NULL)
     {
       ERRORPRINTF ("Failed to find installation directory.\n");

http://wald.intevation.org/projects/trustbridge/