2 * Babeltrace common functions
4 * Copyright 2016 Philippe Proulx <pproulx@efficios.com>
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 #include <sys/types.h>
31 #include <babeltrace/babeltrace-internal.h>
33 #define SYSTEM_PLUGIN_PATH INSTALL_LIBDIR "/babeltrace/plugins"
34 #define HOME_ENV_VAR "HOME"
35 #define HOME_PLUGIN_SUBPATH "/.local/lib/babeltrace/plugins"
38 const char *bt_common_get_system_plugin_path(void)
40 return SYSTEM_PLUGIN_PATH
;
44 bool bt_common_is_setuid_setgid(void)
46 return (geteuid() != getuid() || getegid() != getgid());
49 static char *bt_secure_getenv(const char *name
)
51 if (bt_common_is_setuid_setgid()) {
52 printf_error("Disregarding %s environment variable for setuid/setgid binary",
59 static const char *get_home_dir(void)
64 val
= bt_secure_getenv(HOME_ENV_VAR
);
68 /* Fallback on password file. */
69 pwd
= getpwuid(getuid());
79 char *bt_common_get_home_plugin_path(void)
84 home_dir
= get_home_dir();
89 if (strlen(home_dir
) + strlen(HOME_PLUGIN_SUBPATH
) + 1 >= PATH_MAX
) {
90 printf_error("Home directory path is too long: `%s`\n",
95 path
= malloc(PATH_MAX
);
100 strcpy(path
, home_dir
);
101 strcat(path
, HOME_PLUGIN_SUBPATH
);
108 int bt_common_append_plugin_path_dirs(const char *paths
, GPtrArray
*dirs
)
113 size_t init_dirs_len
;
116 init_dirs_len
= dirs
->len
;
119 /* Nothing to append */
124 end
= paths
+ strlen(paths
);
128 const char *next_colon
;
130 next_colon
= strchr(at
, ':');
131 if (next_colon
== at
) {
133 * Empty path: try next character (supported
134 * to conform to the typical parsing of $PATH).
138 } else if (!next_colon
) {
139 /* No more colon: use the remaining */
140 next_colon
= paths
+ strlen(paths
);
143 path
= g_string_new(NULL
);
148 g_string_append_len(path
, at
, next_colon
- at
);
150 g_ptr_array_add(dirs
, path
);
158 /* Remove the new entries in dirs */
159 while (dirs
->len
> init_dirs_len
) {
160 g_ptr_array_remove_index(dirs
, init_dirs_len
);
This page took 0.033443 seconds and 4 git commands to generate.