2107e2dd6254043f89ab3b99e2bc3e461b87b585
[userv-utils] / ipif / slattach.diff
1 --- net-tools/slattach.c~ Sun Sep 19 19:04:28 1999
2 +++ net-tools/slattach.c Sun Sep 19 19:35:56 1999
3 @@ -451,27 +451,39 @@
4 static int
5 tty_open(char *name, char *speed)
6 {
7 - char path[PATH_MAX];
8 - register char *sp;
9 + char pathbuf[PATH_MAX];
10 + register char *path_open, *path_lock;
11 int fd;
12
13 /* Try opening the TTY device. */
14 if (name != NULL) {
15 - if ((sp = strrchr(name, '/')) != (char *)NULL) *sp++ = '\0';
16 - else sp = name;
17 - sprintf(path, "/dev/%s", sp);
18 - if (tty_lock(sp, 1)) return(-1); /* can we lock the device? */
19 - if ((fd = open(path, O_RDWR)) < 0) {
20 + if (name[0] != '/') {
21 + if (strlen(name) + 6 > sizeof(pathbuf)) {
22 + if (opt_q == 0) fprintf(stderr,
23 + _("slattach: tty name too long\n"));
24 + return(-1);
25 + }
26 + sprintf(pathbuf, "/dev/%s", name);
27 + path_open = pathbuf;
28 + path_lock = name;
29 + } else if (!strncmp(name,"/dev/",5)) {
30 + path_open = name;
31 + path_lock = name+5;
32 + } else {
33 + path_open = name;
34 + path_lock = name;
35 + }
36 + if (tty_lock(path_lock, 1)) return(-1); /* can we lock the device? */
37 + if ((fd = open(path_open, O_RDWR)) < 0) {
38 if (opt_q == 0) fprintf(stderr,
39 "slattach: tty_open(%s, RW): %s\n",
40 - path, strerror(errno));
41 + path_open, strerror(errno));
42 return(-errno);
43 }
44 tty_fd = fd;
45 - if (opt_d) printf("slattach: tty_open: %s (%d) ", path, fd);
46 + if (opt_d) printf("slattach: tty_open: %s (%d) ", path_open, fd);
47 } else {
48 tty_fd = 0;
49 - sp = (char *)NULL;
50 }
51
52 /* Fetch the current state of the terminal. */
53 @@ -562,20 +574,21 @@
54 int
55 main(int argc, char *argv[])
56 {
57 - char path[128];
58 + char path_buf[128];
59 + char *path_dev;
60 char buff[128];
61 char *speed = NULL;
62 char *proto = DEF_PROTO;
63 char *extcmd = (char *)0;
64 struct hwtype *ht;
65 - char *sp;
66 int s;
67 static struct option longopts[] = {
68 { "version", 0, NULL, 'V' },
69 { NULL, 0, NULL, 0 }
70 };
71
72 - strcpy(path, "");
73 + strcpy(path_buf, "");
74 + path_dev= path_buf;
75
76 /* Scan command line for any arguments. */
77 opterr = 0;
78 @@ -649,6 +662,12 @@
79 /*NOTREACHED*/
80 }
81
82 + if (setvbuf(stdout,0,_IOLBF,0)) {
83 + if (opt_q == 0) fprintf(stderr, _("slattach: setvbuf(stdout,0,_IOLBF,0): %s\n"),
84 + strerror(errno));
85 + exit(1);
86 + }
87 +
88 activate_init();
89
90 /* Check the protocol. */
91 @@ -660,15 +679,14 @@
92
93 /* Is a terminal given? */
94 if (optind != (argc - 1)) usage();
95 - safe_strncpy(path, argv[optind], sizeof(path));
96 - if (!strcmp(path, "-")) {
97 + safe_strncpy(path_buf, argv[optind], sizeof(path_buf));
98 + if (!strcmp(path_buf, "-")) {
99 opt_e = 1;
100 - sp = NULL;
101 + path_dev = NULL;
102 if (tty_open(NULL, speed) < 0) { return(3); }
103 } else {
104 - if ((sp = strrchr(path, '/')) != NULL) *sp++ = '\0';
105 - else sp = path;
106 - if (tty_open(sp, speed) < 0) { return(3); }
107 + path_dev = path_buf;
108 + if (tty_open(path_dev, speed) < 0) { return(3); }
109 }
110
111 /* Start the correct protocol. */
112 @@ -681,7 +699,7 @@
113 if (opt_v == 1) {
114 tty_get_name(buff);
115 printf(_("%s started"), proto);
116 - if (sp != NULL) printf(_(" on %s"), sp);
117 + if (path_dev != NULL) printf(_(" on %s"), path_dev);
118 printf(_(" interface %s\n"), buff);
119 }
120
121