1 /* |
1 /* |
2 * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
490 System.err.println("Lock file name is not specified"); |
490 System.err.println("Lock file name is not specified"); |
491 System.exit(7); |
491 System.exit(7); |
492 } |
492 } |
493 |
493 |
494 String theLockFileName = args[0]; |
494 String theLockFileName = args[0]; |
|
495 Path path = Paths.get(theLockFileName); |
495 |
496 |
496 try { |
497 try { |
497 Path path = Paths.get(theLockFileName); |
|
498 |
|
499 while (Files.exists(path)) { |
498 while (Files.exists(path)) { |
500 // Touch the lock to indicate our readiness |
499 // Touch the lock to indicate our readiness |
501 setLastModified(theLockFileName, epoch()); |
500 setLastModified(theLockFileName, epoch()); |
502 Thread.sleep(spinDelay); |
501 Thread.sleep(spinDelay); |
503 } |
502 } |
504 } catch (NoSuchFileException ex) { |
503 } catch (IOException ex) { |
505 // Lock deleted while we are setting last modified time. |
504 // Lock deleted while we are setting last modified time. |
506 // Ignore error and lets the app exits |
505 // Ignore the error and let the app exit. |
|
506 if (Files.exists(path)) { |
|
507 // If the lock file was not removed, return an error. |
|
508 System.err.println("LingeredApp IOException: lock file still exists"); |
|
509 System.exit(4); |
|
510 } |
507 } catch (Exception ex) { |
511 } catch (Exception ex) { |
508 System.err.println("LingeredApp ERROR: " + ex); |
512 System.err.println("LingeredApp ERROR: " + ex); |
509 // Leave exit_code = 1 to Java launcher |
513 // Leave exit_code = 1 to Java launcher |
510 System.exit(3); |
514 System.exit(3); |
511 } |
515 } |