* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#define _GNU_SOURCE
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif
#define __STDC_FORMAT_MACROS /* Required for PRIu64 to work. */
-#include <stdint.h>
-#include <stdio.h>
#include <errno.h>
+#include <fcntl.h>
#include <inttypes.h>
#include <limits.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <string.h>
#include <pthread.h>
-
-#include <syslog.h>
+#include <stdint.h>
#include <stdio.h>
-
-#include <fcntl.h>
#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <syslog.h>
+#include <unistd.h>
-#include "log.h"
#include "caps.h"
-#include "utils.h"
+#include "config.h"
+#include "file_utils.h"
+#include "log.h"
#include "lxccontainer.h"
+#include "utils.h"
#ifndef HAVE_STRLCPY
#include "include/strlcpy.h"
return NULL;
va_copy(args, *event->vap);
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wformat-nonliteral"
len = vsnprintf(NULL, 0, event->fmt, args) + 1;
+#pragma GCC diagnostic pop
va_end(args);
msg = malloc(len * sizeof(char));
if (!msg)
return NULL;
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wformat-nonliteral"
rc = vsnprintf(msg, len, event->fmt, *event->vap);
+#pragma GCC diagnostic pop
if (rc == -1 || rc >= len) {
free(msg);
return NULL;
log_container_name ? ": " : "");
fprintf(stderr, "%s: %s: %d ", event->locinfo->file,
event->locinfo->func, event->locinfo->line);
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wformat-nonliteral"
vfprintf(stderr, event->fmt, *event->vap);
+#pragma GCC diagnostic pop
fprintf(stderr, "\n");
return 0;
/* Transform hours to seconds. */
h_in_s = hours * 3600;
- /* Calculate minutes by substracting the seconds for all days in the
+ /* Calculate minutes by subtracting the seconds for all days in the
* epoch and for all hours in the epoch and divide by the number of
* minutes in an hour.
*/
minutes = (time->tv_sec - d_in_s - h_in_s) / 60;
- /* Calculate the seconds by substracting the seconds for all days in the
+ /* Calculate the seconds by subtracting the seconds for all days in the
* epoch, hours in the epoch and minutes in the epoch.
*/
seconds = (time->tv_sec - d_in_s - h_in_s - (minutes * 60));
* think you are, you __will__ cause trouble using them.
* (As a short example how this can cause trouble: LXD uses forkstart to fork
* off a new process that runs the container. At the same time the go runtime
- * LXD relies on does its own multi-threading thing which we can't controll. The
+ * LXD relies on does its own multi-threading thing which we can't control. The
* fork()ing + threading then seems to mess with the locking states in these
* time functions causing deadlocks.)
* The current solution is to be good old unix people and use the Epoch as our
if (n < 0)
return n;
- if ((size_t)n < (sizeof(buffer) - 1)) {
+ if ((size_t)n < STRARRAYLEN(buffer)) {
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wformat-nonliteral"
ret = vsnprintf(buffer + n, sizeof(buffer) - n, event->fmt, *event->vap);
+#pragma GCC diagnostic pop
if (ret < 0)
return 0;
}
if ((size_t)n >= sizeof(buffer))
- n = sizeof(buffer) - 1;
+ n = STRARRAYLEN(buffer);
buffer[n] = '\n';
-again:
- ret = write(fd_to_use, buffer, n + 1);
- if (ret < 0 && errno == EINTR)
- goto again;
-
- return ret;
+ return lxc_write_nointr(fd_to_use, buffer, n + 1);
}
#if HAVE_DLOG
ret = lxc_unpriv(mkdir(n, 0755));
if (ret && errno != EEXIST) {
- SYSERROR("Failed to create directory %s", n);
+ SYSERROR("Failed to create directory \"%s\"", n);
free(n);
return -1;
}
int fd;
int newfd;
- fd = lxc_unpriv(open(name, O_CREAT | O_WRONLY | O_APPEND | O_CLOEXEC, 0666));
+ fd = lxc_unpriv(open(name, O_CREAT | O_WRONLY | O_APPEND | O_CLOEXEC, 0660));
if (fd < 0) {
SYSERROR("Failed to open log file \"%s\"", name);
return -1;
/*
* lxc_log_init:
* Called from lxc front-end programs (like lxc-create, lxc-start) to
- * initalize the log defaults.
+ * initialize the log defaults.
*/
int lxc_log_init(struct lxc_log *log)
{
inline void lxc_log_set_prefix(const char *prefix)
{
- /* We don't care if thte prefix is truncated. */
+ /* We don't care if the prefix is truncated. */
(void)strlcpy(log_prefix, prefix, sizeof(log_prefix));
}