Skip to content

Commit 38b1124

Browse files
committed
Report payload launch failures
1 parent eb23f20 commit 38b1124

2 files changed

Lines changed: 24 additions & 7 deletions

File tree

src/main.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,7 @@ static enum MHD_Result on_request(void *cls, struct MHD_Connection *conn,
731731

732732
struct MHD_Response *resp = NULL;
733733
enum MHD_Result ret;
734+
int http_status = MHD_HTTP_OK;
734735

735736
if (strcmp(url, ROUTE_USB_MOVE_CHECK) == 0) {
736737
const char *path = MHD_lookup_connection_value(conn, MHD_GET_ARGUMENT_KIND, "path");
@@ -922,16 +923,19 @@ static enum MHD_Result on_request(void *cls, struct MHD_Connection *conn,
922923
}
923924

924925
if (!final_path) {
926+
pldmgr_log("[PLDMGR] !!! Payload path rejected: %s\n", path);
925927
const char *err = "Invalid payload name\n";
926928
resp = MHD_create_response_from_buffer(strlen(err), (void *)err,
927929
MHD_RESPMEM_PERSISTENT);
930+
http_status = MHD_HTTP_BAD_REQUEST;
928931
} else if (ps5_launch_elf(final_path) == 0) {
929932
resp = MHD_create_response_from_buffer(strlen(MSG_OK), (void *)MSG_OK,
930933
MHD_RESPMEM_PERSISTENT);
931934
} else {
932935
const char *err = "Failed to launch payload\n";
933936
resp = MHD_create_response_from_buffer(strlen(err), (void *)err,
934937
MHD_RESPMEM_PERSISTENT);
938+
http_status = MHD_HTTP_INTERNAL_SERVER_ERROR;
935939
}
936940
MHD_add_response_header(resp, "Content-Type", "text/plain");
937941
} else if (strncmp(url, ROUTE_DELETE, strlen(ROUTE_DELETE)) == 0) {
@@ -1134,7 +1138,7 @@ static enum MHD_Result on_request(void *cls, struct MHD_Connection *conn,
11341138
/* Add CORS headers */
11351139
add_cors_headers(resp);
11361140

1137-
ret = MHD_queue_response(conn, MHD_HTTP_OK, resp);
1141+
ret = MHD_queue_response(conn, http_status, resp);
11381142
MHD_destroy_response(resp);
11391143

11401144
return ret;

src/ps5_launcher.c

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,33 @@ int ps5_launch_elf(const char *path) {
5454
/* Stream the file */
5555
char buffer[8192];
5656
ssize_t read_bytes;
57+
int error = 0;
5758
while ((read_bytes = read(fd, buffer, sizeof(buffer))) > 0) {
58-
ssize_t sent = send(sock, buffer, read_bytes, 0);
59-
if (sent < 0) {
60-
perror("send");
61-
break;
59+
size_t offset = 0;
60+
while (offset < (size_t)read_bytes) {
61+
ssize_t sent = send(sock, buffer + offset, (size_t)read_bytes - offset, 0);
62+
if (sent <= 0) {
63+
pldmgr_log("[PLDMGR] !!! send failed while launching payload\n");
64+
error = 1;
65+
break;
66+
}
67+
offset += (size_t)sent;
68+
total_sent += (size_t)sent;
6269
}
63-
total_sent += sent;
70+
if (error)
71+
break;
72+
}
73+
74+
if (read_bytes < 0) {
75+
pldmgr_log("[PLDMGR] !!! read failed while launching payload\n");
76+
error = 1;
6477
}
6578

6679
pldmgr_log("[PLDMGR] Sent %zu bytes to loader.\n", total_sent);
6780

6881
close(sock);
6982
close(fd);
70-
return 0;
83+
return error ? -1 : 0;
7184
}
7285

7386
extern int sceSystemServiceLaunchWebBrowser(const char *uri);

0 commit comments

Comments
 (0)