1
/* $Id: changehat_fork.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>
21
#include <linux/unistd.h>
23
#include "changehat.h"
25
int main(int argc, char *argv[])
33
fprintf(stderr, "usage: %s profile file\n",
38
/* change hat if hatname != nochange */
39
if (strcmp(argv[1], "nochange") != 0){
40
rc = change_hat(argv[1], SD_ID_MAGIC+1);
41
/* we want to test what happens when change_hat fails,
42
* changehat.c tests will fail if you can't change_hat
45
/* changehat failed, we are likely in a null
46
* profile at this point
54
fprintf(stderr, "FAIL: fork failed - %s\n",
57
} else if (pid != 0) {
59
rc = wait(&waitstatus);
61
fprintf(stderr, "FAIL: wait failed - %s\n",
67
exit(do_open(argv[2]));
70
/* If in a null profile, change hat back to parent */
71
if (strcmp(argv[1], "nochange") != 0 && innullprofile){
72
rc = change_hat(NULL, SD_ID_MAGIC+1);
75
if ((WIFEXITED(waitstatus) != 0) && (WEXITSTATUS(waitstatus) == 0)) {
78
/* if in null profile, FAIL output from do_open will
79
* have been suppressed, so output a FAIL here now
80
* that we have changehatted back to parent
83
printf("FAIL %d\n", WEXITSTATUS(waitstatus));