Skip to content

Commit

Permalink
monitor: log cleanups
Browse files Browse the repository at this point in the history
Signed-off-by: 2xsec <dh48.jeong@samsung.com>
  • Loading branch information
2xsec committed Oct 12, 2018
1 parent af5e7ee commit 6dd32d3
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions src/lxc/monitor.c
Expand Up @@ -73,7 +73,7 @@ int lxc_monitor_fifo_name(const char *lxcpath, char *fifo_path, size_t fifo_path
if (do_mkdirp) {
ret = snprintf(fifo_path, fifo_path_sz, "%s/lxc/%s", rundir, lxcpath);
if (ret < 0 || (size_t)ret >= fifo_path_sz) {
ERROR("rundir/lxcpath (%s/%s) too long for monitor fifo.", rundir, lxcpath);
ERROR("rundir/lxcpath (%s/%s) too long for monitor fifo", rundir, lxcpath);
free(rundir);
return -1;
}
Expand All @@ -86,7 +86,7 @@ int lxc_monitor_fifo_name(const char *lxcpath, char *fifo_path, size_t fifo_path
}
ret = snprintf(fifo_path, fifo_path_sz, "%s/lxc/%s/monitor-fifo", rundir, lxcpath);
if (ret < 0 || (size_t)ret >= fifo_path_sz) {
ERROR("rundir/lxcpath (%s/%s) too long for monitor fifo.", rundir, lxcpath);
ERROR("rundir/lxcpath (%s/%s) too long for monitor fifo", rundir, lxcpath);
free(rundir);
return -1;
}
Expand Down Expand Up @@ -128,7 +128,7 @@ static void lxc_monitor_fifo_send(struct lxc_msg *msg, const char *lxcpath)
ret = lxc_write_nointr(fd, msg, sizeof(*msg));
if (ret != sizeof(*msg)) {
close(fd);
SYSERROR("Failed to write to monitor fifo \"%s\".", fifo_path);
SYSERROR("Failed to write to monitor fifo \"%s\"", fifo_path);
return;
}

Expand Down Expand Up @@ -185,7 +185,7 @@ int lxc_monitor_sock_name(const char *lxcpath, struct sockaddr_un *addr) {
path = alloca(len);
ret = snprintf(path, len, "lxc/%s/monitor-sock", lxcpath);
if (ret < 0 || (size_t)ret >= len) {
ERROR("failed to create name for monitor socket");
ERROR("Failed to create name for monitor socket");
return -1;
}

Expand All @@ -198,13 +198,13 @@ int lxc_monitor_sock_name(const char *lxcpath, struct sockaddr_un *addr) {
hash = fnv_64a_buf(path, ret, FNV1A_64_INIT);
ret = snprintf(addr->sun_path, len, "@lxc/%016" PRIx64 "/%s", hash, lxcpath);
if (ret < 0) {
ERROR("failed to create hashed name for monitor socket");
ERROR("Failed to create hashed name for monitor socket");
return -1;
}

/* replace @ with \0 */
addr->sun_path[0] = '\0';
INFO("using monitor socket name \"%s\" (length of socket name %zu must be <= %zu)", &addr->sun_path[1], strlen(&addr->sun_path[1]), sizeof(addr->sun_path) - 3);
INFO("Using monitor socket name \"%s\" (length of socket name %zu must be <= %zu)", &addr->sun_path[1], strlen(&addr->sun_path[1]), sizeof(addr->sun_path) - 3);

return 0;
}
Expand All @@ -221,7 +221,7 @@ int lxc_monitor_open(const char *lxcpath)
return -1;

len = strlen(&addr.sun_path[1]);
DEBUG("opening monitor socket %s with len %zu", &addr.sun_path[1], len);
DEBUG("Opening monitor socket %s with len %zu", &addr.sun_path[1], len);
if (len >= sizeof(addr.sun_path) - 1) {
errno = ENAMETOOLONG;
SYSERROR("The name of monitor socket too long (%zu bytes)", len);
Expand Down Expand Up @@ -272,7 +272,7 @@ int lxc_monitor_read_fdset(struct pollfd *fds, nfds_t nfds, struct lxc_msg *msg,
}
}

SYSERROR("No ready fd found.");
SYSERROR("No ready fd found");

return -1;
}
Expand Down Expand Up @@ -315,33 +315,33 @@ int lxc_monitord_spawn(const char *lxcpath)
/* double fork to avoid zombies when monitord exits */
pid1 = fork();
if (pid1 < 0) {
SYSERROR("Failed to fork().");
SYSERROR("Failed to fork()");
return -1;
}

if (pid1) {
DEBUG("Going to wait for pid %d.", pid1);
DEBUG("Going to wait for pid %d", pid1);

if (waitpid(pid1, NULL, 0) != pid1)
return -1;

DEBUG("Finished waiting on pid %d.", pid1);
DEBUG("Finished waiting on pid %d", pid1);
return 0;
}

if (pipe(pipefd) < 0) {
SYSERROR("Failed to create pipe.");
SYSERROR("Failed to create pipe");
_exit(EXIT_FAILURE);
}

pid2 = fork();
if (pid2 < 0) {
SYSERROR("Failed to fork().");
SYSERROR("Failed to fork()");
_exit(EXIT_FAILURE);
}

if (pid2) {
DEBUG("Trying to sync with child process.");
DEBUG("Trying to sync with child process");
char c;
/* Wait for daemon to create socket. */
close(pipefd[1]);
Expand All @@ -356,33 +356,33 @@ int lxc_monitord_spawn(const char *lxcpath)

close(pipefd[0]);

DEBUG("Successfully synced with child process.");
DEBUG("Successfully synced with child process");
_exit(EXIT_SUCCESS);
}

if (setsid() < 0) {
SYSERROR("Failed to setsid().");
SYSERROR("Failed to setsid()");
_exit(EXIT_FAILURE);
}

lxc_check_inherited(NULL, true, &pipefd[1], 1);
if (null_stdfds() < 0) {
SYSERROR("Failed to dup2() standard file descriptors to /dev/null.");
SYSERROR("Failed to dup2() standard file descriptors to /dev/null");
_exit(EXIT_FAILURE);
}

close(pipefd[0]);

ret = snprintf(pipefd_str, sizeof(pipefd_str), "%d", pipefd[1]);
if (ret < 0 || ret >= sizeof(pipefd_str)) {
ERROR("Failed to create pid argument to pass to monitord.");
ERROR("Failed to create pid argument to pass to monitord");
_exit(EXIT_FAILURE);
}

DEBUG("Using pipe file descriptor %d for monitord.", pipefd[1]);
DEBUG("Using pipe file descriptor %d for monitord", pipefd[1]);

execvp(args[0], args);
SYSERROR("failed to exec lxc-monitord");
SYSERROR("Failed to exec lxc-monitord");

_exit(EXIT_FAILURE);
}

0 comments on commit 6dd32d3

Please sign in to comment.