tizen id: reset tizen id if there is no content in the id file 05/56705/1
authorTaeyoung Kim <ty317.kim@samsung.com>
Tue, 12 Jan 2016 07:41:42 +0000 (16:41 +0900)
committerTaeyoung Kim <ty317.kim@samsung.com>
Tue, 12 Jan 2016 07:41:42 +0000 (16:41 +0900)
- Tizen ID file can be empty when the device is rebooted
  during making Tizen ID. Thus the content in the Tizen ID file
  should be checked and reset if there is no content

Change-Id: I506fee8476ee0f43edc437ebbcf2c77e4fb262a3
Signed-off-by: Taeyoung Kim <ty317.kim@samsung.com>
src/tizenid/tizenid.c

index 197786eac55bbbe3241f1eed8f35970b6ac0c0ae..46046fb7c7081cb589e2fd31b07669d652999077 100755 (executable)
@@ -208,6 +208,40 @@ out:
        return ret;
 }
 
+static int check_tizen_id_content(void)
+{
+       FILE *fp;
+       int ret;
+       char id[KEY_MAX] = {0, };
+
+       fp = fopen(TIZEN_ID_PATH, "r");
+       if (!fp) {
+               _E("Failed to open tizen id");
+               return -ENOMEM;
+       }
+
+       if (fgets(id, sizeof(id), fp) == NULL) {
+               if (errno == 0) {
+                       _E("Invalid Tizen ID (empty)");
+                       ret = -ENOENT;
+               } else {
+                       _E("Failed to get tizen id (errno:%d)", errno);
+                       ret = -errno;
+               }
+               fclose(fp);
+               return ret;
+       }
+
+       fclose(fp);
+
+       if (strlen(id) == 0) {
+               _E("Invalid Tizen ID (empty)");
+               return -ENOENT;
+       }
+
+       return 0;
+}
+
 static int check_tizen_id(void)
 {
        struct stat buf;
@@ -227,6 +261,10 @@ static int check_tizen_id(void)
        mode = buf.st_mode & S_IFMT;
        switch (mode) {
        case S_IFREG:
+               if (check_tizen_id_content() < 0) {
+                       _I("Tizen ID is empty");
+                       break;
+               }
                _I("Tizen ID already exists");
                return 0;
        case S_IFLNK: