update: Don't cast returns from malloc()
[openafs.git] / src / update / client.c
index b176aac..5bf827b 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,45 +9,22 @@
 
 #include <afsconfig.h>
 #include <afs/param.h>
+#include <afs/stds.h>
 
-RCSID
-    ("$Header$");
+#include <afs/procmgmt.h>
+#include <roken.h>
+#include <afs/opr.h>
 
-#include <afs/stds.h>
-#ifdef AFS_AIX32_ENV
-#include <signal.h>
-#endif
-#include <sys/types.h>
-#include <sys/stat.h>
 #ifdef AFS_NT40_ENV
-#include <fcntl.h>
-#include <winsock2.h>
 #include <WINNT/afsevent.h>
 #include <sys/utime.h>
-#include <afs/dirent.h>
 #include <direct.h>
-#include <process.h>
-#include <io.h>
-#include <afs/procmgmt.h>
-#else
-#include <sys/file.h>
-#include <netdb.h>
-#include <netinet/in.h>
-#include <sys/time.h>
-#include <dirent.h>
-#endif
-#ifdef HAVE_STRING_H
-#include <string.h>
-#else
-#ifdef HAVE_STRINGS_H
-#include <strings.h>
 #endif
+
+#ifdef AFS_AIX_ENV
+#include <sys/statfs.h>
 #endif
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-#include <stdio.h>
-#include <errno.h>
+
 #include <rx/xdr.h>
 #include <rx/rx.h>
 #include <rx/rxkad.h>
@@ -55,11 +32,10 @@ RCSID
 #include <afs/cellconfig.h>
 #include <afs/afsutil.h>
 #include <afs/fileutil.h>
-#ifdef AFS_AIX_ENV
-#include <sys/statfs.h>
-#endif
+
 #include "update.h"
 #include "global.h"
+#include "update_internal.h"
 
 char *whoami;
 static int verbose;
@@ -70,11 +46,15 @@ static int GetFileFromUpServer(struct rx_connection *conn, char *filename,
                               afs_int32 atime, afs_int32 mtime);
 static int RenameNewFiles(struct filestr *modFiles);
 static int PathsAreEquivalent(char *path1, char *path2);
+int FetchFile(struct rx_call *, char *, char *, int);
+int IsCompatible(char *, afs_int32, afs_int32);
+int NotOnHost(char *, struct filestr *);
+int update_ReceiveFile(int, struct rx_call *, struct stat *);
 
 afs_int32
 GetServer(char *aname)
 {
-    register struct hostent *th;
+    struct hostent *th;
     afs_int32 addr;
 
     th = gethostbyname(aname);
@@ -88,7 +68,7 @@ GetServer(char *aname)
 
 
 int
-osi_audit()
+osi_audit(void)
 {
 /* this sucks but it works for now.
 */
@@ -114,7 +94,7 @@ main(int argc, char **argv)
 
     afs_uint32 mode;
     int error;
-    char hostname[MAXSIZE];
+    char hostname[MAXFNSIZE];
     FILE *stream;
     afs_int32 time, length, atime;
     struct filestr *df;
@@ -125,12 +105,12 @@ main(int argc, char **argv)
     int a, cnt;
     rxkad_level level;
 
-    char dirbuf[MAXSIZE], filename[MAXSIZE];
+    char dirbuf[MAXFNSIZE], filename[MAXFNSIZE];
     struct filestr *dirname, *ModFiles, *okhostfiles;
 #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.
      */
@@ -323,13 +303,13 @@ main(int argc, char **argv)
                if (verbose >= 3)
                    printf("    checking %s\n", filename);
                if (!IsCompatible(filename, time, length)) {
-                   /* if the file info has changed , record all the 
+                   /* if the file info has changed , record all the
                     *changed files in the ModFiles array*/
                    if (verbose >= 2)
                        printf("  getting %s\n", filename);
                    AddToList(&ModFiles, filename);
 
-                   /* now get the file from the server. The received 
+                   /* now get the file from the server. The received
                     * file is created under the name filename.NEW */
                    errcode =
                        GetFileFromUpServer(conn, filename, uid, gid, mode,
@@ -350,7 +330,7 @@ main(int argc, char **argv)
            {                   /*delete all the redundant files on the client */
                DIR *dirp;
                struct dirent *dp;
-               char filename[MAXSIZE];
+               char filename[MAXFNSIZE];
 
                dirp = opendir(curDir);
                if (dirp == 0) {
@@ -407,7 +387,7 @@ main(int argc, char **argv)
 /* returns 1 if the file is upto date else returns 0*/
 /*check the dir case more carefully */
 int
-IsCompatible(char *filename, afs_int32 time, afs_int32 length) 
+IsCompatible(char *filename, afs_int32 time, afs_int32 length)
 {
     struct stat status;
     afs_int32 error;
@@ -455,7 +435,7 @@ FetchFile(struct rx_call *call, char *remoteFile, char *localFile, int dirFlag)
     if (fstat(fd, &status) < 0) {
        afs_com_err(whoami, errno, "Could not stat %s", localFile);
        close(fd);
-       printf("could not stast %s\n", localFile);
+       printf("could not stat %s\n", localFile);
        return UPDATE_ERROR;
     }
     if (update_ReceiveFile(fd, call, &status))
@@ -469,17 +449,17 @@ FetchFile(struct rx_call *call, char *remoteFile, char *localFile, int dirFlag)
 
 
 int
-update_ReceiveFile(register int fd, register struct rx_call *call, register struct stat *status)
+update_ReceiveFile(int fd, struct rx_call *call, struct stat *status)
 {
-    register char *buffer = (char *)0;
+    char *buffer = (char *)0;
     afs_int32 length;
-    register int blockSize;
+    int blockSize;
     afs_int32 error = 0, len;
 #ifdef AFS_AIX_ENV
     struct statfs tstatfs;
 #endif
 
-    len = rx_Read(call, &length, sizeof(afs_int32));
+    len = rx_Read(call, (char *)&length, sizeof(afs_int32));
     length = ntohl(length);
     if (len != sizeof(afs_int32))
        return UPDATE_ERROR;
@@ -492,13 +472,13 @@ update_ReceiveFile(register int fd, register struct rx_call *call, register stru
 #else
     blockSize = status->st_blksize;
 #endif
-    buffer = (char *)malloc(blockSize);
+    buffer = malloc(blockSize);
     if (!buffer) {
        printf("malloc failed\n");
        return UPDATE_ERROR;
     }
     while (!error && length) {
-       register int nbytes = (length > blockSize ? blockSize : length);
+       int nbytes = (length > blockSize ? blockSize : length);
        nbytes = rx_Read(call, buffer, nbytes);
        if (!nbytes)
            error = UPDATE_ERROR;
@@ -605,7 +585,7 @@ NotOnHost(char *filename, struct filestr *okhostfiles)
 static int
 RenameNewFiles(struct filestr *modFiles)
 {
-    char newname[MAXSIZE];
+    char newname[MAXFNSIZE];
     char *fname;
     int errcode = 0;
     struct filestr *tf;
@@ -634,12 +614,12 @@ RenameNewFiles(struct filestr *modFiles)
 
 
 /* GetFileFromUpServer() - Makes the FetchFile() call and gets the
- * file from the upserver. 
+ * file from the upserver.
  * Return Values:
  *   0 -  Alls well
  *   -1 - Serious error. Quit right away.
- *   1  - Error, but keep trying for the other files 
- * 
+ *   1  - Error, but keep trying for the other files
+ *
  * The file obtained is written to the localized version of the filename.NEW
  * and the uid, gid, file mode, access and modification times will be set to
  * the passed in values.
@@ -659,7 +639,7 @@ GetFileFromUpServer(struct rx_connection *conn,     /* handle for upserver */
 #else
     struct timeval tvp[2];
 #endif
-    char newfile[MAXSIZE];
+    char newfile[MAXFNSIZE];
 
     /* construct local path from canonical (wire-format) path */
     errcode = ConstructLocalPath(filename, "/", &lfile);
@@ -682,6 +662,7 @@ GetFileFromUpServer(struct rx_connection *conn,     /* handle for upserver */
     if (errcode) {
        printf("failed to fetch file %s \n", filename);
        afs_com_err(whoami, errcode, "fetching file");
+        unlink(newfile);
        return 1;
     }
 
@@ -692,6 +673,7 @@ GetFileFromUpServer(struct rx_connection *conn,     /* handle for upserver */
               (unsigned int)mode);
        afs_com_err(whoami, errno, "could not change protection on %s to %u",
                newfile, mode);
+        unlink(newfile);
        return 1;
     }
 #ifdef AFS_NT40_ENV
@@ -719,6 +701,7 @@ GetFileFromUpServer(struct rx_connection *conn,     /* handle for upserver */
        afs_com_err(whoami, errno,
                "could not change access and modify times on %s to %u %u",
                newfile, atime, mtime);
+        unlink(newfile);
        return 1;
     }