Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F107086793
D48225.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D48225.diff
View Options
diff --git a/bin/timeout/timeout.1 b/bin/timeout/timeout.1
--- a/bin/timeout/timeout.1
+++ b/bin/timeout/timeout.1
@@ -24,7 +24,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd December 28, 2024
+.Dd January 4, 2025
.Dt TIMEOUT 1
.Os
.Sh NAME
@@ -34,7 +34,7 @@
.Nm
.Op Fl k Ar time | Fl -kill-after Ar time
.Op Fl s Ar sig | Fl -signal Ar sig
-.Op Fl -kill-after Ar time | Fl k Ar time
+.Op Fl v | Fl -verbose
.Op Fl -foreground
.Op Fl -preserve-status
.Ar duration
@@ -76,6 +76,8 @@
By default,
.Dv SIGTERM
is sent.
+.It Fl v , Fl -verbose
+Show information to stderr about any signal sent on timeout.
.It Fl -foreground
Do not propagate timeout to the children of
.Ar command .
diff --git a/bin/timeout/timeout.c b/bin/timeout/timeout.c
--- a/bin/timeout/timeout.c
+++ b/bin/timeout/timeout.c
@@ -49,14 +49,17 @@
static sig_atomic_t sig_term = 0;
static sig_atomic_t sig_alrm = 0;
static sig_atomic_t sig_ign = 0;
+static const char *command = NULL;
+static bool verbose = false;
static void
usage(void)
{
fprintf(stderr, "Usage: %s [-k time | --kill-after time]"
- " [-s sig | --signal sig] [--foreground] [--preserve-status]"
- " <duration> <command> <arg ...>\n", getprogname());
+ " [-s sig | --signal sig] [-v | --verbose] [--foreground]"
+ " [--preserve-status] <duration> <command> <arg ...>\n",
+ getprogname());
exit(EXIT_FAILURE);
}
@@ -146,6 +149,16 @@
}
}
+static void
+send_sig(pid_t pid, int signo)
+{
+ if (verbose) {
+ warnx("sending signal %s(%d) to command '%s'",
+ sys_signame[signo], signo, command);
+ }
+ kill(pid, signo);
+}
+
static void
set_interval(double iv)
{
@@ -196,10 +209,11 @@
{ "kill-after", required_argument, NULL, 'k'},
{ "signal", required_argument, NULL, 's'},
{ "help", no_argument, NULL, 'h'},
+ { "verbose", no_argument, NULL, 'v'},
{ NULL, 0, NULL, 0 }
};
- while ((ch = getopt_long(argc, argv, "+k:s:h", longopts, NULL)) != -1) {
+ while ((ch = getopt_long(argc, argv, "+k:s:vh", longopts, NULL)) != -1) {
switch (ch) {
case 'k':
do_second_kill = true;
@@ -208,6 +222,9 @@
case 's':
killsig = parse_signal(optarg);
break;
+ case 'v':
+ verbose = true;
+ break;
case 0:
break;
case 'h':
@@ -225,6 +242,7 @@
first_kill = parse_duration(argv[0]);
argc--;
argv++;
+ command = argv[0];
if (!foreground) {
/* Acquire a reaper */
@@ -315,7 +333,7 @@
procctl(P_PID, getpid(), PROC_REAP_KILL,
&killemall);
} else
- kill(pid, killsig);
+ send_sig(pid, killsig);
if (do_second_kill) {
set_interval(second_kill);
@@ -332,7 +350,7 @@
procctl(P_PID, getpid(), PROC_REAP_KILL,
&killemall);
} else
- kill(pid, sig_term);
+ send_sig(pid, sig_term);
if (do_second_kill) {
set_interval(second_kill);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Jan 10, 9:55 PM (4 h, 20 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
15736932
Default Alt Text
D48225.diff (2 KB)
Attached To
Mode
D48225: timeout(1): Add -v/--verbose option to show diagnosis info
Attached
Detach File
Event Timeline
Log In to Comment