| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: ttyflags.c,v 1.17 2008/07/20 01:20:23 lukem Exp $ */ | | 1 | /* $NetBSD: ttyflags.c,v 1.18 2011/08/27 18:58:51 joerg Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 1994 Christopher G. Demetriou | | 4 | * Copyright (c) 1994 Christopher G. Demetriou |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | | 7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | | 8 | * modification, are permitted provided that the following conditions |
9 | * are met: | | 9 | * are met: |
10 | * 1. Redistributions of source code must retain the above copyright | | 10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. | | 11 | * notice, this list of conditions and the following disclaimer. |
12 | * 2. Redistributions in binary form must reproduce the above copyright | | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the | | 13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. | | 14 | * documentation and/or other materials provided with the distribution. |
| @@ -31,49 +31,49 @@ | | | @@ -31,49 +31,49 @@ |
31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | | 31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
32 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | | 32 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
33 | * | | 33 | * |
34 | * <<Id: LICENSE,v 1.2 2000/06/14 15:57:33 cgd Exp>> | | 34 | * <<Id: LICENSE,v 1.2 2000/06/14 15:57:33 cgd Exp>> |
35 | */ | | 35 | */ |
36 | | | 36 | |
37 | #include <sys/cdefs.h> | | 37 | #include <sys/cdefs.h> |
38 | #ifndef lint | | 38 | #ifndef lint |
39 | __COPYRIGHT("@(#) Copyright (c) 1994\ | | 39 | __COPYRIGHT("@(#) Copyright (c) 1994\ |
40 | Christopher G. Demetriou. All rights reserved."); | | 40 | Christopher G. Demetriou. All rights reserved."); |
41 | #endif /* not lint */ | | 41 | #endif /* not lint */ |
42 | | | 42 | |
43 | #ifndef lint | | 43 | #ifndef lint |
44 | __RCSID("$NetBSD: ttyflags.c,v 1.17 2008/07/20 01:20:23 lukem Exp $"); | | 44 | __RCSID("$NetBSD: ttyflags.c,v 1.18 2011/08/27 18:58:51 joerg Exp $"); |
45 | #endif /* not lint */ | | 45 | #endif /* not lint */ |
46 | | | 46 | |
47 | #include <sys/types.h> | | 47 | #include <sys/types.h> |
48 | #include <sys/ioctl.h> | | 48 | #include <sys/ioctl.h> |
49 | | | 49 | |
50 | #include <err.h> | | 50 | #include <err.h> |
51 | #include <errno.h> | | 51 | #include <errno.h> |
52 | #include <fcntl.h> | | 52 | #include <fcntl.h> |
53 | #include <limits.h> | | 53 | #include <limits.h> |
54 | #include <paths.h> | | 54 | #include <paths.h> |
55 | #include <stdio.h> | | 55 | #include <stdio.h> |
56 | #include <stdlib.h> | | 56 | #include <stdlib.h> |
57 | #include <string.h> | | 57 | #include <string.h> |
58 | #include <ttyent.h> | | 58 | #include <ttyent.h> |
59 | #include <unistd.h> | | 59 | #include <unistd.h> |
60 | | | 60 | |
61 | int change_all(void); | | 61 | static int change_all(void); |
62 | int change_ttyflags(struct ttyent *); | | 62 | static int change_ttyflags(struct ttyent *); |
63 | int change_ttys(char **); | | 63 | static int change_ttys(char **); |
64 | void usage(void); | | 64 | __dead static void usage(void); |
65 | | | 65 | |
66 | int nflag, vflag; | | 66 | static int nflag, vflag; |
67 | | | 67 | |
68 | /* | | 68 | /* |
69 | * Ttyflags sets the device-specific tty flags, based on the contents | | 69 | * Ttyflags sets the device-specific tty flags, based on the contents |
70 | * of /etc/ttys. It can either set all of the ttys' flags, or set | | 70 | * of /etc/ttys. It can either set all of the ttys' flags, or set |
71 | * the flags of the ttys specified on the command line. | | 71 | * the flags of the ttys specified on the command line. |
72 | */ | | 72 | */ |
73 | int | | 73 | int |
74 | main(int argc, char *argv[]) | | 74 | main(int argc, char *argv[]) |
75 | { | | 75 | { |
76 | int aflag, ch, rval; | | 76 | int aflag, ch, rval; |
77 | | | 77 | |
78 | aflag = nflag = vflag = 0; | | 78 | aflag = nflag = vflag = 0; |
79 | while ((ch = getopt(argc, argv, "anv")) != -1) | | 79 | while ((ch = getopt(argc, argv, "anv")) != -1) |
| @@ -106,70 +106,70 @@ main(int argc, char *argv[]) | | | @@ -106,70 +106,70 @@ main(int argc, char *argv[]) |
106 | rval = change_all(); | | 106 | rval = change_all(); |
107 | else | | 107 | else |
108 | rval = change_ttys(argv); | | 108 | rval = change_ttys(argv); |
109 | | | 109 | |
110 | if (endttyent() == 0) | | 110 | if (endttyent() == 0) |
111 | warn("endttyent"); | | 111 | warn("endttyent"); |
112 | | | 112 | |
113 | exit(rval); | | 113 | exit(rval); |
114 | } | | 114 | } |
115 | | | 115 | |
116 | /* | | 116 | /* |
117 | * Change all /etc/ttys entries' flags. | | 117 | * Change all /etc/ttys entries' flags. |
118 | */ | | 118 | */ |
119 | int | | 119 | static int |
120 | change_all(void) | | 120 | change_all(void) |
121 | { | | 121 | { |
122 | struct ttyent *tep; | | 122 | struct ttyent *tep; |
123 | int rval; | | 123 | int rval; |
124 | | | 124 | |
125 | rval = 0; | | 125 | rval = 0; |
126 | for (tep = getttyent(); tep != NULL; tep = getttyent()) | | 126 | for (tep = getttyent(); tep != NULL; tep = getttyent()) |
127 | if (change_ttyflags(tep)) | | 127 | if (change_ttyflags(tep)) |
128 | rval = 1; | | 128 | rval = 1; |
129 | return (rval); | | 129 | return (rval); |
130 | } | | 130 | } |
131 | | | 131 | |
132 | /* | | 132 | /* |
133 | * Change the specified ttys' flags. | | 133 | * Change the specified ttys' flags. |
134 | */ | | 134 | */ |
135 | int | | 135 | static int |
136 | change_ttys(char **ttylist) | | 136 | change_ttys(char **ttylist) |
137 | { | | 137 | { |
138 | struct ttyent *tep; | | 138 | struct ttyent *tep; |
139 | int rval; | | 139 | int rval; |
140 | | | 140 | |
141 | rval = 0; | | 141 | rval = 0; |
142 | for (; *ttylist != NULL; ttylist++) { | | 142 | for (; *ttylist != NULL; ttylist++) { |
143 | tep = getttynam(*ttylist); | | 143 | tep = getttynam(*ttylist); |
144 | if (tep == NULL) { | | 144 | if (tep == NULL) { |
145 | warnx("couldn't find an entry in %s for \"%s\"", | | 145 | warnx("couldn't find an entry in %s for \"%s\"", |
146 | _PATH_TTYS, *ttylist); | | 146 | _PATH_TTYS, *ttylist); |
147 | rval = 1; | | 147 | rval = 1; |
148 | continue; | | 148 | continue; |
149 | } | | 149 | } |
150 | | | 150 | |
151 | if (change_ttyflags(tep)) | | 151 | if (change_ttyflags(tep)) |
152 | rval = 1; | | 152 | rval = 1; |
153 | } | | 153 | } |
154 | return (rval); | | 154 | return (rval); |
155 | } | | 155 | } |
156 | | | 156 | |
157 | | | 157 | |
158 | /* | | 158 | /* |
159 | * Actually do the work; find out what the new flags value should be, | | 159 | * Actually do the work; find out what the new flags value should be, |
160 | * open the device, and change the flags. | | 160 | * open the device, and change the flags. |
161 | */ | | 161 | */ |
162 | int | | 162 | static int |
163 | change_ttyflags(struct ttyent *tep) | | 163 | change_ttyflags(struct ttyent *tep) |
164 | { | | 164 | { |
165 | int fd, flags, rval, st, sep; | | 165 | int fd, flags, rval, st, sep; |
166 | char path[PATH_MAX]; | | 166 | char path[PATH_MAX]; |
167 | char strflags[256]; | | 167 | char strflags[256]; |
168 | | | 168 | |
169 | st = tep->ty_status; | | 169 | st = tep->ty_status; |
170 | sep = flags = rval = 0; | | 170 | sep = flags = rval = 0; |
171 | strflags[0] = '\0'; | | 171 | strflags[0] = '\0'; |
172 | | | 172 | |
173 | | | 173 | |
174 | /* Convert ttyent.h flags into ioctl flags. */ | | 174 | /* Convert ttyent.h flags into ioctl flags. */ |
175 | if (st & TTY_LOCAL) { | | 175 | if (st & TTY_LOCAL) { |
| @@ -227,19 +227,19 @@ change_ttyflags(struct ttyent *tep) | | | @@ -227,19 +227,19 @@ change_ttyflags(struct ttyent *tep) |
227 | warn("TIOCSFLAGS on %s", path); | | 227 | warn("TIOCSFLAGS on %s", path); |
228 | rval = (errno != ENOTTY); | | 228 | rval = (errno != ENOTTY); |
229 | } | | 229 | } |
230 | if (close(fd) == -1) { | | 230 | if (close(fd) == -1) { |
231 | warn("close %s", path); | | 231 | warn("close %s", path); |
232 | return (1); | | 232 | return (1); |
233 | } | | 233 | } |
234 | return (rval); | | 234 | return (rval); |
235 | } | | 235 | } |
236 | | | 236 | |
237 | /* | | 237 | /* |
238 | * Print usage information when a bogus set of arguments is given. | | 238 | * Print usage information when a bogus set of arguments is given. |
239 | */ | | 239 | */ |
240 | void | | 240 | static void |
241 | usage(void) | | 241 | usage(void) |
242 | { | | 242 | { |
243 | (void)fprintf(stderr, "usage: ttyflags [-v] [-a | tty ... ]\n"); | | 243 | (void)fprintf(stderr, "usage: ttyflags [-v] [-a | tty ... ]\n"); |
244 | exit(1); | | 244 | exit(1); |
245 | } | | 245 | } |