plan9fox/sys/src/cmd/bind.c
cinap_lenrek ac88ce4f7f make bind(2) error handling consistent
The mount() and bind() syscalls return -1 on error,
and the mountid sequence number on success.

The manpage states that the mountid sequence number
is a positive integer, but the kernels implementation
currently uses a unsigned 32-bit integer and does not
guarantee that the mountid will not become negative.

Most code just cares about the error, so test for
the -1 error value only.
2020-05-02 17:32:01 +02:00

53 lines
832 B
C

#include <u.h>
#include <libc.h>
void usage(void);
void
main(int argc, char *argv[])
{
ulong flag = 0;
int qflag = 0;
ARGBEGIN{
case 'a':
flag |= MAFTER;
break;
case 'b':
flag |= MBEFORE;
break;
case 'c':
flag |= MCREATE;
break;
case 'q':
qflag = 1;
break;
default:
usage();
}ARGEND
if(argc != 2 || (flag&MAFTER)&&(flag&MBEFORE))
usage();
if(bind(argv[0], argv[1], flag) == -1){
if(qflag)
exits(0);
/* try to give a less confusing error than the default */
if(access(argv[0], 0) < 0)
fprint(2, "bind: %s: %r\n", argv[0]);
else if(access(argv[1], 0) < 0)
fprint(2, "bind: %s: %r\n", argv[1]);
else
fprint(2, "bind %s %s: %r\n", argv[0], argv[1]);
exits("bind");
}
exits(0);
}
void
usage(void)
{
fprint(2, "usage: bind [-b|-a|-c|-bc|-ac] new old\n");
exits("usage");
}