Bug Summary

File:src/usr.sbin/rpc.lockd/lockd.c
Warning:line 87, column 4
Value stored to 'grace_period' 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 lockd.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/rpc.lockd/obj -resource-dir /usr/local/lib/clang/13.0.0 -I . -D SYSLOG -internal-isystem /usr/local/lib/clang/13.0.0/include -internal-externc-isystem /usr/include -O2 -Wno-enum-conversion -fdebug-compilation-dir=/usr/src/usr.sbin/rpc.lockd/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/rpc.lockd/lockd.c
1/* $OpenBSD: lockd.c,v 1.14 2015/04/18 18:28:38 deraadt Exp $ */
2
3/*
4 * Copyright (c) 1995
5 * A.R. Gordon (andrew.gordon@net-tel.co.uk). All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed for the FreeBSD project
18 * 4. Neither the name of the author nor the names of any co-contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY ANDREW GORDON AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 *
34 */
35
36#include <sys/socket.h>
37#include <netinet/in.h>
38#include <rpc/rpc.h>
39#include <rpc/pmap_clnt.h>
40#include <rpcsvc/sm_inter.h>
41#include "nlm_prot.h"
42#include <arpa/inet.h>
43#include <stdio.h>
44#include <syslog.h>
45#include <stdlib.h>
46#include <err.h>
47#include <errno(*__errno()).h>
48#include <signal.h>
49#include <limits.h>
50#include <string.h>
51#include <unistd.h>
52#include <netdb.h>
53
54#include "lockd.h"
55
56int debug_level = 0; /* 0 = no debugging syslog() calls */
57int _rpcsvcdirty = 0;
58int grace_expired;
59
60void nlm_prog_0(struct svc_req *, SVCXPRT *);
61void nlm_prog_1(struct svc_req *, SVCXPRT *);
62void nlm_prog_3(struct svc_req *, SVCXPRT *);
63void nlm_prog_4(struct svc_req *, SVCXPRT *);
64
65static void sigalarm_handler(int);
66static void usage(void);
67
68int
69main(int argc, char *argv[])
70{
71 SVCXPRT *transp;
72 const char *errstr;
73 int ch;
74 struct sigaction sigchild, sigalarm;
75 int grace_period = 30;
76
77 while ((ch = getopt(argc, argv, "d:g:")) != (-1)) {
78 switch (ch) {
79 case 'd':
80 debug_level = strtonum(optarg, 1, INT_MAX2147483647, &errstr);
81 if (errstr) {
82 usage();
83 /* NOTREACHED */
84 }
85 break;
86 case 'g':
87 grace_period = strtonum(optarg, 1, INT_MAX2147483647, &errstr);
Value stored to 'grace_period' is never read
88 if (errstr) {
89 usage();
90 /* NOTREACHED */
91 }
92 break;
93 default:
94 case '?':
95 usage();
96 /* NOTREACHED */
97 }
98 }
99
100 (void) pmap_unset(NLM_PROG((u_long)100021), NLM_SM((u_long)0));
101 (void) pmap_unset(NLM_PROG((u_long)100021), NLM_VERS((u_long)1));
102 (void) pmap_unset(NLM_PROG((u_long)100021), NLM_VERSX((u_long)3));
103 (void) pmap_unset(NLM_PROG((u_long)100021), NLM_VERS4((u_long)4));
104
105 transp = svcudp_create(RPC_ANYSOCK-1);
106 if (transp == NULL0) {
107 fprintf(stderr(&__sF[2]), "cannot create udp service.\n");
108 exit(1);
109 }
110 if (!svc_register(transp, NLM_PROG((u_long)100021), NLM_SM((u_long)0),
111 (void (*) (struct svc_req *, SVCXPRT *)) nlm_prog_0, IPPROTO_UDP17)) {
112 fprintf(stderr(&__sF[2]), "unable to register (NLM_PROG, NLM_SM, udp).\n");
113 exit(1);
114 }
115 if (!svc_register(transp, NLM_PROG((u_long)100021), NLM_VERS((u_long)1),
116 (void (*) (struct svc_req *, SVCXPRT *)) nlm_prog_1, IPPROTO_UDP17)) {
117 fprintf(stderr(&__sF[2]), "unable to register (NLM_PROG, NLM_VERS, udp).\n");
118 exit(1);
119 }
120 if (!svc_register(transp, NLM_PROG((u_long)100021), NLM_VERSX((u_long)3),
121 (void (*) (struct svc_req *, SVCXPRT *)) nlm_prog_3, IPPROTO_UDP17)) {
122 fprintf(stderr(&__sF[2]), "unable to register (NLM_PROG, NLM_VERSX, udp).\n");
123 exit(1);
124 }
125 if (!svc_register(transp, NLM_PROG((u_long)100021), NLM_VERS4((u_long)4),
126 (void (*) (struct svc_req *, SVCXPRT *)) nlm_prog_4, IPPROTO_UDP17)) {
127 fprintf(stderr(&__sF[2]), "unable to register (NLM_PROG, NLM_VERS4, udp).\n");
128 exit(1);
129 }
130 transp = svctcp_create(RPC_ANYSOCK-1, 0, 0);
131 if (transp == NULL0) {
132 fprintf(stderr(&__sF[2]), "cannot create tcp service.\n");
133 exit(1);
134 }
135 if (!svc_register(transp, NLM_PROG((u_long)100021), NLM_VERS((u_long)1),
136 (void (*) (struct svc_req *, SVCXPRT *)) nlm_prog_1, IPPROTO_TCP6)) {
137 fprintf(stderr(&__sF[2]), "unable to register (NLM_PROG, NLM_VERS, tcp).\n");
138 exit(1);
139 }
140 if (!svc_register(transp, NLM_PROG((u_long)100021), NLM_VERSX((u_long)3),
141 (void (*) (struct svc_req *, SVCXPRT *)) nlm_prog_3, IPPROTO_TCP6)) {
142 fprintf(stderr(&__sF[2]), "unable to register (NLM_PROG, NLM_VERSX, tcp).\n");
143 exit(1);
144 }
145 if (!svc_register(transp, NLM_PROG((u_long)100021), NLM_VERS4((u_long)4),
146 (void (*) (struct svc_req *, SVCXPRT *)) nlm_prog_4, IPPROTO_TCP6)) {
147 fprintf(stderr(&__sF[2]), "unable to register (NLM_PROG, NLM_VERS4, tcp).\n");
148 exit(1);
149 }
150
151 /*
152 * Note that it is NOT sensible to run this program from inetd - the
153 * protocol assumes that it will run immediately at boot time.
154 */
155 if (daemon(0, 0) == -1) {
156 err(1, "cannot fork");
157 /* NOTREACHED */
158 }
159
160 openlog("rpc.lockd", 0, LOG_DAEMON(3<<3));
161 if (debug_level)
162 syslog(LOG_INFO6, "Starting, debug level %d", debug_level);
163 else
164 syslog(LOG_INFO6, "Starting");
165
166 sigchild.sa_handler__sigaction_u.__sa_handler = sigchild_handler;
167 sigemptyset(&sigchild.sa_mask);
168 sigchild.sa_flags = SA_RESTART0x0002;
169 if (sigaction(SIGCHLD20, &sigchild, NULL0) != 0) {
170 syslog(LOG_WARNING4, "sigaction(SIGCHLD) failed (%m)");
171 exit(1);
172 }
173 sigalarm.sa_handler__sigaction_u.__sa_handler = sigalarm_handler;
174 sigemptyset(&sigalarm.sa_mask);
175 sigalarm.sa_flags = SA_RESETHAND0x0004; /* should only happen once */
176 sigalarm.sa_flags |= SA_RESTART0x0002;
177 if (sigaction(SIGALRM14, &sigalarm, NULL0) != 0) {
178 syslog(LOG_WARNING4, "sigaction(SIGALRM) failed (%m)");
179 exit(1);
180 }
181 grace_expired = 0;
182 if (alarm(10) == (unsigned int)-1) {
183 syslog(LOG_WARNING4, "alarm failed (%m)");
184 exit(1);
185 }
186
187 svc_run(); /* Should never return */
188 return 1;
189}
190
191static void
192/*ARGSUSED*/
193sigalarm_handler(int s)
194{
195 grace_expired = 1;
196}
197
198static void
199usage()
200{
201 errx(1, "usage: rpc.lockd [-d [debug_level]] [-g grace_period]");
202}