109
111
rc = virCgroupAddTask(cgroup, getpid());
112
lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
113
_("Failed to set lxc resources: %s\n"), strerror(-rc));
114
virReportSystemError(NULL, -rc, "%s",
115
_("Failed to set lxc resources"));
114
116
virCgroupRemove(cgroup);
122
124
static char*lxcMonitorPath(virDomainDefPtr def)
125
if (asprintf(&sockpath, "%s/%s.sock",
126
LXC_STATE_DIR, def->name) < 0) {
127
lxcError(NULL, NULL, VIR_ERR_NO_MEMORY, NULL);
128
if (virAsprintf(&sockpath, "%s/%s.sock",
129
LXC_STATE_DIR, def->name) < 0)
130
virReportOOMError(NULL);
136
137
struct sockaddr_un addr;
138
139
if ((fd = socket(PF_UNIX, SOCK_STREAM, 0)) < 0) {
139
lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
140
_("failed to create server socket %s: %s"),
141
sockpath, strerror(errno));
140
virReportSystemError(NULL, errno,
141
_("failed to create server socket '%s'"),
148
149
strncpy(addr.sun_path, sockpath, sizeof(addr.sun_path));
150
151
if (bind(fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
151
lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
152
_("failed to bind server socket %s: %s"),
153
sockpath, strerror(errno));
152
virReportSystemError(NULL, errno,
153
_("failed to bind server socket '%s'"),
156
157
if (listen(fd, 30 /* backlog */ ) < 0) {
157
lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
158
_("failed to listen server socket %s: %s"),
159
sockpath, strerror(errno));
158
virReportSystemError(NULL, errno,
159
_("failed to listen server socket %s"),
191
lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
192
_("read of fd %d failed: %s"), readFd, strerror(errno));
192
virReportSystemError(NULL, errno,
193
_("read of fd %d failed"),
196
198
if (1 != (safewrite(writeFd, buf, 1))) {
197
lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
198
_("write to fd %d failed: %s"), writeFd, strerror(errno));
199
virReportSystemError(NULL, errno,
200
_("write to fd %d failed"),
245
248
/* create the epoll fild descriptor */
246
249
epollFd = epoll_create(2);
247
250
if (0 > epollFd) {
248
lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
249
_("epoll_create(2) failed: %s"), strerror(errno));
251
virReportSystemError(NULL, errno, "%s",
252
_("epoll_create(2) failed"));
255
258
epollEvent.events = EPOLLIN|EPOLLET; /* edge triggered */
256
259
epollEvent.data.fd = appPty;
257
260
if (0 > epoll_ctl(epollFd, EPOLL_CTL_ADD, appPty, &epollEvent)) {
258
lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
259
_("epoll_ctl(appPty) failed: %s"), strerror(errno));
261
virReportSystemError(NULL, errno, "%s",
262
_("epoll_ctl(appPty) failed"));
262
265
epollEvent.data.fd = contPty;
263
266
if (0 > epoll_ctl(epollFd, EPOLL_CTL_ADD, contPty, &epollEvent)) {
264
lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
265
_("epoll_ctl(contPty) failed: %s"), strerror(errno));
267
virReportSystemError(NULL, errno, "%s",
268
_("epoll_ctl(contPty) failed"));
269
272
epollEvent.events = EPOLLIN;
270
273
epollEvent.data.fd = monitor;
271
274
if (0 > epoll_ctl(epollFd, EPOLL_CTL_ADD, monitor, &epollEvent)) {
272
lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
273
_("epoll_ctl(contPty) failed: %s"), strerror(errno));
275
virReportSystemError(NULL, errno, "%s",
276
_("epoll_ctl(contPty) failed"));
277
280
epollEvent.events = EPOLLHUP;
278
281
epollEvent.data.fd = client;
279
282
if (0 > epoll_ctl(epollFd, EPOLL_CTL_ADD, client, &epollEvent)) {
280
lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
281
_("epoll_ctl(contPty) failed: %s"), strerror(errno));
283
virReportSystemError(NULL, errno, "%s",
284
_("epoll_ctl(contPty) failed"));
297
300
epollEvent.events = EPOLLHUP;
298
301
epollEvent.data.fd = client;
299
302
if (0 > epoll_ctl(epollFd, EPOLL_CTL_ADD, client, &epollEvent)) {
300
lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
301
_("epoll_ctl(contPty) failed: %s"), strerror(errno));
303
virReportSystemError(NULL, errno, "%s",
304
_("epoll_ctl(contPty) failed"));
304
307
} else if (client != -1 && epollEvent.data.fd == client) {
305
308
if (0 > epoll_ctl(epollFd, EPOLL_CTL_DEL, client, &epollEvent)) {
306
lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
307
_("epoll_ctl(contPty) failed: %s"), strerror(errno));
309
virReportSystemError(NULL, errno, "%s",
310
_("epoll_ctl(contPty) failed"));
344
lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
345
_("epoll_wait() failed: %s"), strerror(errno));
347
virReportSystemError(NULL, errno, "%s",
348
_("epoll_wait() failed"));
439
442
pid_t container = -1;
441
444
if (socketpair(PF_UNIX, SOCK_STREAM, 0, control) < 0) {
442
lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
443
_("sockpair failed: %s"), strerror(errno));
445
virReportSystemError(NULL, errno, "%s",
446
_("sockpair failed"));
447
450
if (virFileOpenTty(&containerPty,
448
451
&containerPtyPath,
450
lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
451
_("failed to allocate tty: %s"), strerror(errno));
453
virReportSystemError(NULL, errno, "%s",
454
_("failed to allocate tty"));
531
534
if ((name = strdup(optarg)) == NULL) {
532
fprintf(stderr, "%s", strerror(errno));
535
virReportOOMError(NULL);
538
541
if (VIR_REALLOC_N(veths, nveths+1) < 0) {
539
fprintf(stderr, "cannot allocate veths %s", strerror(errno));
542
virReportOOMError(NULL);
542
545
if ((veths[nveths++] = strdup(optarg)) == NULL) {
543
fprintf(stderr, "cannot allocate veth name %s", strerror(errno));
546
virReportOOMError(NULL);
617
620
if ((rc = virFileWritePid(LXC_STATE_DIR, name, pid)) != 0) {
618
fprintf(stderr, _("Unable to write pid file: %s\n"),
621
virReportSystemError(NULL, rc,
622
_("Unable to write pid file '%s/%s.pid'"),
623
LXC_STATE_DIR, name);
629
633
/* Don't hold onto any cwd we inherit from libvirtd either */
630
634
if (chdir("/") < 0) {
631
fprintf(stderr, _("Unable to change to root dir: %s\n"),
635
virReportSystemError(NULL, errno, "%s",
636
_("Unable to change to root dir"));
636
640
if (setsid() < 0) {
637
fprintf(stderr, _("Unable to become session leader: %s\n"),
641
virReportSystemError(NULL, errno, "%s",
642
_("Unable to become session leader"));
643
647
/* Accept initial client which is the libvirtd daemon */
644
648
if ((client = accept(monitor, NULL, 0)) < 0) {
645
fprintf(stderr, _("Failed connection from LXC driver: %s\n"),
649
virReportSystemError(NULL, errno, "%s",
650
_("Failed connection from LXC driver"));