/* For verification the correct connection is acting. */
struct connection *conn;
+ /* Pointer to the command used to request LU */
+ struct buffered_data *in;
+
#ifdef __MINIOS__
void *kernel;
unsigned int kernel_size;
if (!lu_status)
return "Allocation failure.";
lu_status->conn = conn;
+ lu_status->in = conn->in;
talloc_set_destructor(lu_status, lu_destroy);
return NULL;
return lu_status ? lu_status->conn : NULL;
}
+unsigned int lu_write_response(FILE *fp)
+{
+ struct xsd_sockmsg msg;
+
+ assert(lu_status);
+
+ msg = lu_status->in->hdr.msg;
+
+ msg.len = sizeof("OK");
+ if (fp && fwrite(&msg, sizeof(msg), 1, fp) != 1)
+ return 0;
+ if (fp && fwrite("OK", msg.len, 1, fp) != 1)
+ return 0;
+
+ return sizeof(msg) + msg.len;
+}
+
#else
struct connection *lu_get_connection(void)
{
return NULL;
}
+
+unsigned int lu_write_response(FILE *fp)
+{
+ /* Unsupported */
+ return 0;
+}
#endif
struct cmd_s {
{
time_t now = time(NULL);
const char *ret;
+ struct buffered_data *saved_in;
+ struct connection *conn = lu_status->conn;
if (!lu_check_lu_allowed()) {
if (now < lu_status->started_at + lu_status->timeout)
}
}
+ assert(req->in == lu_status->in);
/* Dump out internal state, including "OK" for live update. */
- ret = lu_dump_state(req->in, lu_status->conn);
+ ret = lu_dump_state(req->in, conn);
if (!ret) {
/* Perform the activation of new binary. */
ret = lu_activate_binary(req->in);
/* We will reach this point only in case of failure. */
out:
- send_reply(lu_status->conn, XS_CONTROL, ret, strlen(ret) + 1);
+ /*
+ * send_reply() will send the response for conn->in. Save the current
+ * conn->in and restore it afterwards.
+ */
+ saved_in = conn->in;
+ conn->in = req->in;
+ send_reply(conn, XS_CONTROL, ret, strlen(ret) + 1);
+ conn->in = saved_in;
talloc_free(lu_status);
return true;
return 0;
}
-static void call_delayed(struct connection *conn, struct delayed_request *req)
+static void call_delayed(struct delayed_request *req)
{
- assert(conn->in == NULL);
- conn->in = req->in;
-
if (req->func(req)) {
undelay_request(req);
talloc_set_destructor(req, NULL);
}
-
- conn->in = NULL;
}
int delay_request(struct connection *conn, struct buffered_data *in,
list_for_each_entry_safe(req, tmp,
&conn->delayed, list)
- call_delayed(conn, req);
+ call_delayed(req);
}
}
struct buffered_data *out, *in = c->in;
bool partial = true;
- if (in && c != lu_get_connection()) {
+ if (in) {
len = in->inhdr ? in->used : sizeof(in->hdr);
if (fp && fwrite(&in->hdr, len, 1, fp) != 1)
return "Dump read data error";
/* Add "OK" for live-update command. */
if (c == lu_get_connection()) {
- struct xsd_sockmsg msg = c->in->hdr.msg;
+ unsigned int rc = lu_write_response(fp);
- msg.len = sizeof("OK");
- if (fp && fwrite(&msg, sizeof(msg), 1, fp) != 1)
+ if (!rc)
return "Dump buffered data error";
- len += sizeof(msg);
- if (fp && fwrite("OK", msg.len, 1, fp) != 1)
- return "Dump buffered data error";
- len += msg.len;
+ len += rc;
}
if (sc)