Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
net-tools
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
net-tools
Commits
510362ea
Commit
510362ea
authored
Aug 14, 2000
by
Bernd Eckenfels
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Debian's patch for better device name/lock handling
parent
764e6d05
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
21 deletions
+39
-21
slattach.c
slattach.c
+39
-21
No files found.
slattach.c
View file @
510362ea
...
...
@@ -456,29 +456,41 @@ tty_close(void)
static
int
tty_open
(
char
*
name
,
const
char
*
speed
)
{
char
path
[
PATH_MAX
];
register
char
*
sp
;
char
path
buf
[
PATH_MAX
];
register
char
*
path_open
,
*
path_lock
;
int
fd
;
/* Try opening the TTY device. */
if
(
name
!=
NULL
)
{
if
((
sp
=
strrchr
(
name
,
'/'
))
!=
(
char
*
)
NULL
)
*
sp
++
=
'\0'
;
else
sp
=
name
;
sprintf
(
path
,
"/dev/%s"
,
sp
);
if
(
name
[
0
]
!=
'/'
)
{
if
(
strlen
(
name
+
6
)
>
sizeof
(
pathbuf
))
{
if
(
opt_q
==
0
)
fprintf
(
stderr
,
_
(
"slattach: tty name too long
\n
"
));
return
(
-
1
);
}
sprintf
(
pathbuf
,
"/dev/%s"
,
name
);
path_open
=
pathbuf
;
path_lock
=
name
;
}
else
if
(
!
strncmp
(
name
,
"/dev/"
,
5
))
{
path_open
=
name
;
path_lock
=
name
+
5
;
}
else
{
path_open
=
name
;
path_lock
=
name
;
}
if
(
opt_d
)
printf
(
"slattach: tty_open: looking for lock
\n
"
);
if
(
tty_lock
(
sp
,
1
))
return
(
-
1
);
/* can we lock the device? */
if
(
opt_d
)
printf
(
"slattach: tty_open: trying to open %s
\n
"
,
path
);
if
((
fd
=
open
(
path
,
O_RDWR
|
O_NDELAY
))
<
0
)
{
if
(
tty_lock
(
path_lock
,
1
))
return
(
-
1
);
/* can we lock the device? */
if
(
opt_d
)
printf
(
"slattach: tty_open: trying to open %s
\n
"
,
path
_open
);
if
((
fd
=
open
(
path
_open
,
O_RDWR
|
O_NDELAY
))
<
0
)
{
if
(
opt_q
==
0
)
fprintf
(
stderr
,
"slattach: tty_open(%s, RW): %s
\n
"
,
path
,
strerror
(
errno
));
path
_open
,
strerror
(
errno
));
return
(
-
errno
);
}
tty_fd
=
fd
;
if
(
opt_d
)
printf
(
"slattach: tty_open: %s (fd=%d) "
,
path
,
fd
);
if
(
opt_d
)
printf
(
"slattach: tty_open: %s (fd=%d) "
,
path
_open
,
fd
);
}
else
{
tty_fd
=
0
;
sp
=
(
char
*
)
NULL
;
}
/* Fetch the current state of the terminal. */
...
...
@@ -569,19 +581,20 @@ version(void)
int
main
(
int
argc
,
char
*
argv
[])
{
char
path
[
128
];
char
path_buf
[
128
];
char
*
path_dev
;
char
buff
[
128
];
const
char
*
speed
=
NULL
;
const
char
*
proto
=
DEF_PROTO
;
const
char
*
extcmd
=
NULL
;
char
*
sp
;
int
s
;
static
struct
option
longopts
[]
=
{
{
"version"
,
0
,
NULL
,
'V'
},
{
NULL
,
0
,
NULL
,
0
}
};
strcpy
(
path
,
""
);
strcpy
(
path_buf
,
""
);
path_dev
=
path_buf
;
/* Scan command line for any arguments. */
opterr
=
0
;
...
...
@@ -655,6 +668,12 @@ main(int argc, char *argv[])
/*NOTREACHED*/
}
if
(
setvbuf
(
stdout
,
0
,
_IOLBF
,
0
))
{
if
(
opt_q
==
0
)
fprintf
(
stderr
,
_
(
"slattach: setvbuf(stdout,0,_IOLBF,0) : %s
\n
"
),
strerror
(
errno
));
exit
(
1
);
}
activate_init
();
if
(
!
strcmp
(
proto
,
"tty"
))
...
...
@@ -662,15 +681,14 @@ main(int argc, char *argv[])
/* Is a terminal given? */
if
(
optind
!=
(
argc
-
1
))
usage
();
safe_strncpy
(
path
,
argv
[
optind
],
sizeof
(
path
));
if
(
!
strcmp
(
path
,
"-"
))
{
safe_strncpy
(
path
_buf
,
argv
[
optind
],
sizeof
(
path_buf
));
if
(
!
strcmp
(
path
_buf
,
"-"
))
{
opt_e
=
1
;
sp
=
NULL
;
path_dev
=
NULL
;
if
(
tty_open
(
NULL
,
speed
)
<
0
)
{
return
(
3
);
}
}
else
{
if
((
sp
=
strrchr
(
path
,
'/'
))
!=
NULL
)
*
sp
++
=
'\0'
;
else
sp
=
path
;
if
(
tty_open
(
sp
,
speed
)
<
0
)
{
return
(
3
);
}
path_dev
=
path_buf
;
if
(
tty_open
(
path_dev
,
speed
)
<
0
)
{
return
(
3
);
}
}
/* Start the correct protocol. */
...
...
@@ -684,7 +702,7 @@ main(int argc, char *argv[])
if
((
opt_v
==
1
)
||
(
opt_d
==
1
))
{
if
(
tty_get_name
(
buff
))
{
return
(
3
);
}
printf
(
_
(
"%s started"
),
proto
);
if
(
sp
!=
NULL
)
printf
(
_
(
" on %s"
),
sp
);
if
(
path_dev
!=
NULL
)
printf
(
_
(
" on %s"
),
path_dev
);
printf
(
_
(
" interface %s
\n
"
),
buff
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment