]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/binfmt/binfmt.c
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright 2010 Lennart Poettering
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
35 static int delete_rule(const char *rule
) {
36 char *x
, *fn
= NULL
, *e
;
41 if (!(x
= strdup(rule
)))
44 e
= strchrnul(x
+1, x
[0]);
47 asprintf(&fn
, "/proc/sys/fs/binfmt_misc/%s", x
+1);
53 r
= write_one_line_file(fn
, "-1");
59 static int apply_rule(const char *rule
) {
64 if ((r
= write_one_line_file("/proc/sys/fs/binfmt_misc/register", rule
)) < 0) {
65 log_error("Failed to add binary format: %s", strerror(-r
));
72 static int apply_file(const char *path
, bool ignore_enoent
) {
78 if (!(f
= fopen(path
, "re"))) {
79 if (ignore_enoent
&& errno
== ENOENT
)
82 log_error("Failed to open file '%s', ignoring: %m", path
);
86 log_debug("apply: %s\n", path
);
91 if (!fgets(l
, sizeof(l
), f
)) {
95 log_error("Failed to read file '%s', ignoring: %m", path
);
105 if (strchr(COMMENTS
, *p
))
108 if ((k
= apply_rule(p
)) < 0 && r
== 0)
118 int main(int argc
, char *argv
[]) {
121 log_set_target(LOG_TARGET_AUTO
);
122 log_parse_environment();
130 for (i
= 1; i
< argc
; i
++) {
133 k
= apply_file(argv
[i
], false);
140 r
= conf_files_list(&files
, ".conf",
143 "/usr/local/lib/binfmt.d",
145 #ifdef HAVE_SPLIT_USR
150 log_error("Failed to enumerate binfmt.d files: %s", strerror(-r
));
154 /* Flush out all rules */
155 write_one_line_file("/proc/sys/fs/binfmt_misc/status", "-1");
157 STRV_FOREACH(f
, files
) {
160 k
= apply_file(*f
, true);
168 return r
< 0 ? EXIT_FAILURE
: EXIT_SUCCESS
;