comparison 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
comparison
equal deleted inserted replaced
840:c9a31544aaab 841:216a65d7fc4b
23 #include <pwd.h> 23 #include <pwd.h>
24 24
25 #include "nssstore.h" 25 #include "nssstore.h"
26 #include "logging.h" 26 #include "logging.h"
27 #include "strhelp.h" 27 #include "strhelp.h"
28 #include "util.h"
28 29
29 #define NSS_PROCESS_NAME "mozilla" 30 #define NSS_PROCESS_NAME "mozilla"
30 31
31 /**@brief get the current path of the executable
32 *
33 * Looks up the current executables directory. The caller
34 * has to free the return value.
35 *
36 * The returned value includes the last /
37 *
38 * @returns the absolute directory of the currently executed executable or NULL
39 */
40 char *
41 get_exe_dir()
42 {
43 char *retval = NULL,
44 *p = NULL,
45 buf[PATH_MAX];
46 ssize_t ret;
47 size_t path_len = 0;
48
49 ret = readlink ("/proc/self/exe", buf, PATH_MAX);
50 if (ret <= 0)
51 {
52 ERRORPRINTF ("readlink failed\n");
53 return NULL;
54 }
55
56 buf[ret] = '\0';
57
58 /* cut off the filename */
59 p = strrchr (buf, '/');
60 if (p == NULL)
61 {
62 ERRORPRINTF ("No filename found.\n");
63 return NULL;
64 }
65 *(p + 1) = '\0';
66
67 path_len = strlen (buf);
68 retval = xmalloc (path_len + 1);
69 strncpy (retval, buf, path_len);
70 retval[path_len] = '\0';
71
72 return retval;
73 }
74 32
75 /**@brief Start the process to install / remove 33 /**@brief Start the process to install / remove
76 * 34 *
77 * This forks the process and executes the NSS installation 35 * This forks the process and executes the NSS installation
78 * process. It also writes the Instructions to that process. 36 * process. It also writes the Instructions to that process.
121 xfree (envp[0]); 79 xfree (envp[0]);
122 return -1; 80 return -1;
123 } 81 }
124 82
125 /* Set up the file name of the installer process */ 83 /* Set up the file name of the installer process */
126 inst_dir = get_exe_dir(); 84 inst_dir = get_install_dir();
127 if (inst_dir == NULL) 85 if (inst_dir == NULL)
128 { 86 {
129 ERRORPRINTF ("Failed to find installation directory.\n"); 87 ERRORPRINTF ("Failed to find installation directory.\n");
130 xfree (envp[0]); 88 xfree (envp[0]);
131 return -1; 89 return -1;

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