summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Santtu Lakkala2025-02-01 14:31:18 +0200
committerGravatar Santtu Lakkala2025-02-05 11:02:10 +0200
commita356ca255acf2119f10acbe577c3f8008ad8e160 (patch)
tree5210a15ab75e6905b0ecc345f3c2c3c1e4cc0d14
parentUpdated RELEASE_NOTES. (diff)
downloadpenes-snac2-a356ca255acf2119f10acbe577c3f8008ad8e160.tar.gz
penes-snac2-a356ca255acf2119f10acbe577c3f8008ad8e160.tar.xz
penes-snac2-a356ca255acf2119f10acbe577c3f8008ad8e160.zip
Allow multiple editors at the same time
Instead of a hard-coded message file, use mkstemp() to have an unique temp file for each invocation.
-rw-r--r--main.c35
1 files changed, 23 insertions, 12 deletions
diff --git a/main.c b/main.c
index 347c495..58a46de 100644
--- a/main.c
+++ b/main.c
@@ -676,19 +676,25 @@ int main(int argc, char *argv[])
676 676
677 if (strcmp(url, "-e") == 0) { 677 if (strcmp(url, "-e") == 0) {
678 /* get the content from an editor */ 678 /* get the content from an editor */
679#define EDITOR "$EDITOR "
680 char cmd[] = EDITOR "/tmp/snac-XXXXXX";
679 FILE *f; 681 FILE *f;
680 682 int fd = mkstemp(cmd + strlen(EDITOR));
681 unlink("/tmp/snac-edit.txt"); 683
682 system("$EDITOR /tmp/snac-edit.txt"); 684 if (fd >= 0) {
683 685 int status = system(cmd);
684 if ((f = fopen("/tmp/snac-edit.txt", "r")) != NULL) { 686
685 content = xs_readall(f); 687 if (WIFEXITED(status) && WEXITSTATUS(status) == 0 && (f = fdopen(fd, "r")) != NULL) {
686 fclose(f); 688 content = xs_readall(f);
687 689 fclose(f);
688 unlink("/tmp/snac-edit.txt"); 690 unlink(cmd + strlen(EDITOR));
689 } 691 } else {
690 else { 692 printf("Nothing to send\n");
691 printf("Nothing to send\n"); 693 close(fd);
694 return 1;
695 }
696 } else {
697 fprintf(stderr, "Temp file creation failed\n");
692 return 1; 698 return 1;
693 } 699 }
694 } 700 }
@@ -700,6 +706,11 @@ int main(int argc, char *argv[])
700 else 706 else
701 content = xs_dup(url); 707 content = xs_dup(url);
702 708
709 if (!content || !*content) {
710 printf("Nothing to send\n");
711 return 1;
712 }
713
703 int scope = 0; 714 int scope = 0;
704 if (strcmp(cmd, "note_mention") == 0) 715 if (strcmp(cmd, "note_mention") == 0)
705 scope = 1; 716 scope = 1;