Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libcmt io hook #35

Closed
wants to merge 10 commits into from
Closed

libcmt io hook #35

wants to merge 10 commits into from

Conversation

mpolitzer
Copy link
Collaborator

@mpolitzer mpolitzer commented Feb 21, 2024

Mock implementation of "dehash" read operations.

The strategy employed was to delegate the IO to an external executables specified by an environment variable.
The user specified the mappings as a list of pairs: (reason, executable).
The request is written to stdin of the executable and its reply is read back via its stdout.
This frees the user to choose any programming language to handle the request.

As an example, assume:

  • application is the C program below, linked against libcmt (mock version).
  • echo.lua is the lua script below.

Invoked with: CMT_HOOKS=10:echo.lua ./application (echo.lua can be found on PATH).

application.c

#include<stdio.h>
#include<string.h>
#include "libcmt/rollup.h"

int main()
{
    cmt_rollup_t rollup;
    if (cmt_rollup_init(&rollup))
        return -1;

    cmt_buf_t tx[1] = {cmt_io_get_tx(rollup.io)};
    cmt_buf_t rx[1] = {cmt_io_get_rx(rollup.io)};

    int m = snprintf((char *)tx->begin, cmt_buf_length(tx), "request");
    struct cmt_io_yield req[1] = {{
        .dev    = CMT_IO_DEV,
        .cmd    = CMT_IO_CMD_MANUAL,
        .reason = 10,
        .data   = m,
    }};
    int rc = cmt_io_yield(rollup.io, req);
    printf("%d:%s \"%.*s\"\n", rc, strerror(rc), req->data, (char *)rx->begin);

    return 0;
}

echo.lua

io.stderr:write("got a request for reason: " .. arg[1] .. "\n")
local line = io.read()
io.write(line)

@mpolitzer mpolitzer self-assigned this Feb 21, 2024
@mpolitzer mpolitzer added the enhancement New feature or request label Feb 21, 2024
@vfusco vfusco force-pushed the feature/libcmt branch 2 times, most recently from 12be112 to d38bf4e Compare March 18, 2024 18:53
@vfusco vfusco force-pushed the feature/libcmt branch 2 times, most recently from fb1a7e5 to de3aa18 Compare March 30, 2024 12:18
@mpolitzer mpolitzer mentioned this pull request Apr 8, 2024
@mpolitzer mpolitzer force-pushed the feature/libcmt branch 4 times, most recently from 414aea6 to 5b2a267 Compare April 11, 2024 20:52
@vfusco vfusco force-pushed the feature/libcmt branch 4 times, most recently from ffc7a2f to ce1d537 Compare April 15, 2024 16:02
@mpolitzer mpolitzer force-pushed the feature/libcmt branch 2 times, most recently from bc79f8e to 770e876 Compare April 19, 2024 13:50
Base automatically changed from feature/libcmt to main April 19, 2024 14:40
@mpolitzer mpolitzer closed this Apr 19, 2024
@mpolitzer mpolitzer deleted the feature/libcmt-io-hook branch April 19, 2024 20:51
@mpolitzer
Copy link
Collaborator Author

We took a simpler approach to inject predefined binaries.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant