commit:     40bc3d7770d8f2d60f7cbfbbcffdb39c5f114a03
Author:     Michał Górny <mgorny <AT> gentoo <DOT> org>
AuthorDate: Tue Nov 18 06:19:23 2025 +0000
Commit:     Michał Górny <mgorny <AT> gentoo <DOT> org>
CommitDate: Tue Nov 18 06:19:23 2025 +0000
URL:        https://gitweb.gentoo.org/proj/steve.git/commit/?id=40bc3d77

Report opening and closing the device

Signed-off-by: Michał Górny <mgorny <AT> gentoo.org>

 steve.cxx | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/steve.cxx b/steve.cxx
index ec8ade4..0c9f1e1 100644
--- a/steve.cxx
+++ b/steve.cxx
@@ -105,7 +105,23 @@ static void steve_destroy(void *userdata)
 
 static void steve_open(fuse_req_t req, struct fuse_file_info *fi)
 {
+       const struct fuse_ctx *context = fuse_req_ctx(req);
+       steve_state *state = static_cast<steve_state *>(fuse_req_userdata(req));
+
+       /* pid is not available in release, so store it here */
+       fi->fh = context->pid;
        fuse_reply_open(req, fi);
+
+       if (state->verbose)
+               printf("Device open by PID %d\n", context->pid);
+}
+
+static void steve_release(fuse_req_t req, struct fuse_file_info *fi)
+{
+       steve_state *state = static_cast<steve_state *>(fuse_req_userdata(req));
+
+       if (state->verbose)
+               printf("Device closed by PID %ld\n", fi->fh);
 }
 
 static void steve_interrupt(fuse_req_t req, void *userdata)
@@ -201,6 +217,7 @@ static const struct cuse_lowlevel_ops steve_ops = {
        .open = steve_open,
        .read = steve_read,
        .write = steve_write,
+       .release = steve_release,
 };
 
 int main(int argc, char **argv)

Reply via email to