Mon Nov 2 20:50:24 2020 UTC ()
make(1): clean up CompatDeleteTarget and CompatInterrupt


(rillig)
diff -r1.173 -r1.174 src/usr.bin/make/compat.c

cvs diff -r1.173 -r1.174 src/usr.bin/make/compat.c (expand / switch to unified diff)

--- src/usr.bin/make/compat.c 2020/11/01 17:47:26 1.173
+++ src/usr.bin/make/compat.c 2020/11/02 20:50:24 1.174
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: compat.c,v 1.173 2020/11/01 17:47:26 rillig Exp $ */ 1/* $NetBSD: compat.c,v 1.174 2020/11/02 20:50:24 rillig Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. 4 * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to Berkeley by 7 * This code is derived from software contributed to Berkeley by
8 * Adam de Boor. 8 * Adam de Boor.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -86,69 +86,67 @@ @@ -86,69 +86,67 @@
86#include <sys/stat.h> 86#include <sys/stat.h>
87#include <sys/wait.h> 87#include <sys/wait.h>
88 88
89#include <errno.h> 89#include <errno.h>
90#include <signal.h> 90#include <signal.h>
91 91
92#include "make.h" 92#include "make.h"
93#include "dir.h" 93#include "dir.h"
94#include "job.h" 94#include "job.h"
95#include "metachar.h" 95#include "metachar.h"
96#include "pathnames.h" 96#include "pathnames.h"
97 97
98/* "@(#)compat.c 8.2 (Berkeley) 3/19/94" */ 98/* "@(#)compat.c 8.2 (Berkeley) 3/19/94" */
99MAKE_RCSID("$NetBSD: compat.c,v 1.173 2020/11/01 17:47:26 rillig Exp $"); 99MAKE_RCSID("$NetBSD: compat.c,v 1.174 2020/11/02 20:50:24 rillig Exp $");
100 100
101static GNode *curTarg = NULL; 101static GNode *curTarg = NULL;
102static pid_t compatChild; 102static pid_t compatChild;
103static int compatSigno; 103static int compatSigno;
104 104
105/* 105/*
106 * CompatDeleteTarget -- delete a failed, interrupted, or otherwise 106 * CompatDeleteTarget -- delete the file of a failed, interrupted, or
107 * duffed target if not inhibited by .PRECIOUS. 107 * otherwise duffed target if not inhibited by .PRECIOUS.
108 */ 108 */
109static void 109static void
110CompatDeleteTarget(GNode *gn) 110CompatDeleteTarget(GNode *gn)
111{ 111{
112 if (gn != NULL && !Targ_Precious(gn)) { 112 if (gn != NULL && !Targ_Precious(gn)) {
113 const char *file = GNode_VarTarget(gn); 113 const char *file = GNode_VarTarget(gn);
114 114
115 if (!opts.noExecute && eunlink(file) != -1) { 115 if (!opts.noExecute && eunlink(file) != -1) {
116 Error("*** %s removed", file); 116 Error("*** %s removed", file);
117 } 117 }
118 } 118 }
119} 119}
120 120
121/* Interrupt the creation of the current target and remove it if it ain't 121/* Interrupt the creation of the current target and remove it if it ain't
122 * precious. Then exit. 122 * precious. Then exit.
123 * 123 *
124 * If .INTERRUPT exists, its commands are run first WITH INTERRUPTS IGNORED. 124 * If .INTERRUPT exists, its commands are run first WITH INTERRUPTS IGNORED.
125 * 125 *
126 * XXX: is .PRECIOUS supposed to inhibit .INTERRUPT? I doubt it, but I've 126 * XXX: is .PRECIOUS supposed to inhibit .INTERRUPT? I doubt it, but I've
127 * left the logic alone for now. - dholland 20160826 127 * left the logic alone for now. - dholland 20160826
128 */ 128 */
129static void 129static void
130CompatInterrupt(int signo) 130CompatInterrupt(int signo)
131{ 131{
132 GNode *gn; 
133 
134 CompatDeleteTarget(curTarg); 132 CompatDeleteTarget(curTarg);
135 133
136 if (curTarg != NULL && !Targ_Precious(curTarg)) { 134 if (curTarg != NULL && !Targ_Precious(curTarg)) {
137 /* 135 /*
138 * Run .INTERRUPT only if hit with interrupt signal 136 * Run .INTERRUPT only if hit with interrupt signal
139 */ 137 */
140 if (signo == SIGINT) { 138 if (signo == SIGINT) {
141 gn = Targ_FindNode(".INTERRUPT"); 139 GNode *gn = Targ_FindNode(".INTERRUPT");
142 if (gn != NULL) { 140 if (gn != NULL) {
143 Compat_Make(gn, gn); 141 Compat_Make(gn, gn);
144 } 142 }
145 } 143 }
146 } 144 }
147 145
148 if (signo == SIGQUIT) 146 if (signo == SIGQUIT)
149 _exit(signo); 147 _exit(signo);
150 148
151 /* 149 /*
152 * If there is a child running, pass the signal on. 150 * If there is a child running, pass the signal on.
153 * We will exist after it has exited. 151 * We will exist after it has exited.
154 */ 152 */