char *printed = NULL;
Unit *u = userdata;
ExecContext *c;
- int r;
+ int r = 0;
assert(u);
if (r < 0)
return -ENODATA;
- asprintf(&printed, UID_FMT, uid);
+ r = asprintf(&printed, UID_FMT, uid);
}
}
if (specifier == 'u')
printed = strdup(username);
else
- asprintf(&printed, UID_FMT, uid);
+ r = asprintf(&printed, UID_FMT, uid);
}
- if (!printed)
+ if (r < 0 || !printed)
return -ENOMEM;
*ret = printed;
description = NULL;
}
+ k = 0;
if (mount_point && description)
- asprintf(&name_buffer, "%s (%s) on %s", description, argv[2], mount_point);
+ k = asprintf(&name_buffer, "%s (%s) on %s", description, argv[2], mount_point);
else if (mount_point)
- asprintf(&name_buffer, "%s on %s", argv[2], mount_point);
+ k = asprintf(&name_buffer, "%s on %s", argv[2], mount_point);
else if (description)
- asprintf(&name_buffer, "%s (%s)", description, argv[2]);
+ k = asprintf(&name_buffer, "%s (%s)", description, argv[2]);
+ if (k < 0) {
+ log_oom();
+ goto finish;
+ }
name = name_buffer ? name_buffer : argv[2];
k = crypt_init(&cd, argv[3]);
}
if (sd_pid_get_owner_uid(pid, &owner_uid) >= 0) {
- asprintf(&core_owner_uid, "COREDUMP_OWNER_UID=" UID_FMT, owner_uid);
-
- if (core_owner_uid)
+ r = asprintf(&core_owner_uid,
+ "COREDUMP_OWNER_UID=" UID_FMT, owner_uid);
+ if (r > 0)
IOVEC_SET_STRING(iovec[j++], core_owner_uid);
}
}
} else
t = strappend("_EXE=", path);
- } else if (S_ISCHR(st.st_mode))
- asprintf(&t, "_KERNEL_DEVICE=c%u:%u", major(st.st_rdev), minor(st.st_rdev));
- else if (S_ISBLK(st.st_mode))
- asprintf(&t, "_KERNEL_DEVICE=b%u:%u", major(st.st_rdev), minor(st.st_rdev));
- else {
+ } else if (S_ISCHR(st.st_mode)) {
+ if (asprintf(&t, "_KERNEL_DEVICE=c%u:%u",
+ major(st.st_rdev),
+ minor(st.st_rdev)) < 0)
+ return -ENOMEM;
+ } else if (S_ISBLK(st.st_mode)) {
+ if (asprintf(&t, "_KERNEL_DEVICE=b%u:%u",
+ major(st.st_rdev),
+ minor(st.st_rdev)) < 0)
+ return -ENOMEM;
+ } else {
log_error("File is neither a device node, nor regular file, nor executable: %s", *i);
return -EINVAL;
}
_cleanup_free_ char *name = NULL;
int r;
- if (arg_unit)
+ if (arg_unit) {
name = unit_name_mangle_with_suffix(arg_unit, MANGLE_NOGLOB, ".service");
- else
- asprintf(&name, "run-"PID_FMT".service", getpid());
- if (!name)
+ if (!name)
+ return log_oom();
+ } else if (asprintf(&name, "run-"PID_FMT".service", getpid()) < 0)
return log_oom();
r = message_start_transient_unit_new(bus, name, &m);
assert(bus);
- if (arg_unit)
+ if (arg_unit) {
name = unit_name_mangle_with_suffix(arg_unit, MANGLE_NOGLOB, ".scope");
- else
- asprintf(&name, "run-"PID_FMT".scope", getpid());
- if (!name)
+ if (!name)
+ return log_oom();
+ } else if (asprintf(&name, "run-"PID_FMT".scope", getpid()) < 0)
return log_oom();
r = message_start_transient_unit_new(bus, name, &m);
case UNIT_FILE_SYSTEM:
- if (root_dir && runtime)
- asprintf(&p, "%s/run/systemd/system", root_dir);
- else if (runtime)
+ if (root_dir && runtime) {
+ if (asprintf(&p, "%s/run/systemd/system", root_dir) < 0)
+ return -ENOMEM;
+ } else if (runtime)
p = strdup("/run/systemd/system");
- else if (root_dir)
- asprintf(&p, "%s/%s", root_dir, SYSTEM_CONFIG_UNIT_PATH);
- else
+ else if (root_dir) {
+ if (asprintf(&p, "%s/%s", root_dir,
+ SYSTEM_CONFIG_UNIT_PATH) < 0)
+ return -ENOMEM;
+ } else
p = strdup(SYSTEM_CONFIG_UNIT_PATH);
break;
_cleanup_free_ char *path = NULL;
if (!isempty(arg_root))
- asprintf(&path, "%s/%s/%s", arg_root, *k, name);
+ j = asprintf(&path, "%s/%s/%s", arg_root, *k, name);
else
- asprintf(&path, "%s/%s", *k, name);
-
- if (!path) {
+ j = asprintf(&path, "%s/%s", *k, name);
+ if (j < 0) {
r = log_oom();
goto finish;
}
continue;
if (!isempty(arg_root))
- asprintf(&p, "%s/" SYSTEM_SYSVINIT_PATH "/%s", arg_root, name);
+ j = asprintf(&p, "%s/" SYSTEM_SYSVINIT_PATH "/%s", arg_root, name);
else
- asprintf(&p, SYSTEM_SYSVINIT_PATH "/%s", name);
- if (!p) {
+ j = asprintf(&p, SYSTEM_SYSVINIT_PATH "/%s", name);
+ if (j < 0) {
r = log_oom();
goto finish;
}
if (accept_cached) {
packet = strdup("c");
n = 1;
- } else
- asprintf(&packet, "*\002%c%s%n", (int) (strlen(message) + 1), message, &n);
+ } else if (asprintf(&packet, "*\002%c%s%n", (int) (strlen(message) + 1),
+ message, &n) < 0)
+ packet = NULL;
if (!packet) {
r = -ENOMEM;