Added uid switching to generate specifc error codes.
diff --git a/testcases/kernel/syscalls/chmod/chmod04.c b/testcases/kernel/syscalls/chmod/chmod04.c
index 50a9f42..a5faf1b 100644
--- a/testcases/kernel/syscalls/chmod/chmod04.c
+++ b/testcases/kernel/syscalls/chmod/chmod04.c
@@ -77,6 +77,7 @@
#include <errno.h>
#include <string.h>
#include <signal.h>
+#include <pwd.h>
#include "test.h"
#include "usctest.h"
@@ -91,6 +92,8 @@
char *TCID="chmod04"; /* Test program identifier. */
int TST_TOTAL=1; /* Total number of test cases. */
extern int Tst_count; /* Test Case counter for tst_* routines */
+char nobody_uid[] = "nobody";
+struct passwd *ltpuser;
void setup(); /* Setup function for the test */
void cleanup(); /* Cleanup function for the test */
@@ -181,11 +184,18 @@
/* capture signals */
tst_sig(NOFORK, DEF_HANDLER, cleanup);
- /* Check that the test process id is not super/root */
- if (geteuid() == 0) {
- tst_brkm(TBROK, NULL, "Must be non-super/root for this test!");
- tst_exit();
- }
+ /* Switch to nobody user for correct error code collection */
+ if (geteuid() != 0) {
+ tst_brkm(TBROK, tst_exit, "Test must be run as root");
+ }
+ ltpuser = getpwnam(nobody_uid);
+ if (setuid(ltpuser->pw_uid) == -1) {
+ tst_resm(TINFO, "setuid failed to "
+ "to set the effective uid to %d",
+ ltpuser->pw_uid);
+ perror("setuid");
+ }
+
/* Pause if that option was specified */
TEST_PAUSE;