date and time created 88/10/18 21:46:24 by bostic
[unix-history] / usr / src / old / berknet / netdaemon.c
index eadc718..db24e3e 100644 (file)
@@ -1,4 +1,4 @@
-static char sccsid[] = "@(#)netdaemon.c        4.1     (Berkeley)      %G%";
+static char sccsid[] = "@(#)netdaemon.c        4.5     (Berkeley)      %G%";
 
 /* sccs id variable */
 static char *netdaemon_sid = "@(#)netdaemon.c  1.10";
 
 /* sccs id variable */
 static char *netdaemon_sid = "@(#)netdaemon.c  1.10";
@@ -45,12 +45,11 @@ struct userinfo status;
 
 /* local variables */
 static long length;
 
 /* local variables */
 static long length;
-static FILE *dir;
+static DIR *dir;
 /* static char sheader[] =             "ABCDE"; */
 static char tempfile[]=        TEMPFILE;
 static char publogfile[]=      PUBLOGFILE;
 static struct stat statbuf;
 /* static char sheader[] =             "ABCDE"; */
 static char tempfile[]=        TEMPFILE;
 static char publogfile[]=      PUBLOGFILE;
 static struct stat statbuf;
-static struct direct dirbuf;
 int handlekill();
 static char frommach;
 long linechars();
 int handlekill();
 static char frommach;
 long linechars();
@@ -86,7 +85,7 @@ main(argc,argv)
                perror(senddir);
                exit(EX_OSFILE);
                }
                perror(senddir);
                exit(EX_OSFILE);
                }
-       dir = fopen(senddir,"r");
+       dir = opendir(senddir);
        if(dir == NULL){
                perror(senddir);
                exit(EX_OSFILE);
        if(dir == NULL){
                perror(senddir);
                exit(EX_OSFILE);
@@ -148,12 +147,13 @@ netsend(){
        static char nleft = 1;
        long lFileLen,diff;
        double drate;
        static char nleft = 1;
        long lFileLen,diff;
        double drate;
-       register unsigned uid,uidBest;
+       register int uid,uidBest;
        char *sdate,*sn,*swait;
        long ot,nt,filesize;
        register int i;
        char stemp[20];
        static char jname[FNS];
        char *sdate,*sn,*swait;
        long ot,nt,filesize;
        register int i;
        char stemp[20];
        static char jname[FNS];
+       register struct direct *dp;
 
        debug("ck send");
        if(stat(senddir,&statbuf) < 0){
 
        debug("ck send");
        if(stat(senddir,&statbuf) < 0){
@@ -162,19 +162,18 @@ netsend(){
                }
        if(statbuf.st_mtime == lasttime && nleft == 0)return;   /* no need to search */
        lasttime = statbuf.st_mtime;
                }
        if(statbuf.st_mtime == lasttime && nleft == 0)return;   /* no need to search */
        lasttime = statbuf.st_mtime;
-       fseek(dir,0L,0);
+       rewinddir(dir);
        lFileLen = 10000000L;
        nleft = 0;
        lFileLen = 10000000L;
        nleft = 0;
-       while(fread(&dirbuf,1,sizeof dirbuf,dir) == sizeof dirbuf){
-               if(dirbuf.d_ino == 0
-                  || dirbuf.d_name[0] != 'c'
-                  || dirbuf.d_name[1] != 'f'
-                  || dirbuf.d_name[2] != remote
-                  || stat(dirbuf.d_name,&statbuf) < 0
+       while((dp = readdir(dir)) != NULL){
+               if(dp->d_name[0] != 'c'
+                  || dp->d_name[1] != 'f'
+                  || dp->d_name[2] != remote
+                  || stat(dp->d_name,&statbuf) < 0
                   || statbuf.st_mode == 0)
                        continue;
                   || statbuf.st_mode == 0)
                        continue;
-               dirbuf.d_name[0] = 'd';
-               if(stat(dirbuf.d_name,&statbuf) < 0 || statbuf.st_mode == 0)
+               dp->d_name[0] = 'd';
+               if(stat(dp->d_name,&statbuf) < 0 || statbuf.st_mode == 0)
                        continue;
                uid = guid(statbuf.st_uid,statbuf.st_gid);
                if(netd.dp_onlyuid != 0 && uid != netd.dp_onlyuid && uid != SUPERUSER
                        continue;
                uid = guid(statbuf.st_uid,statbuf.st_gid);
                if(netd.dp_onlyuid != 0 && uid != netd.dp_onlyuid && uid != SUPERUSER
@@ -186,13 +185,12 @@ netsend(){
                        if( !debugflg )
                                continue;
                        else
                        if( !debugflg )
                                continue;
                        else
-                               debug("sending large file %s\n", dirbuf.d_name );
+                               debug("sending large file %s\n", dp->d_name );
                }
 #endif DONTHOLDBIG
                if(lFileLen > filesize){
                        lFileLen = filesize;
                }
 #endif DONTHOLDBIG
                if(lFileLen > filesize){
                        lFileLen = filesize;
-                       for(i=0; i<DIRSIZ; i++)
-                               jname[i] = dirbuf.d_name[i];
+                       strcpy(jname,dp->d_name);
                        uidBest = uid;
                }
 # ifdef MAXSENDQ
                        uidBest = uid;
                }
 # ifdef MAXSENDQ
@@ -437,9 +435,7 @@ forw:
                        dump.elaptot += diff;
                        while((pid = fork()) == -1)sleep(2);
                        if(pid == 0){
                        dump.elaptot += diff;
                        while((pid = fork()) == -1)sleep(2);
                        if(pid == 0){
-# ifndef V6
                                RENICE0();
                                RENICE0();
-# endif V6
 #ifdef CCV7
                                /* make sure the spawned child has it's own
                                        group process to avoid the nasty
 #ifdef CCV7
                                /* make sure the spawned child has it's own
                                        group process to avoid the nasty
@@ -456,7 +452,7 @@ forw:
                        unlink(tempfile);
                        rcode >>= 8;
                        if(rcode != 0)
                        unlink(tempfile);
                        rcode >>= 8;
                        if(rcode != 0)
-                               error("pass-thru rcode %d");
+                               error("pass-thru rcode %d", rcode);
                        debug("passthru to %c code %c rcode %d",
                                hd.hd_mchto,hd.hd_code,rcode);
                        return(1);
                        debug("passthru to %c code %c rcode %d",
                                hd.hd_mchto,hd.hd_code,rcode);
                        return(1);
@@ -472,9 +468,7 @@ forw:
        }
        /* this is a child, who will go ahead and execute the command */
        /* running uid=0 at this point */
        }
        /* this is a child, who will go ahead and execute the command */
        /* running uid=0 at this point */
-# ifndef V6
        RENICE0();
        RENICE0();
-# endif V6
        /* nice(0 set back to 0 */
 #ifdef CCV7
        /* separate group process */
        /* nice(0 set back to 0 */
 #ifdef CCV7
        /* separate group process */