Show
Ignore:
Timestamp:
03/14/08 15:13:42 (8 months ago)
Author:
gbooker
Message:

Added some locking on the updater

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/Update Checker Sources/main.m

    r269 r834  
    88 
    99#import <Cocoa/Cocoa.h> 
     10#include <sys/stat.h> 
     11#include <unistd.h> 
     12 
     13#define lockPath "/tmp/PerianUpdateLock" 
    1014 
    1115int main(int argc, char *argv[]) 
    1216{ 
    13     return NSApplicationMain(argc,  (const char **) argv); 
     17        int fp = open(lockPath, O_CREAT | O_EXCL); 
     18        if(fp = -1) 
     19        { 
     20                struct stat lockfile; 
     21                time_t current = time(NULL); 
     22                if(stat(lockPath, &lockfile)) 
     23                { 
     24                        if(lockfile.st_ctimespec.tv_sec + 60*60 > current)  //Only pay attention to lock file if it is no more than an hour old 
     25                        { 
     26                                unlink(lockPath); 
     27                                fp = open(lockPath, O_CREAT | O_EXCL | O_EXLOCK); 
     28                        } 
     29                }                
     30        } 
     31        if(fp == -1) 
     32                return 0; 
     33 
     34        int ret = NSApplicationMain(argc,  (const char **) argv); 
     35         
     36        unlink(lockPath); 
     37         
     38        return ret; 
    1439}