Add the `rename' command for renaming links.

This commit is contained in:
Brian Somers 1998-05-16 23:47:28 +00:00
parent b102f4bc26
commit 58d5533465
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/cvs2svn/branches/MP/; revision=36113
6 changed files with 65 additions and 7 deletions

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: bundle.c,v 1.1.2.83 1998/05/15 18:21:32 brian Exp $
* $Id: bundle.c,v 1.1.2.84 1998/05/15 23:58:14 brian Exp $
*/
#include <sys/types.h>
@ -1376,6 +1376,23 @@ bundle_SendDatalink(struct datalink *dl, int s, struct sockaddr_un *sun)
free(iov[niov].iov_base);
}
int
bundle_RenameDatalink(struct bundle *bundle, struct datalink *ndl,
const char *name)
{
struct datalink *dl;
if (!strcasecmp(ndl->name, name))
return 1;
for (dl = bundle->links; dl; dl = dl->next)
if (!strcasecmp(dl->name, name))
return 0;
datalink_Rename(ndl, name);
return 1;
}
int
bundle_SetMode(struct bundle *bundle, struct datalink *dl, int mode)
{

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: bundle.h,v 1.1.2.39 1998/05/10 10:21:11 brian Exp $
* $Id: bundle.h,v 1.1.2.40 1998/05/15 23:58:15 brian Exp $
*/
#define PHASE_DEAD 0 /* Link is dead */
@ -153,3 +153,5 @@ extern const char *bundle_GetLabel(struct bundle *);
extern void bundle_SendDatalink(struct datalink *, int, struct sockaddr_un *);
extern void bundle_ReceiveDatalink(struct bundle *, int, struct sockaddr_un *);
extern int bundle_SetMode(struct bundle *, struct datalink *, int);
extern int bundle_RenameDatalink(struct bundle *, struct datalink *,
const char *);

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: command.c,v 1.131.2.83 1998/05/15 18:20:58 brian Exp $
* $Id: command.c,v 1.131.2.84 1998/05/15 23:58:17 brian Exp $
*
*/
#include <sys/types.h>
@ -124,7 +124,7 @@
#define NEG_DNS 50
const char Version[] = "2.0-beta";
const char VersionDate[] = "$Date: 1998/05/15 18:20:58 $";
const char VersionDate[] = "$Date: 1998/05/15 23:58:17 $";
static int ShowCommand(struct cmdargs const *);
static int TerminalCommand(struct cmdargs const *);
@ -225,6 +225,20 @@ RemoveCommand(struct cmdargs const *arg)
return 0;
}
static int
RenameCommand(struct cmdargs const *arg)
{
if (arg->argc != arg->argn + 1)
return -1;
if (bundle_RenameDatalink(arg->bundle, arg->cx, arg->argv[arg->argn]))
return 0;
log_Printf(LogWARN, "%s -> %s: target name already exists\n",
arg->cx->name, arg->argv[arg->argn]);
return 1;
}
int
LoadCommand(struct cmdargs const *arg)
{
@ -443,6 +457,8 @@ static struct cmdtab const Commands[] = {
"Quit PPP program", "quit|bye [all]"},
{"remove", "rm", RemoveCommand, LOCAL_AUTH | LOCAL_CX,
"Remove a link", "remove"},
{"rename", "mv", RenameCommand, LOCAL_AUTH | LOCAL_CX,
"Rename a link", "rename name"},
{"save", NULL, SaveCommand, LOCAL_AUTH,
"Save settings", "save"},
{"set", "setup", SetCommand, LOCAL_AUTH | LOCAL_CX_OPT,

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: datalink.c,v 1.1.2.61 1998/05/15 18:21:34 brian Exp $
* $Id: datalink.c,v 1.1.2.62 1998/05/15 23:58:20 brian Exp $
*/
#include <sys/types.h>
@ -1056,6 +1056,13 @@ datalink2iov(struct datalink *dl, struct iovec *iov, int *niov, int maxiov)
return link_fd;
}
void
datalink_Rename(struct datalink *dl, const char *name)
{
free(dl->name);
dl->physical->link.name = dl->name = strdup(name);
}
char *
datalink_NextName(struct datalink *dl)
{

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: datalink.h,v 1.1.2.24 1998/05/15 18:21:35 brian Exp $
* $Id: datalink.h,v 1.1.2.25 1998/05/15 23:58:21 brian Exp $
*/
#define DATALINK_CLOSED (0)
@ -123,6 +123,7 @@ extern int datalink_Show(struct cmdargs const *);
extern int datalink_SetRedial(struct cmdargs const *);
extern int datalink_SetReconnect(struct cmdargs const *);
extern const char *datalink_State(struct datalink *);
extern void datalink_Rename(struct datalink *, const char *);
extern char *datalink_NextName(struct datalink *);
extern int datalink_RemoveFromSet(struct datalink *, fd_set *, fd_set *,
fd_set *);

View File

@ -1,4 +1,4 @@
.\" $Id: ppp.8,v 1.97.2.33 1998/05/15 18:21:12 brian Exp $
.\" $Id: ppp.8,v 1.97.2.34 1998/05/15 23:58:27 brian Exp $
.Dd 20 September 1995
.Os FreeBSD
.Dt PPP 8
@ -2268,6 +2268,21 @@ multilink mode. A link must be
in the
.Dv CLOSED
state before it is removed.
.It rename|mv Ar name
This command renames the given link to
.Ar name .
It will fail if
.Ar name
is already used by another link.
.Pp
The default link name is
.Sq deflink .
Renaming it to
.Sq modem ,
.Sq cuaa0
or
.Sq USR
may make the log file more readable.
.It save
This option is not (yet) implemented.
.It set[up] Ar var value