console.c revision 95ee490bbdb97ab2b4f1dfa63a0a26e0dd1c2f17
/* liblxcapi
*
* Copyright © 2013 Oracle.
*
* Authors:
* Dwight Engen <dwight.engen@oracle.com>
*
* it under the terms of the GNU General Public License version 2, as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <lxc/lxccontainer.h>
#include <errno.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#define TTYCNT 4
#define TTYCNT_STR "4"
#define TSTNAME "lxcconsoletest"
#define MAXCONSOLES 512
} while (0)
int masterfd[MAXCONSOLES])
{
int i;
for (i = 0; i < MAXCONSOLES; i++) {
if (masterfd[i] != -1) {
masterfd[i] = -1;
}
if (ttyfd[i] != -1) {
ttyfd[i] = -1;
}
}
}
static int test_console_running_container(struct lxc_container *c)
{
int ttynum [MAXCONSOLES];
int ttyfd [MAXCONSOLES];
int masterfd[MAXCONSOLES];
for (i = 0; i < MAXCONSOLES; i++)
ttynum[0] = 1;
if (ret < 0) {
TSTERR("console allocate failed");
goto err1;
}
if (ttynum[0] != 1) {
goto err2;
}
/* attempt to alloc same ttynum */
if (ret != -1) {
goto err2;
}
/* ensure we can allocate all consoles, we do this a few times to
* show that the closes are freeing up the allocated slots
*/
for (i = 0; i < 10; i++) {
if (ret < 0)
break;
}
if (nrconsoles != TTYCNT) {
goto err2;
}
}
ret = 0;
err2:
err1:
return ret;
}
/* test_container: test console function
*
* @lxcpath : the lxcpath in which to create the container
* @group : name of the container group or NULL for default "lxc"
* @name : name of the container
* @template : template to use when creating the container
*/
static int test_console(const char *lxcpath,
const char *template)
{
int ret;
struct lxc_container *c = NULL;
if (lxcpath) {
goto out1;
}
}
ret = -1;
goto out1;
}
if (c->is_defined(c)) {
c->stop(c);
c->destroy(c);
}
goto out2;
}
c->load_config(c, NULL);
c->save_config(c, NULL);
c->want_daemonize(c, true);
goto out3;
}
c->stop(c);
out3:
c->destroy(c);
out2:
out1:
return ret;
}
{
int ret;
if (ret < 0)
goto err1;
if (ret < 0)
goto err1;
printf("All tests passed\n");
err1:
return ret;
}