Bug Summary

File:src/usr.sbin/watchdogd/watchdogd.c
Warning:line 93, column 2
Value stored to 'argv' is never read

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple amd64-unknown-openbsd7.0 -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name watchdogd.c -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 1 -pic-is-pie -mframe-pointer=all -relaxed-aliasing -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -target-feature +retpoline-indirect-calls -target-feature +retpoline-indirect-branches -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/usr/src/usr.sbin/watchdogd/obj -resource-dir /usr/local/lib/clang/13.0.0 -internal-isystem /usr/local/lib/clang/13.0.0/include -internal-externc-isystem /usr/include -O2 -fdebug-compilation-dir=/usr/src/usr.sbin/watchdogd/obj -ferror-limit 19 -fwrapv -D_RET_PROTECTOR -ret-protector -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-valloc -fno-builtin-free -fno-builtin-strdup -fno-builtin-strndup -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /home/ben/Projects/vmm/scan-build/2022-01-12-194120-40624-1 -x c /usr/src/usr.sbin/watchdogd/watchdogd.c
1/* $OpenBSD: watchdogd.c,v 1.15 2015/01/16 06:40:22 deraadt Exp $ */
2
3/*
4 * Copyright (c) 2005 Marc Balmer <mbalmer@openbsd.org>
5 *
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18
19#include <sys/types.h>
20#include <sys/resource.h>
21#include <sys/signal.h>
22#include <sys/sysctl.h>
23#include <sys/mman.h>
24
25#include <err.h>
26#include <errno(*__errno()).h>
27#include <stdio.h>
28#include <stdlib.h>
29#include <unistd.h>
30
31volatile sig_atomic_t quit = 0;
32
33__dead__attribute__((__noreturn__)) void usage(void);
34void sighdlr(int);
35int main(int, char *[]);
36
37__dead__attribute__((__noreturn__)) void
38usage(void)
39{
40 extern char *__progname;
41
42 fprintf(stderr(&__sF[2]), "usage: %s [-dnq] [-i interval] [-p period]\n",
43 __progname);
44 exit(1);
45}
46
47/* ARGSUSED */
48void
49sighdlr(int signum)
50{
51 quit = 1;
52}
53
54int
55main(int argc, char *argv[])
56{
57 struct rlimit rlim;
58 const char *errstr;
59 size_t len;
60 u_int interval = 0, period = 30, nperiod;
61 int ch, trigauto, sauto, speriod;
62 int quiet = 0, daemonize = 1, retval = 1, do_restore = 1;
63 int mib[3];
64
65 while ((ch = getopt(argc, argv, "di:np:q")) != -1) {
66 switch (ch) {
67 case 'd':
68 daemonize = 0;
69 break;
70 case 'i':
71 interval = (u_int)strtonum(optarg, 1LL, 86400LL,
72 &errstr);
73 if (errstr)
74 errx(1, "interval is %s: %s", errstr, optarg);
75 break;
76 case 'n':
77 do_restore = 0;
78 break;
79 case 'p':
80 period = (u_int)strtonum(optarg, 2LL, 86400LL, &errstr);
81 if (errstr)
82 errx(1, "period is %s: %s", errstr, optarg);
83 break;
84 case 'q':
85 quiet = 1;
86 break;
87 default:
88 usage();
89 }
90 }
91
92 argc -= optind;
93 argv += optind;
Value stored to 'argv' is never read
94 if (argc > 0)
95 usage();
96
97 if (interval == 0 && (interval = period / 3) == 0)
98 interval = 1;
99
100 if (period <= interval)
101 errx(1, "retrigger interval too long");
102
103 /* save kern.watchdog.period and kern.watchdog.auto for restore */
104 mib[0] = CTL_KERN1;
105 mib[1] = KERN_WATCHDOG64;
106 mib[2] = KERN_WATCHDOG_PERIOD1;
107
108 len = sizeof(speriod);
109 if (sysctl(mib, 3, &speriod, &len, &period, sizeof(period)) == -1) {
110 if (errno(*__errno()) == EOPNOTSUPP45)
111 errx(1, "no watchdog timer available");
112 else
113 err(1, "can't access kern.watchdog.period");
114 }
115
116 mib[2] = KERN_WATCHDOG_AUTO2;
117 len = sizeof(sauto);
118 trigauto = 0;
119
120 if (sysctl(mib, 3, &sauto, &len, &trigauto, sizeof(trigauto)) == -1)
121 err(1, "can't access kern.watchdog.auto");
122
123 /* Double check the timeout period, some devices change the value */
124 mib[2] = KERN_WATCHDOG_PERIOD1;
125 len = sizeof(nperiod);
126 if (sysctl(mib, 3, &nperiod, &len, NULL((void *)0), 0) == -1) {
127 warnx("can't read back kern.watchdog.period, "
128 "restoring original values");
129 goto restore;
130 }
131
132 if (nperiod != period && !quiet)
133 warnx("period adjusted to %d by device", nperiod);
134
135 if (nperiod <= interval) {
136 warnx("retrigger interval %d too long, "
137 "restoring original values", interval);
138 goto restore;
139 }
140
141 if (daemonize && daemon(0, 0)) {
142 warn("can't daemonize, restoring original values");
143 goto restore;
144 }
145
146 /*
147 * mlockall() below will wire the whole stack up to the limit
148 * thus we have to reduce stack size to avoid resource abuse
149 */
150 rlim.rlim_cur = 256 * 1024;
151 rlim.rlim_max = 256 * 1024;
152 (void)setrlimit(RLIMIT_STACK3, &rlim);
153
154 (void)mlockall(MCL_CURRENT0x01 | MCL_FUTURE0x02);
155 setpriority(PRIO_PROCESS0, getpid(), -5);
156
157 signal(SIGTERM15, sighdlr);
158
159 retval = 0;
160 while (!quit) {
161 if (sysctl(mib, 3, NULL((void *)0), 0, &period, sizeof(period)) == -1)
162 quit = retval = 1;
163 sleep(interval);
164 }
165
166 if (do_restore) {
167restore: sysctl(mib, 3, NULL((void *)0), 0, &speriod, sizeof(speriod));
168 mib[2] = KERN_WATCHDOG_AUTO2;
169 sysctl(mib, 3, NULL((void *)0), 0, &sauto, sizeof(sauto));
170 }
171
172 return retval;
173}