static const char *SDK_TOOL_PATH="/home/developer/sdk_tools";
static const char *APP_PATH_PREFIX="/opt/apps";
+// the time limit to wait for connection with device
+static const int DEVICE_ONLINE_CHECK_INTERVAL = 500; // msec
+static const int DEVICE_ONLINE_CHECK_REPEAT = 6;
+
static void __inline__ format_host_command(char* buffer, size_t buflen, const char* command, transport_type ttype, const char* serial);
static int get_pkgtype_file_name(const char* file_name);
static int kill_gdbserver_if_running(const char* process_cmd);
char full_cmd[PATH_MAX];
char * tmp;
char remote_target_info[30] = { 0, };
+ int i;
if (strstr(argv[1], ":") == NULL)
snprintf(remote_target_info, sizeof remote_target_info, "%s:%d", argv[1], DEFAULT_SDB_LOCAL_TRANSPORT_PORT);
if(strstr(tmp, "connecting") == NULL)
return 0;
- // check if device state is online for 3 sec
- int i = 0;
- for (i; i < 6; i++) {
- sdb_sleep_ms(500);
+ // check if device state is online for 3 secs
+ for (i = 0; i < DEVICE_ONLINE_CHECK_REPEAT; i++) {
+ sdb_sleep_ms(DEVICE_ONLINE_CHECK_INTERVAL);
snprintf(full_cmd, sizeof full_cmd, "host-serial:%s:get-state", remote_target_info);
tmp = sdb_query(full_cmd);
- if(!strcmp(tmp, STATE_DEVICE) || !strcmp(tmp, STATE_LOCKED) || !strcmp(tmp, STATE_SUSPENDED)) {
- printf("connected to %s\n", remote_target_info);
- return 0;
+ if (tmp != NULL) {
+ if(!strcmp(tmp, STATE_DEVICE) || !strcmp(tmp, STATE_LOCKED) || !strcmp(tmp, STATE_SUSPENDED)) {
+ printf("connected to %s\n", remote_target_info);
+ return 0;
+ }
+ } else {
+ // connection error occurred
+ break;
}
}
}
char buf[1024] = {0, };
char* portstr = strchr(host, ':');
- int port = -1;
+ long port = -1;
+ char* reststr;
if(portstr) {
*portstr++ = 0;
- if (!sscanf(portstr, "%d", &port)) {
+
+ // use 'strtol' to make sure that port string contains only number character
+ errno = 0;
+ port = strtol(portstr, &reststr, 10);
+ LOG_DEBUG("port number(%ld), reststr(%s)\n", port, reststr);
+ if (errno != 0 || reststr[0] != '\0') {
snprintf(buf, sizeof(buf), "bad port format '%s'", portstr);
goto connect_done;
}
}
- connect_emulator(host, port, buf, sizeof(buf));
+ connect_emulator(host, (int)port, buf, sizeof(buf));
connect_done:
free_list(socket->pkt_list, put_apacket);