X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=citadel%2Futils%2Fsendcommand.c;h=001a4b1dcdbe24334d0a3b98e764f0fd34c08cfd;hb=3cfffe2479a77433a5e0801d24b902b33b0078f3;hp=bef37c7be7dccc6e51b422e9828e808c11d3fdac;hpb=475c21c8532b6ba682535c2b2e19a1427040a669;p=citadel.git diff --git a/citadel/utils/sendcommand.c b/citadel/utils/sendcommand.c index bef37c7be..001a4b1dc 100644 --- a/citadel/utils/sendcommand.c +++ b/citadel/utils/sendcommand.c @@ -12,6 +12,7 @@ * GNU General Public License for more details. */ +#include #include #include #include @@ -27,12 +28,10 @@ #include #include "citadel.h" #include "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. */ @@ -149,6 +145,8 @@ int main(int argc, char **argv) char relhome[PATH_MAX]=""; char ctdldir[PATH_MAX]=CTDLDIR; + StartLibCitadel(SIZ); + /* Parse command line */ while ((a = getopt(argc, argv, "h:w:")) != EOF) { switch (a) { @@ -163,6 +161,7 @@ int main(int argc, char **argv) break; case 'w': watchdog = atoi(optarg); + break; default: fprintf(stderr, "sendcommand: usage: sendcommand [-h server_dir] [-w watchdog_timeout]\n"); return(1); @@ -179,7 +178,6 @@ int main(int argc, char **argv) alarm(watchdog); serv_sock = uds_connectsock(file_citadel_admin_socket); - serv_gets(buf); fprintf(stderr, "%s\n", buf); @@ -199,18 +197,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 */ } }