mirror of
https://git.proxmox.com/git/mirror_lxc
synced 2025-07-27 11:13:50 +00:00
execute: use static buffer
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
This commit is contained in:
parent
aa769a272f
commit
321614a5da
@ -38,10 +38,11 @@ lxc_log_define(lxc_execute, lxc_start);
|
|||||||
|
|
||||||
static int execute_start(struct lxc_handler *handler, void* data)
|
static int execute_start(struct lxc_handler *handler, void* data)
|
||||||
{
|
{
|
||||||
int j, i = 0, log = -1;
|
int argc_add, j;
|
||||||
|
char **argv;
|
||||||
|
int argc = 0, i = 0, logfd = -1;
|
||||||
struct execute_args *my_args = data;
|
struct execute_args *my_args = data;
|
||||||
char **argv, *logfd;
|
char logfile[LXC_PROC_PID_FD_LEN];
|
||||||
int argc = 0, argc_add;
|
|
||||||
|
|
||||||
while (my_args->argv[argc++]);
|
while (my_args->argv[argc++]);
|
||||||
|
|
||||||
@ -49,8 +50,10 @@ static int execute_start(struct lxc_handler *handler, void* data)
|
|||||||
argc_add = 5;
|
argc_add = 5;
|
||||||
if (my_args->quiet)
|
if (my_args->quiet)
|
||||||
argc_add++;
|
argc_add++;
|
||||||
|
|
||||||
if (!handler->conf->rootfs.path)
|
if (!handler->conf->rootfs.path)
|
||||||
argc_add += 2;
|
argc_add += 2;
|
||||||
|
|
||||||
if (lxc_log_has_valid_level())
|
if (lxc_log_has_valid_level())
|
||||||
argc_add += 2;
|
argc_add += 2;
|
||||||
|
|
||||||
@ -72,24 +75,24 @@ static int execute_start(struct lxc_handler *handler, void* data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (current_config->logfd != -1 || lxc_log_fd != -1) {
|
if (current_config->logfd != -1 || lxc_log_fd != -1) {
|
||||||
|
int ret;
|
||||||
int to_dup = current_config->logfd;
|
int to_dup = current_config->logfd;
|
||||||
|
|
||||||
if (current_config->logfd == -1)
|
if (current_config->logfd == -1)
|
||||||
to_dup = lxc_log_fd;
|
to_dup = lxc_log_fd;
|
||||||
|
|
||||||
log = dup(to_dup);
|
logfd = dup(to_dup);
|
||||||
if (log < 0) {
|
if (logfd < 0) {
|
||||||
SYSERROR("dup of log fd failed");
|
SYSERROR("Failed to duplicate log file descriptor");
|
||||||
goto out2;
|
goto out2;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (asprintf(&logfd, "/proc/1/fd/%d", log) < 0) {
|
ret = snprintf(logfile, sizeof(logfile), "/proc/1/fd/%d", logfd);
|
||||||
ERROR("Couldn't allocate memory for log string");
|
if (ret < 0 || (size_t)ret >= sizeof(logfile))
|
||||||
goto out3;
|
goto out3;
|
||||||
}
|
|
||||||
|
|
||||||
argv[i++] = "-o";
|
argv[i++] = "-o";
|
||||||
argv[i++] = logfd;
|
argv[i++] = logfile;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (my_args->quiet)
|
if (my_args->quiet)
|
||||||
@ -110,9 +113,8 @@ static int execute_start(struct lxc_handler *handler, void* data)
|
|||||||
execvp(argv[0], argv);
|
execvp(argv[0], argv);
|
||||||
SYSERROR("Failed to exec %s", argv[0]);
|
SYSERROR("Failed to exec %s", argv[0]);
|
||||||
|
|
||||||
free(logfd);
|
|
||||||
out3:
|
out3:
|
||||||
close(log);
|
close(logfd);
|
||||||
out2:
|
out2:
|
||||||
free(argv);
|
free(argv);
|
||||||
out1:
|
out1:
|
||||||
|
Loading…
Reference in New Issue
Block a user