aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaeMan Park <jaeman@google.com>2021-10-07 16:18:20 +0900
committerJaeMan Park <jaeman@google.com>2021-11-12 11:22:41 +0900
commit62f1c825c48e257bfd304a5f34a897c1ee1de596 (patch)
treee316d3688f67aefa3fe7dfceb17c39aef474a920
parent8122ca0b01da720c849846756671b058a5075e5e (diff)
downloadwmediumd-62f1c825c48e257bfd304a5f34a897c1ee1de596.tar.gz
Ignore SIGPIPE when using api server
Wmediumd exits with unhandled signal because signal SIGPIPE is received when wmediumd tries to write closed api socket. So, set wmediumd to ignore SIGPIPE and check write result to handle writing to closed client socket. Bug: 201616800 Test: lunch aosp_cf_x86_64_phone-userdebug && m PRODUCT_ENFORCE_MAC80211_HWSIM=true droid wmediumd && launch_cvd --ap_rootfs_image=$(path for OpenWRT image) \ --ap_kernel_image=$(path for OpenWRT kernel image) And then, control wmediumd with wmediumd_control Change-Id: I07428695c8f5a2469b429f7d0b5e33091ad9b985
-rw-r--r--wmediumd/wmediumd.c27
1 files changed, 23 insertions, 4 deletions
diff --git a/wmediumd/wmediumd.c b/wmediumd/wmediumd.c
index 8a59782..1f91508 100644
--- a/wmediumd/wmediumd.c
+++ b/wmediumd/wmediumd.c
@@ -275,6 +275,8 @@ static void wmediumd_wait_for_client_ack(struct wmediumd *ctx,
usfstl_loop_wait_and_handle();
}
+static void wmediumd_remove_client(struct wmediumd *ctx, struct client *client);
+
static void wmediumd_notify_frame_start(struct usfstl_job *job)
{
struct frame *frame = container_of(job, struct frame, start_job);
@@ -304,7 +306,11 @@ static void wmediumd_notify_frame_start(struct usfstl_job *job)
/* must be API socket since flags cannot otherwise be set */
assert(client->type == CLIENT_API_SOCK);
- write(client->loop.fd, &msg, sizeof(msg));
+ if (write(client->loop.fd, &msg, sizeof(msg)) < sizeof(msg)) {
+ usfstl_loop_unregister(&client->loop);
+ wmediumd_remove_client(ctx, client);
+ continue;
+ }
wmediumd_wait_for_client_ack(ctx, client);
}
@@ -548,11 +554,22 @@ static void wmediumd_send_to_client(struct wmediumd *ctx,
len = nlmsg_total_size(nlmsg_datalen(nlmsg_hdr(msg)));
hdr.type = WMEDIUMD_MSG_NETLINK;
hdr.data_len = len;
- write(client->loop.fd, &hdr, sizeof(hdr));
- write(client->loop.fd, (void *)nlmsg_hdr(msg), len);
+
+ if (write(client->loop.fd, &hdr, sizeof(hdr)) < sizeof(hdr))
+ goto disconnect;
+
+ if (write(client->loop.fd, (void *)nlmsg_hdr(msg), len) < len)
+ goto disconnect;
+
wmediumd_wait_for_client_ack(ctx, client);
break;
}
+
+ return;
+
+ disconnect:
+ usfstl_loop_unregister(&client->loop);
+ wmediumd_remove_client(ctx, client);
}
static void wmediumd_remove_client(struct wmediumd *ctx, struct client *client)
@@ -1398,8 +1415,10 @@ int main(int argc, char *argv[])
w_logf(&ctx, LOG_NOTICE, "REGISTER SENT!\n");
}
- if (api_socket)
+ if (api_socket) {
+ signal(SIGPIPE, SIG_IGN);
usfstl_uds_create(api_socket, wmediumd_api_connected, &ctx);
+ }
if (time_socket) {
usfstl_sched_ctrl_start(&ctrl, time_socket,