Lines 282-287
Link Here
|
282 |
static final class Status { |
282 |
static final class Status { |
283 |
public static final int CANNOT_CONNECT = -255; |
283 |
public static final int CANNOT_CONNECT = -255; |
284 |
public static final int CANNOT_WRITE = -254; |
284 |
public static final int CANNOT_WRITE = -254; |
|
|
285 |
public static final int ALREADY_RUNNING = -253; |
285 |
|
286 |
|
286 |
private final File lockFile; |
287 |
private final File lockFile; |
287 |
private final int port; |
288 |
private final int port; |
Lines 608-684
Link Here
|
608 |
|
609 |
|
609 |
final RandomAccessFile os = raf; |
610 |
final RandomAccessFile os = raf; |
610 |
raf.seek(0L); |
611 |
raf.seek(0L); |
611 |
|
612 |
|
612 |
server = new Server(new FileAndLock(os, lock), arr, block, handlers, failOnUnknownOptions); |
613 |
int p; |
613 |
int p = server.getLocalPort(); |
614 |
if ("false".equals(System.getProperty("org.netbeans.CLIHandler.server"))) { // NOI18N |
|
|
615 |
server = null; |
616 |
p = 0; |
617 |
} else { |
618 |
server = new Server(new FileAndLock(os, lock), arr, block, handlers, failOnUnknownOptions); |
619 |
p = server.getLocalPort(); |
620 |
} |
614 |
os.writeInt(p); |
621 |
os.writeInt(p); |
615 |
os.getChannel().force(true); |
622 |
os.getChannel().force(true); |
616 |
|
623 |
|
617 |
enterState(20, block); |
624 |
enterState(20, block); |
618 |
|
625 |
|
619 |
Task parael = secureCLIPort.post(new Runnable() { // NOI18N |
626 |
Task parael; |
620 |
@Override |
627 |
if (server != null) { |
621 |
public void run() { |
628 |
parael = secureCLIPort.post(new Runnable() { // NOI18N |
622 |
SecureRandom random = null; |
629 |
@Override |
623 |
enterState(95, block); |
630 |
public void run() { |
624 |
try { |
631 |
SecureRandom random = null; |
625 |
random = SecureRandom.getInstance("SHA1PRNG"); // NOI18N |
632 |
enterState(95, block); |
626 |
} catch (NoSuchAlgorithmException e) { |
|
|
627 |
// #36966: IBM JDK doesn't have it. |
628 |
try { |
633 |
try { |
629 |
random = SecureRandom.getInstance("IBMSecureRandom"); // NOI18N |
634 |
random = SecureRandom.getInstance("SHA1PRNG"); // NOI18N |
630 |
} catch (NoSuchAlgorithmException e2) { |
635 |
} catch (NoSuchAlgorithmException e) { |
631 |
// OK, disable server... |
636 |
// #36966: IBM JDK doesn't have it. |
632 |
server.stopServer(); |
637 |
try { |
|
|
638 |
random = SecureRandom.getInstance("IBMSecureRandom"); // NOI18N |
639 |
} catch (NoSuchAlgorithmException e2) { |
640 |
// OK, disable server... |
641 |
server.stopServer(); |
642 |
} |
643 |
} |
644 |
|
645 |
enterState(96, block); |
646 |
|
647 |
if (random != null) { |
648 |
random.nextBytes(arr); |
649 |
} |
650 |
|
651 |
enterState(97, block); |
652 |
|
653 |
try { |
654 |
os.write(arr); |
655 |
os.getChannel().force(true); |
656 |
|
657 |
enterState(27,block); |
658 |
// if this turns to be slow due to lookup of getLocalHost |
659 |
// address, it can be done asynchronously as nobody needs |
660 |
// the address in the stream if the server is listening |
661 |
byte[] host; |
662 |
try { |
663 |
if (block != null && block.intValue() == 667) { |
664 |
// this is here to emulate #64004 |
665 |
throw new UnknownHostException("dhcppc0"); // NOI18N |
666 |
} |
667 |
host = InetAddress.getLocalHost().getAddress(); |
668 |
} catch (UnknownHostException unknownHost) { |
669 |
if (!"dhcppc0".equals(unknownHost.getMessage())) { // NOI18N, see above |
670 |
// if we just cannot get the address, we can go on |
671 |
unknownHost.printStackTrace(); |
672 |
} |
673 |
host = new byte[] {127, 0, 0, 1}; |
674 |
} |
675 |
os.write(host); |
676 |
} catch (IOException ex) { |
677 |
ex.printStackTrace(); |
678 |
} |
679 |
try { |
680 |
os.getChannel().force(true); |
681 |
} catch (IOException ex) { |
682 |
// ignore |
633 |
} |
683 |
} |
634 |
} |
684 |
} |
635 |
|
685 |
}); |
636 |
enterState(96, block); |
686 |
} else { |
637 |
|
687 |
parael = Task.EMPTY; |
638 |
if (random != null) { |
688 |
} |
639 |
random.nextBytes(arr); |
|
|
640 |
} |
641 |
|
642 |
enterState(97, block); |
643 |
|
644 |
try { |
645 |
os.write(arr); |
646 |
os.getChannel().force(true); |
647 |
|
648 |
enterState(27,block); |
649 |
// if this turns to be slow due to lookup of getLocalHost |
650 |
// address, it can be done asynchronously as nobody needs |
651 |
// the address in the stream if the server is listening |
652 |
byte[] host; |
653 |
try { |
654 |
if (block != null && block.intValue() == 667) { |
655 |
// this is here to emulate #64004 |
656 |
throw new UnknownHostException("dhcppc0"); // NOI18N |
657 |
} |
658 |
host = InetAddress.getLocalHost().getAddress(); |
659 |
} catch (UnknownHostException unknownHost) { |
660 |
if (!"dhcppc0".equals(unknownHost.getMessage())) { // NOI18N, see above |
661 |
// if we just cannot get the address, we can go on |
662 |
unknownHost.printStackTrace(); |
663 |
} |
664 |
host = new byte[] {127, 0, 0, 1}; |
665 |
} |
666 |
os.write(host); |
667 |
} catch (IOException ex) { |
668 |
ex.printStackTrace(); |
669 |
} |
670 |
try { |
671 |
os.getChannel().force(true); |
672 |
} catch (IOException ex) { |
673 |
// ignore |
674 |
} |
675 |
} |
676 |
}); |
677 |
|
689 |
|
678 |
int execCode = processInitLevelCLI (args, handlers, failOnUnknownOptions); |
690 |
int execCode = processInitLevelCLI (args, handlers, failOnUnknownOptions); |
679 |
|
691 |
|
680 |
enterState(0, block); |
692 |
enterState(0, block); |
681 |
return new Status(lockFile, server.getLocalPort(), execCode, parael); |
693 |
return new Status(lockFile, p, execCode, parael); |
682 |
} catch (IOException ex) { |
694 |
} catch (IOException ex) { |
683 |
if (!"EXISTS".equals(ex.getMessage())) { // NOI18N |
695 |
if (!"EXISTS".equals(ex.getMessage())) { // NOI18N |
684 |
ex.printStackTrace(); |
696 |
ex.printStackTrace(); |
Lines 695-700
Link Here
|
695 |
} |
707 |
} |
696 |
is = raf; |
708 |
is = raf; |
697 |
port = is.readInt(); |
709 |
port = is.readInt(); |
|
|
710 |
if (port == 0) { |
711 |
return new Status(lockFile, 0, Status.ALREADY_RUNNING, Task.EMPTY); |
712 |
} |
698 |
enterState(22, block); |
713 |
enterState(22, block); |
699 |
key = new byte[KEY_LENGTH]; |
714 |
key = new byte[KEY_LENGTH]; |
700 |
is.readFully(key); |
715 |
is.readFully(key); |