Репозиторий Sisyphus
Последнее обновление: 1 октября 2023 | Пакетов: 18631 | Посещений: 37858634
en ru br
Репозитории ALT
S:2.39.2-alt1
5.1: 2.16.1-alt1
4.1: 2.13-alt8
4.0: 2.12r-alt6
3.0: 2.12q-alt1
www.altlinux.org/Changes

Группа :: Система/Основа
Пакет: util-linux

 Главная   Изменения   Спек   Патчи   Sources   Загрузить   Gear   Bugs and FR  Repocop 

Патч: util-linux-ng-2.13-owl-write.patch
Скачать


--- util-linux-2.14/misc-utils/write.c.fix41	2008-07-30 03:12:47 +0400
+++ util-linux-2.14/misc-utils/write.c	2008-07-30 03:13:37 +0400
@@ -54,8 +54,9 @@
 #include <pwd.h>
 #include <string.h>
 #include <stdlib.h>
 #include <signal.h>
+#include <limits.h>
 #include <sys/param.h>
 #include <sys/stat.h>
 #include <sys/file.h>
 #include <sys/time.h>
@@ -64,9 +65,9 @@
 #include "carefulputc.h"
 #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);
 int utmp_chk(char *, char *);
@@ -79,11 +80,10 @@ main(int argc, char **argv) {
 	uid_t myuid;
 	int msgsok, myttyfd;
 	char tty[MAXPATHLEN], *mytty;
 
-	setlocale(LC_ALL, "");
-	bindtextdomain(PACKAGE, LOCALEDIR);
-	textdomain(PACKAGE);
+	unsetenv("TZ");
+	setlocale(LC_CTYPE, "");
 
 	myegid = getegid();
 
 	/* check that sender has write enabled */
@@ -122,9 +122,9 @@ main(int argc, char **argv) {
 	/* check args */
 	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))
 			argv[2] += 5;
@@ -141,9 +141,9 @@ main(int argc, char **argv) {
 			    _("write: %s has messages disabled on %s\n"),
 			    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"));
 		exit(1);
@@ -279,22 +279,36 @@ int term_chk(char *tty, int *msgsokP, ti
 
 /*
  * 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);
 	if ((freopen(path, "w", stdout)) == NULL) {
@@ -320,18 +334,27 @@ void do_write(char *tty, char *mytty, ui
 		(void)printf(_("Message from %s@%s on %s at %s ..."),
 			     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);
+	}
 }
 
 /*
  * done - cleanup and exit
  */
 static void
 done(int dummy) {
 	(void)printf("EOF\r\n");
+	if (isatty(STDIN_FILENO)) fputc('\n', stderr);
 	exit(0);
 }
 
 /*
--- util-linux-2.14/include/carefulputc.h.fix41	2008-07-30 03:12:47 +0400
+++ util-linux-2.14/include/carefulputc.h	2008-07-30 03:12:48 +0400
@@ -15,10 +15,10 @@ static inline int carefulputc(int c, FIL
 
 	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)
 			ret = putc(c^0x40, fp);
 
дизайн и разработка: Vladimir Lettiev aka crux © 2004-2005, Andrew Avramenko aka liks © 2007-2008
текущий майнтейнер: Michael Shigorin