3 * Copyright (c) International Business Machines Corp., 2001
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
13 * the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 * file containing generic routines which are used by some of the LTP
26 * testsuite tests. Currently, the following routines are present in
29 * my_getpwnam(), do_file_setup()
32 * 11/03/2008 Renaud Lottiaux (Renaud.Lottiaux@kerlabs.com)
33 * - Add the following functions to synchronise father and sons processes
34 * sync_pipe_create(), sync_pipe_wait(), sync_pipe_notify()
42 #include "libtestsuite.h"
47 my_getpwnam(char *name
)
49 struct passwd
*saved_pwent
;
52 if ((pwent
= getpwnam(name
)) == NULL
) {
54 tst_brkm(TBROK
, NULL
, "getpwnam() failed");
56 saved_pwent
= (struct passwd
*)malloc(sizeof(struct passwd
));
58 *saved_pwent
= *pwent
;
64 do_file_setup(char *fname
)
68 if ((fd
= open(fname
,O_RDWR
|O_CREAT
,0700)) == -1) {
69 tst_resm(TBROK
, "open(%s, O_RDWR|O_CREAT,0700) Failed, "
70 "errno=%d : %s", fname
, errno
, strerror(errno
));
73 if (close(fd
) == -1) {
74 tst_resm(TWARN
, "close(%s) Failed on file create, errno=%d : "
75 "%s", fname
, errno
, strerror(errno
));
79 static char pipe_name
[256];
81 void generate_pipe_name(const char *name
)
85 p
= strrchr(name
, '/');
90 snprintf(pipe_name
, 255, "%s/ltp_fifo_%s", P_tmpdir
, p
);
93 int sync_pipe_create(int fd
[], const char *name
)
98 generate_pipe_name(name
);
100 ret
= open(pipe_name
, O_RDWR
);
103 fd
[1] = open(pipe_name
, O_RDWR
);
105 ret
= mkfifo(pipe_name
, S_IRWXU
);
107 fd
[0] = open(pipe_name
, O_RDWR
);
108 fd
[1] = open(pipe_name
, O_RDWR
);
116 int sync_pipe_close(int fd
[], const char *name
)
126 generate_pipe_name(name
);
132 int sync_pipe_wait(int fd
[])
142 r
= read (fd
[0], &buf
, 1);
144 if ((r
!= 1) || (buf
!= 'A'))
149 int sync_pipe_notify(int fd
[])
159 r
= write (fd
[1], &buf
, 1);