Remove annoying warnings and fix tty for restart

From: Daniel Lezcano <dlezcano@fr.ibm.com>

Remove annoying compilation messages and fix tty for the restart.

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
This commit is contained in:
dlezcano 2008-11-26 17:05:11 +00:00
parent 526e288e42
commit caf249f40e
3 changed files with 7 additions and 17 deletions

View File

@ -83,6 +83,5 @@ int lxc_destroy(const char *name)
out_lock: out_lock:
lxc_put_lock(lock); lxc_put_lock(lock);
out:
return ret; return ret;
} }

View File

@ -48,7 +48,7 @@ int lxc_restart(const char *name, const char *statefile,
unsigned long flags) unsigned long flags)
{ {
char *init = NULL, *val = NULL; char *init = NULL, *val = NULL;
char ttyname[MAXPATHLEN]; char tty[MAXPATHLEN];
int fd, lock, sv[2], sync = 0, err = -1; int fd, lock, sv[2], sync = 0, err = -1;
pid_t pid; pid_t pid;
int clone_flags; int clone_flags;
@ -65,12 +65,11 @@ int lxc_restart(const char *name, const char *statefile,
goto out; goto out;
} }
if (readlink("/proc/self/fd/0", ttyname, sizeof(ttyname)) < 0) { if (ttyname_r(0, tty, sizeof(tty))) {
lxc_log_syserror("failed to read '/proc/self/fd/0'"); tty[0] = '\0';
goto out; lxc_log_warning("failed to get tty name");
} }
/* Synchro socketpair */ /* Synchro socketpair */
if (socketpair(AF_LOCAL, SOCK_STREAM, 0, sv)) { if (socketpair(AF_LOCAL, SOCK_STREAM, 0, sv)) {
lxc_log_syserror("failed to create communication socketpair"); lxc_log_syserror("failed to create communication socketpair");
@ -96,7 +95,6 @@ int lxc_restart(const char *name, const char *statefile,
if (!pid) { if (!pid) {
char dummytty = '\0';
close(sv[1]); close(sv[1]);
/* Be sure we don't inherit this after the exec */ /* Be sure we don't inherit this after the exec */
@ -115,18 +113,13 @@ int lxc_restart(const char *name, const char *statefile,
} }
/* Setup the container, ip, names, utsname, ... */ /* Setup the container, ip, names, utsname, ... */
if (lxc_setup(name, &dummytty)) { if (lxc_setup(name, tty)) {
lxc_log_error("failed to setup the container"); lxc_log_error("failed to setup the container");
if (write(sv[0], &sync, sizeof(sync)) < 0) if (write(sv[0], &sync, sizeof(sync)) < 0)
lxc_log_syserror("failed to write the socket"); lxc_log_syserror("failed to write the socket");
return -1; return -1;
} }
if (mount(ttyname, "/dev/console", "none", MS_BIND, 0)) {
lxc_log_syserror("failed to mount '/dev/console'");
return -1;
}
lxc_plugin_restart(getpid(), statefile, flags); lxc_plugin_restart(getpid(), statefile, flags);
lxc_log_syserror("failed to restart"); lxc_log_syserror("failed to restart");
@ -243,6 +236,5 @@ err_fork_ns:
LXC_TTY_DEL_HANDLER(SIGINT); LXC_TTY_DEL_HANDLER(SIGINT);
close(sv[0]); close(sv[0]);
close(sv[1]); close(sv[1]);
err:
goto out; goto out;
} }

View File

@ -70,10 +70,9 @@ int lxc_start(const char *name, char *argv[])
goto out; goto out;
} }
if (ttyname_r(0, tty, sizeof(tty))) { /* If we are not attached to a tty, disable it */
if (ttyname_r(0, tty, sizeof(tty)))
tty[0] = '\0'; tty[0] = '\0';
lxc_log_warning("failed to get tty name");
}
/* Synchro socketpair */ /* Synchro socketpair */
if (socketpair(AF_LOCAL, SOCK_STREAM, 0, sv)) { if (socketpair(AF_LOCAL, SOCK_STREAM, 0, sv)) {