X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=citadel%2Futils%2Fsendcommand.c;h=7d8e089853fc1416e11739d8a29a23f3da922d06;hb=2bc27bb07d088ead764da7064df2633f552b9eb0;hp=e97965f19b329dda6c0107549467381db21f4096;hpb=3f558a41a437dad1d8ae77312318101027fd016e;p=citadel.git diff --git a/citadel/utils/sendcommand.c b/citadel/utils/sendcommand.c index e97965f19..7d8e08985 100644 --- a/citadel/utils/sendcommand.c +++ b/citadel/utils/sendcommand.c @@ -1,7 +1,7 @@ /* * Command-line utility to transmit a server command. * - * Copyright (c) 1987-2012 by the citadel.org team + * Copyright (c) 1987-2021 by the citadel.org team * * This program is open source software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3. @@ -12,6 +12,7 @@ * GNU General Public License for more details. */ +#include #include #include #include @@ -26,13 +27,11 @@ #include #include #include "citadel.h" -#include "include/citadel_dirs.h" - - +#include "citadel_dirs.h" +#include int serv_sock = (-1); - int uds_connectsock(char *sockpath) { int s; @@ -93,7 +92,6 @@ void serv_write(char *buf, int nbytes) } - /* * input string from socket - implemented in terms of serv_read() */ @@ -133,8 +131,6 @@ void serv_puts(char *buf) } - - /* * Main loop. Do things and have fun. */ @@ -144,22 +140,15 @@ int main(int argc, char **argv) int watchdog = 60; char buf[SIZ]; int xfermode = 0; - int relh=0; - int home=0; - char relhome[PATH_MAX]=""; char ctdldir[PATH_MAX]=CTDLDIR; + StartLibCitadel(SIZ); + /* Parse command line */ while ((a = getopt(argc, argv, "h:w:")) != EOF) { switch (a) { case 'h': - relh=optarg[0]!='/'; - if (!relh) { - strncpy(ctdl_home_directory, optarg, sizeof ctdl_home_directory); - } else { - strncpy(relhome, optarg, sizeof relhome); - } - home = 1; + strncpy(ctdldir, optarg, sizeof ctdldir); break; case 'w': watchdog = atoi(optarg); @@ -170,17 +159,19 @@ int main(int argc, char **argv) } } - calc_dirs_n_files(relh, home, relhome, ctdldir, 0); - - fprintf(stderr, "sendcommand: started (pid=%d) connecting to Citadel server at %s\n", + fprintf(stderr, "sendcommand: started (pid=%d) connecting to Citadel server with data directory %s\n", (int) getpid(), - file_citadel_admin_socket + ctdldir ); fflush(stderr); + if (chdir(ctdldir) != 0) { + fprintf(stderr, "sendcommand: %s: %s\n", ctdldir, strerror(errno)); + exit(errno); + } + alarm(watchdog); serv_sock = uds_connectsock(file_citadel_admin_socket); - serv_gets(buf); fprintf(stderr, "%s\n", buf); @@ -200,18 +191,18 @@ int main(int argc, char **argv) xfermode = buf[0]; if ((xfermode == '4') || (xfermode == '8')) { /* send text */ - while (fgets(buf, sizeof buf, stdin)) { - buf[strlen(buf)-1] = 0; + while (fgets(buf, sizeof buf, stdin) > 0) { + if (buf[strlen(buf)-1] == '\n') { + buf[strlen(buf)-1] = 0; + } serv_puts(buf); - alarm(watchdog); /* reset the watchdog timer */ } serv_puts("000"); } if ((xfermode == '1') || (xfermode == '8')) { /* receive text */ - while (serv_gets(buf), strcmp(buf, "000")) { + while(serv_gets(buf), strcmp(buf, "000")) { printf("%s\n", buf); - alarm(watchdog); /* reset the watchdog timer */ } }