feat(dbms): introduce TDBMS CLI client app

This commit is contained in:
Masahiko AMANO 2023-02-05 15:06:16 +03:00
parent 86dae4c264
commit 84e3dd19e1
2 changed files with 49 additions and 0 deletions

41
tdbms/cli/tdbms-cli.c Normal file
View File

@ -0,0 +1,41 @@
#include <stdio.h>
#include <stdlib.h>
#include "../../include/tdbms-client.h"
int main(int argc, char **argv) {
char *db_name, request_code, *request_body;
if (argc < 4) {
request_body = "";
} else {
request_body = argv[3];
}
if (argc < 3) {
request_code = 0;
} else {
char *endptr;
request_code = (char) strtol(argv[2], &endptr, 0);
if (*endptr != 0) {
fprintf(stderr, "FATAL: invalid request code '%s'\n", argv[2]);
return 1;
}
}
if (argc < 2) {
db_name = "";
} else {
db_name = argv[1];
}
int socket_fd = tdbms_connect("UNIX", "/tmp/tdbms.sock");
if (socket_fd < 0) {
fprintf(stderr, "FATAL: failed to connect to TDBMS server\n");
return 1;
}
char *response = tdb_query(socket_fd, db_name, request_code, request_body);
if (response == NULL) {
fprintf(stderr, "FATAL: failed to execute request\n");
return 1;
}
printf("%s\n", response);
tdbms_close(socket_fd);
return 0;
}

View File

@ -80,5 +80,13 @@ fi
chown 0:0 /etc/systemd/system/tdbms.service chown 0:0 /etc/systemd/system/tdbms.service
chmod 0644 /etc/systemd/system/tdbms.service chmod 0644 /etc/systemd/system/tdbms.service
if ! (cmake -S .. -B ../build && cmake --build ../build --target tdb); then
echo "FATAL: failed to build TDB CLI client"
exit 1
fi
mv -f ../build/tdb /usr/bin/
chown 42776 /usr/bin/tdb
chmod 4755 /usr/bin/tdb
echo "TDBMS server successfully installed." echo "TDBMS server successfully installed."
echo "Start it with 'systemctl start tdbms'" echo "Start it with 'systemctl start tdbms'"