b0VIM 6.1V=Srupeternebula.mac.wiwa.loc~peter/projects/watchfolder-0.3.1/watchd.c0123 !"#Upt r !s:,v  =4dar6~: = z d Q = )   w v ] B )  r n ] O 8 ) %   x A / . Nauh^[=8  F  ~pfX6-{xsrpoGE)wgW strcpy(p2,""); strcpy(p1,""); // null-terminate a substring by itself! s[pos1]=0x00; // Needed, because strncpy is too stupid to int pos1 = (((equal==NULL)||(equal#include #include #include #include #include #include #include #include #include #include #include #define __USE_BSD*/ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. along with this program; if not, write to the Free Software You should have received a copy of the GNU General Public License GNU General Public License for more details. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the but WITHOUT ANY WARRANTY; without even the implied warranty of This program is distributed in the hope that it will be useful, (at your option) any later version. the Free Software Foundation; either version 2 of the License, or it under the terms of the GNU General Public License as published by This program is free software; you can redistribute it and/or modifySyntax : watchdAuthor : Peter Turczak Modified : 25.09.2002Created : 20.08.2001Program : watchd/*da =C?1 `WUF4,  w V H | t I } #endif return(0); } #ifndef DEBUG } sleep(interval); } } } ((Twatchfolder *)c->cur)->curcount=((Twatchfolder *)c->cur)->interval-1; processdir((Twatchfolder *)c->cur); { if (((Twatchfolder *)c->cur)->curcount--<1) } ((Twatchfolder *)c->cur)->gracetime=timeofgrace; ((Twatchfolder *)c->cur)->filechain=scanchain(((Twatchfolder *)c->cur)->filechain); #endif printf("scanchain()\n"); #ifdef DEBUG { if (((Twatchfolder *)c->cur)->gracetime--<1) { if (c->cur!=NULL) c=c->next; { while (c->next!=NULL) c=head(folders); { while (1) #endif if (fork()==0) { #ifndef DEBUG init();// signal(SIGHUP, sighandler); element *c; int i;{int main(int argc, char *argv[] )} } init(); // Reread config file! { if (signal==SIGHUP) {void sighandler(int signal)} closedir(dir); free(tmpS); } syslog(LOG_WARNING||LOG_DAEMON,"could not read directory %s",f->dir); { printf("Warning: Could not read directory '%s'\n",f->dir); } else } de=readdir(dir); } da ,RB:}lYO0 z g _ Y T / ( ^ E . % fclose(f); closelog(); } syslog((r==0)?LOG_NOTICE:LOG_WARNING, "%s\n", buf); if (fgets(buf, 511, f)!=NULL) { while (!feof(f)) f=fdopen(fd, "r"); openlog(folder->runprg, LOG_PID, LOG_DAEMON); snprintf(buf, 511, "Program %s returned %d, stdout/err follows:\n", folder->runprg, r); lseek(fd, SEEK_SET, 0); // Rewind temp log file.. { if (folder->flags&FL_LOG_SYSLOG) } } close(log); fd=0; } #endif printf("Error closing fd=%d!\n",fd); #ifdef DEBUG { if (close(fd)) // Close the tempfile } write(log, buf, l); l=read(fd, buf, 512); { while (l>0) l=222222; write(log, buf, strlen(buf)); snprintf(buf, 511, "Program %s returned %d, stdout/err follows:\n", folder->runprg, r); lseek(fd, SEEK_SET, 0); // Rewind temp log file.. { if (log>0) log=open(curfolder->logfile, O_CREAT | O_WRONLY | O_APPEND ); { if (folder->flags&FL_LOG_FILE) { if ((folder->flags&FL_LOG_ALWAYS) | (r!=0)) {if (fd>0)da0TusYHG:(!  mgVSQD.'%$ E = 2 %   r [ 3 a Y J E 4  G @ /   ` "se3+('jgTQPIH:87aTf` mH7$phb]81gN7. fclose(f); } syslog((r==0)?LOG_NOTICE:LOG_WARNING, "%s\n", buf); if (fgets(buf, 511, f)!=NULL) { while (!feof(f)) f=fdopen(fd, "r"); openlog(folder->runprg, LOG_PID, LOG_DAEMON); snprintf(buf, 511, "Program %s returned %d, stdout/err follows:\n", folder->runprg, r); lseek(fd, SEEK_SET, 0); // Rewind temp log file.. { if (folder->flags&FL_LOG_SYSLOG) } } unlink(logname); // Kill it! close(log); close(fd); // Close the tempfile } write(log, buf, l); l=read(fd, buf, 512); { while (l>0) l=222222; write(log, buf, strlen(buf)); snprintf(buf, 511, "Program %s returned %d, stdout/err follows:\n", folder->runprg, r); lseek(fd, SEEK_SET, 0); // Rewind temp log file.. { if (log>0) log=open(curfolder->logfile, O_CREAT | O_WRONLY | #endif DEBUG printf("Entering finalize_logfd(fd=%i, r=%d, folder, logname='%s');\n", fd, r, logname);#ifdef DEBUGFILE *f;char buf[512];int log,l;{void finalize_logfd(int fd, int r, Twatchfolder *folder, char *logname)}return(name);*fd=r; } r=mkstemp(name); {if ((folder->flags & (FL_LOG_SYSLOG|FL_LOG_FILE|FL_LOG_MAIL))!=0)char *name=strdup("/tmp/watchdrun.XXXXXX");int r=-1;{char *prepare_logfd(Twatchfolder *folder, int *fd)} return(r); } #endif printf("child died: pid=%d return=%d\n", f, r); #ifdef DEBUG waitpid(f,&r,0); // wait for process to finish.. #endif printf("pid of child=%d\n",f); #ifdef DEBUG { } else exit(0); // Should never occur, but we are paranoid... syslog(LOG_WARNING||LOG_DAEMON,"Could not execute %s",cmd); printf("Something went wrong! Could not execute %s... (%s) ",cmd, strerror(errno)); execvp(cmd,args); #endif printf("Executing %s...\n", cmd); #ifdef DEBUG } #endif printf("ok..\n"); #ifdef DEBUG } syslog(LOG_WARNING||LOG_DAEMON,"Could not setuid(%d): %s", uid, strerror(errno)); #endif printf("failed!\n"); #ifdef DEBUG { if (setuid(uid)!=0) #endif fprintf(stderr, "Doing setuid(%d)...",uid); #ifdef DEBUG { if (uid!=-1) #endif fprintf(stderr,"forked of, uid=%d...\n", uid); #ifdef DEBUG cmd=args[0]; deinit(); args[4]=arg4!=NULL?strdup(arg4):NULL; args[3]=arg3!=NULL?strdup(arg3):NULL; args[2]=arg2!=NULL?strdup(arg2):NULL; args[1]=arg1!=NULL?strdup(arg1):NULL; args[0]=strdup(cmd); args=malloc(sizeof(args)*5); // allocate ram for 4 arguments... } close(logfd); dup2(STDOUT_FILENO , STDERR_FILENO); dup2(logfd, STDOUT_FILENO); { if (logfd>0) if (f==0) { f=fork(); #endif printf("run(cmd=%s,arg1=%s,arg2=%s,arg3=%s,arg4=%s)\n",cmd, arg1, arg2, arg3, arg4); #ifdef DEBUG int r; int f; char **args;{int run(char* cmd, char* arg1, char* arg2, char* arg3, char* arg4, uid_t uid, int logfd)}#endifprintf("deinited\n");#ifdef DEBUG } e=unchain(e); } killfilechain(w->filechain); free(w->dir); free(w->runprg); { if (w!=NULL) w=(Twatchfolder *)e->cur; #endif printf("."); #ifdef DEBUG {while (e!=NULL)#endifprintf("deinit");#ifdef DEBUGTwatchfolder *w;element *e=head(folders);{void deinit()} #endif dumpfolders(); #ifdef DEBUG consolidate(); ini_close(f); } } free(buf); parseequal(buf); daGwwmkj'yxk! w p o M !  k # w H > ; +  h \ $   b 5 2 qmc pn`C;9sk\WUT31&_W  `Lzq2(% } */ //processdir(de->d_name); printf("Found a dir!\n"); syslog(LOG_WARNING||LOG_DAEMON,"sorry, cannot read dirs, currently ",folders[n].dir); {/* } else// processfile(de->d_name,f->dir,f->runprg, f->user); #endif printf("Entering processdir()..."); #ifdef DEBUG// if (isdir(de->d_name)==0) { processfile(de->d_name,f); #endif printf("Processing '%s' (de->d_name).\n ", de->d_name); #ifdef DEBUG if ((strcmp(de->d_name,".")!=0) && (strcmp(de->d_name,"..")!=0)) { // we don't process dirs, yet... { while (de!=NULL) de=readdir(dir); { if (dir!=NULL) tmpS=malloc(1024); if (f->dir!=NULL) dir=opendir(f->dir); else dir=NULL; #endif printf("Processing dir '%s' prg='%s' uid='%d' interval='%d' curcount='%d'...\n", f->dir, f->runprg, f->user, f->interval, f->curcount); #ifdef DEBUG int child; char* tmpS; struct dirent *de; DIR* dir;{void processdir(Twatchfolder *f)} } return(0); #endif printf("0\n"); #ifdef DEBUG free(st); } else { return(1); #endif printf("1\n"); #ifdef DEBUG free(st); if (S_ISDIR(st->st_mode)) { stat(name, st); st=malloc(sizeof(stat)); #endif printf("isdir(%s)=", name); #ifdef DEBUG struct stat *st;{int isdir(char *name)} fflush(stderr); fflush(stdin); fflush(stdout); //printf("flushing...\n"); free(srcfile); free(complete); } syslog(LOG_NOTICE||LOG_DAEMON,"file %s is locked, not processed",file,w.runprg); } else { run(rmprg,"-rf",srcfile, NULL, NULL, w.user, -1); if ((w.flags & FL_ACT_DELETE)!=0) run(rmprg,"-rf",complete, NULL, NULL, w.user, -1); if ((w.flags & FL_ACT_COPY) == FL_ACT_COPY) finalize_logfd(logfd, r, folder, logname); r=run(w.runprg, srcfile, NULL, NULL, NULL, w.user, logfd); logname=prepare_logfd(folder, &logfd); } strcat(srcfile,file); strcat(srcfile,"/"); strcpy(srcfile,complete); } run(rmprg, srcfile, NULL, NULL, NULL, w.user, -1); #endif printf("running rm...\n"); #ifdef DEBUG { if ((w.flags & FL_ACT_DELETE)!=0) run(cpprg,srcfile,complete, NULL, NULL, w.user, -1); #endif printf("running cp...\n"); #ifdef DEBUG #endif printf("created tempdir : %s\n",complete); #ifdef DEBUG mkdir(complete,0700); sprintf(complete, "%s/watchdtmp.%d%d", tmpdir, tp.time, tp.millitm); ftime(&tp); { if ((w.flags & FL_ACT_COPY)!=0) syslog(LOG_NOTICE||LOG_DAEMON,"processing %s with %s",file,w.runprg); if (nolock(srcfile)) { } return(0); free(srcfile); free(complete); // an there is no demand of processing // Happens in case a folder should be watched for changes { if (checkfile(srcfile, 0, w.filechain)!=2)if ((w.flags & FL_ACT_CHANGE)!=0)#endif printf("calling checkfile...\n");#ifdef DEBUG strcat(srcfile,file);strcat(srcfile,"/");strcpy(srcfile,w.dir);srcfile=malloc(1024);complete=malloc(1024);#endif printf("processfile called! (folder=%s, flags=%d\n)\n", w.dir, w.flags);#ifdef DEBUGmemcpy(&w,folder,sizeof(w));int logfd,r;Twatchfolder w;struct timeb tp;char *logname;char *srcfile;char *complete;{int processfile(char *file, Twatchfolder *folder)/ fd=0; #endif close(fd); // Is there a need to kill a file which h fd=0; } #endif printf("Error closing fd=%d!\n",fd); #ifdef DEBUG { if (close(fd)) // Close the tempfiledamXHGML> u q +  d I *   ~ } o _ ^ > ; .  Z E D   ? : 9 ig`_EB,)'& jiMK ]S"wsqPL<PF {kVE // brain-damaged! } // set interval if the value is not completely addfolder(curfolder, NULL, NULL, -1, tmpi, 0); if (tmpi>0) { tmpi=atoi(tmpc3); tmpc3=tmpc2; #endif printf("'interval' line found. Trying to set interval...\n"); #ifdef DEBUG { if (strncmp(tmpc1,"interval",8)==0) } addfolder(curfolder,NULL,NULL, -1, -1, flags2int(tmpc2)); #endif printf("'flags' line found. Modifying program...\n"); #ifdef DEBUG { if (strncmp(tmpc1,"flags",5)==0) } addfolder(curfolder,NULL,NULL,atoi(tmpc2), -1, 0); #endif printf("'uid' line found. Modifying program...\n"); #ifdef DEBUG { if (strncmp(tmpc1,"uid",3)==0) } addfolder(curfolder, tmpc2, NULL, -1, -1, 0); #endif printf("'dir' line found. Adding directory...\n"); #ifdef DEBUG { if (strncmp(tmpc1,"dir",3)==0) } addfolder(curfolder, NULL, tmpc2, -1, -1, 0); #endif printf("'prg' line found. Adding program...\n"); #ifdef DEBUG { if (strncmp(tmpc1,"prg",3)==0) #endif printf("lowercase returned '%s'!\n",tmpc1); #ifdef DEBUG lowercase(tmpc1); // Drop the case on the left side... splits(buf, tmpc1, tmpc2); tmpc2=malloc(strlen(buf)+1); tmpc1=malloc(strlen(buf)+1); int tmpi; // a place to store temorary integers ... char *tmpc3; char *tmpc2; char *tmpc1;{void parseequal(char* buf) } } c[i]=tolower(c[i]); {for (i=0;icurcount=interval; f->interval=interval; { if (interval!=-1) if (flags!=0) f->flags=flags; if (uid!=-1) f->user=uid; if (dir!=NULL) f->dir=strdup(dir); if (prg!=NULL) f->runprg=strdup(prg); } f=curfolder; curfolder->filechain=newchain(); curfolder=(Twatchfolder *)folders->cur; folders=tail(folders); folders=addelement(&defaultfolder, sizeof(defaultfolder), folders); { if (f==NULL){void addfolder(Twatchfolder *f, char *dir, char *prg, uid_t uid, int interval, int flags)} } return(0); #endif printf("split(s='%s',p1='%s',p2='%s',pos1=%d);\n",s,p1,p2,pos1); #ifdef DEBUG while (p1[strlen(p1)-1]==' ') {p1[strlen(p1)-1]=0;} // Need to say anything?;) while (p2[0]==' ') {p2++;} // Again, quick and dirty.. p2[(int)p2tmp-(int)p2]=0x00; // but in fact: It works ;) p2tmp=strchr(p2,0xa); // Not very nice,// free(p2tmp);// strcpy(p2,p2tmp);// strncpy(p2tmp,p2,strlen(p2)-1);// p2tmp=malloc(strlen(p2)); strcpy(p2, equal+1); strncpy(p1, s, pos1+1); { if (pos1==0) return(1); else daF<#r<2 m c K ;    | l K A = 9    l b ^ Z 5 1 ! w m i h Z L J I 8 6 * ( '  z x ^ ] F B 4 YUSR?=#" tnjhg[YL@87 rqo^\vlhtpoa*" Y3. if (strstr(buf,"=")!=NULL) { while ((buf=ini_nextline(f))!=NULL) if (strcasecmp(f->sts.cur_grp,"common")!=0) addfolder(NULL, NULL, NULL, -1, -1, 0); { while ((ini_nextgrp(f)!=-1)) ini_rewind(f); #endif printf("Stage 2 : Read folders..\n"); #ifdef DEBUG #endif else printf("Waring: could't read common options\n"); #ifdef DEBUG } parsecommon(f); { if (i!=-1) i=ini_goto_grp(f, "common"); #endif printf("Stage 1 : Read common options..\n"); #ifdef DEBUG } exit(1); printf("Error: Could not open /etc/watchd.conf (%s) , exiting..\n", strerror(errno)); { if (!f) f=ini_open("/etc/watchd.conf"); buf=malloc(1024); folders=newchain(); defaultfolder.logfile=strdup("/dev/stdout"); defaultfolder.gracetime=timeofgrace; defaultfolder.flags=(FL_ACT_EXISTENCE | FL_ACT_COPY | FL_ACT_DELETE); timeofgrace=30; strcpy(cpprg,"/bin/cp"); cpprg=malloc(1024); strcpy(rmprg,"/bin/rm"); rmprg=malloc(1024); strcpy(mvprg,"/bin/mv"); mvprg=malloc(1024); strcpy(tmpdir,"/tmp/"); tmpdir=malloc(1024); int i; char *buf; inifile *f;{void init()} } } c=head(folders); folders=unchain(c); { if (((Twatchfolder *)c->cur)->dir==NULL) curfolder=(Twatchfolder *)c->cur; c=c->next; {while (c->next!=NULL)element *c=head(folders);{void consolidate()} } printf("Will watch dir '%s' for files and run '%s' on them with uid='%d' flags: %d\n",curfolder->dir, curfolder->runprg, curfolder->user, curfolder->flags); if (c->cur!=NULL) curfolder=(Twatchfolder *)c->cur; c=c->next; { while (c->next!=NULL)element *c=head(folders);{void dumpfolders()} } free(s); parseequal(s); if (strchr(s, '=')!=NULL) { while ((s=ini_nextline(i))!=NULL) char *s=NULL;{void parsecommon(inifile *i)}// FOO BAR {void defraglst()} free(tmpc2); free(tmpc1); } #endif printf("set to %s!\n",curfolder->logfile); #ifdef DEBUG curfolder->logfile=strdup(tmpc2); #endif printf("'logfile' line found. Trying to set logfile..."); #ifdef DEBUG { if (strncmp(tmpc1,"logfile",7)==0) } #endif printf("set to %s!\n",cpprg); #ifdef DEBUG curfolder->notify=strdup(tmpc2); #endif printf("'mail' line found. Trying to set mvprg..."); #ifdef DEBUG { if (strncmp(tmpc1,"mail",4)==0) } #endif printf("set to %s!\n",cpprg); #ifdef DEBUG strcpy(cpprg,tmpc2); #endif printf("'cp' line found. Trying to set mvprg..."); #ifdef DEBUG { if (strncmp(tmpc1,"cp",2)==0) } #endif printf("set to %s!\n",rmprg); #ifdef DEBUG strcpy(rmprg,tmpc2); #endif printf("'rm' line found. Trying to set mvprg..."); #ifdef DEBUG { if (strncmp(tmpc1,"rm",2)==0) } #endif printf("set to %s!\n",mvprg); #ifdef DEBUG strcpy(mvprg,tmpc2); #endif printf("'mv' line found. Trying to set mvprg..."); #ifdef DEBUG { if (strncmp(tmpc1,"mv",2)==0) } #endif printf("set to %s!\n",tmpdir); #ifdef DEBUG if (tmpdir[strlen(tmpdir)-1]!='/') {strcat(tmpdir,"/");} strcpy(tmpdir,tmpc2); #endif printf("'tempdir' line found. Trying to set tempdir..."); #ifdef DEBUG { if (strncmp(tmpc1,"tempdir",7)==0) } #endif printf("set to %d!\n",interval); #ifdef DEBUGda}h64$b[ZC-, b _ " d a ? ; ,  | l M C  e _ B *  v s E  QN=-|z`O1$trgSF:8*aM<8$ TF#sif } */ //processdir(de->d_name); printf("Found a dir!\n"); syslog(LOG_WARNING||LOG_DAEMON,"sorry, cannot read dirs, currently ",folders[n].dir); {/* } else// processfile(de->d_name,f->dir,f->runprg, f->user); #endif printf("Entering processdir()..."); #ifdef DEBUG// if (isdir(de->d_name)==0) { processfile(de->d_name,f); #endif printf("Processing '%s' (de->d_name).\n ", de->d_name); #ifdef DEBUG if ((strcmp(de->d_name,".")!=0) && (strcmp(de->d_name,"..")!=0)) { // we don't process dirs, yet... { while (de!=NULL) de=readdir(dir); { if (dir!=NULL) tmpS=malloc(1024); if (f->dir!=NULL) dir=opendir(f->dir); else dir=NULL; #endif printf("Processing dir '%s' prg='%s' uid='%d' interval='%d' curcount='%d'...\n", f->dir, f->runprg, f->user, f->interval, f->curcount); #ifdef DEBUG int child; char* tmpS; struct dirent *de; DIR* dir;{void processdir(Twatchfolder *f)} } return(0); #endif printf("0\n"); #ifdef DEBUG free(st); } else { return(1); #endif printf("1\n"); #ifdef DEBUG free(st); if (S_ISDIR(st->st_mode)) { stat(name, st); st=malloc(sizeof(stat)); #endif printf("isdir(%s)=", name); #ifdef DEBUG struct stat *st;{int isdir(char *name)} fflush(stderr); fflush(stdin); fflush(stdout); //printf("flushing...\n"); free(srcfile); free(complete); } syslog(LOG_NOTICE||LOG_DAEMON,"file %s is locked, not processed",file,w.runprg); } else { run(rmprg,"-rf",srcfile, NULL, NULL, w.user, -1); if ((w.flags & FL_ACT_DELETE)!=0) run(rmprg,"-rf",complete, NULL, NULL, w.user, -1); if ((w.flags & FL_ACT_COPY) == FL_ACT_COPY) finalize_logfd(logfd, r, folder, logname); r=run(w.runprg, srcfile, NULL, NULL, NULL, w.user, logfd); logname=prepare_logfd(folder, &logfd); } strcat(srcfile,file); strcat(srcfile,"/"); strcpy(srcfile,complete); } run(rmprg, srcfile, NULL, NULL, NULL, w.user, -1); #endif printf("running rm...\n"); #ifdef DEBUG { if ((w.flags & FL_ACT_DELETE)!=0) run(cpprg,srcfile,complete, NULL, NULL, w.user, -1); #endif printf("running cp...\n"); #ifdef DEBUG #endif printf("created tempdir : %s\n",complete); #ifdef DEBUG mkdir(complete,0700); sprintf(complete, "%s/watchdtmp.%d%d", tmpdir, tp.time, tp.millitm); ftime(&tp); { if ((w.flags & FL_ACT_COPY)!=0) syslog(LOG_NOTICE||LOG_DAEMON,"processing %s with %s",file,w.runprg); if (nolock(srcfile)) { } return(0); free(srcfile); free(complete); // an there is no demand of processing // Happens in case a folder should be watched for changes { if (checkfile(srcfile, 0, w.filechain)!=2)if ((w.flags & FL_ACT_CHANGE)!=0)#endif printf("calling checkfile...\n");#ifdef DEBUG strcat(srcfile,file);strcat(srcfile,"/");strcpy(srcfile,w.dir);srcfile=malloc(1024);complete=malloc(1024);#endif printf("processfile called! (folder=%s, flags=%d\n)\n", w.dir, w.flags);#ifdef DEBUGmemcpy(&w,folder,sizeof(w));int logfd,r;Twatchfolder w;struct timeb tp;char *logname;char *srcfile;char *complete;{int processfile(char *file, Twatchfolder *folder)//void processfile(ch close(fd); // Is there a need to kill a file which has no name... Strange... close(fd); if (fd!=0) } }dafdTE6%s]\E0 R )   o k \   } s ; 7  r Z A < 9  u ? < ~m]A0   aTF4,vjhZ}lhT@:vS.7 } */ //processdir(de->d_name); printf("Found a dir!\n"); syslog(LOG_WARNING||LOG_DAEMON,"sorry, cannot read dirs, currently ",folders[n].dir); {/* } else// processfile(de->d_name,f->dir,f->runprg, f->user); #endif printf("Entering processdir()..."); #ifdef DEBUG// if (isdir(de->d_name)==0) { processfile(de->d_name,f); #endif printf("Processing '%s' (de->d_name).\n ", de->d_name); #ifdef DEBUG if ((strcmp(de->d_name,".")!=0) && (strcmp(de->d_name,"..")!=0)) { // we don't process dirs, yet... { while (de!=NULL) de=readdir(dir); { if (dir!=NULL) tmpS=malloc(1024); if (f->dir!=NULL) dir=opendir(f->dir); else dir=NULL; #endif printf("Processing dir '%s' prg='%s' uid='%d' interval='%d' curcount='%d'...\n", f->dir, f->runprg, f->user, f->interval, f->curcount); #ifdef DEBUG int child; char* tmpS; struct dirent *de; DIR* dir;{void processdir(Twatchfolder *f)} } return(0); #endif printf("0\n"); #ifdef DEBUG free(st); } else { return(1); #endif printf("1\n"); #ifdef DEBUG free(st); if (S_ISDIR(st->st_mode)) { stat(name, st); st=malloc(sizeof(stat)); #endif printf("isdir(%s)=", name); #ifdef DEBUG struct stat *st;{int isdir(char *name)} fflush(stderr); fflush(stdin); fflush(stdout); //printf("flushing...\n"); free(srcfile); free(complete); } syslog(LOG_NOTICE||LOG_DAEMON,"file %s is locked, not processed",file,w.runprg); } else { run(rmprg,"-rf",srcfile, NULL, NULL, w.user, -1); if ((w.flags & FL_ACT_DELETE)!=0) run(rmprg,"-rf",complete, NULL, NULL, w.user, -1); if ((w.flags & FL_ACT_COPY) == FL_ACT_COPY) finalize_logfd(logfd, r, folder, logname); r=run(w.runprg, srcfile, NULL, NULL, NULL, w.user, logfd); logname=prepare_logfd(folder, &logfd); } strcat(srcfile,file); strcat(srcfile,"/"); strcpy(srcfile,complete); } run(rmprg, srcfile, NULL, NULL, NULL, w.user, -1); #endif printf("running rm...\n"); #ifdef DEBUG { if ((w.flags & FL_ACT_DELETE)!=0) run(cpprg,srcfile,complete, NULL, NULL, w.user, -1); #endif printf("running cp...\n"); #ifdef DEBUG #endif printf("created tempdir : %s\n",complete); #ifdef DEBUG mkdir(complete,0700); sprintf(complete, "%s/watchdtmp.%d%d", tmpdir, tp.time, tp.millitm); ftime(&tp); { if ((w.flags & FL_ACT_COPY)!=0) syslog(LOG_NOTICE||LOG_DAEMON,"processing %s with %s",file,w.runprg); if (nolock(srcfile)) { } return(0); free(srcfile); free(complete); // an there is no demand of processing // Happens in case a folder should be watched for changes { if (checkfile(srcfile, 0, w.filechain)!=2)if ((w.flags & FL_ACT_CHANGE)!=0)#endif printf("calling checkfile...\n");#ifdef DEBUG strcat(srcfile,file);strcat(srcfile,"/");strcpy(srcfile,w.dir);srcfile=malloc(1024);complete=malloc(1024);#endif printf("processfile called! (folder=%s, flags=%d\n)\n", w.dir, w.flags);#ifdef DEBUGmemcpy(&w,folder,sizeof(w));int logfd,r;Twatchfolder w;struct timeb tp;char *logname;char *srcfile;char *complete;{int processfile(char *file, Twatchfolder *folder)//void processfile(char *file, char *srcdir, char *cmd, uid_t uid)} } unlink(logname); // Kill it!da !ri2  vtXJ strcpy(p2,""); strcpy(p1,""); // null-terminate a substring by itself! s[pos1]=0x00; // Needed, because strncpy is too stupid to int pos1 = (((equal==NULL)||(equal