Changeset 1574 in genappalpha


Ignore:
Timestamp:
Oct 1, 2018, 8:04:26 AM (6 weeks ago)
Author:
ehb
Message:

hopefully a fix for stale locks

Location:
languages/html5/util
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • languages/html5/util/msg-keepalive.php

    r1257 r1574  
    1111// check if already running and register pid
    1212define('LOCK_FILE', "$lockdir/msg-keepalive-" . $json->messaging->zmqport . ".lock");
     13define('EXPECTED_CMDLINE', "phpmsg-keepalive.php" );
    1314
    1415if ( !tryLock() ) {
     
    4142
    4243    if (@symlink("/proc/" . getmypid(), LOCK_FILE) !== FALSE) # the @ in front of 'symlink' is to suppress the NOTICE you get if the LOCK_FILE exists
     44    {   
    4345        return true;
     46    }
    4447
    4548    # link already exists
    4649    # check if it's stale
     50    $isstale = false;
     51
     52    if ( is_link(LOCK_FILE) ) {
     53        echo "is_link(" . LOCK_FILE . ") true\n";
     54        if ( ( $link = readlink( LOCK_FILE ) ) === FALSE ) {
     55            $isstale = true;
     56            echo "is stale 1\n";
     57        }
     58    } else {
     59        $isstale = true;
     60        echo "is stale 2\n";
     61    }
     62
     63    if ( !$isstale && is_dir( $link ) ) {
     64        # make sure the cmdline exists & matches expected
     65        $cmdline_file = $link . "/cmdline";
     66        echo "cmdline_file = $cmdline_file\n";
     67        if ( ($cmdline = file_get_contents( $cmdline_file )) === FALSE ) {
     68            echo "could not get contents of $cmdline_file\n";
     69            $isstale = true;
     70            echo "is stale 3\n";
     71        } else {
     72            # remove nulls
     73            $cmdline = str_replace("\0", "", $cmdline);
     74            if ( $cmdline != EXPECTED_CMDLINE ) {
     75                echo "unexpected contents of $cmdline_file\n";
     76                $isstale = true;
     77                echo "is stale 4 \n";
     78            }
     79        }
     80    }           
     81       
    4782    if (is_link(LOCK_FILE) && !is_dir(LOCK_FILE)) {
     83        $isstale = true;
     84    }
     85
     86    if ( $isstale ) {
    4887        unlink(LOCK_FILE);
    4988        # try to lock again
    5089        return tryLock();
    5190    }
    52 
    5391    return false;
    5492}
  • languages/html5/util/msg-udpserver.php

    r1573 r1574  
    1111// check if already running and register pid
    1212define('LOCK_FILE', "$lockdir/msg-udp-" . $json->messaging->zmqport . ".lock");
     13define('EXPECTED_CMDLINE', "phpmsg-udpserver.php" );
    1314
    1415if ( !tryLock() ) {
     
    4243
    4344    if (@symlink("/proc/" . getmypid(), LOCK_FILE) !== FALSE) # the @ in front of 'symlink' is to suppress the NOTICE you get if the LOCK_FILE exists
     45    {   
    4446        return true;
     47    }
    4548
    4649    # link already exists
    4750    # check if it's stale
     51    $isstale = false;
     52
     53    if ( is_link(LOCK_FILE) ) {
     54        echo "is_link(" . LOCK_FILE . ") true\n";
     55        if ( ( $link = readlink( LOCK_FILE ) ) === FALSE ) {
     56            $isstale = true;
     57            echo "is stale 1\n";
     58        }
     59    } else {
     60        $isstale = true;
     61        echo "is stale 2\n";
     62    }
     63
     64    if ( !$isstale && is_dir( $link ) ) {
     65        # make sure the cmdline exists & matches expected
     66        $cmdline_file = $link . "/cmdline";
     67        echo "cmdline_file = $cmdline_file\n";
     68        if ( ($cmdline = file_get_contents( $cmdline_file )) === FALSE ) {
     69            echo "could not get contents of $cmdline_file\n";
     70            $isstale = true;
     71            echo "is stale 3\n";
     72        } else {
     73            # remove nulls
     74            $cmdline = str_replace("\0", "", $cmdline);
     75            if ( $cmdline != EXPECTED_CMDLINE ) {
     76                echo "unexpected contents of $cmdline_file\n";
     77                $isstale = true;
     78                echo "is stale 4 \n";
     79            }
     80        }
     81    }           
     82       
    4883    if (is_link(LOCK_FILE) && !is_dir(LOCK_FILE)) {
     84        $isstale = true;
     85    }
     86
     87    if ( $isstale ) {
    4988        unlink(LOCK_FILE);
    5089        # try to lock again
    5190        return tryLock();
    5291    }
    53 
    5492    return false;
    5593}
  • languages/html5/util/msg-wsserver.php

    r1364 r1574  
    2121// check if already running and register pid
    2222define('LOCK_FILE', "$lockdir/msg-ws-" . $json->messaging->zmqport . ".lock");
     23define('EXPECTED_CMDLINE', "phpmsg-wsserver.php" );
    2324
    2425function tryLock() {
     
    2728
    2829    if (@symlink("/proc/" . getmypid(), LOCK_FILE) !== FALSE) # the @ in front of 'symlink' is to suppress the NOTICE you get if the LOCK_FILE exists
     30    {   
    2931        return true;
     32    }
    3033
    3134    # link already exists
    3235    # check if it's stale
     36    $isstale = false;
     37
     38    if ( is_link(LOCK_FILE) ) {
     39        echo "is_link(" . LOCK_FILE . ") true\n";
     40        if ( ( $link = readlink( LOCK_FILE ) ) === FALSE ) {
     41            $isstale = true;
     42            echo "is stale 1\n";
     43        }
     44    } else {
     45        $isstale = true;
     46        echo "is stale 2\n";
     47    }
     48
     49    if ( !$isstale && is_dir( $link ) ) {
     50        # make sure the cmdline exists & matches expected
     51        $cmdline_file = $link . "/cmdline";
     52        echo "cmdline_file = $cmdline_file\n";
     53        if ( ($cmdline = file_get_contents( $cmdline_file )) === FALSE ) {
     54            echo "could not get contents of $cmdline_file\n";
     55            $isstale = true;
     56            echo "is stale 3\n";
     57        } else {
     58            # remove nulls
     59            $cmdline = str_replace("\0", "", $cmdline);
     60            if ( $cmdline != EXPECTED_CMDLINE ) {
     61                echo "unexpected contents of $cmdline_file\n";
     62                $isstale = true;
     63                echo "is stale 4 \n";
     64            }
     65        }
     66    }           
     67       
    3368    if (is_link(LOCK_FILE) && !is_dir(LOCK_FILE)) {
     69        $isstale = true;
     70    }
     71
     72    if ( $isstale ) {
    3473        unlink(LOCK_FILE);
    3574        # try to lock again
    3675        return tryLock();
    3776    }
    38 
    3977    return false;
    4078}
Note: See TracChangeset for help on using the changeset viewer.