Fix camcontrol timestamp setting and update the man page.

camcontrol timestamp -s would somtimes fail due to stack garbage.  Zero out
the timestamp parameters to fix it.

Fix another nearby bug, and update the man page.

sbin/camcontrol/timestamp.c:
	In set_timestamp(), bzero ts_p prior to creating the timestamp.
	Previously stack garbage could cause some tape drives to reject the
	timestamp.

	In set_timestamp(), check for failures from strptime().

sbin/camcontrol/camcontrol.8:
	Add the time argument to the -T option to camcontrol timestamp -s
	in the long description.

	Change the time/date format used in the camcontrol timestamp
	example to RFC 2822 format.  This fixes a time zone issue with the
	original example by specifying the time zone as -0600.  Otherwise,
	the time zone seems to default to standard time in the current
	locale, which makes the time, when reported back from the drive,
	1 hour off from the intended setting.  This also fixes a duplicate
	day of the week ("Wednesday Wed") in the previous example.

Submitted by:	Sam Klopsch
MFC after:	3 days
Sponsored by:	Spectra Logic
This commit is contained in:
Kenneth D. Merry 2017-05-01 18:53:47 +00:00
parent 23bff6073b
commit d618624cbd
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=317657
2 changed files with 11 additions and 5 deletions

View File

@ -27,7 +27,7 @@
.\"
.\" $FreeBSD$
.\"
.Dd February 17, 2017
.Dd May 1, 2017
.Dt CAMCONTROL 8
.Os
.Sh NAME
@ -2488,7 +2488,7 @@ Specify the strptime format string, as documented in strptime(3).
The time must also be specified with the
.Fl T
option.
.It Fl T
.It Fl T Ar time
Provide the time in the format specified with the
.Fl f
option.
@ -2814,8 +2814,8 @@ drive
.Pa ada0 .
.Pp
.Bd -literal -offset indent
camcontrol timestamp sa0 -s -f "%A %c" \e
-T "Wednesday Wed Oct 26 21:43:57 2016"
camcontrol timestamp sa0 -s -f "%a, %d %b %Y %T %z" \e
-T "Wed, 26 Oct 2016 21:43:57 -0600"
.Ed
.Pp
Set the timestamp of drive

View File

@ -282,12 +282,18 @@ set_timestamp(struct cam_device *device, char *format_string,
ts = (uint64_t) time_value;
} else {
bzero(&time_struct, sizeof(struct tm));
strptime(timestamp_string, format_string, &time_struct);
if (strptime(timestamp_string, format_string,
&time_struct) == NULL) {
warnx("%s: strptime(3) failed", __func__);
error = 1;
goto bailout;
}
time_value = mktime(&time_struct);
ts = (uint64_t) time_value;
}
/* Convert time from seconds to milliseconds */
ts *= 1000;
bzero(&ts_p, sizeof(ts_p));
scsi_create_timestamp(ts_p.timestamp, ts);
scsi_set_timestamp(&ccb->csio,