aboutsummaryrefslogtreecommitdiffstats
path: root/fuse_sideload.cpp
diff options
context:
space:
mode:
authorTom Marshall <tdm@cyngn.com>2015-11-05 21:30:40 -0800
committerTom Marshall <tdm@cyngn.com>2015-11-25 15:34:35 -0800
commitffc8a8702d9e1568995ce155c648fd029909cdac (patch)
tree3dcf3d34ebb03c3ac8d140d249e55838a90e2e14 /fuse_sideload.cpp
parent3381ac447175af3252c79c3e066cbbc38c400c85 (diff)
downloadbootable_recovery-ffc8a8702d9e1568995ce155c648fd029909cdac.zip
bootable_recovery-ffc8a8702d9e1568995ce155c648fd029909cdac.tar.gz
bootable_recovery-ffc8a8702d9e1568995ce155c648fd029909cdac.tar.bz2
recovery: Provide sideload cancellation
Change-Id: I13f0c9ae5444652a2141442ef24258679a78d320
Diffstat (limited to 'fuse_sideload.cpp')
-rw-r--r--fuse_sideload.cpp39
1 files changed, 21 insertions, 18 deletions
diff --git a/fuse_sideload.cpp b/fuse_sideload.cpp
index 9c3e75f..39c7237 100644
--- a/fuse_sideload.cpp
+++ b/fuse_sideload.cpp
@@ -65,10 +65,8 @@
#include "fuse_sideload.h"
#define PACKAGE_FILE_ID (FUSE_ROOT_ID+1)
-#define EXIT_FLAG_ID (FUSE_ROOT_ID+2)
#define NO_STATUS 1
-#define NO_STATUS_EXIT 2
struct fuse_data {
int ffd; // file descriptor for the fuse socket
@@ -179,14 +177,12 @@ static int handle_getattr(void* /* data */, struct fuse_data* fd, const struct f
fill_attr(&(out.attr), fd, hdr->nodeid, 4096, S_IFDIR | 0555);
} else if (hdr->nodeid == PACKAGE_FILE_ID) {
fill_attr(&(out.attr), fd, PACKAGE_FILE_ID, fd->file_size, S_IFREG | 0444);
- } else if (hdr->nodeid == EXIT_FLAG_ID) {
- fill_attr(&(out.attr), fd, EXIT_FLAG_ID, 0, S_IFREG | 0);
} else {
return -ENOENT;
}
fuse_reply(fd, hdr->unique, &out, sizeof(out));
- return (hdr->nodeid == EXIT_FLAG_ID) ? NO_STATUS_EXIT : NO_STATUS;
+ return NO_STATUS;
}
static int handle_lookup(void* data, struct fuse_data* fd,
@@ -201,21 +197,15 @@ static int handle_lookup(void* data, struct fuse_data* fd,
out.nodeid = PACKAGE_FILE_ID;
out.generation = PACKAGE_FILE_ID;
fill_attr(&(out.attr), fd, PACKAGE_FILE_ID, fd->file_size, S_IFREG | 0444);
- } else if (strncmp(FUSE_SIDELOAD_HOST_EXIT_FLAG, reinterpret_cast<const char*>(data),
- sizeof(FUSE_SIDELOAD_HOST_EXIT_FLAG)) == 0) {
- out.nodeid = EXIT_FLAG_ID;
- out.generation = EXIT_FLAG_ID;
- fill_attr(&(out.attr), fd, EXIT_FLAG_ID, 0, S_IFREG | 0);
} else {
return -ENOENT;
}
fuse_reply(fd, hdr->unique, &out, sizeof(out));
- return (out.nodeid == EXIT_FLAG_ID) ? NO_STATUS_EXIT : NO_STATUS;
+ return NO_STATUS;
}
static int handle_open(void* /* data */, struct fuse_data* fd, const struct fuse_in_header* hdr) {
- if (hdr->nodeid == EXIT_FLAG_ID) return -EPERM;
if (hdr->nodeid != PACKAGE_FILE_ID) return -ENOENT;
struct fuse_open_out out;
@@ -361,6 +351,12 @@ static int handle_read(void* data, struct fuse_data* fd, const struct fuse_in_he
return NO_STATUS;
}
+static volatile int terminated = 0;
+static void sig_term(int sig)
+{
+ terminated = 1;
+}
+
int run_fuse_sideload(struct provider_vtab* vtab, void* cookie,
uint64_t file_size, uint32_t block_size)
{
@@ -418,6 +414,8 @@ int run_fuse_sideload(struct provider_vtab* vtab, void* cookie,
goto done;
}
+ signal(SIGTERM, sig_term);
+
fd.ffd = open("/dev/fuse", O_RDWR);
if (fd.ffd < 0) {
perror("open /dev/fuse");
@@ -438,7 +436,17 @@ int run_fuse_sideload(struct provider_vtab* vtab, void* cookie,
goto done;
}
uint8_t request_buffer[sizeof(struct fuse_in_header) + PATH_MAX*8];
- for (;;) {
+ while (!terminated) {
+ fd_set fds;
+ struct timeval tv;
+ FD_ZERO(&fds);
+ FD_SET(fd.ffd, &fds);
+ tv.tv_sec = 1;
+ tv.tv_usec = 0;
+ int rc = select(fd.ffd+1, &fds, NULL, NULL, &tv);
+ if (rc <= 0) {
+ continue;
+ }
ssize_t len = TEMP_FAILURE_RETRY(read(fd.ffd, request_buffer, sizeof(request_buffer)));
if (len == -1) {
perror("read request");
@@ -493,11 +501,6 @@ int run_fuse_sideload(struct provider_vtab* vtab, void* cookie,
break;
}
- if (result == NO_STATUS_EXIT) {
- result = 0;
- break;
- }
-
if (result != NO_STATUS) {
struct fuse_out_header outhdr;
outhdr.len = sizeof(outhdr);