]> granicus.if.org Git - vnstat/commitdiff
make test execution possible even when current user or group doesn't exist
authorTeemu Toivola <git@humdi.net>
Sat, 29 Jun 2019 16:39:18 +0000 (19:39 +0300)
committerTeemu Toivola <git@humdi.net>
Sat, 29 Jun 2019 16:39:18 +0000 (19:39 +0300)
tests/id_tests.c

index ddb4511e548a59bbecbdbe2849a2432bdf9c66ad..9f7bc25ffeaeb538d796d7d8c076f5f1f49a0451 100644 (file)
@@ -69,9 +69,17 @@ END_TEST
 START_TEST(setuser_with_current_user)
 {
        char temp[16];
-       suppress_output();
-       snprintf(temp, 16, "%d", getuser(""));
-       setuser(temp);
+       struct passwd *pw;
+
+       pw = getpwuid(getuid());
+
+       if (pw != NULL) {
+               suppress_output();
+               snprintf(temp, 16, "%d", getuser(""));
+               setuser(temp);
+       } else {
+               printf("Note: skipping test setuser_with_current_user due to non-existing user\n");
+       }
 }
 END_TEST
 
@@ -85,9 +93,17 @@ END_TEST
 START_TEST(setgroup_with_current_group)
 {
        char temp[16];
-       suppress_output();
-       snprintf(temp, 16, "%d", getgroup(""));
-       setgroup(temp);
+       struct group *gr;
+
+       gr = getgrgid(getgid());
+
+       if (gr != NULL) {
+               suppress_output();
+               snprintf(temp, 16, "%d", getgroup(""));
+               setgroup(temp);
+       } else {
+               printf("Note: skipping test setgroup_with_current_group due to non-existing group\n");
+       }
 }
 END_TEST