Annotation of researchv10no/cmd/asd++/locksubs.c, revision 1.1.1.1

1.1       root        1: #include "decl.h"
                      2: #include <signal.h>
                      3: 
                      4: static lockcount = 0;
                      5: static SIG_TYP intsav, quitsav, hupsav, pipesave, termsav;
                      6: 
                      7: void
                      8: lock (Path& dir)
                      9: {
                     10:        Path com = dir & "L." + String(dec(getpid()));
                     11:        int snooze = 0;
                     12: 
                     13:        if (lockcount++ == 0) {
                     14:                intsav = signal (SIGINT, SIG_IGN);
                     15:                quitsav = signal (SIGQUIT, SIG_IGN);
                     16:                hupsav = signal (SIGHUP, SIG_IGN);
                     17:                pipesave = signal (SIGPIPE, SIG_IGN);
                     18:                termsav = signal (SIGTERM, SIG_IGN);
                     19:        }
                     20: 
                     21:        int fd;
                     22:        if ((fd = creat (com, 0)) < 0) {
                     23:                cout << "cannot create lock file " << com << "\n";
                     24:                exit (1);
                     25:        }
                     26:        close (fd);
                     27: 
                     28:        while (link (com, dir & "lock") < 0)
                     29:                sleep (snooze++);
                     30: }
                     31: 
                     32: void
                     33: unlock (Path& dir)
                     34: {
                     35:        unlink (dir & "L." + String(dec(getpid())));
                     36:        unlink (dir & "lock");
                     37: 
                     38:        if (--lockcount == 0) {
                     39:                signal (SIGINT, intsav);
                     40:                signal (SIGQUIT, quitsav);
                     41:                signal (SIGHUP, hupsav);
                     42:                signal (SIGPIPE, pipesave);
                     43:                signal (SIGTERM, termsav);
                     44:        }
                     45: }

unix.superglobalmegacorp.com

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