1
/* $Id: pipe.c 61 2006-05-19 18:32:14Z steve-beattie $ */
4
* Copyright (C) 2002-2005 Novell/SUSE
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License as
8
* published by the Free Software Foundation, version 2 of the
15
#include <sys/types.h>
19
#include <linux/unistd.h>
22
#include "changehat.h"
24
const char *data="hello world";
32
fprintf(stderr, "FAIL: read failed - no descriptor passed\n");
36
rc=read(fd, buf, sizeof(buf));
38
if (rc != strlen(data)){
39
fprintf(stderr, "FAIL: read failed - %s\n",
44
if (memcmp(buf, data, strlen(data)) != 0){
45
fprintf(stderr, "FAIL: comparison failed - %s\n",
59
rc=write(fd, data, strlen(data));
61
if (rc != strlen(data)){
62
fprintf(stderr, "FAIL: write failed - %s\n",
72
int main(int argc, char *argv[])
81
fprintf(stderr, "usage: %s hatname\n",
86
/* change hat if hatname != nochange */
87
if (strcmp(argv[1], "nochange") != 0){
88
rc = change_hat(argv[1], SD_ID_MAGIC+1);
90
fprintf(stderr, "FAIL: changehat %s failed - %s\n",
91
argv[1], strerror(errno));
96
if (pipe(filedes) == -1){
97
fprintf(stderr, "FAIL: pipe() failed - %s\n",
104
fprintf(stderr, "FAIL: fork failed - %s\n",
107
} else if (pid != 0) {
109
read_error = do_read(filedes[0]);
110
rc = wait(&waitstatus);
112
fprintf(stderr, "FAIL: wait failed - %s\n",
118
exit(do_write(filedes[1]));
121
if ((WIFEXITED(waitstatus) != 0) && (WEXITSTATUS(waitstatus) == 0)
122
&& read_error == 0) {
125
return (WEXITSTATUS(waitstatus) & read_error);