[PATCH] tests/uname.c: use print_quoted_string to print members of uname

Dmitry V. Levin ldv at altlinux.org
Mon Mar 28 23:35:19 UTC 2016


On Sat, Mar 26, 2016 at 01:48:16PM +0530, Jay Joshi wrote:
[...]
> Okay, print statements will be indented same way.
> Patch is attached.
> I've used getopts for flag abbrev, even if there is this only flag. Is
> it fine?

getopt for passing 1 bit of informations seems like overkill.

> Any other changes required?

I've applied your patch with the following modifications:

--- a/tests/uname.c
+++ b/tests/uname.c
@@ -6,47 +6,33 @@
 # include <stdio.h>
 # include <sys/utsname.h>
 # include <unistd.h>
-# include <assert.h>
 
 int main(int ac, char **av)
 {
-	assert(ac <= 2);
-
-	int abbrev = 0, c;
-	while ((c = getopt (ac, av, "a")) != -1) {
-		switch (c) {
-			case 'a':
-				abbrev = 1;
-				break;
-		}
-	}
-
+	int abbrev = ac > 1;
 	struct utsname *const uname = tail_alloc(sizeof(struct utsname));
 	int rc = syscall(__NR_uname, uname);
 	printf("uname({sysname=\"");
 	print_quoted_string(uname->sysname);
 	printf("\", nodename=\"");
 	print_quoted_string(uname->nodename);
-	printf("\"");
 	if (abbrev) {
-		printf(", ...");
-		goto print_and_exit;
-	}
-	printf(", release=\"");
-	print_quoted_string(uname->release);
-	printf("\", version=\"");
-	print_quoted_string(uname->version);
-	printf("\", machine=\"");
-	print_quoted_string(uname->machine);
-	printf("\"");
+		printf("\", ...");
+	} else {
+		printf("\", release=\"");
+		print_quoted_string(uname->release);
+		printf("\", version=\"");
+		print_quoted_string(uname->version);
+		printf("\", machine=\"");
+		print_quoted_string(uname->machine);
 # ifdef HAVE_STRUCT_UTSNAME_DOMAINNAME
-	printf(", domainname=\"");
-	print_quoted_string(uname->domainname);
-	printf("\"");
+		printf("\", domainname=\"");
+		print_quoted_string(uname->domainname);
 # endif
-
-print_and_exit:
+		printf("\"");
+	}
 	printf("}) = %d\n", rc);
+
 	puts("+++ exited with 0 +++");
 	return 0;
 }
--- a/tests/uname.test
+++ b/tests/uname.test
@@ -13,7 +13,7 @@ run_prog > /dev/null
 run_strace -v -euname $args > "$EXP"
 uniq < "$LOG" > "$OUT"
 
-run_prog "./${ME_%.test}" -a > /dev/null
+run_prog "./${ME_%.test}" abbrev > /dev/null
 run_strace -euname $args >> "$EXP"
 uniq < "$LOG" >> "$OUT"


-- 
ldv
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.strace.io/pipermail/strace-devel/attachments/20160329/82046995/attachment.bin>


More information about the Strace-devel mailing list