mirror of
https://github.com/sheumann/hush.git
synced 2024-12-27 01:32:08 +00:00
0ef64bdb40
This change retains "or later" state! No licensing _changes_ here, only form is adjusted (article, space between "GPL" and "v2" and so on). Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
37 lines
829 B
C
37 lines
829 B
C
/* vi: set sw=4 ts=4: */
|
|
/*
|
|
* wall - write a message to all logged-in users
|
|
* Copyright (c) 2009 Bernhard Reutner-Fischer
|
|
*
|
|
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
|
*/
|
|
|
|
#include "libbb.h"
|
|
#include <utmp.h>
|
|
|
|
int wall_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
|
int wall_main(int argc UNUSED_PARAM, char **argv)
|
|
{
|
|
struct utmp *ut;
|
|
char *msg;
|
|
int fd = argv[1] ? xopen(argv[1], O_RDONLY) : STDIN_FILENO;
|
|
|
|
msg = xmalloc_read(fd, NULL);
|
|
if (ENABLE_FEATURE_CLEAN_UP && argv[1])
|
|
close(fd);
|
|
setutent();
|
|
while ((ut = getutent()) != NULL) {
|
|
char *line;
|
|
if (ut->ut_type != USER_PROCESS)
|
|
continue;
|
|
line = concat_path_file("/dev", ut->ut_line);
|
|
xopen_xwrite_close(line, msg);
|
|
free(line);
|
|
}
|
|
if (ENABLE_FEATURE_CLEAN_UP) {
|
|
endutent();
|
|
free(msg);
|
|
}
|
|
return EXIT_SUCCESS;
|
|
}
|