Print this page
make: translate using gettext, rather than the unmaintainable catgets
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/make/lib/vroot/lock.cc
+++ new/usr/src/cmd/make/lib/vroot/lock.cc
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
↓ open down ↓ |
15 lines elided |
↑ open up ↑ |
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
23 23 * Use is subject to license terms.
24 24 */
25 25
26 -#include <avo/intl.h> /* for NOCATGETS */
27 26 #include <stdio.h>
28 27 #include <stdlib.h>
29 28 #include <string.h>
30 29 #include <sys/errno.h>
31 30 #include <sys/param.h>
32 31 #include <sys/stat.h>
33 32 #include <sys/types.h>
34 33 #include <unistd.h>
35 34 #include <vroot/vroot.h>
36 -#include <mksdmsi18n/mksdmsi18n.h>
37 35 #include <signal.h>
38 36 #include <errno.h> /* errno */
37 +#include <libintl.h>
39 38
40 39 extern char *sys_errlist[];
41 40 extern int sys_nerr;
42 41
43 42 static void file_lock_error(char *msg, char *file, char *str, int arg1, int arg2);
44 43
45 44 #define BLOCK_INTERUPTS sigfillset(&newset) ; \
46 45 sigprocmask(SIG_SETMASK, &newset, &oldset)
47 46
48 47 #define UNBLOCK_INTERUPTS \
49 48 sigprocmask(SIG_SETMASK, &oldset, &newset)
50 49
51 50 /*
52 51 * This code stolen from the NSE library and changed to not depend
53 52 * upon any NSE routines or header files.
54 53 *
55 54 * Simple file locking.
56 55 * Create a symlink to a file. The "test and set" will be
57 56 * atomic as creating the symlink provides both functions.
58 57 *
59 58 * The timeout value specifies how long to wait for stale locks
60 59 * to disappear. If the lock is more than 'timeout' seconds old
61 60 * then it is ok to blow it away. This part has a small window
62 61 * of vunerability as the operations of testing the time,
63 62 * removing the lock and creating a new one are not atomic.
64 63 * It would be possible for two processes to both decide to blow
65 64 * away the lock and then have process A remove the lock and establish
66 65 * its own, and then then have process B remove the lock which accidentily
67 66 * removes A's lock rather than the stale one.
68 67 *
69 68 * A further complication is with the NFS. If the file in question is
70 69 * being served by an NFS server, then its time is set by that server.
71 70 * We can not use the time on the client machine to check for a stale
72 71 * lock. Therefore, a temp file on the server is created to get
73 72 * the servers current time.
74 73 *
75 74 * Returns an error message. NULL return means the lock was obtained.
76 75 *
77 76 * 12/6/91 Added the parameter "file_locked". Before this parameter
78 77 * was added, the calling procedure would have to wait for file_lock()
79 78 * to return before it sets the flag. If the user interrupted "make"
80 79 * between the time the lock was acquired and the time file_lock()
81 80 * returns, make wouldn't know that the file has been locked, and therefore
82 81 * it wouldn' remove the lock. Setting the flag right after locking the file
83 82 * makes this window much smaller.
84 83 */
85 84
86 85 int
87 86 file_lock(char *name, char *lockname, int *file_locked, int timeout)
88 87 {
89 88 int counter = 0;
90 89 static char msg[MAXPATHLEN+1];
91 90 int printed_warning = 0;
92 91 int r;
93 92 struct stat statb;
94 93 sigset_t newset;
95 94 sigset_t oldset;
96 95
97 96 *file_locked = 0;
98 97 if (timeout <= 0) {
99 98 timeout = 120;
100 99 }
101 100 for (;;) {
↓ open down ↓ |
53 lines elided |
↑ open up ↑ |
102 101 BLOCK_INTERUPTS;
103 102 r = symlink(name, lockname);
104 103 if (r == 0) {
105 104 *file_locked = 1;
106 105 UNBLOCK_INTERUPTS;
107 106 return 0; /* success */
108 107 }
109 108 UNBLOCK_INTERUPTS;
110 109
111 110 if (errno != EEXIST) {
112 - file_lock_error(msg, name, (char *)NOCATGETS("symlink(%s, %s)"),
111 + file_lock_error(msg, name, (char *)"symlink(%s, %s)",
113 112 (int) name, (int) lockname);
114 113 fprintf(stderr, "%s", msg);
115 114 return errno;
116 115 }
117 116
118 117 counter = 0;
119 118 for (;;) {
120 119 sleep(1);
121 120 r = lstat(lockname, &statb);
122 121 if (r == -1) {
123 122 /*
↓ open down ↓ |
1 lines elided |
↑ open up ↑ |
124 123 * The lock must have just gone away - try
125 124 * again.
126 125 */
127 126 break;
128 127 }
129 128
130 129 if ((counter > 5) && (!printed_warning)) {
131 130 /* Print waiting message after 5 secs */
132 131 (void) getcwd(msg, MAXPATHLEN);
133 132 fprintf(stderr,
134 - catgets(libmksdmsi18n_catd, 1, 162, "file_lock: file %s is already locked.\n"),
133 + gettext("file_lock: file %s is already locked.\n"),
135 134 name);
136 135 fprintf(stderr,
137 - catgets(libmksdmsi18n_catd, 1, 163, "file_lock: will periodically check the lockfile %s for two minutes.\n"),
136 + gettext("file_lock: will periodically check the lockfile %s for two minutes.\n"),
138 137 lockname);
139 138 fprintf(stderr,
140 - catgets(libmksdmsi18n_catd, 1, 144, "Current working directory %s\n"),
139 + gettext("Current working directory %s\n"),
141 140 msg);
142 141
143 142 printed_warning = 1;
144 143 }
145 144
146 145 if (++counter > timeout ) {
147 146 /*
148 147 * Waited enough - return an error..
149 148 */
150 149 return EEXIST;
151 150 }
152 151 }
153 152 }
154 153 /* NOTREACHED */
↓ open down ↓ |
4 lines elided |
↑ open up ↑ |
155 154 }
156 155
157 156 /*
158 157 * Format a message telling why the lock could not be created.
159 158 */
160 159 static void
161 160 file_lock_error(char *msg, char *file, char *str, int arg1, int arg2)
162 161 {
163 162 int len;
164 163
165 - sprintf(msg, catgets(libmksdmsi18n_catd, 1, 145, "Could not lock file `%s'; "), file);
164 + sprintf(msg, gettext("Could not lock file `%s'; "), file);
166 165 len = strlen(msg);
167 166 sprintf(&msg[len], str, arg1, arg2);
168 - strcat(msg, catgets(libmksdmsi18n_catd, 1, 146, " failed - "));
167 + strcat(msg, gettext(" failed - "));
169 168 if (errno < sys_nerr) {
170 169 strcat(msg, strerror(errno));
171 170 } else {
172 171 len = strlen(msg);
173 - sprintf(&msg[len], NOCATGETS("errno %d"), errno);
172 + sprintf(&msg[len], "errno %d", errno);
174 173 }
175 174 }
176 175
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX