feat(dbms): introduce TDBMS CLI client app
This commit is contained in:
parent
86dae4c264
commit
84e3dd19e1
41
tdbms/cli/tdbms-cli.c
Normal file
41
tdbms/cli/tdbms-cli.c
Normal 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;
|
||||||
|
}
|
||||||
@ -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'"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user