[4957] in Athena Bugs
track
daemon@ATHENA.MIT.EDU (John Carr)
Sun May 20 22:54:25 1990
To: bugs@ATHENA.MIT.EDU
Date: Sun, 20 May 90 22:54:08 EDT
From: John Carr <jfc@ATHENA.MIT.EDU>
I first wanted to start this bug report with a long flame about portable
programming; instead I'll settle for pointing out one thing: there is a good
reason that system header files define symbolic constants. The reason is that
these constants are not universal, but implementation dependent (else there
would be no need for the header files). The authors of track apparently did
not understand this.
The following patches
(1) make track compile on a PS/2 running AIX
(2) fix a call to fchmod with wrong arguments
*** ref/stamp.c Tue Jun 21 19:45:19 1988
--- stamp.c Sun May 20 22:45:50 1990
***************
*** 95,132 ****
#include "track.h"
! /* XXX
! * convert right-shifted st_mode type-bits to corresponding formats:
! * S_IFCHR = 0020000 gets mapped to elt 1 of the array,
! * S_IFDIR = 0040000 => elt 2 of the array,
! * S_IFBLK = 0060000 => elt 3 of the array,
! * S_IFREG = 0100000 => elt 4 of the array,
! * S_IFLNK = 0120000 => elt 5 of the array,
! * S_IFSOCK= 0140000 => elt 6 of the array, ( only for error messagess),
! * S_IFMT = 0170000 => elt 7 of the array, ( dropping 1 bit).
! */
! static char *write_formats[] = {
! "*ERROR (write_statline): %s's file type is 0.\n",
! "c%s %c%d(%d.%d.%o)\n", /* S_IFCHR */
! "d%s %c%d(%d.%d.%o)\n", /* S_IFDIR */
! "b%s %c%d(%d.%d.%o)\n", /* S_IFBLK */
! "f%s %c%x(%d.%d.%o)%ld\n", /* S_IFREG */
! "l%s %c%s\n", /* S_IFLNK */
! "*ERROR (write_statline): can't track socket %s.\n",
! "*ERROR (write_statline): bad type S_IFMT %s.\n"
! };
- static char *read_formats[] = {
- "",
- "%d(%d.%d.%o)\n", /* S_IFCHR */
- "%d(%d.%d.%o)\n", /* S_IFDIR */
- "%d(%d.%d.%o)\n", /* S_IFBLK */
- "%x(%d.%d.%o)%ld\n", /* S_IFREG */
- "", /* S_IFLNK */
- "", /* S_IFSOCK */
- "" /* S_IFMT */
- };
-
char type_char[] = " cdbfls*89ABCDEF";
/*
--- 95,102 ----
#include "track.h"
! extern char *mode_to_char(), *mode_to_fmt(), *mode_to_rfmt();
char type_char[] = " cdbfls*89ABCDEF";
/*
***************
*** 188,194 ****
default:
sprintf( errmsg,
"bad type for inode %d, pathname %s.\n\tapparent type = %c\n",
! c->sbuf.st_ino, path[ ROOT], type_char[ type >> 13]);
do_panic();
}
/* set up name & sortkey:
--- 158,164 ----
default:
sprintf( errmsg,
"bad type for inode %d, pathname %s.\n\tapparent type = %c\n",
! c->sbuf.st_ino, path[ ROOT], mode_to_string(type));
do_panic();
}
/* set up name & sortkey:
***************
*** 210,216 ****
/* to choose printing format, convert type-bits to array-index:
* the formats specify 3-7 arguments, according to type:
*/
! format = write_formats[ type >> 13];
sprintf( linebuf, format, name, same_name ? '=' : '~' , curr1,
UID( *s), GID( *s), MODE( *s), extra);
--- 180,186 ----
/* to choose printing format, convert type-bits to array-index:
* the formats specify 3-7 arguments, according to type:
*/
! format = mode_to_fmt(type);
sprintf( linebuf, format, name, same_name ? '=' : '~' , curr1,
UID( *s), GID( *s), MODE( *s), extra);
***************
*** 437,443 ****
/* if we've already parsed the line,
* as in S_IFLNK case, skip the sscanf call:
*/
! if ( *(format = read_formats[ s->st_mode >> 13]))
sscanf( line, format, curr1, &u, &g, &m, extra);
s->st_uid = (short) u;
--- 407,413 ----
/* if we've already parsed the line,
* as in S_IFLNK case, skip the sscanf call:
*/
! if ( *(format = mode_to_rfmt(s->st_mode)))
sscanf( line, format, curr1, &u, &g, &m, extra);
s->st_uid = (short) u;
*** ref/misc.c Mon Sep 19 20:25:15 1988
--- misc.c Sun May 20 22:36:39 1990
***************
*** 76,82 ****
if ( filep);
else if ( nopullflag) return;
else if ( logfile = fopen( logfilepath, "w+")) {
! fchmod( logfile, 0664);
filep = logfile;
}
else {
--- 76,82 ----
if ( filep);
else if ( nopullflag) return;
else if ( logfile = fopen( logfilepath, "w+")) {
! (void)fchmod(fileno(logfile), 0664);
filep = logfile;
}
else {
***************
*** 195,198 ****
--- 195,277 ----
do_panic();
}
strcpy(*to,from);
+ }
+
+ /* Convert mode (file type) bits to a string */
+
+ char *mode_to_string(mode)
+ int mode;
+ {
+ switch(mode & S_IFMT)
+ {
+ case S_IFDIR:
+ return "directory";
+ case S_IFCHR:
+ return "char-device";
+ case S_IFBLK:
+ return "block-device";
+ case S_IFREG:
+ return "file";
+ #ifdef S_IFIFO
+ case S_IFIFO:
+ return "fifo";
+ #endif
+ case S_IFLNK:
+ return "symlink";
+ case S_IFSOCK:
+ return "socket";
+ #ifdef S_IFMPX
+ case S_IFMPX:
+ return "multi char-device";
+ #endif
+ default:
+ return "nonexistent";
+ }
+ }
+
+ char *mode_to_fmt(mode)
+ int mode;
+ {
+ switch(mode & S_IFMT)
+ {
+ case S_IFDIR:
+ return "d%s %c%d(%d.%d.%o)\n";
+ #ifdef S_IFMPX
+ case S_IFMPX:
+ #endif
+ case S_IFCHR:
+ return "c%s %c%d(%d.%d.%o)\n";
+ case S_IFBLK:
+ return "b%s %c%d(%d.%d.%o)\n";
+ case S_IFREG:
+ return "f%s %c%x(%d.%d.%o)%ld\n";
+ case S_IFLNK:
+ return "l%s %c%s\n";
+ #ifdef S_IFIFO
+ case S_IFIFO:
+ #endif
+ case S_IFSOCK:
+ return "*ERROR (write_statline): can't track socket %s.\n";
+ default:
+ return "*ERROR (write_statline): %s's file type is unknown.\n";
+ }
+ }
+
+ char *mode_to_rfmt(mode)
+ int mode;
+ {
+ switch(mode & S_IFMT)
+ {
+ #ifdef S_IFMPX
+ case S_IFMPX:
+ #endif
+ case S_IFDIR:
+ case S_IFCHR:
+ case S_IFBLK:
+ return "%d(%d.%d.%o)\n";
+ case S_IFREG:
+ return "%x(%d.%d.%o)%ld\n";
+ default:
+ return "";
+ }
}
*** ref/update.c Mon Sep 19 20:27:50 1988
--- update.c Sun May 20 22:13:19 1990
***************
*** 76,87 ****
#include "track.h"
#include <sys/errno.h>
! /* this array converts stat()'s type-bits to a character string:
! * to make the index, right-shift the st_mode field by 13 bits.
! */
! static char *type_str[] = { "ERROR", "char-device", "directory",
! "block-device", "file", "symlink", "socket(ERROR)", "nonexistent"
! };
#define DIFF( l, r, field) (short)(((l).sbuf.field) != ((r).sbuf.field))
--- 76,82 ----
#include "track.h"
#include <sys/errno.h>
! extern char *mode_to_string();
#define DIFF( l, r, field) (short)(((l).sbuf.field) != ((r).sbuf.field))
***************
*** 207,213 ****
if ( get_currentness( rpath, r)) {
sprintf( errmsg,
"master-copy doesn't exist:\n\t%s should be a %s.\n",
! rpath[ ROOT], type_str[ remote_type >> 13]);
do_gripe();
/* for nopullflag,
--- 202,208 ----
if ( get_currentness( rpath, r)) {
sprintf( errmsg,
"master-copy doesn't exist:\n\t%s should be a %s.\n",
! rpath[ ROOT], mode_to_string(remote_type));
do_gripe();
/* for nopullflag,
***************
*** 463,473 ****
return( error);
}
copy_file(from,to)
char *from,*to;
{
- char buf[MAXBSIZE],temp[LINELEN];
int cc, fdf, fdt;
fdf = open(from,O_RDONLY);
if ( 0 > fdf) {
--- 458,472 ----
return( error);
}
+ #ifndef MAXBSIZE
+ #define MAXBSIZE 8192
+ #endif
+
copy_file(from,to)
char *from,*to;
{
int cc, fdf, fdt;
+ char buf[MAXBSIZE],temp[LINELEN];
fdf = open(from,O_RDONLY);
if ( 0 > fdf) {
***************
*** 528,535 ****
char fill[ LINELEN], *lfill = "", *rfill = "";
int dlen;
! ltype = type_str[ TYPE( *ls) >> 13];
! rtype = type_str[ TYPE( *rs) >> 13];
dlen = strlen( lname) - strlen( rname) +
strlen( ltype) - strlen( rtype);
--- 527,534 ----
char fill[ LINELEN], *lfill = "", *rfill = "";
int dlen;
! ltype = mode_to_string(TYPE(*ls));
! rtype = mode_to_string(TYPE(*rs));
dlen = strlen( lname) - strlen( rname) +
strlen( ltype) - strlen( rtype);
*** ref/track.c Mon Sep 19 20:27:26 1988
--- track.c Sun May 20 21:55:58 1990
***************
*** 504,515 ****
poppath( to);
poppath( from);
}
- /* track is often used just before a reboot;
- * flush the kernel's text-table,
- * to ensure that the vnodes we've freed get scavenged,
- */
- unmount("/"); /* XXX */
-
/* then make sure that the file-systems' superblocks are up-to-date.
*/
sync();
--- 504,509 ----