Annotation of sbbs/src/xpdev/semfile.c, revision 1.1.1.2

1.1       root        1: /* semfile.c */
                      2: 
1.1.1.2 ! root        3: /* $Id: semfile.c,v 1.5 2008/11/03 05:52:02 rswindell Exp $ */
1.1       root        4: 
                      5: /****************************************************************************
                      6:  * @format.tab-size 4          (Plain Text/Source Code File Header)                    *
                      7:  * @format.use-tabs true       (see http://www.synchro.net/ptsc_hdr.html)              *
                      8:  *                                                                                                                                                     *
1.1.1.2 ! root        9:  * Copyright 2007 Rob Swindell - http://www.synchro.net/copyright.html         *
1.1       root       10:  *                                                                                                                                                     *
                     11:  * This program is free software; you can redistribute it and/or                       *
                     12:  * modify it under the terms of the GNU General Public License                         *
                     13:  * as published by the Free Software Foundation; either version 2                      *
                     14:  * of the License, or (at your option) any later version.                                      *
                     15:  * See the GNU General Public License for more details: gpl.txt or                     *
                     16:  * http://www.fsf.org/copyleft/gpl.html                                                                                *
                     17:  *                                                                                                                                                     *
                     18:  * Anonymous FTP access to the most recent released source is available at     *
                     19:  * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net     *
                     20:  *                                                                                                                                                     *
                     21:  * Anonymous CVS access to the development source and modification history     *
                     22:  * is available at cvs.synchro.net:/cvsroot/sbbs, example:                                     *
                     23:  * cvs -d :pserver:[email protected]:/cvsroot/sbbs login                       *
                     24:  *     (just hit return, no password is necessary)                                                     *
                     25:  * cvs -d :pserver:[email protected]:/cvsroot/sbbs checkout src                *
                     26:  *                                                                                                                                                     *
                     27:  * For Synchronet coding style and modification guidelines, see                                *
                     28:  * http://www.synchro.net/source.html                                                                          *
                     29:  *                                                                                                                                                     *
                     30:  * You are encouraged to submit any modifications (preferably in Unix diff     *
                     31:  * format) via e-mail to [email protected]                                                                      *
                     32:  *                                                                                                                                                     *
                     33:  * Note: If this box doesn't appear square, then you need to fix your tabs.    *
                     34:  ****************************************************************************/
                     35: 
                     36: #include <string.h>
                     37: 
                     38: #include "semfile.h"
                     39: #include "filewrap.h"
                     40: #include "dirwrap.h"
                     41: #include "genwrap.h"
                     42: 
                     43: #if !defined(NO_SOCKET_SUPPORT)
                     44:        #include "sockwrap.h"
                     45: #endif
                     46: 
                     47: /****************************************************************************/
                     48: /* This function compares a single semaphore file's                                                    */
                     49: /* date/time stamp (if the file exists) against the passed time stamp (t)      */
                     50: /* updating the time stamp to the latest dated semaphore file and returning    */
                     51: /* TRUE if any where newer than the initial value.                                                     */
                     52: /****************************************************************************/
                     53: BOOL DLLCALL semfile_check(time_t* t, const char* fname)
                     54: {
                     55:        time_t  ft;
                     56: 
                     57:        if(*t==0)       /* uninitialized */
                     58:                *t=time(NULL);
                     59: 
                     60:        if((ft=fdate(fname))==-1 || ft<=*t)
                     61:                return(FALSE);
                     62: 
                     63:        *t=ft;
                     64:        return(TRUE);
                     65: }
                     66: 
                     67: /****************************************************************************/
                     68: /* This function goes through a list of semaphore files, comparing the file    */
                     69: /* date/time stamp (if the file exists) against the passed time stamp (t)      */
                     70: /* updating the time stamp to the latest dated semaphore file and returning    */
                     71: /* a pointer to the filename if any where newer than the initial timestamp.    */
                     72: /****************************************************************************/
                     73: char* DLLCALL semfile_list_check(time_t* t, str_list_t filelist)
                     74: {
                     75:        char*   signaled=NULL;
                     76:        size_t          i;
                     77: 
                     78:        for(i=0;filelist[i]!=NULL;i++)
                     79:                if(semfile_check(t, filelist[i]))
                     80:                        signaled = filelist[i];
                     81: 
                     82:        return(signaled);
                     83: }
                     84: 
                     85: str_list_t DLLCALL semfile_list_init(const char* parent, 
                     86:                                                           const char* action, const char* service)
                     87: {
                     88:        char    path[MAX_PATH+1];
                     89:        char    hostname[128];
                     90:        char*   p;
                     91:        str_list_t      list;
                     92: 
                     93:        if((list=strListInit())==NULL)
                     94:                return(NULL);
                     95:        SAFEPRINTF2(path,"%s%s",parent,action);
                     96:        strListPush(&list,path);
                     97:        SAFEPRINTF3(path,"%s%s.%s",parent,action,service);
                     98:        strListPush(&list,path);
                     99:        if(gethostname(hostname,sizeof(hostname))==0) {
                    100:                SAFEPRINTF3(path,"%s%s.%s",parent,action,hostname);
                    101:                strListPush(&list,path);
                    102:                SAFEPRINTF4(path,"%s%s.%s.%s",parent,action,hostname,service);
                    103:                strListPush(&list,path);
                    104:                if((p=strchr(hostname,'.'))!=NULL) {
                    105:                        *p=0;
                    106:                        SAFEPRINTF3(path,"%s%s.%s",parent,action,hostname);
                    107:                        strListPush(&list,path);
                    108:                        SAFEPRINTF4(path,"%s%s.%s.%s",parent,action,hostname,service);
                    109:                        strListPush(&list,path);
                    110:                }
                    111:        }
                    112: 
                    113:        return(list);
                    114: }
                    115: 
                    116: void DLLCALL semfile_list_add(str_list_t* filelist, const char* path)
                    117: {
                    118:        strListPush(filelist, path);
                    119: }
                    120: 
                    121: void DLLCALL semfile_list_free(str_list_t* filelist)
                    122: {
                    123:        strListFree(filelist);
                    124: }
                    125: 
                    126: BOOL DLLCALL semfile_signal(const char* fname, const char* text)
                    127: {
                    128:        int file;
1.1.1.2 ! root      129:        struct utimbuf ut;
1.1       root      130: #if !defined(NO_SOCKET_SUPPORT)
                    131:        char hostname[128];
                    132: 
                    133:        if(text==NULL && gethostname(hostname,sizeof(hostname))==0)
                    134:                text=hostname;
                    135: #endif
1.1.1.2 ! root      136:        if((file=open(fname,O_CREAT|O_WRONLY,S_IREAD|S_IWRITE))<0)      /* use sopen instead? */
1.1       root      137:                return(FALSE);
                    138:        if(text!=NULL)
                    139:                write(file,text,strlen(text));
                    140:        close(file);
1.1.1.2 ! root      141: 
        !           142:        /* update the time stamp */
        !           143:        ut.actime = ut.modtime = time(NULL);
        !           144:        return utime(fname, &ut)==0;
1.1       root      145: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.