Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/cgroup.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ static gboolean oom_cb_cgroup_v2(int fd, GIOCondition condition, G_GNUC_UNUSED g
ssize_t num_read = read(fd, &events, events_size);
if (num_read < 0) {
nwarn("Failed to read oom event from eventfd in v2");
/* On non-recoverable errors, remove the source */
if (errno != EAGAIN && errno != EWOULDBLOCK && errno != EINTR)
return G_SOURCE_REMOVE;
return G_SOURCE_CONTINUE;
}

Expand Down Expand Up @@ -234,6 +237,9 @@ static gboolean oom_cb_cgroup_v1(int fd, GIOCondition condition, gpointer user_d
ssize_t num_read = read(fd, &event_count, sizeof(uint64_t));
if (num_read < 0) {
nwarn("Failed to read oom event from eventfd");
/* On non-recoverable errors, remove the source */
if (errno != EAGAIN && errno != EWOULDBLOCK && errno != EINTR)
return G_SOURCE_REMOVE;
return G_SOURCE_CONTINUE;
}

Expand Down Expand Up @@ -276,6 +282,11 @@ gboolean check_cgroup2_oom()
if (!is_cgroup_v2)
return G_SOURCE_REMOVE;

if (!cgroup2_path) {
nwarn("cgroup2_path not initialized");
return G_SOURCE_REMOVE;
}

_cleanup_free_ char *memory_events_file_path = g_build_filename(cgroup2_path, "memory.events", NULL);

_cleanup_fclose_ FILE *fp = fopen(memory_events_file_path, "re");
Expand Down
1 change: 0 additions & 1 deletion src/cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ void process_cli()
}

// we should always override the container pid file if it's empty
// TODO FIXME I removed default_pid_file here. shouldn't opt_container_pid_file be cleaned up?
if (opt_container_pid_file == NULL)
opt_container_pid_file = g_strdup_printf("%s/pidfile-%s", cwd, opt_cid);

Expand Down
2 changes: 0 additions & 2 deletions src/conmon.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,6 @@ int main(int argc, char *argv[])
if (workerfd_stdout != dev_null_w && fchmod(STDOUT_FILENO, 0777) < 0 && errno != EINVAL)
nwarn("Failed to chmod stdout");

if (workerfd_stderr < 0)
workerfd_stderr = workerfd_stdout;
if (dup2(workerfd_stderr, STDERR_FILENO) < 0)
_pexit("Failed to dup over stderr");
if (workerfd_stderr != dev_null_w && fchmod(STDERR_FILENO, 0777) < 0 && errno != EINVAL)
Expand Down
1 change: 1 addition & 0 deletions src/conn_sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ static void bind_relative_to_dir(int dir_fd, int sock_fd, const char *path)
addr.sun_family = AF_UNIX;
if (dir_fd == -1) {
strncpy(addr.sun_path, path, sizeof(addr.sun_path) - 1);
addr.sun_path[sizeof(addr.sun_path) - 1] = '\0';
} else {
snprintf(addr.sun_path, sizeof(addr.sun_path), "/proc/self/fd/%d/%s", dir_fd, path);
}
Expand Down
10 changes: 4 additions & 6 deletions src/ctr_exit.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
#include <stdlib.h>
#include <unistd.h>

volatile pid_t container_pid = -1;
volatile pid_t create_pid = -1;
volatile sig_atomic_t container_pid = -1;
volatile sig_atomic_t create_pid = -1;

void on_sig_exit(int signal)
{
Expand Down Expand Up @@ -206,9 +206,7 @@ void do_exit_command()
for (; opt_exit_args[n_args]; n_args++)
;

gchar **args = malloc(sizeof(gchar *) * (n_args + 2));
if (args == NULL)
_exit(EXIT_FAILURE);
gchar **args = g_malloc(sizeof(gchar *) * (n_args + 2));

args[0] = opt_exit_command;
if (opt_exit_args)
Expand Down Expand Up @@ -249,5 +247,5 @@ void cleanup_socket_dir_symlink()

void handle_signal(G_GNUC_UNUSED const int signum)
{
exit(EXIT_FAILURE);
_exit(EXIT_FAILURE);
}
5 changes: 3 additions & 2 deletions src/ctr_exit.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
#define CTR_EXIT_H

#include <sys/types.h> /* pid_t */
#include <signal.h> /* sig_atomic_t */
#include <glib.h> /* gpointer, gboolean, GHashTable, and GPid */


extern volatile pid_t container_pid;
extern volatile pid_t create_pid;
extern volatile sig_atomic_t container_pid;
extern volatile sig_atomic_t create_pid;

struct pid_check_data {
GHashTable *pid_to_handler;
Expand Down
8 changes: 4 additions & 4 deletions src/ctrl.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ static gboolean process_winsz_ctrl_line(char *line)
int height, width, ret = -1;
ret = sscanf(line, "%d %d\n", &height, &width);
ndebugf("Height: %d, Width: %d", height, width);
if (ret != 2) {
nwarn("Failed to sscanf message");
if (ret != 2 || height < 0 || width < 0) {
nwarn("Failed to parse window size message");
return FALSE;
}
resize_winsz(height, width);
Expand Down Expand Up @@ -137,8 +137,8 @@ static gboolean process_terminal_ctrl_line(char *line)
*/
int ctl_msg_type, height, width, ret = -1;
ret = sscanf(line, "%d %d %d\n", &ctl_msg_type, &height, &width);
if (ret != 3) {
nwarn("Failed to sscanf message");
if (ret != 3 || height < 0 || width < 0) {
nwarn("Failed to parse control message");
return FALSE;
}

Expand Down
1 change: 0 additions & 1 deletion src/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <glib.h> /* gboolean and GMainLoop */

/* Global state */
// TODO FIXME not static
extern int runtime_status;
extern int container_status;

Expand Down
Loading