From: Dmitry V. Levin Date: Wed, 6 Jan 2016 11:55:13 +0000 (+0000) Subject: tests/ipc_msgbuf.c: use libtests X-Git-Tag: v4.12~692 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4e4958e0f967a36247c5f31ac8b5d2129713617b;p=strace tests/ipc_msgbuf.c: use libtests * tests/ipc_msgbuf.c (cleanup): New function. (main): Use it and perror_msg_and_skip. --- diff --git a/tests/ipc_msgbuf.c b/tests/ipc_msgbuf.c index 1cb42fde..2c90d268 100644 --- a/tests/ipc_msgbuf.c +++ b/tests/ipc_msgbuf.c @@ -1,5 +1,6 @@ /* * Copyright (c) 2015 Elvira Khabirova + * Copyright (c) 2015-2016 Dmitry V. Levin * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -26,15 +27,24 @@ */ #include "tests.h" +#include #include #include #include - #include "kernel_types.h" #define text_string "STRACE_STRING" #define msgsz sizeof(text_string) +static int msqid = -1; + +static void +cleanup(void) +{ + msgctl(msqid, IPC_RMID, 0); + msqid = -1; +} + int main (void) { @@ -46,18 +56,13 @@ main (void) .mtype = mtype, .mtext = text_string }; - int msqid = msgget(IPC_PRIVATE, IPC_CREAT | S_IRWXU); + msqid = msgget(IPC_PRIVATE, IPC_CREAT | S_IRWXU); if (msqid == -1) - return 77; + perror_msg_and_skip("msgget"); + atexit(cleanup); if (msgsnd(msqid, &msg, msgsz, 0) == -1) - goto cleanup; + perror_msg_and_skip("msgsnd"); if (msgrcv(msqid, &msg, msgsz, mtype, 0) != msgsz) - goto cleanup; - if (msgctl(msqid, IPC_RMID, 0) == -1) - return 77; + perror_msg_and_skip("msgrcv"); return 0; - -cleanup: - msgctl(msqid, IPC_RMID, 0); - return 77; }