OSDN Git Service

BandwidthController: allow UID 0 as a "special uid"
authorJP Abgrall <jpa@google.com>
Wed, 3 Jul 2013 19:23:55 +0000 (12:23 -0700)
committerJP Abgrall <jpa@google.com>
Wed, 3 Jul 2013 19:23:55 +0000 (12:23 -0700)
The happy box needs to be able to let UID 0 (dhcp, ...) pass through.

Bug: 6212480
Change-Id: I9867b7db4e5ad71cfb1170659d2d6a14ca9590be

BandwidthController.cpp

index debb005..26a2739 100644 (file)
@@ -413,11 +413,11 @@ int BandwidthController::manipulateSpecialApps(int numUids, char *appStrUids[],
     switch (appOp) {
     case SpecialAppOpAdd:
         op = IptOpInsert;
-        failLogTemplate = "Failed to add app uid %d to %s.";
+        failLogTemplate = "Failed to add app uid %s(%d) to %s.";
         break;
     case SpecialAppOpRemove:
         op = IptOpDelete;
-        failLogTemplate = "Failed to delete app uid %d from %s box.";
+        failLogTemplate = "Failed to delete app uid %s(%d) from %s box.";
         break;
     default:
         ALOGE("Unexpected app Op %d", appOp);
@@ -425,9 +425,10 @@ int BandwidthController::manipulateSpecialApps(int numUids, char *appStrUids[],
     }
 
     for (uidNum = 0; uidNum < numUids; uidNum++) {
-        appUids[uidNum] = atol(appStrUids[uidNum]);
-        if (appUids[uidNum] == 0) {
-            ALOGE(failLogTemplate, appUids[uidNum], chain);
+        char *end;
+        appUids[uidNum] = strtoul(appStrUids[uidNum], &end, 0);
+        if (*end || !*appStrUids[uidNum]) {
+            ALOGE(failLogTemplate, appStrUids[uidNum], appUids[uidNum], chain);
             goto fail_parse;
         }
     }
@@ -456,7 +457,7 @@ int BandwidthController::manipulateSpecialApps(int numUids, char *appStrUids[],
 
         iptCmd = makeIptablesSpecialAppCmd(op, uid, chain);
         if (runIpxtablesCmd(iptCmd.c_str(), jumpHandling)) {
-            ALOGE(failLogTemplate, uid, chain);
+            ALOGE(failLogTemplate, appStrUids[uidNum], uid, chain);
             goto fail_with_uidNum;
         }
     }