various: use strdup_to() after getenv()
This commit is contained in:
+2
-10
@@ -398,16 +398,8 @@ int systemd_efi_options_variable(char **ret) {
|
||||
|
||||
/* For testing purposes it is sometimes useful to be able to override this */
|
||||
e = secure_getenv("SYSTEMD_EFI_OPTIONS");
|
||||
if (e) {
|
||||
char *m;
|
||||
|
||||
m = strdup(e);
|
||||
if (!m)
|
||||
return -ENOMEM;
|
||||
|
||||
*ret = m;
|
||||
return 0;
|
||||
}
|
||||
if (e)
|
||||
return strdup_to(ret, e);
|
||||
|
||||
r = read_one_line_file(EFIVAR_CACHE_PATH(EFI_SYSTEMD_VARIABLE(SystemdOptions)), ret);
|
||||
if (r == -ENOENT)
|
||||
|
||||
+5
-12
@@ -92,7 +92,6 @@ int xdg_user_data_dir(char **ret, const char *suffix) {
|
||||
}
|
||||
|
||||
int runtime_directory(char **ret, RuntimeScope scope, const char *suffix) {
|
||||
_cleanup_free_ char *d = NULL;
|
||||
int r;
|
||||
|
||||
assert(ret);
|
||||
@@ -106,26 +105,20 @@ int runtime_directory(char **ret, RuntimeScope scope, const char *suffix) {
|
||||
* Return value indicates whether the suffix was applied or not */
|
||||
|
||||
const char *e = secure_getenv("RUNTIME_DIRECTORY");
|
||||
if (e) {
|
||||
d = strdup(e);
|
||||
if (!d)
|
||||
return -ENOMEM;
|
||||
|
||||
*ret = TAKE_PTR(d);
|
||||
return false;
|
||||
}
|
||||
if (e)
|
||||
return strdup_to(ret, e);
|
||||
|
||||
if (scope == RUNTIME_SCOPE_USER) {
|
||||
r = xdg_user_runtime_dir(&d, suffix);
|
||||
r = xdg_user_runtime_dir(ret, suffix);
|
||||
if (r < 0)
|
||||
return r;
|
||||
} else {
|
||||
d = path_join("/run", suffix);
|
||||
char *d = path_join("/run", suffix);
|
||||
if (!d)
|
||||
return -ENOMEM;
|
||||
*ret = d;
|
||||
}
|
||||
|
||||
*ret = TAKE_PTR(d);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -116,16 +116,8 @@ int proc_cmdline(char **ret) {
|
||||
|
||||
/* For testing purposes it is sometimes useful to be able to override what we consider /proc/cmdline to be */
|
||||
e = secure_getenv("SYSTEMD_PROC_CMDLINE");
|
||||
if (e) {
|
||||
char *m;
|
||||
|
||||
m = strdup(e);
|
||||
if (!m)
|
||||
return -ENOMEM;
|
||||
|
||||
*ret = m;
|
||||
return 0;
|
||||
}
|
||||
if (e)
|
||||
return strdup_to(ret, e);
|
||||
|
||||
if (detect_container() > 0)
|
||||
return pid_get_cmdline(1, SIZE_MAX, 0, ret);
|
||||
|
||||
@@ -1022,7 +1022,6 @@ int kill_and_sigcont(pid_t pid, int sig) {
|
||||
|
||||
int getenv_for_pid(pid_t pid, const char *field, char **ret) {
|
||||
_cleanup_fclose_ FILE *f = NULL;
|
||||
char *value = NULL;
|
||||
const char *path;
|
||||
size_t sum = 0;
|
||||
int r;
|
||||
@@ -1031,22 +1030,8 @@ int getenv_for_pid(pid_t pid, const char *field, char **ret) {
|
||||
assert(field);
|
||||
assert(ret);
|
||||
|
||||
if (pid == 0 || pid == getpid_cached()) {
|
||||
const char *e;
|
||||
|
||||
e = getenv(field);
|
||||
if (!e) {
|
||||
*ret = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
value = strdup(e);
|
||||
if (!value)
|
||||
return -ENOMEM;
|
||||
|
||||
*ret = value;
|
||||
return 1;
|
||||
}
|
||||
if (pid == 0 || pid == getpid_cached())
|
||||
return strdup_to_full(ret, getenv(field));
|
||||
|
||||
if (!pid_is_valid(pid))
|
||||
return -EINVAL;
|
||||
@@ -1075,14 +1060,8 @@ int getenv_for_pid(pid_t pid, const char *field, char **ret) {
|
||||
sum += r;
|
||||
|
||||
match = startswith(line, field);
|
||||
if (match && *match == '=') {
|
||||
value = strdup(match + 1);
|
||||
if (!value)
|
||||
return -ENOMEM;
|
||||
|
||||
*ret = value;
|
||||
return 1;
|
||||
}
|
||||
if (match && *match == '=')
|
||||
return strdup_to_full(ret, match + 1);
|
||||
}
|
||||
|
||||
*ret = NULL;
|
||||
|
||||
Reference in New Issue
Block a user