Last change
on this file since 3268 was 3232, checked in by Bruno Cornec, 11 years ago |
- Update mindi-busybox to 1.21.1
|
-
Property svn:eol-style
set to
native
|
File size:
1.0 KB
|
Rev | Line | |
---|
[2725] | 1 | /* vi: set sw=4 ts=4: */
|
---|
| 2 | /*
|
---|
| 3 | * wall - write a message to all logged-in users
|
---|
| 4 | * Copyright (c) 2009 Bernhard Reutner-Fischer
|
---|
| 5 | *
|
---|
| 6 | * Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
---|
| 7 | */
|
---|
| 8 |
|
---|
[3232] | 9 | //usage:#define wall_trivial_usage
|
---|
| 10 | //usage: "[FILE]"
|
---|
| 11 | //usage:#define wall_full_usage "\n\n"
|
---|
| 12 | //usage: "Write content of FILE or stdin to all logged-in users"
|
---|
| 13 | //usage:
|
---|
| 14 | //usage:#define wall_sample_usage
|
---|
| 15 | //usage: "echo foo | wall\n"
|
---|
| 16 | //usage: "wall ./mymessage"
|
---|
| 17 |
|
---|
[2725] | 18 | #include "libbb.h"
|
---|
| 19 |
|
---|
| 20 | int wall_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
---|
| 21 | int wall_main(int argc UNUSED_PARAM, char **argv)
|
---|
| 22 | {
|
---|
| 23 | struct utmp *ut;
|
---|
| 24 | char *msg;
|
---|
| 25 | int fd = argv[1] ? xopen(argv[1], O_RDONLY) : STDIN_FILENO;
|
---|
| 26 |
|
---|
| 27 | msg = xmalloc_read(fd, NULL);
|
---|
| 28 | if (ENABLE_FEATURE_CLEAN_UP && argv[1])
|
---|
| 29 | close(fd);
|
---|
| 30 | setutent();
|
---|
| 31 | while ((ut = getutent()) != NULL) {
|
---|
| 32 | char *line;
|
---|
| 33 | if (ut->ut_type != USER_PROCESS)
|
---|
| 34 | continue;
|
---|
| 35 | line = concat_path_file("/dev", ut->ut_line);
|
---|
| 36 | xopen_xwrite_close(line, msg);
|
---|
| 37 | free(line);
|
---|
| 38 | }
|
---|
| 39 | if (ENABLE_FEATURE_CLEAN_UP) {
|
---|
| 40 | endutent();
|
---|
| 41 | free(msg);
|
---|
| 42 | }
|
---|
| 43 | return EXIT_SUCCESS;
|
---|
| 44 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.