mirror of
https://git.proxmox.com/git/mirror_lxc
synced 2025-07-23 20:32:17 +00:00
format and fix small typos
Indent and make the code cleaner. Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
This commit is contained in:
parent
fa4b063c6e
commit
ded1d23faa
@ -36,11 +36,24 @@
|
|||||||
#include "mainloop.h"
|
#include "mainloop.h"
|
||||||
#include "af_unix.h"
|
#include "af_unix.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file provides the different functions to have the client
|
||||||
|
* and the server to communicate
|
||||||
|
*
|
||||||
|
* Each command is transactional, the client send a request to
|
||||||
|
* the server and the server answer the request with a message
|
||||||
|
* giving the request's status (zero or a negative errno value).
|
||||||
|
*
|
||||||
|
* Each command is wrapped in a ancillary message in order to pass
|
||||||
|
* a credential making possible to the server to check if the client
|
||||||
|
* is allowed to ask for this command or not.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
lxc_log_define(lxc_commands, lxc);
|
lxc_log_define(lxc_commands, lxc);
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------
|
#define abstractname "LXCPATH/%s/command"
|
||||||
* functions used by processes requesting command to lxc-start
|
|
||||||
*--------------------------------------------------------------------------*/
|
|
||||||
static int receive_answer(int sock, struct lxc_answer *answer)
|
static int receive_answer(int sock, struct lxc_answer *answer)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
@ -59,7 +72,7 @@ extern int lxc_command(const char *name, struct lxc_command *command,
|
|||||||
char path[sizeof(((struct sockaddr_un *)0)->sun_path)] = { 0 };
|
char path[sizeof(((struct sockaddr_un *)0)->sun_path)] = { 0 };
|
||||||
char *offset = &path[1];
|
char *offset = &path[1];
|
||||||
|
|
||||||
sprintf(offset, "/var/run/lxc/%s/command", name);
|
sprintf(offset, abstractname, name);
|
||||||
|
|
||||||
sock = lxc_af_unix_connect(path);
|
sock = lxc_af_unix_connect(path);
|
||||||
if (sock < 0 && errno == ECONNREFUSED) {
|
if (sock < 0 && errno == ECONNREFUSED) {
|
||||||
@ -94,22 +107,15 @@ out_close:
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------
|
extern void lxc_console_remove_fd(int, struct lxc_tty_info *);
|
||||||
* functions used by lxc-start process
|
extern int lxc_console_callback(int, struct lxc_request *, struct lxc_handler *);
|
||||||
*--------------------------------------------------------------------------*/
|
extern int lxc_stop_callback(int, struct lxc_request *, struct lxc_handler *);
|
||||||
extern void lxc_console_remove_fd(int fd, struct lxc_tty_info *tty_info);
|
extern int lxc_state_callback(int, struct lxc_request *, struct lxc_handler *);
|
||||||
extern int lxc_console_callback(int fd, struct lxc_request *request,
|
|
||||||
struct lxc_handler *handler);
|
|
||||||
extern int lxc_stop_callback(int fd, struct lxc_request *request,
|
|
||||||
struct lxc_handler *handler);
|
|
||||||
extern int lxc_state_callback(int fd, struct lxc_request *request,
|
|
||||||
struct lxc_handler *handler);
|
|
||||||
|
|
||||||
static int trigger_command(int fd, struct lxc_request *request,
|
static int trigger_command(int fd, struct lxc_request *request,
|
||||||
struct lxc_handler *handler)
|
struct lxc_handler *handler)
|
||||||
{
|
{
|
||||||
typedef int (*callback)(int, struct lxc_request *,
|
typedef int (*callback)(int, struct lxc_request *, struct lxc_handler *);
|
||||||
struct lxc_handler *);
|
|
||||||
|
|
||||||
callback cb[LXC_COMMAND_MAX] = {
|
callback cb[LXC_COMMAND_MAX] = {
|
||||||
[LXC_COMMAND_TTY] = lxc_console_callback,
|
[LXC_COMMAND_TTY] = lxc_console_callback,
|
||||||
@ -131,8 +137,7 @@ static void command_fd_cleanup(int fd, struct lxc_handler *handler,
|
|||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int command_handler(int fd, void *data,
|
static int command_handler(int fd, void *data, struct lxc_epoll_descr *descr)
|
||||||
struct lxc_epoll_descr *descr)
|
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
struct lxc_request request;
|
struct lxc_request request;
|
||||||
@ -144,7 +149,9 @@ static int command_handler(int fd, void *data,
|
|||||||
struct lxc_answer answer = { .ret = ret };
|
struct lxc_answer answer = { .ret = ret };
|
||||||
send(fd, &answer, sizeof(answer), 0);
|
send(fd, &answer, sizeof(answer), 0);
|
||||||
goto out_close;
|
goto out_close;
|
||||||
} else if (ret < 0) {
|
}
|
||||||
|
|
||||||
|
if (ret < 0) {
|
||||||
SYSERROR("failed to receive data on command socket");
|
SYSERROR("failed to receive data on command socket");
|
||||||
goto out_close;
|
goto out_close;
|
||||||
}
|
}
|
||||||
@ -176,7 +183,7 @@ out_close:
|
|||||||
static int incoming_command_handler(int fd, void *data,
|
static int incoming_command_handler(int fd, void *data,
|
||||||
struct lxc_epoll_descr *descr)
|
struct lxc_epoll_descr *descr)
|
||||||
{
|
{
|
||||||
int ret = 1, connection;
|
int opt = 1, ret = -1, connection;
|
||||||
|
|
||||||
connection = accept(fd, NULL, 0);
|
connection = accept(fd, NULL, 0);
|
||||||
if (connection < 0) {
|
if (connection < 0) {
|
||||||
@ -184,7 +191,7 @@ static int incoming_command_handler(int fd, void *data,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (setsockopt(connection, SOL_SOCKET, SO_PASSCRED, &ret, sizeof(ret))) {
|
if (setsockopt(connection, SOL_SOCKET, SO_PASSCRED, &opt, sizeof(opt))) {
|
||||||
SYSERROR("failed to enable credential on socket");
|
SYSERROR("failed to enable credential on socket");
|
||||||
goto out_close;
|
goto out_close;
|
||||||
}
|
}
|
||||||
@ -210,7 +217,7 @@ extern int lxc_command_mainloop_add(const char *name, struct lxc_epoll_descr *de
|
|||||||
char path[sizeof(((struct sockaddr_un *)0)->sun_path)] = { 0 };
|
char path[sizeof(((struct sockaddr_un *)0)->sun_path)] = { 0 };
|
||||||
char *offset = &path[1];
|
char *offset = &path[1];
|
||||||
|
|
||||||
sprintf(offset, "/var/run/lxc/%s/command", name);
|
sprintf(offset, abstractname, name);
|
||||||
|
|
||||||
fd = lxc_af_unix_open(path, SOCK_STREAM, 0);
|
fd = lxc_af_unix_open(path, SOCK_STREAM, 0);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
@ -218,8 +225,7 @@ extern int lxc_command_mainloop_add(const char *name, struct lxc_epoll_descr *de
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = lxc_mainloop_add_handler(descr, fd, incoming_command_handler,
|
ret = lxc_mainloop_add_handler(descr, fd, incoming_command_handler, handler);
|
||||||
handler);
|
|
||||||
if (ret) {
|
if (ret) {
|
||||||
ERROR("failed to add handler for command socket");
|
ERROR("failed to add handler for command socket");
|
||||||
close(fd);
|
close(fd);
|
||||||
|
Loading…
Reference in New Issue
Block a user