Arduino-Yun Bridge Bugs, Help Me

i code the bellow and program it to the mcu, then i open the Serial(cdc) in the tool->Serial Monitor

when the bridge connectted, i input "/etc/init.d/network restart";

wait a minite,

then i close the Serial(Cdc) then then reset the mcu

again, i open the Serial(Cdc) and wait the bridge to setup ,

but i wait long long time, but the bridge count'd be setup correctlly:

who know this bugs? pelease help me:

/* This is simple led blink program.
*

  • D30 is the led on the board.

  • When startup, the mcu set the D30 to output mode,

  • and then switch the led every 2 seconds.

  • author : au

  • date: 2015/11/12

  • email: dongliang@lierda.com

  • Steps:

    1. program the code to the arduino-yun's mcu
    1. open the Serial(tool->Serial monitor)
    1. wait for setup the bridge
    1. enter /etc/init.d/network restart, and wait a time
    1. close the Serial
    1. reboot the mcu and reopen the Serial
    1. this time the bridge will not be setup correctlly.
      */

#include <Bridge.h>
#include <YunServer.h>
#include <YunClient.h>

bool get_cmd(char *buf, unsigned int size);
void execute_cmd(char *buf);

void setup() {
Serial.begin(19200);
while (!Serial);

Serial.println("Init Bridge...");
Bridge.begin();
Serial.println("Set Up Bridge OK.");
}

void loop() {
char cmd[64];
while (true) {
if (get_cmd(cmd, sizeof(cmd))) {
//Serial.print("execute:[");
//Serial.print(cmd);
//Serial.println("]:");
execute_cmd(cmd);
//Serial.println("[arduino@Yun]:");
} else {
delay(100);
}
}
}

bool get_cmd(char *buf, unsigned int size) {
int len = 0;

if (!Serial) {
return false;
}

while (Serial.available() && len < size - 1) {
char c = Serial.read();
buf[len++] = c;
delay(2);
}

if (len == 0) {
return false;
}

buf[len] = 0;
return true;
}

void execute_cmd(char *buf) {
Process p;
p.runShellCommand(buf);
while (p.running());
while (p.available()) {
char c = p.read();
Serial.print(c);
}
}