Commit 492f58df 492f58dfaecf81a00ee0123a40e328281530acb4 by Sergey Poznyakoff

Do not use program_invocation_short_name: examples are not linked against libmailutils.

1 parent acf16565
...@@ -59,7 +59,6 @@ ...@@ -59,7 +59,6 @@
59 #include <netinet/in.h> 59 #include <netinet/in.h>
60 #include <mu_asprintf.h> 60 #include <mu_asprintf.h>
61 #include <mailutils/argcv.h> 61 #include <mailutils/argcv.h>
62 #include <mailutils/argp.h>
63 #include <mailutils/mailutils.h> 62 #include <mailutils/mailutils.h>
64 63
65 FILE *diag = NULL; /* diagnostic output */ 64 FILE *diag = NULL; /* diagnostic output */
...@@ -71,6 +70,7 @@ int dot = 1; /* Message is terminated by a lone dot on a line */ ...@@ -71,6 +70,7 @@ int dot = 1; /* Message is terminated by a lone dot on a line */
71 70
72 header_t header; 71 header_t header;
73 address_t recipients = NULL; 72 address_t recipients = NULL;
73 char *progname;
74 74
75 int mta_stdin __P((int argc, char **argv)); 75 int mta_stdin __P((int argc, char **argv));
76 int mta_smtp __P((int argc, char **argv)); 76 int mta_smtp __P((int argc, char **argv));
...@@ -82,6 +82,10 @@ main (int argc, char **argv) ...@@ -82,6 +82,10 @@ main (int argc, char **argv)
82 int c, status; 82 int c, status;
83 char *domain; 83 char *domain;
84 84
85 progname = strrchr (argv[0], '/');
86 if (!progname)
87 progname = argv[0];
88
85 while ((c = getopt (argc, argv, "b:f:p:to:")) != EOF) 89 while ((c = getopt (argc, argv, "b:f:p:to:")) != EOF)
86 { 90 {
87 switch (c) 91 switch (c)
...@@ -137,7 +141,7 @@ main (int argc, char **argv) ...@@ -137,7 +141,7 @@ main (int argc, char **argv)
137 if (!diag) 141 if (!diag)
138 { 142 {
139 mu_error ("%s: can't open diagnostic output: %s", 143 mu_error ("%s: can't open diagnostic output: %s",
140 program_invocation_short_name, name); 144 progname, name);
141 return 1; 145 return 1;
142 } 146 }
143 } 147 }
...@@ -153,7 +157,7 @@ main (int argc, char **argv) ...@@ -153,7 +157,7 @@ main (int argc, char **argv)
153 if ((status = header_create (&header, NULL, 0, NULL)) != 0) 157 if ((status = header_create (&header, NULL, 0, NULL)) != 0)
154 { 158 {
155 mu_error ("%s: can't create header: %s", 159 mu_error ("%s: can't create header: %s",
156 program_invocation_short_name, mu_errstring (status)); 160 progname, mu_errstring (status));
157 return 1; 161 return 1;
158 } 162 }
159 163
...@@ -191,8 +195,7 @@ make_tmp (FILE *input, const char *from, char **tempfile) ...@@ -191,8 +195,7 @@ make_tmp (FILE *input, const char *from, char **tempfile)
191 195
192 if (fd == -1 || (fp = fdopen (fd, "w+")) == NULL) 196 if (fd == -1 || (fp = fdopen (fd, "w+")) == NULL)
193 { 197 {
194 mu_error ("%s: unable to open temporary file", 198 mu_error ("%s: unable to open temporary file", progname);
195 program_invocation_short_name);
196 exit (1); 199 exit (1);
197 } 200 }
198 201
...@@ -221,8 +224,7 @@ make_tmp (FILE *input, const char *from, char **tempfile) ...@@ -221,8 +224,7 @@ make_tmp (FILE *input, const char *from, char **tempfile)
221 } 224 }
222 else 225 else
223 { 226 {
224 mu_error ("%s: can't determine sender address", 227 mu_error ("%s: can't determine sender address", progname);
225 program_invocation_short_name);
226 exit (1); 228 exit (1);
227 } 229 }
228 } 230 }
...@@ -236,8 +238,7 @@ make_tmp (FILE *input, const char *from, char **tempfile) ...@@ -236,8 +238,7 @@ make_tmp (FILE *input, const char *from, char **tempfile)
236 238
237 if (fputs (buf, fp) == EOF) 239 if (fputs (buf, fp) == EOF)
238 { 240 {
239 mu_error ("%s: temporary file write error", 241 mu_error ("%s: temporary file write error", progname);
240 program_invocation_short_name);
241 fclose (fp); 242 fclose (fp);
242 exit (1); 243 exit (1);
243 } 244 }
...@@ -297,13 +298,13 @@ mta_send (message_t msg) ...@@ -297,13 +298,13 @@ mta_send (message_t msg)
297 if (c) 298 if (c)
298 { 299 {
299 mu_error ("%s: address_to_string failure: %s", 300 mu_error ("%s: address_to_string failure: %s",
300 program_invocation_short_name, mu_errstring (c)); 301 progname, mu_errstring (c));
301 return 1; 302 return 1;
302 } 303 }
303 value = malloc (n + 1); 304 value = malloc (n + 1);
304 if (!value) 305 if (!value)
305 { 306 {
306 mu_error ("%s: not enough memory", program_invocation_short_name); 307 mu_error ("%s: not enough memory", progname);
307 return 1; 308 return 1;
308 } 309 }
309 310
...@@ -361,8 +362,7 @@ message_finalize (message_t msg, int warn) ...@@ -361,8 +362,7 @@ message_finalize (message_t msg, int warn)
361 { 362 {
362 if (add_recipient (value)) 363 if (add_recipient (value))
363 { 364 {
364 mu_error ("%s: bad address %s", 365 mu_error ("%s: bad address %s", progname, value);
365 program_invocation_short_name, value);
366 return 1; 366 return 1;
367 } 367 }
368 free (value); 368 free (value);
...@@ -372,8 +372,7 @@ message_finalize (message_t msg, int warn) ...@@ -372,8 +372,7 @@ message_finalize (message_t msg, int warn)
372 { 372 {
373 if (add_recipient (value)) 373 if (add_recipient (value))
374 { 374 {
375 mu_error ("%s: bad address %s", 375 mu_error ("%s: bad address %s", progname, value);
376 program_invocation_short_name, value);
377 return 1; 376 return 1;
378 } 377 }
379 free (value); 378 free (value);
...@@ -383,8 +382,7 @@ message_finalize (message_t msg, int warn) ...@@ -383,8 +382,7 @@ message_finalize (message_t msg, int warn)
383 { 382 {
384 if (add_recipient (value)) 383 if (add_recipient (value))
385 { 384 {
386 mu_error ("%s: bad address %s: %s", 385 mu_error ("%s: bad address %s: %s", progname, value);
387 program_invocation_short_name, value);
388 return 1; 386 return 1;
389 } 387 }
390 free (value); 388 free (value);
...@@ -401,14 +399,13 @@ message_finalize (message_t msg, int warn) ...@@ -401,14 +399,13 @@ message_finalize (message_t msg, int warn)
401 if (c) 399 if (c)
402 { 400 {
403 mu_error ("%s: address_to_string failure: %s", 401 mu_error ("%s: address_to_string failure: %s",
404 program_invocation_short_name, mu_errstring (c)); 402 progname, mu_errstring (c));
405 return 1; 403 return 1;
406 } 404 }
407 value = malloc (n + 1); 405 value = malloc (n + 1);
408 if (!value) 406 if (!value)
409 { 407 {
410 mu_error ("%s: not enough memory", 408 mu_error ("%s: not enough memory", progname);
411 program_invocation_short_name);
412 return 1; 409 return 1;
413 } 410 }
414 411
...@@ -431,8 +428,7 @@ mta_stdin (int argc, char **argv) ...@@ -431,8 +428,7 @@ mta_stdin (int argc, char **argv)
431 { 428 {
432 if (add_recipient (argv[c])) 429 if (add_recipient (argv[c]))
433 { 430 {
434 mu_error ("%s: bad address %s", 431 mu_error ("%s: bad address %s", progname, argv[c]);
435 program_invocation_short_name, argv[c]);
436 return 1; 432 return 1;
437 } 433 }
438 } 434 }
...@@ -441,7 +437,7 @@ mta_stdin (int argc, char **argv) ...@@ -441,7 +437,7 @@ mta_stdin (int argc, char **argv)
441 if ((c = mailbox_create_default (&mbox, tempfile)) != 0) 437 if ((c = mailbox_create_default (&mbox, tempfile)) != 0)
442 { 438 {
443 mu_error ("%s: can't create mailbox %s: %s", 439 mu_error ("%s: can't create mailbox %s: %s",
444 program_invocation_short_name, tempfile, mu_errstring (c)); 440 progname, tempfile, mu_errstring (c));
445 unlink (tempfile); 441 unlink (tempfile);
446 return 1; 442 return 1;
447 } 443 }
...@@ -449,7 +445,7 @@ mta_stdin (int argc, char **argv) ...@@ -449,7 +445,7 @@ mta_stdin (int argc, char **argv)
449 if ((c = mailbox_open (mbox, MU_STREAM_RDWR)) != 0) 445 if ((c = mailbox_open (mbox, MU_STREAM_RDWR)) != 0)
450 { 446 {
451 mu_error ("%s: can't open mailbox %s: %s", 447 mu_error ("%s: can't open mailbox %s: %s",
452 program_invocation_short_name, tempfile, mu_errstring (c)); 448 progname, tempfile, mu_errstring (c));
453 unlink (tempfile); 449 unlink (tempfile);
454 return 1; 450 return 1;
455 } 451 }
...@@ -460,8 +456,7 @@ mta_stdin (int argc, char **argv) ...@@ -460,8 +456,7 @@ mta_stdin (int argc, char **argv)
460 456
461 if (!recipients) 457 if (!recipients)
462 { 458 {
463 mu_error ("%s: Recipient names must be specified", 459 mu_error ("%s: Recipient names must be specified", progname);
464 program_invocation_short_name);
465 return 1; 460 return 1;
466 } 461 }
467 462
...@@ -654,7 +649,7 @@ smtp (int fd) ...@@ -654,7 +649,7 @@ smtp (int fd)
654 if ((c = mailbox_create_default (&mbox, tempfile)) != 0) 649 if ((c = mailbox_create_default (&mbox, tempfile)) != 0)
655 { 650 {
656 mu_error ("%s: can't create mailbox %s: %s", 651 mu_error ("%s: can't create mailbox %s: %s",
657 program_invocation_short_name, 652 progname,
658 tempfile, mu_errstring (c)); 653 tempfile, mu_errstring (c));
659 unlink (tempfile); 654 unlink (tempfile);
660 exit (1); 655 exit (1);
...@@ -663,7 +658,7 @@ smtp (int fd) ...@@ -663,7 +658,7 @@ smtp (int fd)
663 if ((c = mailbox_open (mbox, MU_STREAM_RDWR)) != 0) 658 if ((c = mailbox_open (mbox, MU_STREAM_RDWR)) != 0)
664 { 659 {
665 mu_error ("%s: can't open mailbox %s: %s", 660 mu_error ("%s: can't open mailbox %s: %s",
666 program_invocation_short_name, 661 progname,
667 tempfile, mu_errstring (c)); 662 tempfile, mu_errstring (c));
668 unlink (tempfile); 663 unlink (tempfile);
669 exit (1); 664 exit (1);
...@@ -706,8 +701,7 @@ mta_smtp (int argc, char **argv) ...@@ -706,8 +701,7 @@ mta_smtp (int argc, char **argv)
706 fd = socket (PF_INET, SOCK_STREAM, 0); 701 fd = socket (PF_INET, SOCK_STREAM, 0);
707 if (fd < 0) 702 if (fd < 0)
708 { 703 {
709 mu_error ("%s: socket: %s", program_invocation_short_name, 704 mu_error ("%s: socket: %s", progname, strerror (errno));
710 strerror (errno));
711 return 1; 705 return 1;
712 } 706 }
713 707
...@@ -723,8 +717,7 @@ mta_smtp (int argc, char **argv) ...@@ -723,8 +717,7 @@ mta_smtp (int argc, char **argv)
723 if (bind (fd, (struct sockaddr *) &address, sizeof (address)) < 0) 717 if (bind (fd, (struct sockaddr *) &address, sizeof (address)) < 0)
724 { 718 {
725 close (fd); 719 close (fd);
726 mu_error ("%s: bind: %s", program_invocation_short_name, 720 mu_error ("%s: bind: %s", progname, strerror(errno));
727 strerror(errno));
728 return 1; 721 return 1;
729 } 722 }
730 } 723 }
...@@ -738,7 +731,7 @@ mta_smtp (int argc, char **argv) ...@@ -738,7 +731,7 @@ mta_smtp (int argc, char **argv)
738 if (++port >= 65535) 731 if (++port >= 65535)
739 { 732 {
740 mu_error ("%s: can't bind socket: all ports in use?", 733 mu_error ("%s: can't bind socket: all ports in use?",
741 program_invocation_short_name); 734 progname);
742 return 1; 735 return 1;
743 } 736 }
744 address.sin_port = htons (port); 737 address.sin_port = htons (port);
...@@ -764,16 +757,14 @@ mta_smtp (int argc, char **argv) ...@@ -764,16 +757,14 @@ mta_smtp (int argc, char **argv)
764 { 757 {
765 if (errno == EINTR) 758 if (errno == EINTR)
766 continue; 759 continue;
767 mu_error ("%s: select: %s", program_invocation_short_name, 760 mu_error ("%s: select: %s", progname, strerror (errno));
768 strerror (errno));
769 return 1; 761 return 1;
770 } 762 }
771 763
772 len = sizeof (his_addr); 764 len = sizeof (his_addr);
773 if ((sfd = accept (fd, (struct sockaddr *)&his_addr, &len)) < 0) 765 if ((sfd = accept (fd, (struct sockaddr *)&his_addr, &len)) < 0)
774 { 766 {
775 mu_error ("%s: accept: %s", program_invocation_short_name, 767 mu_error ("%s: accept: %s", progname, strerror (errno));
776 strerror (errno));
777 return 1; 768 return 1;
778 } 769 }
779 770
......