Группа :: Система/Основа
Пакет: util-linux
Главная Изменения Спек Патчи Загрузить Bugs and FR
Патч: util-linux-2.10r-owl-write.patch
diff -Naur util-linux-2.11a.orig/lib/carefulputc.c util-linux-2.11a/lib/carefulputc.c
--- util-linux-2.11a.orig/lib/carefulputc.c Thu Nov 9 20:57:28 2000
+++ util-linux-2.11a/lib/carefulputc.c Thu May 17 12:21:10 2001
@@ -15,8 +15,8 @@
if (c == '\007' || c == '\t' || c == '\r' || c == '\n' ||
(!iso8859x_iscntrl(c) && (isprint(c) || isspace(c))))
ret = putc(c, fp);
- else if ((c & 0x80) || !isprint(c^0x40))
- ret = fprintf(fp, "\\%3o", (unsigned char) c);
+ else if ((c & 0x80) || iso8859x_iscntrl(c^0x40) || !isprint(c^0x40))
+ ret = fprintf(fp, "\\%3o", (unsigned char) c) > 0 ? 0 : EOF;
else {
ret = putc('^', fp);
if (ret != EOF)
diff -Naur util-linux-2.11a.orig/misc-utils/write.c util-linux-2.11a/misc-utils/write.c
--- util-linux-2.11a.orig/misc-utils/write.c Mon Mar 5 00:42:15 2001
+++ util-linux-2.11a/misc-utils/write.c Thu May 17 12:21:10 2001
@@ -46,6 +46,7 @@
*/
#include <stdio.h>
+#include <stdlib.h>
#include <unistd.h>
#include <utmp.h>
#include <errno.h>
@@ -56,6 +57,7 @@
#include <stdlib.h>
#include <locale.h>
#include <signal.h>
+#include <limits.h>
#include <sys/param.h>
#include <sys/signal.h>
#include <sys/stat.h>
@@ -67,7 +69,7 @@
#include "nls.h"
void search_utmp(char *, char *, char *, uid_t);
-void do_write(char *, char *, uid_t);
+void do_write(char *, char *, char *, uid_t);
void wr_fputs(char *);
static void done(int);
int term_chk(char *, int *, time_t *, int);
@@ -80,9 +82,13 @@
int msgsok, myttyfd;
char tty[MAXPATHLEN], *mytty;
- setlocale(LC_ALL, "");
+ unsetenv("TZ");
+
+ setlocale(LC_CTYPE, "");
+#if 0
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
+#endif
/* check that sender has write enabled */
if (isatty(fileno(stdin)))
@@ -121,7 +127,7 @@
switch (argc) {
case 2:
search_utmp(argv[1], tty, mytty, myuid);
- do_write(tty, mytty, myuid);
+ do_write(argv[1], tty, mytty, myuid);
break;
case 3:
if (!strncmp(argv[2], "/dev/", 5))
@@ -140,7 +146,7 @@
argv[1], argv[2]);
exit(1);
}
- do_write(argv[2], mytty, myuid);
+ do_write(argv[1], argv[2], mytty, myuid);
break;
default:
(void)fprintf(stderr, _("usage: write user [tty]\n"));
@@ -276,20 +282,34 @@
/*
* do_write - actually make the connection
*/
-void do_write(char *tty, char *mytty, uid_t myuid) {
- char *login, *pwuid, *nows;
+void do_write(char *user, char *tty, char *mytty, uid_t myuid) {
+ char *login, *pwuid, *nows, *prompt, *prefix;
struct passwd *pwd;
time_t now;
- char path[MAXPATHLEN], host[MAXHOSTNAMELEN], line[512];
+ char path[MAXPATHLEN], host[MAXHOSTNAMELEN], line[BUFSIZ + 1];
/* Determine our login name(s) before the we reopen() stdout */
if ((pwd = getpwuid(myuid)) != NULL)
pwuid = pwd->pw_name;
- else
- pwuid = "???";
+ else {
+ perror("getpwuid");
+ pwuid = alloca(4 + sizeof(myuid) * CHAR_BIT / 3 + 1 + 1);
+ if (!pwuid) exit(1);
+ sprintf(pwuid, "UID %u", myuid);
+ }
if ((login = getlogin()) == NULL)
login = pwuid;
+ if (isatty(STDIN_FILENO)) {
+ prompt = alloca(strlen(user) + 2 + 1);
+ if (!prompt) exit(1);
+ sprintf(prompt, "%s> ", user);
+ } else
+ prompt = "";
+ prefix = alloca(strlen(login) + 3 + 1);
+ if (!prefix) exit(1);
+ sprintf(prefix, "<%s> ", login);
+
if (strlen(tty) + 6 > sizeof(path))
exit(1);
(void)sprintf(path, "/dev/%s", tty);
@@ -317,8 +337,16 @@
login, host, mytty, nows + 11);
printf("\r\n");
- while (fgets(line, sizeof(line), stdin) != NULL)
+ fprintf(stderr, "%s", prompt);
+ while (fgets(line, sizeof(line), stdin) != NULL) {
+ wr_fputs(prefix);
wr_fputs(line);
+ if (!strchr(line, '\n')) {
+ wr_fputs("\n");
+ fputc('\n', stderr);
+ }
+ fprintf(stderr, "%s", prompt);
+ }
}
/*
@@ -327,6 +355,7 @@
static void
done(int dummy) {
(void)printf("EOF\r\n");
+ if (isatty(STDIN_FILENO)) fputc('\n', stderr);
exit(0);
}