/* The "AFSCONF" environment (or contents of "/.AFSCONF") will be typically set to something like "/afs/<cell>/common/etc" where, by convention, the default files for "ThisCell" and "CellServDB" will reside; note that a major drawback is that a given afs client on that cell may NOT contain the same contents... */
char *home_dir;
afsconf_FILE *fp;
- size_t len;
+ size_t len = 0;
int r;
if (!(home_dir = getenv("HOME"))) {
if (fp == 0)
goto fail;
- fgets(afs_confdir, 128, fp);
- fclose(fp);
} else {
char *pathname = NULL;
if (fp == 0)
goto fail;
}
- fgets(afs_confdir, 128, fp);
- fclose(fp);
}
- len = strlen(afs_confdir);
+ if (fgets(afs_confdir, 128, fp) != NULL)
+ len = strlen(afs_confdir);
+ fclose(fp);
if (len == 0)
goto fail;
(!strncmp
(AFSDIR_USR_DIRPATH, AFSDIR_SERVER_BIN_DIRPATH,
strlen(AFSDIR_USR_DIRPATH)))) {
- MakeDir(AFSDIR_USR_DIRPATH);
+ if (MakeDir(AFSDIR_USR_DIRPATH))
+ return errno;
}
if (!strncmp
(AFSDIR_SERVER_AFS_DIRPATH, AFSDIR_SERVER_BIN_DIRPATH,
strlen(AFSDIR_SERVER_AFS_DIRPATH))) {
- MakeDir(AFSDIR_SERVER_AFS_DIRPATH);
+ if (MakeDir(AFSDIR_SERVER_AFS_DIRPATH))
+ return errno;
}
- MakeDir(AFSDIR_SERVER_BIN_DIRPATH);
- MakeDir(AFSDIR_SERVER_ETC_DIRPATH);
- MakeDir(AFSDIR_SERVER_LOCAL_DIRPATH);
- MakeDir(AFSDIR_SERVER_DB_DIRPATH);
- MakeDir(AFSDIR_SERVER_LOGS_DIRPATH);
+ if (MakeDir(AFSDIR_SERVER_BIN_DIRPATH))
+ return errno;
+ if (MakeDir(AFSDIR_SERVER_ETC_DIRPATH))
+ return errno;
+ if (MakeDir(AFSDIR_SERVER_LOCAL_DIRPATH))
+ return errno;
+ if (MakeDir(AFSDIR_SERVER_DB_DIRPATH))
+ return errno;
+ if (MakeDir(AFSDIR_SERVER_LOGS_DIRPATH))
+ return errno;
#ifndef AFS_NT40_ENV
if (!strncmp
(AFSDIR_CLIENT_VICE_DIRPATH, AFSDIR_CLIENT_ETC_DIRPATH,
strlen(AFSDIR_CLIENT_VICE_DIRPATH))) {
- MakeDir(AFSDIR_CLIENT_VICE_DIRPATH);
+ if (MakeDir(AFSDIR_CLIENT_VICE_DIRPATH))
+ return errno;
}
- MakeDir(AFSDIR_CLIENT_ETC_DIRPATH);
+ if (MakeDir(AFSDIR_CLIENT_ETC_DIRPATH))
+ return errno;
- symlink(AFSDIR_SERVER_THISCELL_FILEPATH, AFSDIR_CLIENT_THISCELL_FILEPATH);
- symlink(AFSDIR_SERVER_CELLSERVDB_FILEPATH,
- AFSDIR_CLIENT_CELLSERVDB_FILEPATH);
+ if (symlink(AFSDIR_SERVER_THISCELL_FILEPATH,
+ AFSDIR_CLIENT_THISCELL_FILEPATH))
+ return errno;
+ if (symlink(AFSDIR_SERVER_CELLSERVDB_FILEPATH,
+ AFSDIR_CLIENT_CELLSERVDB_FILEPATH))
+ return errno;
#endif /* AFS_NT40_ENV */
- if (coredir)
- MakeDir(coredir);
+ if (coredir) {
+ if (MakeDir(coredir))
+ return errno;
+ }
return 0;
}
*/
#ifndef AFS_NT40_ENV
- if (!nofork)
- daemon(1, 0);
+ if (!nofork) {
+ if (daemon(1, 0))
+ printf("bosserver: warning - daemon() returned code %d\n", errno);
+ }
#endif /* ! AFS_NT40_ENV */
/* create useful dirs */
- CreateDirs(DoCore);
+ i = CreateDirs(DoCore);
+ if (i) {
+ printf("bosserver: could not set up directories, code %d\n", i);
+ exit(1);
+ }
/* Write current state of directory permissions to log file */
DirAccessOK();
/* chdir to AFS log directory */
if (DoCore)
- chdir(DoCore);
+ i = chdir(DoCore);
else
- chdir(AFSDIR_SERVER_LOGS_DIRPATH);
+ i = chdir(AFSDIR_SERVER_LOGS_DIRPATH);
+ if (i) {
+ printf("bosserver: could not change to %s, code %d\n",
+ DoCore ? DoCore : AFSDIR_SERVER_LOGS_DIRPATH, errno);
+ exit(1);
+ }
/* try to read the key from the config file */
tdir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH);
afs_int32 blockAddr;
struct block block;
char filename[128];
- afs_int32 size, chunkSize;
+ afs_int32 size, totalSize, chunkSize;
int fid;
sprintf(filename, "%s/%s", gettmpdir(), "dbg_XXXXXX");
fid = mkstemp(filename);
- size = ntohl(tbPtr->size);
+ totalSize = size = ntohl(tbPtr->size);
blockAddr = ntohl(tbPtr->textAddr);
while (size) {
chunkSize = min(BLOCK_DATA_SIZE, size);
dbread(ut, blockAddr, (char *)&block, sizeof(block));
- write(fid, &block.a[0], chunkSize);
+ if (write(fid, &block.a[0], chunkSize) < 0)
+ break;
blockAddr = ntohl(block.h.next);
size -= chunkSize;
}
close(fid);
- printf("wrote debug file %s\n", filename);
+ if (size) {
+ printf("Wrote partial debug file (%ld bytes out of %ld)\n",
+ (long)(totalSize - size), (long)totalSize);
+ } else {
+ printf("wrote debug file %s\n", filename);
+ }
}
* reads from the latter, the child reads from the former, and
* writes to the latter.
*/
- pipe(pipe1);
- pipe(pipe2);
+ if (pipe(pipe1) || pipe(pipe2)) {
+ using_child = 0;
+ return 0;
+ }
/* fork a child */
pid = fork();
if (using_child) {
fprintf(childin, "%s\n", pw);
fflush(childin);
- fscanf(childout, "%d", &rc);
+ if (fscanf(childout, "%d", &rc) < 1)
+ rc = -1;
}
return (rc);
currenttime = time(0);
timeStamp = ctime(¤ttime);
timeStamp[24] = 0;
- write(2, timeStamp, strlen(timeStamp));
-
- write(2, msg1, strlen(msg1));
- write(2, lwp_cpptr->name, strlen(lwp_cpptr->name));
- write(2, msg2, strlen(msg2));
+ if (write(2, timeStamp, strlen(timeStamp)) < 0)
+ return;
+
+ if (write(2, msg1, strlen(msg1)) < 0)
+ return;
+ if (write(2, lwp_cpptr->name, strlen(lwp_cpptr->name)) < 0)
+ return;
+ if (write(2, msg2, strlen(msg2)) < 0)
+ return;
}
static void
display_entry(int offset)
{
lseek(dbase_fd, offset + HDRSIZE, L_SET);
- read(dbase_fd, &pre, sizeof(struct prentry));
+ if (read(dbase_fd, &pre, sizeof(struct prentry)) < 0) {
+ fprintf(stderr, "pt_util: error reading entry %d: %s\n",
+ offset, strerror(errno));
+ exit(1);
+ }
fix_pre(&pre);
offset = pre.next;
while (offset) {
lseek(dbase_fd, offset + HDRSIZE, L_SET);
- read(dbase_fd, &prco, sizeof(struct contentry));
+ if (read(dbase_fd, &prco, sizeof(struct contentry)) < 0) {
+ fprintf(stderr, "pt_util: read i/o error: %s\n",
+ strerror(errno));
+ exit(1);
+ }
prco.next = ntohl(prco.next);
for (i = 0; i < COSIZE; i++) {
prco.entries[i] = ntohl(prco.entries[i]);
{
static int init = 0;
struct ubik_hdr thdr;
+ ssize_t count;
if (!init) {
memset(&thdr, 0, sizeof(thdr));
thdr.version.counter = htonl(0);
thdr.magic = htonl(UBIK_MAGIC);
thdr.size = htons(HDRSIZE);
- lseek(dbase_fd, 0, 0);
- write(dbase_fd, &thdr, sizeof(thdr));
- fsync(dbase_fd);
+ if (lseek(dbase_fd, 0, 0) == (off_t)-1)
+ return errno;
+ count = write(dbase_fd, &thdr, sizeof(thdr));
+ if (count < 0)
+ return errno;
+ else if (count != sizeof(thdr))
+ return UIOERROR;
+ if (fsync(dbase_fd))
+ return errno;
init = 1;
}
return (0);
if (!(afs_server = getenv("AFSSERVER"))) {
char *home_dir;
FILE *fp;
- int len;
+ int len = 0;
if (!(home_dir = getenv("HOME"))) {
/* Our last chance is the "/.AFSSERVER" file */
if (fp == 0) {
return 0;
}
- fgets(server_name, 128, fp);
- fclose(fp);
} else {
char *pathname;
return 0;
}
}
- fgets(server_name, 128, fp);
- fclose(fp);
}
- len = strlen(server_name);
+ if (fgets(server_name, 128, fp) != NULL)
+ len = strlen(server_name);
+ fclose(fp);
if (len == 0) {
return 0;
}
perror("open ronly");
return -1;
}
- fchown(fd1, 1, -1); /* don't check error code, may fail on Ultrix */
+ code = fchown(fd1, 1, -1); /* don't check error code, may fail on Ultrix */
code = write(fd1, "test", 4);
if (code != 4) {
printf("rotest short read (%d)\n", code);
}
/* now finish up */
- chdir("..");
+ if (chdir("..") < 0) {
+ perror("chdir ..");
+ return -1;
+ }
rmdir(dirName);
printf("Test completed successfully.\n");
return 0;
fflush(stdout);
}
- mkdir(parent, 0777);
- chown(parent, owner, -1);
+ if (mkdir(parent, 0777))
+ return (0);
+ if (chown(parent, owner, -1))
+ return (0);
}
return (1);
} /*MakeParent */
(afs_uintmax_t) Pos, (afs_uintmax_t) DataLength,
(afs_uintmax_t) FileLength, (afs_uintmax_t) Length));
- /* truncate the file iff it needs it (ftruncate is slow even when its a noop) */
- if (FileLength < DataLength)
- FDH_TRUNC(fdP, FileLength);
bytesTransfered = 0;
#ifndef HAVE_PIOV
tbuffer = AllocSendBuffer();
#endif /* HAVE_PIOV */
+ /* truncate the file iff it needs it (ftruncate is slow even when its a noop) */
+ if (FileLength < DataLength) {
+ errorCode = FDH_TRUNC(fdP, FileLength);
+ if (errorCode)
+ goto done;
+ }
+
/* if length == 0, the loop below isn't going to do anything, including
* extend the length of the inode, which it must do, since the file system
* assumes that the inode length == vnode's file length. So, we extend
fprintf(stderr, "prompt state broken; aborting\n");
return;
}
- fgets(input, 256, stdin);
+ if (fgets(input, 256, stdin) == NULL)
+ return;
if (!strcmp(input, "")) {
/* repeat last command */
static void
CheckAdminName(void)
{
- int fd = 0;
+ int fd = -1;
struct afs_stat status;
if ((afs_stat("/AdminName", &status)) || /* if file does not exist */
(status.st_size <= 0) || /* or it is too short */
(status.st_size >= (MAXADMINNAME)) || /* or it is too long */
- !(fd = afs_open("/AdminName", O_RDONLY, 0))) { /* or the open fails */
+ (fd = afs_open("/AdminName", O_RDONLY, 0)) < 0 || /* or open fails */
+ read(fd, adminName, status.st_size) != status.st_size) { /* or read */
+
strcpy(adminName, "System:Administrators"); /* use the default name */
- } else {
- (void)read(fd, adminName, status.st_size); /* use name from the file */
}
- if (fd)
+ if (fd >= 0)
close(fd); /* close fd if it was opened */
} /*CheckAdminName */
handleit(struct cmd_syndesc *as, void *arock)
{
int w, old, new, rc, dump = 0, fromv = 0;
+ ssize_t count;
+
char ubik[80]; /* space for some ubik header */
union {
struct vlheader_1 header1;
}
/* Read the version */
- lseek(old, 64, L_SET);
- read(old, &fromv, sizeof(int));
+ if (lseek(old, 64, L_SET) == (off_t)-1) {
+ perror(pn);
+ exit(-1);
+ }
+ count = read(old, &fromv, sizeof(int));
+ if (count < 0) {
+ perror(pn);
+ exit(-1);
+ } else if (count != sizeof(int)) {
+ fprintf(stderr, "%s: Premature EOF reading database version.\n", pn);
+ exit(-1);
+ }
fromv = ntohl(fromv);
if ((fromv < 1) || (fromv > 4)) {
fprintf(stderr, "%s", pn);
}
/* Sequentially read the database converting the entries as we go */
- lseek(old, 0, L_SET);
- read(old, ubik, 64);
+ if (lseek(old, 0, L_SET) == (off_t)-1) {
+ perror(pn);
+ exit(-1);
+ }
+ count = read(old, ubik, 64);
+ if (count < 0) {
+ perror(pn);
+ exit(-1);
+ } else if (count != 64) {
+ fprintf(stderr, "%s: Premature EOF reading database header.\n", pn);
+ exit(-1);
+ }
readheader(old, fromv, &oldheader);
if (fromv == 1) {
dbsize = ntohl(oldheader.header1.vital_header.eofPtr);
namei_ViceREADME(char *partition)
{
char filename[32];
- int fd;
+ int fd, len, e = 0;
/* Create the inode directory if we're starting for the first time */
snprintf(filename, sizeof filename, "%s" OS_DIRSEP "%s", partition,
partition, INODEDIR);
fd = OS_OPEN(filename, O_WRONLY | O_CREAT | O_TRUNC, 0444);
if (fd != INVALID_FD) {
- (void)OS_WRITE(fd, VICE_README, strlen(VICE_README));
+ len = strlen(VICE_README);
+ if (OS_WRITE(fd, VICE_README, len) != len)
+ e = errno;
OS_CLOSE(fd);
+ if (e)
+ errno = e;
}
return (errno);
}
NAMEI_GLC_UNLOCK;
goto bad_getLinkByte;
}
- FDH_TRUNC(h, offset+sizeof(row));
+ if (FDH_TRUNC(h, offset+sizeof(row))) {
+ NAMEI_GLC_UNLOCK;
+ goto bad_getLinkByte;
+ }
row = 1 << index;
rc = FDH_PWRITE(h, (char *)&row, sizeof(row), offset);
NAMEI_GLC_UNLOCK;
#ifdef AFS_NT40_ENV
MoveFileEx(n.n_path, newpath, MOVEFILE_WRITE_THROUGH);
#else
- link(newpath, n.n_path);
+ if (link(newpath, n.n_path)) {
+ Log("1 namei_ConvertROtoRWvolume: could not move SmallIndex file: %s\n", n.n_path);
+ code = -1;
+ goto done;
+ }
OS_UNLINK(newpath);
#endif
#ifdef AFS_NT40_ENV
MoveFileEx(n.n_path, newpath, MOVEFILE_WRITE_THROUGH);
#else
- link(newpath, n.n_path);
+ if (link(newpath, n.n_path)) {
+ Log("1 namei_ConvertROtoRWvolume: could not move LargeIndex file: %s\n", n.n_path);
+ code = -1;
+ goto done;
+ }
OS_UNLINK(newpath);
#endif
int fid;
int lfile;
afs_sfsize_t size, s;
+ ssize_t count;
/* Check if its vnode-file-link exists. If not,
* then the file will be an orphaned file.
/* Write the file out */
fid = open(filename, (O_CREAT | O_WRONLY | O_TRUNC), mode);
+ if (fid < 0) {
+ fprintf(stderr, "Open %s: Errno = %d\n", filename, errno);
+ goto open_fail;
+ }
size = vn.dataSize;
while (size > 0) {
s = (afs_int32) ((size > BUFSIZE) ? BUFSIZE : size);
code = fread(buf, 1, s, dumpfile);
- if (code > 0) {
- (void)write(fid, buf, code);
- size -= code;
- }
if (code != s) {
if (code < 0)
fprintf(stderr, "Code = %d; Errno = %d\n", code,
}
break;
}
+ if (code > 0) {
+ count = write(fid, buf, code);
+ if (count < 0) {
+ fprintf(stderr, "Count = %ld, Errno = %d\n",
+ (long)count, errno);
+ break;
+ } else if (count != code) {
+ fprintf(stderr, "Wrote %llu bytes out of %llu\n",
+ (afs_uintmax_t) count,
+ (afs_uintmax_t) code);
+ break;
+ }
+ size -= code;
+ }
}
close(fid);
if (size != 0) {
filename, fname);
}
+open_fail:
/* Remove the link to the file */
if (lfile) {
unlink(filename);