ctpvclear: add option to pass id as argument

This commit is contained in:
Nikita Ivanov 2022-05-29 21:40:11 +05:00
parent ee85f98008
commit 6bc8da73ca
No known key found for this signature in database
GPG Key ID: 6E656AC5B97B5133
6 changed files with 13 additions and 10 deletions

View File

@ -1,3 +1,3 @@
setup_fifo "" 1 setup_fifo "$1" 1
printf '{"action": "remove", "identifier": "preview"}\n' > "$fifo" printf '{"action": "remove", "identifier": "preview"}\n' > "$fifo"

9
ctpv.c
View File

@ -136,9 +136,9 @@ static int server(char const *id_s)
return server_listen(id_s); return server_listen(id_s);
} }
static int clear(void) static int clear(char const *id_s)
{ {
return server_clear(); return server_clear(id_s);
} }
static int end(char const *id_s) static int end(char const *id_s)
@ -264,7 +264,7 @@ int main(int argc, char *argv[])
program = ctpv.ctpv_path ? ctpv.ctpv_path : "ctpv"; program = ctpv.ctpv_path ? ctpv.ctpv_path : "ctpv";
int c; int c;
while ((c = getopt(argc, argv, "s:ce:lmC:")) != -1) { while ((c = getopt(argc, argv, "s:c:e:lmC:")) != -1) {
switch (c) { switch (c) {
case 's': case 's':
ctpv.mode = MODE_SERVER; ctpv.mode = MODE_SERVER;
@ -272,6 +272,7 @@ int main(int argc, char *argv[])
break; break;
case 'c': case 'c':
ctpv.mode = MODE_CLEAR; ctpv.mode = MODE_CLEAR;
ctpv.server_id_s = optarg;
break; break;
case 'e': case 'e':
ctpv.mode = MODE_END; ctpv.mode = MODE_END;
@ -304,7 +305,7 @@ int main(int argc, char *argv[])
ret = server(ctpv.server_id_s); ret = server(ctpv.server_id_s);
break; break;
case MODE_CLEAR: case MODE_CLEAR:
ret = clear(); ret = clear(ctpv.server_id_s);
break; break;
case MODE_END: case MODE_END:
ret = end(ctpv.server_id_s); ret = end(ctpv.server_id_s);

View File

@ -1,3 +1,5 @@
#!/bin/sh #!/bin/sh
exec ctpv -c [ -z "$id" ] && id="$1"
exec ctpv -c "$id"

View File

@ -5,8 +5,8 @@ fifo_open() {
} }
setup_fifo() { setup_fifo() {
exit_code="${2:-127}"
fifo="$(printf '/tmp/ctpvfifo.%s' "${1:-$id}")" fifo="$(printf '/tmp/ctpvfifo.%s' "${1:-$id}")"
exit_code="${2:-127}"
[ -e "$fifo" ] || exit "$exit_code" [ -e "$fifo" ] || exit "$exit_code"
fifo_open "$fifo" || exit "$exit_code" fifo_open "$fifo" || exit "$exit_code"
} }

View File

@ -148,9 +148,9 @@ cleanup:
return ret; return ret;
} }
int server_clear(void) int server_clear(const char *id_s)
{ {
return run_script(scr_clear_sh, LEN(scr_clear_sh)-1, ""); return run_script(scr_clear_sh, LEN(scr_clear_sh)-1, (char *)id_s);
} }
int server_end(const char *id_s) int server_end(const char *id_s)

View File

@ -2,7 +2,7 @@
#define SERVER_H #define SERVER_H
int server_listen(char const *id_s); int server_listen(char const *id_s);
int server_clear(void); int server_clear(const char *id_s);
int server_end(const char *id_s); int server_end(const char *id_s);
#endif #endif