We don't need bvsnprintf() in BIRD client

This commit is contained in:
Ondrej Zajicek (work) 2016-05-12 21:29:04 +02:00
parent 8e433d6a52
commit 3f2c7600fa
6 changed files with 23 additions and 29 deletions

View file

@ -153,7 +153,7 @@ input_init(void)
// readline library does strange things when stdin is nonblocking. // readline library does strange things when stdin is nonblocking.
// if (fcntl(0, F_SETFL, O_NONBLOCK) < 0) // if (fcntl(0, F_SETFL, O_NONBLOCK) < 0)
// die("fcntl: %m"); // DIE("fcntl");
} }
static void static void

View file

@ -11,6 +11,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include <termios.h> #include <termios.h>
#include <errno.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <signal.h> #include <signal.h>
@ -109,7 +110,7 @@ more_begin(void)
tty.c_lflag &= (~ICANON); tty.c_lflag &= (~ICANON);
if (tcsetattr (0, TCSANOW, &tty) < 0) if (tcsetattr (0, TCSANOW, &tty) < 0)
die("tcsetattr: %m"); DIE("tcsetattr");
more_active = 1; more_active = 1;
} }
@ -120,7 +121,7 @@ more_end(void)
more_active = 0; more_active = 0;
if (tcsetattr (0, TCSANOW, &stored_tty) < 0) if (tcsetattr (0, TCSANOW, &stored_tty) < 0)
die("tcsetattr: %m"); DIE("tcsetattr");
} }
static void static void
@ -137,7 +138,7 @@ input_init(void)
return; return;
if (tcgetattr(0, &stored_tty) < 0) if (tcgetattr(0, &stored_tty) < 0)
die("tcgetattr: %m"); DIE("tcgetattr");
if (signal(SIGINT, sig_handler) == SIG_IGN) if (signal(SIGINT, sig_handler) == SIG_IGN)
signal(SIGINT, SIG_IGN); signal(SIGINT, SIG_IGN);

View file

@ -248,7 +248,7 @@ server_connect(void)
server_fd = socket(AF_UNIX, SOCK_STREAM, 0); server_fd = socket(AF_UNIX, SOCK_STREAM, 0);
if (server_fd < 0) if (server_fd < 0)
die("Cannot create socket: %m"); DIE("Cannot create socket");
if (strlen(server_path) >= sizeof(sa.sun_path)) if (strlen(server_path) >= sizeof(sa.sun_path))
die("server_connect: path too long"); die("server_connect: path too long");
@ -257,9 +257,9 @@ server_connect(void)
sa.sun_family = AF_UNIX; sa.sun_family = AF_UNIX;
strcpy(sa.sun_path, server_path); strcpy(sa.sun_path, server_path);
if (connect(server_fd, (struct sockaddr *) &sa, SUN_LEN(&sa)) < 0) if (connect(server_fd, (struct sockaddr *) &sa, SUN_LEN(&sa)) < 0)
die("Unable to connect to server control socket (%s): %m", server_path); DIE("Unable to connect to server control socket (%s)", server_path);
if (fcntl(server_fd, F_SETFL, O_NONBLOCK) < 0) if (fcntl(server_fd, F_SETFL, O_NONBLOCK) < 0)
die("fcntl: %m"); DIE("fcntl");
} }
@ -309,13 +309,13 @@ server_read(void)
redo: redo:
c = read(server_fd, server_read_pos, server_read_buf + sizeof(server_read_buf) - server_read_pos); c = read(server_fd, server_read_pos, server_read_buf + sizeof(server_read_buf) - server_read_pos);
if (!c) if (!c)
die("Connection closed by server."); die("Connection closed by server");
if (c < 0) if (c < 0)
{ {
if (errno == EINTR) if (errno == EINTR)
goto redo; goto redo;
else else
die("Server read error: %m"); DIE("Server read error");
} }
start = server_read_buf; start = server_read_buf;
@ -366,7 +366,7 @@ select_loop(void)
if (errno == EINTR) if (errno == EINTR)
continue; continue;
else else
die("select: %m"); DIE("select");
} }
if (FD_ISSET(0, &select_fds)) if (FD_ISSET(0, &select_fds))
@ -399,7 +399,7 @@ wait_for_write(int fd)
if (errno == EINTR) if (errno == EINTR)
continue; continue;
else else
die("select: %m"); DIE("select");
} }
if (FD_ISSET(server_fd, &set)) if (FD_ISSET(server_fd, &set))
@ -426,7 +426,7 @@ server_send(char *cmd)
else if (errno == EINTR) else if (errno == EINTR)
continue; continue;
else else
die("Server write error: %m"); DIE("Server write error");
} }
else else
{ {
@ -436,19 +436,6 @@ server_send(char *cmd)
} }
} }
/* XXXX
get_term_size();
if (tcgetattr(0, &tty_save) != 0)
{
perror("tcgetattr error");
return(EXIT_FAILURE);
}
}
*/
int int
main(int argc, char **argv) main(int argc, char **argv)
{ {

View file

@ -34,3 +34,6 @@ char *cmd_expand(char *cmd);
/* client.c */ /* client.c */
void submit_command(char *cmd_raw); void submit_command(char *cmd_raw);
/* die() with system error messages */
#define DIE(x, y...) die(x ": %s", ##y, strerror(errno))

View file

@ -60,7 +60,7 @@ cmd_build_tree(void)
if (!new) if (!new)
{ {
int size = sizeof(struct cmd_node) + c-d; int size = sizeof(struct cmd_node) + c-d;
new = xmalloc(size); new = malloc(size);
bzero(new, size); bzero(new, size);
*old->plastson = new; *old->plastson = new;
old->plastson = &new->sibling; old->plastson = &new->sibling;
@ -314,7 +314,7 @@ cmd_expand(char *cmd)
puts("No such command. Press `?' for help."); puts("No such command. Press `?' for help.");
return NULL; return NULL;
} }
b = xmalloc(strlen(n->cmd->command) + strlen(args) + 1); b = malloc(strlen(n->cmd->command) + strlen(args) + 1);
sprintf(b, "%s%s", n->cmd->command, args); sprintf(b, "%s%s", n->cmd->command, args);
return b; return b;
} }

View file

@ -21,8 +21,11 @@ vlog(const char *msg, va_list args)
{ {
char buf[1024]; char buf[1024];
if (bvsnprintf(buf, sizeof(buf)-1, msg, args) < 0) int n = vsnprintf(buf, sizeof(buf), msg, args);
bsprintf(buf + sizeof(buf) - 100, " ... <too long>"); if (n < 0)
snprintf(buf, sizeof(buf), "???");
if (n >= sizeof(buf))
snprintf(buf + sizeof(buf) - 100, 100, " ... <too long>");
fputs(buf, stderr); fputs(buf, stderr);
fputc('\n', stderr); fputc('\n', stderr);
} }