Commit 67ba7e5c authored by Manuel Stoeckl's avatar Manuel Stoeckl
Browse files

Fix minor issues with logging function

Trailing newlines are no longer required for log messages.

A small prefix letter now indicates a debug-level message,
and a large prefix letter indicates an error-level message.
parent d61d431c
......@@ -60,10 +60,10 @@ struct pidstack {
static int run_client_child(int chanfd, const char *socket_path)
{
wp_log(WP_DEBUG, "I'm a client on %s!\n", socket_path);
wp_log(WP_DEBUG, "I'm a client on %s!", socket_path);
struct wl_display *display = wl_display_connect(NULL);
if (!display) {
wp_log(WP_ERROR, "Failed to connect to a wayland server.\n");
wp_log(WP_ERROR, "Failed to connect to a wayland server.");
return EXIT_FAILURE;
}
int dispfd = wl_display_get_fd(display);
......@@ -75,14 +75,13 @@ static int run_client_child(int chanfd, const char *socket_path)
int run_client(const char *socket_path, bool oneshot, pid_t eol_pid)
{
if (verify_connection() == -1) {
wp_log(WP_ERROR,
"Failed to connect to a wayland compositor.\n");
wp_log(WP_ERROR, "Failed to connect to a wayland compositor.");
if (eol_pid) {
waitpid(eol_pid, NULL, 0);
}
return EXIT_FAILURE;
}
wp_log(WP_DEBUG, "A wayland compositor is available. Proceeding.\n");
wp_log(WP_DEBUG, "A wayland compositor is available. Proceeding.");
int nmaxclients = oneshot ? 1 : 3; // << todo, increase
int channelsock = setup_nb_socket(socket_path, nmaxclients);
......@@ -109,7 +108,7 @@ int run_client(const char *socket_path, bool oneshot, pid_t eol_pid)
if (eol_pid) {
int wp = waitpid(eol_pid, NULL, WNOHANG);
if (wp > 0) {
wp_log(WP_DEBUG, "Child (ssh) died, exiting\n");
wp_log(WP_DEBUG, "Child (ssh) died, exiting");
eol_pid = 0; // < recycled
retcode = EXIT_SUCCESS;
break;
......@@ -139,7 +138,7 @@ int run_client(const char *socket_path, bool oneshot, pid_t eol_pid)
// The wakeup may have been spurious
continue;
}
wp_log(WP_ERROR, "Connection failure: %s\n",
wp_log(WP_ERROR, "Connection failure: %s",
strerror(errno));
retcode = EXIT_FAILURE;
break;
......@@ -167,7 +166,7 @@ int run_client(const char *socket_path, bool oneshot, pid_t eol_pid)
// exit path?
return EXIT_SUCCESS;
} else if (npid == -1) {
wp_log(WP_DEBUG, "Fork failure\n");
wp_log(WP_DEBUG, "Fork failure");
retcode = EXIT_FAILURE;
break;
} else {
......
......@@ -204,7 +204,7 @@ static void event_wl_registry_global(void *data,
hide_me |= !strcmp(interface, "wl_shell");
if (hide_me) {
wp_log(WP_DEBUG, "Hiding %s advertisement\n", interface);
wp_log(WP_DEBUG, "Hiding %s advertisement", interface);
context->drop_this_msg = true;
}
......@@ -236,8 +236,8 @@ void request_wl_registry_bind(struct wl_client *client,
listset_remove(&context->mt->objects, the_object);
free(the_object);
wp_log(WP_DEBUG, "Binding fail name=%d %s id=%d (v%d)\n", name,
interface, id, version);
wp_log(WP_DEBUG, "Binding fail name=%d %s id=%d (v%d)", name, interface,
id, version);
(void)name;
(void)version;
}
......@@ -264,11 +264,11 @@ void request_wl_surface_attach(struct wl_client *client,
struct wp_object *bufobj = (struct wp_object *)buffer;
if (!bufobj) {
// todo: if nullable, handle error/abort earlier in the chain
wp_log(WP_ERROR, "Buffer to be attached is null\n");
wp_log(WP_ERROR, "Buffer to be attached is null");
return;
}
if (bufobj->type != &wl_buffer_interface) {
wp_log(WP_ERROR, "Buffer to be attached has the wrong type\n");
wp_log(WP_ERROR, "Buffer to be attached has the wrong type");
return;
}
struct wp_surface *surface = (struct wp_surface *)context->obj;
......@@ -292,23 +292,22 @@ void request_wl_surface_commit(
struct wp_object *obj = listset_get(
&context->mt->objects, surface->attached_buffer_id);
if (!obj) {
wp_log(WP_ERROR, "Attached buffer no longer exists\n");
wp_log(WP_ERROR, "Attached buffer no longer exists");
return;
}
if (obj->type != &wl_buffer_interface) {
wp_log(WP_ERROR,
"Buffer to commit has the wrong type, and may have been recycled\n");
"Buffer to commit has the wrong type, and may have been recycled");
return;
}
struct wp_buffer *buf = (struct wp_buffer *)obj;
struct shadow_fd *sfd = buf->owned_buffer;
if (!sfd) {
wp_log(WP_ERROR, "wp_buffer to be committed has no fd\n");
wp_log(WP_ERROR, "wp_buffer to be committed has no fd");
return;
}
if (sfd->type != FDC_FILE) {
wp_log(WP_ERROR,
"fd associated with surface is not file-like\n");
wp_log(WP_ERROR, "fd associated with surface is not file-like");
return;
}
if (!context->on_display_side) {
......@@ -375,12 +374,12 @@ static void event_wl_keyboard_keymap(void *data,
struct shadow_fd *sfd = get_shadow_for_local_fd(context->map, fd);
if (!sfd) {
wp_log(WP_ERROR, "Failed to find shadow matching lfd=%d\n", fd);
wp_log(WP_ERROR, "Failed to find shadow matching lfd=%d", fd);
return;
}
if (sfd->type != FDC_FILE || sfd->file_size != size) {
wp_log(WP_ERROR,
"keymap candidate RID=%d was not file-like (type=%d), and with size=%ld did not match %d\n",
"keymap candidate RID=%d was not file-like (type=%d), and with size=%ld did not match %d",
sfd->remote_id, sfd->type, sfd->file_size,
size);
return;
......@@ -400,7 +399,7 @@ static void request_wl_shm_create_pool(struct wl_client *client,
&context->mt->objects, id);
struct shadow_fd *sfd = get_shadow_for_local_fd(context->map, fd);
if (!sfd) {
wp_log(WP_ERROR, "Failed to find shadow matching lfd=%d\n", fd);
wp_log(WP_ERROR, "Failed to find shadow matching lfd=%d", fd);
return;
}
/* It may be valid for the file descriptor size to be larger than the
......@@ -409,7 +408,7 @@ static void request_wl_shm_create_pool(struct wl_client *client,
*/
if (sfd->type != FDC_FILE || (int32_t)sfd->file_size < size) {
wp_log(WP_ERROR,
"File type or size mismatch for RID=%d with claimed: %d %d | %ld %d\n",
"File type or size mismatch for RID=%d with claimed: %d %d | %ld %d",
sfd->remote_id, sfd->type, FDC_FILE,
sfd->file_size, size);
return;
......@@ -426,7 +425,7 @@ static void request_wl_shm_pool_resize(struct wl_client *client,
struct wp_shm_pool *the_shm_pool = (struct wp_shm_pool *)context->obj;
if (!the_shm_pool->owned_buffer) {
wp_log(WP_ERROR, "Pool to be resize owns no buffer\n");
wp_log(WP_ERROR, "Pool to be resize owns no buffer");
return;
}
if ((int32_t)the_shm_pool->owned_buffer->file_size >= size) {
......@@ -434,7 +433,7 @@ static void request_wl_shm_pool_resize(struct wl_client *client,
// this protocol message was received
return;
}
wp_log(WP_ERROR, "Pool resize to %d, TODO\n", size);
wp_log(WP_ERROR, "Pool resize to %d, TODO", size);
}
static void request_wl_shm_pool_create_buffer(struct wl_client *client,
struct wl_resource *resource, uint32_t id, int32_t offset,
......
......@@ -73,7 +73,7 @@ void listset_remove(struct obj_list *lst, struct wp_object *obj)
}
}
wp_log(WP_ERROR, "Object not in list\n");
wp_log(WP_ERROR, "Object not in list");
return;
}
struct wp_object *listset_get(struct obj_list *lst, uint32_t id)
......@@ -139,7 +139,7 @@ static void invoke_msg_handler(const struct wl_interface *intf,
ffi_type *call_types[30];
void *call_args_ptr[30];
if (strlen(msg->signature) > 30) {
wp_log(WP_ERROR, "Overly long signature for %s.%s: %s\n",
wp_log(WP_ERROR, "Overly long signature for %s.%s: %s",
intf->name, msg->name, msg->signature);
}
struct uarg call_args_val[30];
......@@ -284,7 +284,7 @@ static void invoke_msg_handler(const struct wl_interface *intf,
default:
wp_log(WP_DEBUG,
"For %s.%s, unidentified message type %c,\n",
"For %s.%s, unidentified message type %c,",
intf->name, msg->name, *c);
break;
}
......@@ -292,14 +292,14 @@ static void invoke_msg_handler(const struct wl_interface *intf,
continue;
len_overflow:
wp_log(WP_ERROR,
"Message %s.%s parse length overflow, bytes=%d/%d, fds=%d/%d, c=%c\n",
"Message %s.%s parse length overflow, bytes=%d/%d, fds=%d/%d, c=%c",
intf->name, msg->name, 4 * i, 4 * paylen,
*fds_used, fdlen, *c);
return;
}
if (i != paylen) {
wp_log(WP_ERROR,
"Parse error length mismatch for %s.%s: used %d expected %d\n",
"Parse error length mismatch for %s.%s: used %d expected %d",
intf->name, msg->name, i * 4, paylen * 4);
}
......@@ -329,7 +329,7 @@ enum message_action handle_message(struct message_tracker *mt,
}
if (len < 2 * (int)sizeof(uint32_t)) {
wp_log(WP_ERROR,
"Message length underflow (%d), probably parsing error\n",
"Message length underflow (%d), probably parsing error",
len);
*consumed_length = 0;
return MESSACT_ERROR;
......@@ -340,7 +340,7 @@ enum message_action handle_message(struct message_tracker *mt,
struct wp_object *objh = listset_get(&mt->objects, obj);
if (!objh || !objh->type) {
wp_log(WP_DEBUG, "Unidentified object %d with %s\n", obj,
wp_log(WP_DEBUG, "Unidentified object %d with %s", obj,
from_client ? "request" : "event");
*unidentified_changes = true;
return MESSACT_KEEP;
......@@ -352,7 +352,7 @@ enum message_action handle_message(struct message_tracker *mt,
msg = &intf->methods[meth];
} else {
wp_log(WP_DEBUG,
"Unidentified request #%d (of %d) on interface %s\n",
"Unidentified request #%d (of %d) on interface %s",
meth, intf->method_count, intf->name);
}
} else {
......@@ -360,12 +360,12 @@ enum message_action handle_message(struct message_tracker *mt,
msg = &intf->events[meth];
} else {
wp_log(WP_ERROR,
"Unidentified event #%d on interface %s\n",
"Unidentified event #%d on interface %s",
meth, intf->name);
}
}
if (!msg) {
wp_log(WP_DEBUG, "Unidentified %s from known object\n",
wp_log(WP_DEBUG, "Unidentified %s from known object",
from_client ? "request" : "event");
*unidentified_changes = true;
return MESSACT_KEEP;
......
......@@ -56,13 +56,12 @@ static int connect_to_channel(const char *socket_path)
strncpy(saddr.sun_path, socket_path, sizeof(saddr.sun_path) - 1);
chanfd = socket(AF_UNIX, SOCK_STREAM, 0);
if (chanfd == -1) {
wp_log(WP_ERROR, "Error creating socket: %s\n",
strerror(errno));
wp_log(WP_ERROR, "Error creating socket: %s", strerror(errno));
return -1;
}
if (connect(chanfd, (struct sockaddr *)&saddr, sizeof(saddr)) == -1) {
wp_log(WP_ERROR, "Error connecting to socket (%s): %s\n",
wp_log(WP_ERROR, "Error connecting to socket (%s): %s",
socket_path, strerror(errno));
close(chanfd);
return -1;
......@@ -73,13 +72,13 @@ static int connect_to_channel(const char *socket_path)
int run_server(const char *socket_path, bool oneshot, bool unlink_at_end,
char *const app_argv[])
{
wp_log(WP_DEBUG, "I'm a server on %s, running: %s\n", socket_path,
wp_log(WP_DEBUG, "I'm a server on %s, running: %s", socket_path,
app_argv[0]);
if (strlen(socket_path) >=
sizeof(((struct sockaddr_un *)NULL)->sun_path)) {
wp_log(WP_ERROR,
"Socket path is too long and would be truncated: %s\n",
"Socket path is too long and would be truncated: %s",
socket_path);
return EXIT_FAILURE;
}
......@@ -91,12 +90,12 @@ int run_server(const char *socket_path, bool oneshot, bool unlink_at_end,
if (oneshot) {
int csockpair[2];
if (socketpair(AF_UNIX, SOCK_STREAM, 0, csockpair) == -1) {
wp_log(WP_ERROR, "Socketpair failed: %s\n",
wp_log(WP_ERROR, "Socketpair failed: %s",
strerror(errno));
return EXIT_FAILURE;
}
if (set_fnctl_flag(csockpair[0], FD_CLOEXEC) == -1) {
wp_log(WP_ERROR, "Fnctl failed: %s\n", strerror(errno));
wp_log(WP_ERROR, "Fnctl failed: %s", strerror(errno));
return EXIT_FAILURE;
}
wayland_socket = csockpair[1];
......@@ -114,7 +113,7 @@ int run_server(const char *socket_path, bool oneshot, bool unlink_at_end,
// Launch program
pid_t pid = fork();
if (pid == -1) {
wp_log(WP_ERROR, "Fork failed\n");
wp_log(WP_ERROR, "Fork failed");
if (!oneshot) {
unlink(displaypath);
}
......@@ -137,7 +136,7 @@ int run_server(const char *socket_path, bool oneshot, bool unlink_at_end,
}
execvp(app_argv[0], app_argv);
wp_log(WP_ERROR, "Failed to execvp \'%s\': %s\n", app_argv[0],
wp_log(WP_ERROR, "Failed to execvp \'%s\': %s", app_argv[0],
strerror(errno));
return EXIT_FAILURE;
}
......@@ -146,7 +145,7 @@ int run_server(const char *socket_path, bool oneshot, bool unlink_at_end,
close(wayland_socket);
}
wp_log(WP_DEBUG, "Server main!\n");
wp_log(WP_DEBUG, "Server main!");
int retval = EXIT_SUCCESS;
if (oneshot) {
......@@ -155,7 +154,7 @@ int run_server(const char *socket_path, bool oneshot, bool unlink_at_end,
unlink(socket_path);
}
wp_log(WP_DEBUG, "Oneshot connected\n");
wp_log(WP_DEBUG, "Oneshot connected");
if (chanfd != -1) {
retval = run_server_child(chanfd, server_link);
} else {
......@@ -175,11 +174,11 @@ int run_server(const char *socket_path, bool oneshot, bool unlink_at_end,
int wp = waitpid(pid, NULL, WNOHANG);
if (wp > 0) {
wp_log(WP_DEBUG,
"Child program has died, exiting\n");
"Child program has died, exiting");
retval = EXIT_SUCCESS;
break;
} else if (wp == -1) {
wp_log(WP_ERROR, "Failed in waitpid: %s\n",
wp_log(WP_ERROR, "Failed in waitpid: %s",
strerror(errno));
retval = EXIT_FAILURE;
break;
......@@ -194,7 +193,7 @@ int run_server(const char *socket_path, bool oneshot, bool unlink_at_end,
// If SIGINT, the loop ends
continue;
}
fprintf(stderr, "Poll failed: %s\n",
fprintf(stderr, "Poll failed: %s",
strerror(errno));
retval = EXIT_FAILURE;
break;
......@@ -208,7 +207,7 @@ int run_server(const char *socket_path, bool oneshot, bool unlink_at_end,
// The wakeup may have been spurious
continue;
}
wp_log(WP_ERROR, "Connection failure: %s\n",
wp_log(WP_ERROR, "Connection failure: %s",
strerror(errno));
retval = EXIT_FAILURE;
break;
......@@ -232,7 +231,7 @@ int run_server(const char *socket_path, bool oneshot, bool unlink_at_end,
run_server_child(chanfd, appfd);
return EXIT_SUCCESS;
} else if (npid == -1) {
wp_log(WP_DEBUG, "Fork failure\n");
wp_log(WP_DEBUG, "Fork failure");
retval = EXIT_FAILURE;
break;
} else {
......@@ -254,7 +253,7 @@ int run_server(const char *socket_path, bool oneshot, bool unlink_at_end,
}
close(wdisplay_socket);
// Wait for child processes to exit
wp_log(WP_DEBUG, "Waiting for child handlers\n");
wp_log(WP_DEBUG, "Waiting for child handlers");
wait_on_children(&children, shutdown_flag ? WNOHANG : 0);
// Free stack, in case we suddenly shutdown and fail to clean up
// children
......@@ -269,8 +268,8 @@ int run_server(const char *socket_path, bool oneshot, bool unlink_at_end,
unlink(displaypath);
}
// todo: scope manipulation, to ensure all cleanups are done
wp_log(WP_DEBUG, "Waiting for child process\n");
wp_log(WP_DEBUG, "Waiting for child process");
waitpid(pid, NULL, shutdown_flag ? WNOHANG : 0);
wp_log(WP_DEBUG, "Program ended\n");
wp_log(WP_DEBUG, "Program ended");
return retval;
}
......@@ -7,7 +7,7 @@ waypipe=`which waypipe`
program=`which ${1:-weston-terminal}`
debug=
#debug=-d
debug=-d
# Orange=client, purple=server
......
This diff is collapsed.
......@@ -28,7 +28,6 @@
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
......@@ -55,8 +54,8 @@ typedef enum { WP_DEBUG = 1, WP_ERROR = 2 } log_cat_t;
extern char waypipe_log_mode;
extern log_cat_t waypipe_loglevel;
// mutates a static local, hence can only be called singlethreaded
const char *static_timestamp(void);
void wp_log_handler(const char *file, int line, log_cat_t level,
const char *fmt, ...);
#ifndef WAYPIPE_SRC_DIR_LENGTH
#define WAYPIPE_SRC_DIR_LENGTH 0
......@@ -64,10 +63,8 @@ const char *static_timestamp(void);
// no trailing ;, user must supply
#define wp_log(level, fmt, ...) \
if ((level) >= waypipe_loglevel) \
fprintf(stderr, "%c%d:%s [%s:%3d] " fmt, waypipe_log_mode, getpid(), \
static_timestamp(), \
((const char *)__FILE__) + WAYPIPE_SRC_DIR_LENGTH, \
__LINE__, ##__VA_ARGS__)
wp_log_handler(((const char *)__FILE__) + WAYPIPE_SRC_DIR_LENGTH, \
__LINE__, (level), fmt, ##__VA_ARGS__)
struct fd_translation_map {
struct shadow_fd *list;
......
......@@ -242,7 +242,7 @@ int main(int argc, char **argv)
argc--;
}
waypipe_loglevel = debug ? WP_DEBUG : WP_ERROR;
waypipe_log_mode = is_client ? 'C' : 'S';
waypipe_log_mode = setup_ssh ? 'c' : (is_client ? 'C' : 'S');
// Setup signals
struct sigaction ia; // SIGINT: abort operations, and set a flag
......@@ -254,11 +254,11 @@ int main(int argc, char **argv)
sigemptyset(&ca.sa_mask);
ca.sa_flags = SA_RESTART | SA_NOCLDSTOP;
if (sigaction(SIGINT, &ia, NULL) == -1) {
wp_log(WP_ERROR, "Failed to set signal action for SIGINT\n");
wp_log(WP_ERROR, "Failed to set signal action for SIGINT");
return EXIT_FAILURE;
}
if (sigaction(SIGCHLD, &ca, NULL) == -1) {
wp_log(WP_ERROR, "Failed to set signal action for SIGCHLD\n");
wp_log(WP_ERROR, "Failed to set signal action for SIGCHLD");
return EXIT_FAILURE;
}
......@@ -292,7 +292,7 @@ int main(int argc, char **argv)
pid_t conn_pid = fork();
if (conn_pid == -1) {
wp_log(WP_ERROR, "Fork failure\n");
wp_log(WP_ERROR, "Fork failure");
return EXIT_FAILURE;
} else if (conn_pid == 0) {
int dstidx = locate_openssh_cmd_hostname(
......@@ -310,10 +310,8 @@ int main(int argc, char **argv)
arglist[offset++] = "/usr/bin/ssh";
/* Force tty allocation. The user-override is a
* -T flag. Unfortunately, -t disables newline
* translation on the local side, so when using
* debug messages, it is often nicer to store
* stderr and display it somewhere else, to
* avoid a staircasing effect when rendering
* translation on the local side; see
* `wp_log_handler`.
*/
arglist[offset++] = "-t";
arglist[offset++] = "-R";
......@@ -341,7 +339,7 @@ int main(int argc, char **argv)
// execvp effectively frees arglist
execvp(arglist[0], arglist);
wp_log(WP_ERROR, "Fork failed\n");
wp_log(WP_ERROR, "Fork failed");
free(arglist);
return EXIT_FAILURE;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment