Annotation of sbbs/sbbs3/semfile.c, revision 1.1

1.1     ! root        1: /* semfile.c */
        !             2: 
        !             3: /* $Id: semfile.c,v 1.6 2004/12/24 07:50:10 rswindell Exp $ */
        !             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:  *                                                                                                                                                     *
        !             9:  * Copyright 2004 Rob Swindell - http://www.synchro.net/copyright.html         *
        !            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 "sbbs.h"
        !            37: 
        !            38: /****************************************************************************/
        !            39: /* This function compares a single semaphore file's                                                    */
        !            40: /* date/time stamp (if the file exists) against the passed time stamp (t)      */
        !            41: /* updating the time stamp to the latest dated semaphore file and returning    */
        !            42: /* TRUE if any where newer than the initial value.                                                     */
        !            43: /****************************************************************************/
        !            44: BOOL DLLCALL semfile_check(time_t* t, const char* fname)
        !            45: {
        !            46:        time_t  ft;
        !            47: 
        !            48:        if(*t==0)       /* uninitialized */
        !            49:                *t=time(NULL);
        !            50: 
        !            51:        if((ft=fdate(fname))==-1 || ft<=*t)
        !            52:                return(FALSE);
        !            53: 
        !            54:        *t=ft;
        !            55:        return(TRUE);
        !            56: }
        !            57: 
        !            58: /****************************************************************************/
        !            59: /* This function goes through a list of semaphore files, comparing the file    */
        !            60: /* date/time stamp (if the file exists) against the passed time stamp (t)      */
        !            61: /* updating the time stamp to the latest dated semaphore file and returning    */
        !            62: /* a pointer to the filename if any where newer than the initial timestamp.    */
        !            63: /****************************************************************************/
        !            64: char* DLLCALL semfile_list_check(time_t* t, link_list_t* filelist)
        !            65: {
        !            66:        char*   signaled=NULL;
        !            67:        list_node_t* node;
        !            68: 
        !            69:        for(node=listFirstNode(filelist);node!=NULL;node=listNextNode(node))
        !            70:                if(semfile_check(t, node->data))
        !            71:                        signaled = node->data;
        !            72: 
        !            73:        return(signaled);
        !            74: }
        !            75: 
        !            76: void DLLCALL semfile_list_init(link_list_t* filelist, const char* parent, 
        !            77:                                                           const char* action, const char* service)
        !            78: {
        !            79:        char    path[MAX_PATH+1];
        !            80:        char    hostname[128];
        !            81:        char*   p;
        !            82: 
        !            83:        listInit(filelist,0);
        !            84:        SAFEPRINTF2(path,"%s%s",parent,action);
        !            85:        listPushNodeString(filelist,path);
        !            86:        SAFEPRINTF3(path,"%s%s.%s",parent,action,service);
        !            87:        listPushNodeString(filelist,path);
        !            88:        if(gethostname(hostname,sizeof(hostname))==0) {
        !            89:                SAFEPRINTF3(path,"%s%s.%s",parent,action,hostname);
        !            90:                listPushNodeString(filelist,path);
        !            91:                SAFEPRINTF4(path,"%s%s.%s.%s",parent,action,hostname,service);
        !            92:                listPushNodeString(filelist,path);
        !            93:                if((p=strchr(hostname,'.'))!=NULL) {
        !            94:                        *p=0;
        !            95:                        SAFEPRINTF3(path,"%s%s.%s",parent,action,hostname);
        !            96:                        listPushNodeString(filelist,path);
        !            97:                        SAFEPRINTF4(path,"%s%s.%s.%s",parent,action,hostname,service);
        !            98:                        listPushNodeString(filelist,path);
        !            99:                }
        !           100:        }
        !           101: }
        !           102: 
        !           103: void DLLCALL semfile_list_add(link_list_t* filelist, const char* path)
        !           104: {
        !           105:        listPushNodeString(filelist, path);
        !           106: }
        !           107: 
        !           108: void DLLCALL semfile_list_free(link_list_t* filelist)
        !           109: {
        !           110:        listFree(filelist);
        !           111: }
        !           112: 
        !           113: BOOL DLLCALL semfile_signal(const char* fname, const char* text)
        !           114: {
        !           115:        int file;
        !           116:        char hostname[128];
        !           117: 
        !           118:        if((file=nopen(fname,O_CREAT|O_WRONLY))<0)
        !           119:                return(FALSE);
        !           120:        if(text==NULL && gethostname(hostname,sizeof(hostname))==0)
        !           121:                text=hostname;
        !           122:        if(text!=NULL)
        !           123:                write(file,text,strlen(text));
        !           124:        close(file);
        !           125:        return(TRUE);
        !           126: }

unix.superglobalmegacorp.com

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