Upload tizen_2.1 source
authorkh5325.kim <kh5325.kim@samsung.com>
Tue, 16 Apr 2013 07:43:14 +0000 (16:43 +0900)
committerkh5325.kim <kh5325.kim@samsung.com>
Tue, 16 Apr 2013 07:43:14 +0000 (16:43 +0900)
Change-Id: I21e31cad9e7116a7d348b14c2577824d20a6eb84

16 files changed:
package/changelog
package/pkginfo.manifest
src/android_reboot.c
src/commandline.c
src/file_sync_client.c
src/file_sync_service.c
src/jdwp_service.c
src/properties.c
src/remount_service.c
src/sdb.h
src/sdb_client.c
src/transport_local.c
src/usb_libusb.c
src/usb_linux.c
src/usb_osx.c
src/usb_vendors.c

index 6986a91e102fb7ff8a598302d0def8afa317b08b..18cfe9b931e7d74cf7bd7667985b9803669e6cc0 100644 (file)
@@ -1,33 +1,39 @@
+* 2.1.23
+- change pkgcmd path
+== yoonki.park <yoonki.park@samsung.com> 2013-04-13
+* 2.1.22
+- fixed build error for windows
+== yoonki.park <yoonki.park@samsung.com> 2013-04-13
+* 2.1.21
+- Add wgt install / uninstall
+== ho.namkoong <ho.namkoong@samsung.com> 2013-04-12
+* 2.1.2
+- Make install path /opt/usr/apps/
+== ho.namkoong <ho.namkoong@samsung.com> 2013-04-05 12:03
+* 2.1.1
+- add root command
+== yoonki.park <yoonki.park@samsung.com> 2013-03-29
 * 2.1.0
-- Update pkg version to the 2.1.0
+- update version to 2.1.0
 == ho.namkoong <ho.namkoong@samsung.com> 2013-03-11
-* 1.0.24
-- Check gksudo or sudo exist
-== ho.namkoong <ho.namkoong@samsung.com> 2013-03-08
-* 1.0.23
-- comment out goto fail when setting 2 configuration
-== yoonki.park <yoonki.park@samsung.com> 2013-01-22
-* 1.0.21
-- fixed dlog bug
-== ho.namkoong <ho.namkoong@samsung.com> 2012-12-18
 * 1.0.20
-- fixed install command
-== yoonki.park <yoonki.park@samsung.com> 2012-12-18 00:10
+- comment out goto fail when setting 2 configuration
+== yoonki.park <yoonki.park@samsung.com> 2013-01-22 00:11
 * 1.0.19
-- add connect/disconnect command again
-== yoonki.park <yoonki.park@samsung.com> 2012-12-17 22:30
+- remove stdout if command -serial
+== yoonki.park <yoonki.park@samsung.com> 2012-12-22 00:11
 * 1.0.18
-- fixed build error for windows
-== yoonki.park <yoonki.park@samsung.com> 2012-12-17 21:30
+- fixed to install a application
+== yoonki.park <yoonki.park@samsung.com> 2012-12-18 00:11
 * 1.0.17
-- add connect/disconnect command
-== yoonki.park <yoonki.park@samsung.com> 2012-12-17 17:30
+- fixed build error for windows
+== yoonki.park <yoonki.park@samsung.com> 2012-12-17 21:11
 * 1.0.16
-- fixed build error in macos
-== yoonki.park <yoonki.park@samsung.com> 2012-11-27 17:30
+- version up to 1.0.16
+== yoonki.park <yoonki.park@samsung.com> 2012-12-17 17:11
 * 1.0.15
-- support install/uninstall command
-== yoonki.park <yoonki.park@samsung.com> 2012-11-27 17:30
+- add udev rule to give usb node permission 666
+== yoonki.park <yoonki.park@samsung.com> 2012-11-02 18:13
 * 1.0.14
 - remove ssh package from sdb
 == yoonki.park <yoonki.park@samsung.com> 2012-11-06 17:30
index f911c19dfa5c3697e5044243754f765d16a431f6..29ab7df6e92ec42cb870f9fb4e2deec5812d8b49 100644 (file)
@@ -1,4 +1,4 @@
-Version:2.1.0
+Version:2.1.23
 Source:sdb
 Maintainer:Kangho Kim <kh5325.kim@samsung.com>, Yoonki Park<yoonki.park@samsung.com>, Hyunsik Noh<hyunsik.noh@samsung.com>, Gun Kim<gune.kim@samsung.com>, Ho Namkoong<ho.namkoong@samsung.com>, Taeyoung Son<taeyoung2.son@samsung.com>
 
index 238a3d613feb9f28d076cb1a3df07cc01fae4dcb..db8a4a999dd27983c79fba5146719bb8d8ada20e 100644 (file)
@@ -51,8 +51,8 @@ static int remount_ro_done(void)
                        mount_dev, mount_dir, mount_type,
                        mount_opts, &mount_freq, &mount_passno);
         mount_dev[255] = 0;
-        mount_dir[255] = 0;
-        mount_type[255] = 0;
+        //mount_dir[255] = 0;
+        //mount_type[255] = 0;
         mount_opts[255] = 0;
         if ((match == 6) && !strncmp(mount_dev, "/dev/block", 10) && strstr(mount_opts, "rw")) {
             found_rw_fs = 1;
@@ -79,7 +79,6 @@ static int remount_ro_done(void)
 static void remount_ro(void)
 {
     int fd, cnt = 0;
-    int len = 0;
     /* Trigger the remount of the filesystems as read-only,
      * which also marks them clean.
      */
@@ -87,7 +86,7 @@ static void remount_ro(void)
     if (fd < 0) {
         return;
     }
-    len = write(fd, "u", 1);
+    write(fd, "u", 1);
     close(fd);
 
     /* Now poll /proc/mounts till it's done */
index 1e4ec1eed519a0f0cad42ea9891a262d8ba130cb..1b6bba83327b4a5244012ce35d256f579d2b2409 100755 (executable)
@@ -46,7 +46,10 @@ int install_app(transport_type transport, char* serial, int argc, char** argv);
 int uninstall_app_sdb(const char *app_id);
 int install_app_sdb(const char *srcpath);
 int uninstall_app(transport_type transport, char* serial, int argc, char** argv);
+int get_pkgtype_file_name(const char* file_name);
+int get_pkgtype_from_app_id(const char* app_id);
 int sdb_command2(const char* cmd);
+int launch_app(transport_type transport, char* serial, int argc, char** argv);
 void version_sdbd(transport_type ttype, char* serial);
 
 static const char *gProductOutPath = NULL;
@@ -87,11 +90,11 @@ void help()
     " Usage : sdb [option] <command> [parameters]\n"
         "\n"
     " options:\n"
-    " -d                            - directs command to the only connected USB device\n"
-    "                                 returns an error if more than one USB device is present.\n"
-    " -e                            - directs command to the only running emulator.\n"
-    "                                 returns an error if more than one emulator is running.\n"
-    " -s <serial number>            - directs command to the USB device or emulator with\n"
+    " -d                            - direct command to the only connected USB device\n"
+    "                                 return an error if more than one USB device is present.\n"
+    " -e                            - direct command to the only running emulator.\n"
+    "                                 return an error if more than one emulator is running.\n"
+    " -s <serial number>            - direct command to the USB device or emulator with\n"
     "                                 the given serial number.\n"
     " devices                       - list all connected devices\n"
     " connect <host>[:<port>]       - connect to a device via TCP/IP\n"
@@ -108,8 +111,8 @@ void help()
     "  sdb pull <remote> [<local>]  - copy file/dir from device\n"
     "  sdb shell                    - run remote shell interactively\n"
     "  sdb shell <command>          - run remote shell \n"
-    "  sdb dlog [ <filter-spec> ]   - view device log\n"
-    "  sdb install <path_to_tpk>    - push tpk package file and install it\n"
+    "  sdb dlog [<filter-spec>]     - view device log\n"
+    "  sdb install <pkg_path>       - push package file and install it\n"
     "  sdb uninstall <appid>        - uninstall this app from the device\n"
     "  sdb forward <local> <remote> - forward socket connections\n"
 
@@ -120,11 +123,13 @@ void help()
     "\n"
     "  sdb start-server             - ensure that there is a server running\n"
     "  sdb kill-server              - kill the server if it is running\n"
-    "  sdb get-state                - prints: offline | bootloader | device\n"
-    "  sdb get-serialno             - prints: <serial-number>\n"
+    "  sdb get-state                - print: offline | bootloader | device\n"
+    "  sdb get-serialno             - print: <serial-number>\n"
     "  sdb status-window            - continuously print device status for a specified device\n"
 //    "  sdb usb                      - restarts the sdbd daemon listing on USB\n"
-//    "  sdb tcpip                    - restarts the sdbd daemon listing on TCP"
+//    "  sdb tcpip                    - restarts the sdbd daemon listing on TCP\n"
+    "  sdb root <on|off>            - switch to root or developer account mode\n"
+    "                                 'on' means to root mode, and vice versa"
     "\n"
         );
 }
@@ -568,7 +573,7 @@ static int logcat(transport_type transport, char* serial, int argc, char **argv)
     char buf[4096];
 
     snprintf(buf, sizeof(buf),
-        "shell:dlogutil");
+        "shell:/usr/bin/dlogutil");
 
 /*
     if (!strcmp(argv[0],"longcat")) {
@@ -1101,24 +1106,24 @@ top:
         }
     }
 #endif
-    if(!strcmp(argv[0], "remount") || !strcmp(argv[0], "reboot")
-            || !strcmp(argv[0], "reboot-bootloader")
-            || !strcmp(argv[0], "tcpip") || !strcmp(argv[0], "usb")
-            || !strcmp(argv[0], "root")) {
+    if(!strcmp(argv[0], "root")) {
         char command[100];
-        if (!strcmp(argv[0], "reboot-bootloader"))
-            snprintf(command, sizeof(command), "reboot:bootloader");
-        else if (argc > 1)
-            snprintf(command, sizeof(command), "%s:%s", argv[0], argv[1]);
-        else
-            snprintf(command, sizeof(command), "%s:", argv[0]);
+
+        if (argc != 2) {
+            return usage();
+        }
+        if (strcmp(argv[1], "on") != 0 && strcmp(argv[1], "off") != 0) {
+            return usage();
+        }
+        snprintf(command, sizeof(command), "%s:%s", argv[0], argv[1]);
         int fd = sdb_connect(command);
         if(fd >= 0) {
             read_and_dump(fd);
             sdb_close(fd);
             return 0;
         }
-        fprintf(stderr,"error: %s\n", sdb_error());
+        //TODO: it may be here due to connection fail not version mis-match
+        fprintf(stderr, "root command requires at least version 2.1.0\n");
         return 1;
     }
 
@@ -1206,15 +1211,25 @@ top:
     }
 
     if(!strcmp(argv[0], "install")) {
-        if(argc != 2) return usage();
+        if(argc == 2) {
+            return install_app_sdb(argv[1]);
+        }
 
-        return install_app_sdb(argv[1]);
+        return usage();
     }
 
     if(!strcmp(argv[0], "uninstall")) {
-        if(argc != 2) return usage();
+        if(argc == 2) {
+            return uninstall_app_sdb(argv[1]);
+        }
 
-        return uninstall_app_sdb(argv[1]);
+        return usage();
+    }
+
+    if(!strcmp(argv[0], "launch")) {
+        //if (argc < 2) return usage();
+        //TODO : check argument validations
+        return launch_app(ttype, serial, argc, argv);
     }
 
     if(!strcmp(argv[0], "pull")) {
@@ -1457,7 +1472,7 @@ int sdb_command2(const char* cmd) {
 
 int install_app_sdb(const char *srcpath) {
     D("Install start\n");
-    const char * APP_DEST = "/opt/apps/PKGS/%s";
+    const char * APP_DEST = "/opt/usr/apps/tmp/%s";
     const char* filename = sdb_dirstop(srcpath);
     char destination[PATH_MAX];
 
@@ -1468,6 +1483,11 @@ int install_app_sdb(const char *srcpath) {
         snprintf(destination, sizeof destination, APP_DEST, srcpath);
     }
 
+    int tpk = get_pkgtype_file_name(srcpath);
+    if (tpk == -1) {
+        fprintf(stderr, "error: unknown package type\n");
+        return -1;
+    }
     D("Push file: %s to %s\n", srcpath, destination);
     int result = do_sync_push(srcpath, destination, 0, 0);
 
@@ -1476,9 +1496,18 @@ int install_app_sdb(const char *srcpath) {
         return -1;
     }
 
-    const char* SHELL_INSTALL_CMD ="shell:pkgcmd -i -t tpk -p %s -q";
+    const char* SHELL_INSTALL_CMD ="shell:/usr/bin/pkgcmd -i -t %s -p %s -q";
     char full_cmd[PATH_MAX];
-    snprintf(full_cmd, sizeof full_cmd, SHELL_INSTALL_CMD, destination);
+
+    if(tpk == 1) {
+        snprintf(full_cmd, sizeof full_cmd, SHELL_INSTALL_CMD, "tpk", destination);
+    }
+    else if(tpk == 0){
+        snprintf(full_cmd, sizeof full_cmd, SHELL_INSTALL_CMD, "wgt", destination);
+    }
+    else {
+        return tpk;
+    }
     D("Install command: %s\n", full_cmd);
     result = sdb_command2(full_cmd);
 
@@ -1501,10 +1530,19 @@ int install_app_sdb(const char *srcpath) {
 }
 
 int uninstall_app_sdb(const char *appid) {
-    const char* SHELL_UNINSTALL_CMD ="shell:pkgcmd -u -t tpk -n %s -q";
+    const char* SHELL_UNINSTALL_CMD ="shell:/usr/bin/pkgcmd -u -t %s -n %s -q";
     char full_cmd[PATH_MAX];
     int result = 0;
-    snprintf(full_cmd, sizeof full_cmd, SHELL_UNINSTALL_CMD, appid);
+    int tpk = get_pkgtype_from_app_id(appid);
+    if(tpk == 1) {
+        snprintf(full_cmd, sizeof full_cmd, SHELL_UNINSTALL_CMD, "tpk", appid);
+    }
+    else if(tpk == 0){
+        snprintf(full_cmd, sizeof full_cmd, SHELL_UNINSTALL_CMD, "wgt", appid);
+    }
+    else {
+        return tpk;
+    }
     result = sdb_command2(full_cmd);
 
     if(result < 0) {
@@ -1533,6 +1571,56 @@ int uninstall_app(transport_type transport, char* serial, int argc, char** argv)
     return pm_command(transport, serial, argc, argv);
 }
 
+// Returns 0 if pkg type is wgt. Returns 1 if pkg type is tpk. Returns minus if exception happens.
+int get_pkgtype_file_name(const char* file_name) {
+
+    char* pkg_type;
+
+    int result = -1;
+
+    pkg_type = strrchr(file_name, '.')+1;
+    if (pkg_type != NULL) {
+        if(!strcmp(pkg_type, "wgt")) {
+            result = 0;
+        }
+        else if(!strcmp(pkg_type, "tpk")) {
+            result = 1;
+        }
+    }
+
+    return result;
+}
+
+// Returns 0 if pkg type is wgt. Returns 1 if pkg type is tpk. Returns minus if exception happens.
+int get_pkgtype_from_app_id(const char* app_id) {
+
+    char* GET_PKG_TYPE_CMD = "shell:/usr/bin/pkgcmd -l | grep %s | awk '{print $2}'";
+    char full_cmd[PATH_MAX];
+    snprintf(full_cmd, sizeof full_cmd, GET_PKG_TYPE_CMD, app_id);
+
+    int result = sdb_connect(full_cmd);
+    if(result < 0) {
+        return result;
+    }
+    char buf[100] = "";
+
+    int rl_result = read_line(result, buf, 100);
+    if(rl_result < 0) {
+        D("Error to read buffer (fd=%d)\n", rl_result);
+        return rl_result;
+    }
+
+    sdb_close(result);
+    result = -1;
+
+    if(strstr(buf, "[tpk]") != NULL) {
+        result = 1;
+    } else if(strstr(buf, "[wgt]") != NULL) {
+        result = 0;
+    }
+    return result;
+}
+
 static int delete_file(transport_type transport, char* serial, char* filename)
 {
     char buf[4096];
@@ -1670,6 +1758,39 @@ cleanup_apk:
     return err;
 }
 
+int launch_app(transport_type transport, char* serial, int argc, char** argv)
+{
+    static const char *const SHELL_LAUNCH_CMD = "shell:/usr/bin/sdk_launch_app ";
+    char full_cmd[PATH_MAX];
+    int i;
+    int result = 0;
+
+    snprintf(full_cmd, sizeof full_cmd, "%s", SHELL_LAUNCH_CMD);
+
+    //TODO: check argument validation
+
+    for (i=1 ; i<argc ; i++) {
+        strncat(full_cmd, " ", sizeof(full_cmd)-strlen(" ")-1);
+        strncat(full_cmd, argv[i], sizeof(full_cmd)-strlen(argv[i])-1);
+    }
+
+    D("launch command: %s\n", full_cmd);
+    result = sdb_command2(full_cmd);
+
+    if(result < 0) {
+        fprintf(stderr, "error: %s\n", sdb_error());
+        return result;
+    }
+
+    if(result < 0) {
+        fprintf(stderr, "error: %s\n", sdb_error());
+        return result;
+    }
+    sdb_close(result);
+    return 0;
+
+}
+
 void version_sdbd(transport_type ttype, char* serial) {
     char* VERSION_QUERY ="shell:rpm -qa | grep sdbd";
     send_shellcommand(ttype, serial, VERSION_QUERY);
index 2c5016c9a9cf84b03f77faa6d43fc88aba94288f..0a1c4ab416161775c2ad05a2360d329f7b59e577 100755 (executable)
@@ -798,7 +798,7 @@ int do_sync_push(const char *lpath, const char *rpath, int verifyApk, int isUtf8
             } else {
                 rpath = tmp;
             }
-        } // FIXME
+        }// FIXME
         /* else {
             fprintf(stderr, "error: file exists : %s\n", rpath);
             return 1;
@@ -985,7 +985,8 @@ int do_sync_pull(const char *rpath, const char *lpath)
         return 1;
     }
     if(mode == 0) {
-        fprintf(stderr,"remote object '%s' does not exist\n", rpath);
+        fprintf(stderr,"'%s': No such file or directory\n", rpath);
+        sync_quit(fd);
         return 1;
     }
 
@@ -1026,7 +1027,7 @@ int do_sync_pull(const char *rpath, const char *lpath)
             return 0;
         }
     } else {
-        fprintf(stderr,"remote object '%s' not a file or directory\n", rpath);
+        fprintf(stderr,"'%s': No such file or directory\n", rpath);
         return 1;
     }
 }
index c0e342d3b68b87e7716218603010718745000926..5871a8c589850be56ebce08ad3fc9bdcd6bb292b 100644 (file)
@@ -326,7 +326,7 @@ static int do_send(int s, char *path, char *buffer)
 
         ret = handle_send_file(s, path, mode, buffer);
     }
-
+    D("link? %s\n", (is_link==0) ? "no" : "yes");
     return ret;
 }
 
index 1b8b1dcdf72af9391414fb3b3a5f79e73d67aa51..ab6f11bf1b2c3cbc313307ca4a2e017b5c8810bd 100644 (file)
@@ -385,8 +385,9 @@ jdwp_process_event( int  socket, unsigned  events, void*  _proc )
             D("sent file descriptor %d to JDWP process %d\n",
               fd, proc->pid);
 
-            for (n = 1; n < proc->out_count; n++)
+            for (n = 1; n < proc->out_count; n++) {
                 proc->out_fds[n-1] = proc->out_fds[n];
+            }
 
             if (fcntl(proc->socket, F_SETFL, flags) == -1) {
                 D("failed to set O_NONBLOCK flag for socket %d: %s\n",
index 078afc912bb273ba36e2c985ef60bfde8d585339..886669ab32a657729b25bccc834bdb77a67d76a9 100644 (file)
@@ -155,10 +155,9 @@ int read_line(const int fd, char* ptr, const unsigned int maxlen)
 {
     unsigned int n = 0;
     char c[2];
-    int rc;
 
     while(n != maxlen) {
-        if((rc = sdb_read(fd, c, 1)) != 1)
+        if(sdb_read(fd, c, 1) != 1)
             return -1; // eof or read err
 
         if(*c == '\n') {
index 61d439bb4bb16e9dc22087d45712f5fba3c05ee4..21ed259d312337b5a232d61794e00989ebbdbdf0 100644 (file)
@@ -35,7 +35,6 @@ static char *find_mount(const char *dir)
 {
     int fd;
     int res;
-    int size;
     char *token = NULL;
     const char delims[] = "\n";
     char buf[4096];
@@ -45,7 +44,7 @@ static char *find_mount(const char *dir)
         return NULL;
 
     buf[sizeof(buf) - 1] = '\0';
-    size = sdb_read(fd, buf, sizeof(buf) - 1);
+    sdb_read(fd, buf, sizeof(buf) - 1);
     sdb_close(fd);
 
     token = strtok(buf, delims);
index 4eef2aff2f20793c5dd70efc7e385cab1ae50b25..3533da6b3fff1c94225a84c861c5521eebeea5b3 100755 (executable)
--- a/src/sdb.h
+++ b/src/sdb.h
@@ -33,9 +33,9 @@
 #define A_VERSION 0x01000000        // SDB protocol version
 
 #define SDB_VERSION_MAJOR 2       // Used for help/version information
-#define SDB_VERSION_MINOR 0         // Used for help/version information
+#define SDB_VERSION_MINOR 1         // Used for help/version information
 
-#define SDB_SERVER_VERSION    2    // Increment this when we want to force users to start a new sdb server
+#define SDB_SERVER_VERSION    0    // Increment this when we want to force users to start a new sdb server
 
 typedef struct amessage amessage;
 typedef struct apacket apacket;
index 08766cd6b7998b62864f11c55a5dc34ef1d4e131..18fd20bee31890888211d3e42cf9527232f5c324 100644 (file)
@@ -124,6 +124,9 @@ static int switch_socket_transport(int fd)
                 // no switch necessary
                 return 0;
                 break;
+            default:
+                D("unknown transport type\n");
+                break;
         }
 
         snprintf(service, sizeof service, "host:%s", transport_type);
index 8fcd04c50704b498862213db31415a3a93f4b5fa..a87f39f5f9073eb4abe43bc7735aa01dd3464329 100644 (file)
@@ -157,7 +157,6 @@ int get_devicename_from_shdmem(int port, char *device_name)
         D("faild to get shdmem key (%d) : %s\n", port, strerror(errno));
         return -1;
     }
-
     vms = strstr((char*)shared_memory, VMS_PATH);
     if (vms != NULL)
         strncpy(device_name, vms+strlen(VMS_PATH), DEVICENAME_MAX);
@@ -194,6 +193,12 @@ int get_devicename_from_shdmem(int port, char *device_name)
         strncpy(device_name, DEFAULT_DEVICENAME, DEVICENAME_MAX);
     CloseHandle(hMapFile);
 #endif
+    // apply for new vms path policy from Jan 23 2013
+    // vms path should be: ~/tizen-sdk-data/emulator-vms/vms/{name}/emulimg-em1.~~
+    vms = strtok(device_name, OS_PATH_SEPARATOR_STR);
+    if (vms != NULL) {
+        strncpy(device_name, vms, DEVICENAME_MAX);
+    }
     D("init device name %s on port %d\n", device_name, port);
 
     return 0;
@@ -203,10 +208,9 @@ int read_line(const int fd, char* ptr, size_t maxlen)
 {
     unsigned int n = 0;
     char c[2];
-    int rc;
 
     while(n != maxlen) {
-        if((rc = sdb_read(fd, c, 1)) != 1)
+        if(sdb_read(fd, c, 1) != 1)
             return -1; // eof or read err
 
         if(*c == '\n') {
index 8d12ea7542b058558a8e555ad55a2a53a5d8a93a..ab847bfb0028b7df01fcd02103504306763225f8 100644 (file)
@@ -512,8 +512,9 @@ check_device(libusb_device *dev)
                     int j = 0;
                     r /= 2;
                 
-                    for (j = 1; j < r; ++j)
+                    for (j = 1; j < r; ++j) {
                         serial[j - 1] = buffer[j];
+                    }
                 
                     serial[j - 1] = '\0';
                     break; /* languagesCount cycle */
index 2e631837def8554c534307bce05d4530030ae291..158c686474fb1990a678b4654071b37234691bb8 100755 (executable)
@@ -599,7 +599,7 @@ static void register_device(const char *dev_name,
         n = ioctl(usb->desc, USBDEVFS_SETCONFIGURATION, &bConfigurationValue);
         if (n != 0) {
             D("[ usb set %d configuration failed %s fd = %d]\n", bConfigurationValue, usb->fname, usb->desc);
-            D("check kernel is supporting %dth configuration\n", bConfigurationValue); 
+            D("check kernel is supporting %dth configuration\n", bConfigurationValue);
         }
 
         n = ioctl(usb->desc, USBDEVFS_CLAIMINTERFACE, &interface);
@@ -649,12 +649,13 @@ static void register_device(const char *dev_name,
 
             result = ioctl(usb->desc, USBDEVFS_CONTROL, &ctrl);
             if (result > 0) {
-                int i;
+                int j;
                 // skip first word, and copy the rest to the serial string, changing shorts to bytes.
                 result /= 2;
-                for (i = 1; i < result; i++)
-                    serial[i - 1] = __le16_to_cpu(buffer[i]);
-                serial[i - 1] = 0;
+                for (j = 1; j < result; j++) {
+                    serial[j - 1] = __le16_to_cpu(buffer[j]);
+                }
+                serial[j - 1] = 0;
                 break;
             }
         }
index 5fbe1a6525338e14a546ea67fdf25405b39a6484..683dadd95646eb7324de2d4d35a5e6072085a5bf 100644 (file)
@@ -234,8 +234,9 @@ AndroidInterfaceAdded(void *refCon, io_iterator_t iterator)
                                        // skip first word, and copy the rest to the serial string,
                                        // changing shorts to bytes.
                                        count = (req.wLenDone - 1) / 2;
-                                       for (i = 0; i < count; i++)
+                                       for (i = 0; i < count; i++) {
                                                serial[i] = buffer[i + 1];
+                    }
                                        serial[i] = 0;
                                         break;
                                }
index 636482845accfc8e417af2bc5fa73de37b409f68..217aa8ac74a053116278ac17a0520a5b0b3dcda2 100644 (file)
@@ -218,6 +218,7 @@ void usb_vendors_init(void)
                 long value = strtol(temp, NULL, 0);
                 if (errno == EINVAL || errno == ERANGE || value > INT_MAX || value < 0) {
                     fprintf(stderr, "Invalid content in %s. Quitting.\n", ANDROID_SDB_INI);
+                    fclose(f);
                     exit(2);
                 }
 
@@ -228,6 +229,7 @@ void usb_vendors_init(void)
                     break;
                 }
             }
+            fclose(f);
         }
     }
 }