-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmake_door.c
114 lines (98 loc) · 2.55 KB
/
make_door.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*
tdiff - tree diffs
make_door
Copyright (C) 2019, 2024 Philippe Troin <[email protected]>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#if 1
#include <door.h>
#else
typedef struct door_desc door_desc_t;
void door_return(void*, int, void*, int);
int door_create(void*, int, int);
int door_revoke(int);
int fattach(int, const char*);
#endif
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#define UNUSED(x) ((void)(x))
static int
max(int a, int b)
{
if (a >= b) {
return a;
} else {
return b;
}
}
static void
door_proc(void* cookie,
char* argp,
size_t arg_size,
door_desc_t *dp,
unsigned flags)
{
UNUSED(cookie);
UNUSED(argp);
UNUSED(arg_size);
UNUSED(dp);
UNUSED(flags);
door_return(NULL, 0, NULL, 0);
}
int
main(int argc, char* argv[])
{
int i;
int exitcode = 0;
for (i=1; i < argc; ++i) {
int fd_door, fd_file;
fd_door = door_create(&door_proc, 0, 0);
if (fd_door < 0) {
fprintf(stderr, "%s: door_create(): %s\n",
argv[0], strerror(errno));
exitcode = max(exitcode, 2);
continue;
}
fd_file = open(argv[i], O_CREAT|O_EXCL|O_WRONLY, 0666);
if (fd_file < 0) {
fprintf(stderr, "%s: open(%s): %s\n",
argv[0], argv[i], strerror(errno));
exitcode = max(exitcode, 1);
continue;
}
if (close(fd_file) != 0) {
fprintf(stderr, "%s: close(%s): %s\n",
argv[0], argv[i], strerror(errno));
exitcode = max(exitcode, 2);
continue;
}
if (fattach(fd_door, argv[i]) != 0) {
fprintf(stderr, "%s: fattach(%s): %s\n",
argv[0], argv[i], strerror(errno));
exitcode = max(exitcode, 2);
continue;
}
if (door_revoke(fd_door) != 0) {
fprintf(stderr, "%s: door_revoke(%s): %s\n",
argv[0], argv[i], strerror(errno));
exitcode = max(exitcode, 2);
continue;
}
}
exit(exitcode);
}