backup deletedump: Change -port to -portoffset
[openafs.git] / src / bucoord / main.c
index 20fbe5d..818a7f8 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Copyright 2000, International Business Machines Corporation and others.
  * All Rights Reserved.
- * 
+ *
  * This software has been released under the terms of the IBM Public
  * License.  For details, see the LICENSE file in the top-level source
  * directory or online at http://www.openafs.org/dl/license10.html
@@ -9,29 +9,16 @@
 
 #include <afsconfig.h>
 #include <afs/param.h>
+#include <afs/stds.h>
+
+#include <roken.h>
 
-RCSID
-    ("$Header$");
 
-#include <afs/stds.h>
-#include <sys/types.h>
-#ifdef AFS_AIX32_ENV
-#include <signal.h>
-#endif
-#ifdef AFS_NT40_ENV
-#include <winsock2.h>
-#else
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <netdb.h>
-#endif
-#include <errno.h>
 #include <afs/cmd.h>
 #include <rx/rx.h>
 #include <rx/rx_globals.h>
 #include <lwp.h>
 #include <afs/bubasics.h>
-#include <fcntl.h>
 #include <afs/afsutil.h>
 #include <afs/auth.h>
 #include <afs/cellconfig.h>
@@ -39,55 +26,31 @@ RCSID
 #include <ubik.h>
 #include <afs/cmd.h>
 #include <rx/rxkad.h>
+#include <afs/afsint.h>
 #include <afs/volser.h>                /*VLDB_MAXSERVERS */
 #include <afs/com_err.h>
 #include <lock.h>
 #include <afs/budb.h>
+#include <afs/kautils.h>
+#include <afs/vlserver.h>
+#include <afs/butm.h>
+#include <afs/butx.h>
+#include <afs/tcdata.h>
 
 #include "bc.h"                        /*Backup Coordinator structs and defs */
+#include "bucoord_internal.h"
 #include "bucoord_prototypes.h"
 
 int localauth, interact;
 char tcell[64];
 
-extern int bc_AddDumpCmd();
-extern int bc_AddHostCmd();
-extern int bc_AddVolEntryCmd();
-extern int bc_AddVolSetCmd();
-/* extern int bc_CheckDumpStatCmd(); */
-extern int bc_DeleteDumpCmd();
-extern int bc_DeleteHostCmd();
-extern int bc_DeleteVolEntryCmd();
-extern int bc_DeleteVolSetCmd();
-extern int bc_DiskRestoreCmd();
-extern int bc_VolsetRestoreCmd();
-extern int bc_DumpCmd();
-extern int bc_GetTapeStatusCmd();
-extern int bc_JobsCmd();
-extern int bc_KillCmd();
-extern int bc_LabelTapeCmd();
-extern int bc_ListDumpScheduleCmd();
-extern int bc_ListHostsCmd();
-extern int bc_ListVolSetCmd();
-extern int bc_QuitCmd();
-extern int bc_ReadLabelCmd();
-extern int bc_ScanDumpsCmd();
-extern int bc_SetExpCmd();
-extern int bc_VolRestoreCmd();
-extern int bc_dblookupCmd();
-extern int bc_dbVerifyCmd();
-extern int bc_deleteDumpCmd();
-extern int bc_dumpInfoCmd();
-extern int bc_restoreDbCmd();
-extern int bc_saveDbCmd();
-
 /*
  * Global configuration information for the Backup Coordinator.
  */
 struct bc_config *bc_globalConfig;     /*Ptr to global BC configuration info */
 
 struct ubik_client *cstruct;   /* Ptr to Ubik client structure */
-struct ktc_token ttoken;       /* The token */
+time_t tokenExpires;           /* The token's expiration time */
 
 static const char *DefaultConfDir;     /*Default backup config directory */
 static int bcInit = 0;         /* backupInit called yet ? */
@@ -95,7 +58,8 @@ char *whoami = "backup";
 
 /* dummy routine for the audit work.  It should do nothing since audits */
 /* occur at the server level and bos is not a server. */
-osi_audit()
+int
+osi_audit(void)
 {
     return 0;
 }
@@ -105,7 +69,7 @@ osi_audit()
  * in this module.
  */
 void
-InitErrTabs()
+InitErrTabs(void)
 {
     initialize_ACFG_error_table();
     initialize_KA_error_table();
@@ -121,13 +85,12 @@ InitErrTabs()
     initialize_KTC_error_table();
 }
 
-/* 
- * got to account for the errors which are volume related but 
+/*
+ * got to account for the errors which are volume related but
  * not dealt with by standard errno and com_err stuff.
  */
 void
-bc_HandleMisc(code)
-     afs_int32 code;
+bc_HandleMisc(afs_int32 code)
 {
     if (((code <= VMOVED) && (code >= VSALVAGE)) || (code < 0)) {
        switch (code) {
@@ -176,13 +139,12 @@ bc_HandleMisc(code)
 }
 
 /* Return true if line is all whitespace */
-static
-LineIsBlank(aline)
-     register char *aline;
+static int
+LineIsBlank(char *aline)
 {
-    register int tc;
+    int tc;
 
-    while (tc = *aline++)
+    while ((tc = *aline++))
        if ((tc != ' ') && (tc != '\t') && (tc != '\n'))
            return (0);
 
@@ -195,11 +157,10 @@ LineIsBlank(aline)
  */
 
 afs_int32
-bc_InitTextConfig()
+bc_InitTextConfig(void)
 {
     udbClientTextP ctPtr;
     int i;
-    afs_int32 code = 0;
 
     extern struct bc_config *bc_globalConfig;
 
@@ -237,9 +198,9 @@ bc_InitTextConfig()
  */
 
 static int
-backupInit()
+backupInit(void)
 {
-    register afs_int32 code;
+    afs_int32 code;
     static int initd = 0;      /* ever called? */
     PROCESS watcherPid;
     PROCESS pid;               /* LWP process ID */
@@ -254,7 +215,7 @@ backupInit()
     }
     initd = 1;
 
-    code = bc_InitConfig(DefaultConfDir);
+    code = bc_InitConfig((char *)DefaultConfDir);
     if (code) {
        afs_com_err(whoami, code,
                "Can't initialize from config files in directory '%s'",
@@ -280,7 +241,7 @@ backupInit()
     rx_SetRxDeadTime(60);
 
     /* VLDB initialization */
-    code = vldbClientInit(0, localauth, tcell, &cstruct, &ttoken);
+    code = vldbClientInit(0, localauth, tcell, &cstruct, &tokenExpires);
     if (code)
        return (code);
 
@@ -324,7 +285,7 @@ backupInit()
  */
 
 static int
-MyBeforeProc(register struct cmd_syndesc *as, void *arock)
+MyBeforeProc(struct cmd_syndesc *as, void *arock)
 {
     afs_int32 code;
 
@@ -365,14 +326,14 @@ extern int dontExecute;           /* declared in commands.c */
 extern char *loadFile;         /* declared in commands.c */
 char lineBuffer[1024];         /* Line typed in by user or read from load file */
 
-/* 
+/*
  * This will dispatch a command.  It holds a recursive loop for the
  * "dump -file" option. This option reads backup commands from a file.
  *
  * Cannot put this code on other side of cmd_Dispatch call (in
  * commands.c) because when make a dispatch call when in a dispatch
  * call, environment is mucked up.
- * 
+ *
  * To avoid multiple processes stepping on each other in the dispatch code,
  * put a lock around it so only 1 process gets in at a time.
  */
@@ -382,10 +343,9 @@ struct Lock dispatchLock;  /* lock on the Dispatch call */
 #define unlock_Dispatch()   ReleaseWriteLock(&dispatchLock)
 
 afs_int32
-doDispatch(targc, targv, dispatchCount)
-     char *targv[MAXV];
-     afs_int32 targc;
-     afs_int32 dispatchCount;  /* to prevent infinite recursion */
+doDispatch(afs_int32 targc,
+          char *targv[MAXV],
+          afs_int32 dispatchCount) /* to prevent infinite recursion */
 {
     char *sargv[MAXV];
     afs_int32 sargc;
@@ -466,8 +426,7 @@ bc_interactCmd(struct cmd_syndesc *as, void *arock)
 }
 
 static void
-add_std_args(ts)
-     register struct cmd_syndesc *ts;
+add_std_args(struct cmd_syndesc *ts)
 {
     cmd_Seek(ts, 14);
     cmd_AddParm(ts, "-localauth", CMD_FLAG, CMD_OPTIONAL,
@@ -475,22 +434,20 @@ add_std_args(ts)
     cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name");
 }
 
-
-main(argc, argv)
-     int argc;
-     char **argv;
+int
+main(int argc, char **argv)
 {                              /*main */
     char *targv[MAXV];         /*Ptr to parsed argv stuff */
     afs_int32 targc;           /*Num parsed arguments */
     afs_int32 code;            /*Return code */
-    register struct cmd_syndesc *ts;   /*Ptr to parsed command line */
+    struct cmd_syndesc *ts;    /*Ptr to parsed command line */
     int i;
 
 
 #ifdef AFS_AIX32_ENV
     /*
-     * The following signal action for AIX is necessary so that in case of a 
-     * crash (i.e. core is generated) we can include the user's data section 
+     * The following signal action for AIX is necessary so that in case of a
+     * crash (i.e. core is generated) we can include the user's data section
      * in the core dump. Unfortunately, by default, only a partial core is
      * generated which, in many cases, isn't too useful.
      */
@@ -507,7 +464,17 @@ main(argc, argv)
     /* setup the default backup dir */
     DefaultConfDir = AFSDIR_SERVER_BACKUP_DIRPATH;
     /* Get early warning if the command is interacive mode or not */
-    interact = (((argc < 2) || (argv[1][0] == '-')) ? 1 : 0);
+    if (argc < 2) {
+       interact = 1;
+    } else {
+       interact = 0;
+       if (argv[1][0] == '-') {
+           interact = 1;
+           if (strcmp(argv[1], "-help") == 0) {
+               interact = 0;
+           }
+       }
+    }
 
     cmd_SetBeforeProc(MyBeforeProc, NULL);
 
@@ -520,7 +487,9 @@ main(argc, argv)
     cmd_AddParm(ts, "-at", CMD_LIST, CMD_OPTIONAL, "Date/time to start dump");
     cmd_AddParm(ts, "-append", CMD_FLAG, CMD_OPTIONAL,
                "append to existing dump set");
-    cmd_AddParm(ts, "-n", CMD_FLAG, CMD_OPTIONAL, "don't really execute it");
+    cmd_AddParm(ts, "-dryrun", CMD_FLAG, CMD_OPTIONAL,
+                "list what would be done, don't do it");
+    cmd_AddParmAlias(ts, 5, "-n");
     cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "load file");
     if (!interact)
        add_std_args(ts);
@@ -538,7 +507,9 @@ main(argc, argv)
     cmd_AddParm(ts, "-date", CMD_LIST, CMD_OPTIONAL,
                "date from which to restore");
     cmd_AddParm(ts, "-portoffset", CMD_LIST, CMD_OPTIONAL, "TC port offsets");
-    cmd_AddParm(ts, "-n", CMD_FLAG, CMD_OPTIONAL, "don't really execute it");
+    cmd_AddParm(ts, "-dryrun", CMD_FLAG, CMD_OPTIONAL,
+                "list what would be done, don't do it");
+    cmd_AddParmAlias(ts, 6, "-n");
     cmd_AddParm(ts, "-usedump", CMD_SINGLE, CMD_OPTIONAL,
                "specify the dumpID to restore from");
     if (!interact)
@@ -558,11 +529,13 @@ main(argc, argv)
                "destination partition");
     cmd_AddParm(ts, "-extension", CMD_SINGLE, CMD_OPTIONAL,
                "new volume name extension");
-    cmd_AddParm(ts, "-n", CMD_FLAG, CMD_OPTIONAL, "don't really execute it");
+    cmd_AddParm(ts, "-dryrun", CMD_FLAG, CMD_OPTIONAL,
+                "list what would be done, don't do it");
+    cmd_AddParmAlias(ts, 11, "-n");
     if (!interact)
        add_std_args(ts);
 
-    ts = cmd_CreateSyntax("quit", bc_QuitCmd, NULL, "leave the program");
+    cmd_CreateSyntax("quit", bc_QuitCmd, NULL, "leave the program");
 
     ts = cmd_CreateSyntax("volsetrestore", bc_VolsetRestoreCmd, NULL,
                          "restore a set of volumes");
@@ -571,7 +544,9 @@ main(argc, argv)
     cmd_AddParm(ts, "-portoffset", CMD_LIST, CMD_OPTIONAL, "TC port offset");
     cmd_AddParm(ts, "-extension", CMD_SINGLE, CMD_OPTIONAL,
                "new volume name extension");
-    cmd_AddParm(ts, "-n", CMD_FLAG, CMD_OPTIONAL, "don't really execute it");
+    cmd_AddParm(ts, "-dryrun", CMD_FLAG, CMD_OPTIONAL,
+                "list what would be done, don't do it");
+    cmd_AddParmAlias(ts, 4, "-n");
     if (!interact)
        add_std_args(ts);
 
@@ -597,7 +572,7 @@ main(argc, argv)
     if (!interact)
        add_std_args(ts);
 
-    ts = cmd_CreateSyntax("jobs", bc_JobsCmd, NULL, "list running jobs");
+    cmd_CreateSyntax("jobs", bc_JobsCmd, NULL, "list running jobs");
 
     ts = cmd_CreateSyntax("kill", bc_KillCmd, NULL, "kill running job");
     cmd_AddParm(ts, "-id", CMD_SINGLE, CMD_REQUIRED,
@@ -739,14 +714,17 @@ main(argc, argv)
     cmd_AddParm(ts, "-dumpid", CMD_LIST, CMD_OPTIONAL, "dump id");
     cmd_AddParm(ts, "-from", CMD_LIST, CMD_OPTIONAL, "date time");
     cmd_AddParm(ts, "-to", CMD_LIST, CMD_OPTIONAL, "date time");
-    cmd_AddParm(ts, "-port", CMD_SINGLE, CMD_OPTIONAL, "TC port offset");
+    cmd_AddParm(ts, "-portoffset", CMD_SINGLE, CMD_OPTIONAL, "TC port offset");
+    cmd_AddParmAlias(ts, 3, "-port");
     cmd_AddParm(ts, "-groupid", CMD_SINGLE, CMD_OPTIONAL, "group ID");
     cmd_AddParm(ts, "-dbonly", CMD_FLAG, CMD_OPTIONAL,
                "delete the dump from the backup database only");
     cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL,
                "always delete from backup database");
-    cmd_AddParm(ts, "-noexecute", CMD_FLAG, CMD_OPTIONAL,
-               "Just list the dumps");
+    cmd_AddParm(ts, "-noexecute", CMD_FLAG, CMD_OPTIONAL|CMD_HIDDEN, "");
+    cmd_AddParm(ts, "-dryrun", CMD_FLAG, CMD_OPTIONAL,
+               "list the dumps, don't delete anything");
+    cmd_AddParmAlias(ts, 8, "-n");
 
     if (!interact)
        add_std_args(ts);